|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - downloadIndex: ┃ T t ┃
Length: 3931 (0xf5b) Types: TextFile Names: »tgoto.c«
└─⟦87ddcff64⟧ Bits:30001253 CPHDIST85 Tape, 1985 Autumn Conference Copenhagen └─ ⟦this⟧ »cph85dist/search/tgoto.c«
#ifndef lint static char rcsid[] = "$Header: tgoto.c,v 2.1 85/04/10 17:32:07 matt Stab $"; #endif /* * * search * * multi-player and multi-system search and destroy. * * Original by Greg Ordy 1979 * Rewrite by Sam Leffler 1981 * Socket code by Dave Pare 1983 * Ported & improved * by Matt Crawford 1985 * * routine to perform cursor addressing. * * Copyright (c) 1979 * */ #define CTRL(c) ('c' & 037) #include "defines.h" #include "structs.h" /* * CM is a string containing printf type escapes to allow * cursor addressing. We start out ready to print the destination * line, and switch each time we print row or column. * The following escapes are defined for substituting row/column: * * %d as in printf * %2 like %2d * %3 like %3d * %. gives %c hacking special case characters * %+x like %c but adding x first * * The codes below affect the state but don't use up a value. * * %>xy if value > x add y * %r reverses row/column * %i increments row/column (for one origin indexing) * %% gives % * %B BCD (2 decimal digits encoded in one byte) * %D Delta Data (backwards bcd) * * all other characters are ``self-inserting''. */ char *tgoto(p, destcol, destline) register t_player *p; int destcol, destline; { extern char *strcat(), *strcpy(); static char result[16]; static char added[10]; register char *dp = result; register int c; register int which = destline; char *cp = p->CM; int oncol = 0; if (cp == 0) { toohard: /* * "We don't do that under BOZO's big top" */ return ("OOPS"); } added[0] = 0; while (c = *cp++) { if (c != '%') { *dp++ = c; continue; } switch (c = *cp++) { #ifdef CM_N case 'n': destcol ^= 0140; destline ^= 0140; goto setwhich; #endif case 'd': if (which < 10) goto one; if (which < 100) goto two; /* fall into... */ case '3': *dp++ = (which / 100) | '0'; which %= 100; /* fall into... */ case '2': two: *dp++ = which / 10 | '0'; one: *dp++ = which % 10 | '0'; swap: oncol = 1 - oncol; setwhich: which = oncol ? destcol : destline; continue; #ifdef CM_GT case '>': if (which > *cp++) which += *cp++; else cp++; continue; #endif case '+': which += *cp++; /* fall into... */ case '.': /* * This code is worth scratching your head at for a * while. The idea is that various weird things can * happen to nulls, EOT's, tabs, and newlines by the * tty driver, arpanet, and so on, so we don't send * them if we can help it. * * Tab is taken out to get Ann Arbors to work, otherwise * when they go to column 9 we increment which is wrong * because bcd isn't continuous. We should take out * the rest too, or run the thing through more than * once until it doesn't make any of these, but that * would make termlib (and hence pdp-11 ex) bigger, * and also somewhat slower. This requires all * programs which use termlib to stty tabs so they * don't get expanded. They should do this anyway * because some terminals use ^I for other things, * like nondestructive space. */ if (which == 0 || which == CTRL(d) || which == '\t' || which == '\n') { if (oncol || p->UP) /* Assumption: backspace works */ /* * Loop needed because newline happens * to be the successor of tab. */ do { (void)strcat(added, oncol ? (p->BC ? p->BC : "\b") : p->UP); which++; } while (which == '\n'); } *dp++ = which; goto swap; case 'r': oncol = 1; goto setwhich; case 'i': destcol++; destline++; which++; continue; case '%': *dp++ = c; continue; #ifdef CM_B case 'B': which = (which/10 << 4) + which%10; continue; #endif #ifdef CM_D case 'D': which = which - 2 * (which%16); continue; #endif default: goto toohard; } } (void)strcpy(dp, added); return (result); }