|
|
1.1 ! root 1: /* ! 2: This is version 4. The input language is: ! 3: ! 4: Cmd Abbrev Operands / Comments ! 5: comment # only at start of line ! 6: blank b s <vnum> start blanking; erase commands follow ! 7: e <vnum> end blanking current view ! 8: click c <clicknum> ! 9: define d v <number> <viewname> xmin ymin xmax ymax ! 10: c <number> <clickname> ! 11: p e pragma -- end of defs at front of file ! 12: Other possible ``pragmas'': ??? ! 13: Number of views, clicks ! 14: Number of (lines, bytes) in file ! 15: erase e <line repeated here, except for leading g> ! 16: Object is deletable ! 17: geom g <slotn> l <vnum> <opts> <x1> <y1> <x2> <y2> line ! 18: b <vnum> <opts> <x1> <y1> <x2> <y2> box ! 19: c <vnum> <opts> <x> <y> <rad> circle ! 20: t <vnum> <opts> <x> <y> <text string> text ! 21: one separating blank; string unquoted ! 22: <opts> format: string of characters, in order ! 23: <slotn> == 0 => line never erased ! 24: ! 25: At beginning of file: ! 26: d v <number> <view name> ! 27: d c <number> <click name> ! 28: d p <various pragmas here> ! 29: d p e ! 30: ! 31: */ ! 32: ! 33: #include <stdio.h> ! 34: #include "anim.h" ! 35: ! 36: #define sendpoint(p) { sendint(p.x); sendint(p.y); } ! 37: #define sendpair(x,y) { sendint(x); sendint(y); } ! 38: #define eq(s, t) (strcmp(s,t) == 0) ! 39: #define FATAL 1 ! 40: ! 41: char *cmdname; ! 42: char *emalloc(); ! 43: ! 44: #ifdef BLIT ! 45: long memsize = 65000; /* memory allocation */ ! 46: #endif ! 47: #ifdef X11 ! 48: long memsize = 200000; /* X11 memory allocation */ ! 49: #endif ! 50: ! 51: int dbg = 0; ! 52: int lineno = 1; /* ? */ ! 53: ! 54: char *zload = ""; /* will be -z for load and hang on blit */ ! 55: char *termld = TERMLD; /* will be "32ld" or "dmdld" */ ! 56: int nterm = 0; /* number of bytes needed in terminal */ ! 57: ! 58: main(argc, argv) ! 59: char *argv[]; ! 60: { ! 61: FILE *fp; ! 62: char *term_process = ANIMTERM; /* typically "./animterm" */ ! 63: char buf[100]; ! 64: int i, c, bootstat; ! 65: ! 66: cmdname = argv[0]; ! 67: while (argc > 1 && argv[1][0] == '-') { ! 68: switch (argv[1][1]) { ! 69: case 'd': ! 70: dbg = !dbg; ! 71: break; ! 72: case 'z': ! 73: zload = "-z"; ! 74: break; ! 75: case 't': ! 76: term_process = argv[2]; ! 77: argc--; ! 78: argv++; ! 79: break; ! 80: case 'm': ! 81: memsize = atoi(&argv[1][2]); ! 82: if (memsize <= 0) { ! 83: memsize = atoi(argv[2]); ! 84: if (memsize <= 0) ! 85: error(FATAL, "memory size must be positive. use -mN"); ! 86: argc--; ! 87: argv++; ! 88: } ! 89: break; ! 90: } ! 91: argc--; ! 92: argv++; ! 93: } ! 94: if (argc <= 1) ! 95: error(FATAL, "no input file"); ! 96: if ((fp = fopen(argv[1], "r")) == NULL) ! 97: error(FATAL, "can't open %s\n", argv[1]); ! 98: if (!dbg) { ! 99: bootstat = bootterm(term_process); ! 100: set_tty(); ! 101: } ! 102: if (bootstat || dbg) ! 103: send_data(fp); ! 104: if (dbg) { ! 105: printf("\nterminal bytes needed: %d\n", nterm); ! 106: exit(0); ! 107: } ! 108: while ((c = readchar()) != P_QUIT) { ! 109: if (c == P_FILE) { /* rest of line is a filename */ ! 110: readstring(buf); ! 111: if ((fp = fopen(buf, "r")) == NULL) ! 112: send1char(P_ERROR); ! 113: else { ! 114: send1char(P_FILE); /* ack */ ! 115: send_data(fp); ! 116: } ! 117: } else ! 118: send1char(P_ERROR); ! 119: } ! 120: reset_tty(); ! 121: } ! 122: ! 123: send_data(fp) ! 124: FILE *fp; ! 125: { ! 126: char text[100], buf[100], opts[100], *p; ! 127: int c, x1, y1, x2, y2, i, v, slot; ! 128: int ntext; ! 129: ! 130: sendint(memsize); ! 131: send1char(P_INIT); ! 132: send1char(P_PRINT); ! 133: sendstring("here comes the data!"); ! 134: while ((c = getc(fp)) != EOF) { ! 135: switch (c) { ! 136: case ' ': ! 137: case '\t': ! 138: break; ! 139: case '\n': ! 140: lineno++; /* this should be the only increment */ ! 141: break; ! 142: case '#': /* comments */ ! 143: skipline(fp); ! 144: break; ! 145: case 'b': /* blank. ignore for now */ ! 146: skipline(fp); ! 147: break; ! 148: case 'c': /* click */ ! 149: if (fscanf(fp, "%d", &i) != 1) ! 150: return badfile(fp); ! 151: send1char(P_OBJECT); ! 152: send1char(c); ! 153: sendint(i); ! 154: skipline(fp); ! 155: nterm += 3; ! 156: break; ! 157: case 'e': /* erase */ ! 158: if (fscanf(fp, "%d", &i) != 1) ! 159: return badfile(fp); ! 160: send1char(P_OBJECT); ! 161: send1char(c); ! 162: sendint(i); ! 163: skipline(fp); ! 164: nterm += 6; ! 165: break; ! 166: case 'g': /* geom: draw line, box, circle, ... */ ! 167: if (fscanf(fp, "%d", &slot) != 1) ! 168: return badfile(fp); ! 169: switch (c = skipbl(fp)) { ! 170: case 'l': ! 171: case 'b': ! 172: if (fscanf(fp, "%d %s %d %d %d %d", &v, opts, &x1, &y1, &x2, &y2) != 6) ! 173: return badfile(fp); ! 174: send1char(P_OBJECT); ! 175: send1char(c); ! 176: sendint(slot); ! 177: sendint(v); ! 178: sendopt(c=='b' ? boxops : lineops, opts); ! 179: sendpair(x1, y1); ! 180: sendpair(x2, y2); ! 181: nterm += 12; ! 182: break; ! 183: case 'c': /* circle */ ! 184: if (fscanf(fp, "%d %s %d %d %d", &v, opts, &x1, &y1, &x2) != 5) ! 185: return badfile(fp);; ! 186: send1char(P_OBJECT); ! 187: send1char('o'); /* 'o' is for circle */ ! 188: sendint(slot); ! 189: sendint(v); ! 190: sendopt(circops, opts); ! 191: sendpair(x1, y1); ! 192: sendint(x2); ! 193: nterm += 10; ! 194: break; ! 195: case 't': /* text */ ! 196: if (fscanf(fp, "%d %s %d %d", &v, opts, &x1, &y1) != 4) ! 197: return badfile(fp); ! 198: send1char(P_OBJECT); ! 199: send1char('t'); ! 200: sendint(slot); ! 201: sendint(v); ! 202: sendopt(textops, opts); ! 203: sendpair(x1, y1); ! 204: getc(fp); /* skip 1 separator; no quotes */ ! 205: for (p = text; (c = getc(fp)) != '\n'; ) ! 206: *p++ = c; ! 207: *p = 0; ! 208: ungetc('\n', fp); ! 209: ntext = 1; ! 210: /* slow... */ ! 211: if (eq(text, "bullet")) ! 212: sendstring("*"); ! 213: else if (eq(text, "dot")) ! 214: sendstring("."); ! 215: else if (eq(text, "circle")) ! 216: sendstring("o"); ! 217: else if (eq(text, "times")) ! 218: sendstring("x"); ! 219: else { ! 220: sendstring(text); ! 221: ntext = strlen(text); ! 222: } ! 223: nterm += 10 + ntext; ! 224: break; ! 225: default: ! 226: return badfile(fp); ! 227: } ! 228: break; ! 229: case 'd': /* definition of some sort */ ! 230: switch (c = skipbl(fp)) { ! 231: case 'v': /* view */ ! 232: if (fscanf(fp, "%d %s", &i, text) != 2) ! 233: return badfile(fp); ! 234: send1char(P_DEFINE); ! 235: send1char('v'); ! 236: sendint(i); ! 237: sendstring(text); ! 238: skipline(fp); /* might be a title there */ ! 239: break; ! 240: case 'c': /* click */ ! 241: if (fscanf(fp, "%d %s", &i, text) != 2) ! 242: return badfile(fp); ! 243: send1char(P_DEFINE); ! 244: send1char('c'); ! 245: sendint(i); ! 246: sendstring(text); ! 247: break; ! 248: case 'p': ! 249: skipline(fp); ! 250: break; ! 251: default: ! 252: return badfile(fp); ! 253: } ! 254: break; ! 255: default: ! 256: return badfile(fp); ! 257: } ! 258: } ! 259: send1char(P_ENDFILE); ! 260: fclose(fp); ! 261: flushproto(); ! 262: return 1; ! 263: } ! 264: ! 265: badfile(fp) ! 266: FILE *fp; ! 267: { ! 268: send1char(P_ERRPRINT); ! 269: sendstring("file is not in .i format"); ! 270: send1char(P_ENDFILE); ! 271: while (getc(fp) != EOF) ! 272: ; ! 273: fclose(fp); ! 274: flushproto(); ! 275: return 0; ! 276: } ! 277: ! 278: sendopt(optvals, opts) ! 279: int optvals[]; ! 280: char *opts; ! 281: { ! 282: int i, n; ! 283: ! 284: n = 0; ! 285: for (i = 0; optvals[i] && opts; i += 2) ! 286: if (*opts == optvals[i]) { ! 287: n += optvals[i+1]; ! 288: opts++; ! 289: } ! 290: sendint(n); ! 291: } ! 292: ! 293: skipbl(fp) ! 294: FILE *fp; ! 295: { ! 296: int c; ! 297: ! 298: while ((c = getc(fp)) == ' ' || c == '\t') ! 299: ; ! 300: return c; ! 301: } ! 302: ! 303: skipline(fp) ! 304: FILE *fp; ! 305: { ! 306: int c; ! 307: ! 308: while ((c = getc(fp)) != '\n') ! 309: ; ! 310: ungetc('\n', fp); ! 311: } ! 312: ! 313: error(f, s, a1, a2, a3, a4, a5, a6, a7) ! 314: { ! 315: extern char *cmdname; ! 316: extern int dbg; ! 317: ! 318: fprintf(stderr, "%s: ", cmdname); ! 319: fprintf(stderr, s, a1, a2, a3, a4, a5, a6, a7); ! 320: fprintf(stderr, "\n"); ! 321: if (lineno) ! 322: fprintf(stderr, " source line number %d\n", lineno); ! 323: if (f) { ! 324: if (dbg) ! 325: abort(); ! 326: exit(2); ! 327: } ! 328: } ! 329: ! 330: #ifndef X11 ! 331: ! 332: bootterm(procname) ! 333: char *procname; ! 334: { ! 335: char buf[100]; ! 336: ! 337: sprintf(buf, "%s %s %s </dev/tty", termld, zload, procname); ! 338: if (system(buf) != 0) { ! 339: fprintf(stderr, ! 340: "anim: can't create pipe to terminal process\n"); ! 341: return 0; ! 342: } ! 343: return 1; ! 344: } ! 345: ! 346: #endif ! 347: ! 348: #ifdef X11 ! 349: ! 350: bootterm(procname) ! 351: char *procname; ! 352: { ! 353: int afildes[2], bfildes[2], pid; ! 354: if((pipe(afildes)==-1)||(pipe(bfildes)==-1)){ ! 355: fprintf(stderr, ! 356: "anim: can't create pipe to terminal process\n"); ! 357: return 0; ! 358: } ! 359: if((pid=fork())==0){ ! 360: close(0); ! 361: dup(afildes[0]); ! 362: close(1); ! 363: dup(bfildes[1]); ! 364: execl(procname, "animterm", 0); ! 365: exit(127); ! 366: } ! 367: if(pid==-1){ ! 368: fprintf(stderr,"anim: can't fork %s\n", procname); ! 369: return 0; ! 370: } ! 371: close(0); ! 372: dup(bfildes[0]); ! 373: close(1); ! 374: dup(afildes[1]); ! 375: return 1; ! 376: } ! 377: ! 378: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.