|
|
1.1 ! root 1: ! 2: #include <stdio.h> ! 3: #include <string.h> ! 4: #include <signal.h> ! 5: #include <ctype.h> ! 6: #include <fcntl.h> ! 7: ! 8: #include "comments.h" ! 9: #include "gen.h" ! 10: #include "path.h" ! 11: #include "ext.h" ! 12: ! 13: #define dbprt if (debug) fprintf ! 14: ! 15: char *optnames = "a:c:fglm:n:o:p:x:y:C:E:DG:IL:P:"; ! 16: char *prologue = POSTGIF; /* default PostScript prologue */ ! 17: char *formfile = FORMFILE; /* stuff for multiple pages per sheet */ ! 18: int formsperpage = 1; /* page images on each piece of paper */ ! 19: int copies = 1; /* and this many copies of each sheet */ ! 20: int page = 0; /* last page we worked on */ ! 21: int printed = 0; /* and the number of pages printed */ ! 22: ! 23: extern char *malloc(); ! 24: extern void free(); ! 25: extern double atof(), pow(); ! 26: ! 27: unsigned char ibuf[BUFSIZ]; ! 28: unsigned char *cmap, *gcmap, *lcmap; ! 29: unsigned char *gmap, *ggmap, *lgmap; ! 30: unsigned char *pmap; ! 31: double gamma; ! 32: float cr = 0.3, cg = 0.59, cb = 0.11; ! 33: int maplength, gmaplength, lmaplength; ! 34: int scrwidth, scrheight; ! 35: int gcolormap, lcolormap; ! 36: int bitperpixel, background; ! 37: int imageleft, imagetop; ! 38: int imagewidth, imageheight; ! 39: int interlaced, lbitperpixel; ! 40: int gray = 0; ! 41: int gammaflag = 0; ! 42: int negative = 0; ! 43: int terminate = 0; ! 44: int codesize, clearcode, endcode, curstblsize, pmindex, byteinibuf, bitsleft; ! 45: int prefix[4096], suffix[4096], cstbl[4096]; ! 46: int bburx = -32767, bbury = -32767; ! 47: FILE *fp_in = NULL; ! 48: FILE *fp_out = stdout; ! 49: ! 50: char * ! 51: allocate(size) ! 52: int size; ! 53: { ! 54: char *p; ! 55: ! 56: if ((p = malloc(size)) == NULL) error(FATAL, "not enough memory"); ! 57: return(p); ! 58: } ! 59: ! 60: void ! 61: puthex(c, fp) ! 62: unsigned char c; ! 63: FILE *fp; ! 64: { ! 65: static char hextbl[16] = { ! 66: '0', '1', '2', '3', '4', '5', '6', '7', ! 67: '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', ! 68: }; ! 69: ! 70: putc(hextbl[(c >> 4) & 017], fp); ! 71: putc(hextbl[c & 017], fp); ! 72: } ! 73: ! 74: void ! 75: setcolormap(bp) ! 76: int bp; ! 77: { ! 78: int i, entries = 1, scale = 1; ! 79: unsigned char *p, *q; ! 80: ! 81: for (i = 0; i < bp; i++) entries *= 2; ! 82: for (i = 0; i < 8 - bp; i++) scale *= 2; ! 83: gcmap = (unsigned char *) allocate(entries*3); ! 84: ggmap = (unsigned char *) allocate(entries); ! 85: gmaplength = entries; ! 86: for (i = 0, p = gcmap, q = ggmap; i < 256; i += scale, p += 3, q++) { ! 87: if (negative) { ! 88: *p = 255 - i; p[1] = *p; p[2] = *p; ! 89: *q = *p; ! 90: } ! 91: else { ! 92: *p = i; p[1] = i; p[2] = i; ! 93: *q = i; ! 94: } ! 95: } ! 96: if (gammaflag) ! 97: for (i = 0, p = gcmap; i < 256; i += scale, p += 3) { ! 98: *p = (unsigned char) (pow((double) *p/256.0, gamma)*256); ! 99: p[1] = *p; p[2] = *p; ! 100: } ! 101: dbprt(stderr,"default color map:\n"); ! 102: for (i = 0; i < entries*3; i += 3) ! 103: dbprt(stderr, "%d, %d, %d\n", gcmap[i], gcmap[i+1], gcmap[i+2]); ! 104: } ! 105: ! 106: void ! 107: readgcolormap(bp) ! 108: int bp; ! 109: { ! 110: int i, entries = 1; ! 111: unsigned char *p, *q; ! 112: ! 113: for (i = 0; i < bp; i++) entries *= 2; ! 114: gcmap = (unsigned char *) allocate(entries*3); ! 115: ggmap = (unsigned char *) allocate(entries); ! 116: gmaplength = entries; ! 117: fread(gcmap, sizeof(*gcmap), entries*3, fp_in); ! 118: if (negative) ! 119: for (i = 0, p = gcmap; i < entries*3; i++, p++) *p = 255 - *p; ! 120: for (i = 0, p = gcmap, q = ggmap; i < entries; i++, p += 3, q++) ! 121: *q = cr*(int)p[0] + cg*(int)p[1] + cb*(int)p[2] + 0.5; ! 122: if (gammaflag) ! 123: for (i = 0, p = gcmap; i < entries*3; i++, p++) ! 124: *p = (unsigned char) (pow((double) *p/256.0, gamma)*256); ! 125: dbprt(stderr,"global color map:\n"); ! 126: for (i = 0; i < entries*3; i += 3) ! 127: dbprt(stderr, "%d, %d, %d\n", gcmap[i], gcmap[i+1], gcmap[i+2]); ! 128: } ! 129: ! 130: void ! 131: readlcolormap(bp) ! 132: int bp; ! 133: { ! 134: int i, entries = 1; ! 135: unsigned char *p, *q; ! 136: ! 137: for (i = 0; i < bp; i++) entries *= 2; ! 138: lcmap = (unsigned char *) allocate(entries*3); ! 139: lgmap = (unsigned char *) allocate(entries); ! 140: lmaplength = entries; ! 141: fread(lcmap, sizeof(*lcmap), entries*3, fp_in); ! 142: if (negative) ! 143: for (i = 0, p = lcmap; i < entries*3; i++, p++) *p = 255 - *p; ! 144: for (i = 0, p = lcmap, q = lgmap; i < entries; i++, p += 3, q++) ! 145: *q = cr*(int)p[0] + cg*(int)p[1] + cb*(int)p[2] + 0.5; ! 146: if (gammaflag) ! 147: for (i = 0, p = lcmap; i < entries*3; i++, p++) ! 148: *p = (unsigned char) (pow((double) *p/256.0, gamma)*256); ! 149: dbprt(stderr,"local color map:\n"); ! 150: for (i = 0; i < entries*3; i += 3) ! 151: dbprt(stderr, "%d, %d, %d\n", lcmap[i], lcmap[i+1], lcmap[i+2]); ! 152: } ! 153: ! 154: void ! 155: initstbl() ! 156: { ! 157: int i, entries = 1, *p, *s; ! 158: ! 159: for (i = 0; i < codesize; i++) entries *= 2; ! 160: clearcode = entries; ! 161: endcode = clearcode + 1; ! 162: for (i = 0, p = prefix, s = suffix; i <= endcode; i++, p++, s++) { ! 163: *p = endcode; ! 164: *s = i; ! 165: } ! 166: curstblsize = endcode + 1; ! 167: pmindex = 0; ! 168: byteinibuf = 0; ! 169: bitsleft = 0; ! 170: } ! 171: ! 172: int ! 173: nextbyte() ! 174: { ! 175: static ibufindex; ! 176: ! 177: if (byteinibuf) { ! 178: byteinibuf--; ! 179: ibufindex++; ! 180: } ! 181: else { ! 182: fread(ibuf, sizeof(*ibuf), 1, fp_in); ! 183: byteinibuf = ibuf[0]; ! 184: dbprt(stderr, "byte count: %d\n", byteinibuf); ! 185: if (byteinibuf) fread(ibuf, sizeof(*ibuf), byteinibuf, fp_in); ! 186: else error(FATAL, "encounter zero byte count block before end code"); ! 187: ibufindex = 0; ! 188: byteinibuf--; ! 189: ibufindex++; ! 190: } ! 191: return(ibuf[ibufindex-1]); ! 192: } ! 193: ! 194: int masktbl[25] = { ! 195: 0, 01, 03, 07, 017, 037, 077, 0177, 0377, 0777, 01777, 03777, 07777, ! 196: 017777, 037777, 077777, 0177777, 0377777, 0777777, 01777777, 03777777, ! 197: 07777777, 017777777, 037777777, 077777777 ! 198: }; ! 199: ! 200: int ! 201: getcode() ! 202: { ! 203: int cs, c; ! 204: static int oldc; ! 205: ! 206: if (curstblsize < 4096) cs = cstbl[curstblsize]; ! 207: else cs = 12; ! 208: while (bitsleft < cs) { ! 209: oldc = (oldc & masktbl[bitsleft]) | ((nextbyte() & 0377) << bitsleft); ! 210: bitsleft += 8; ! 211: } ! 212: c = oldc & masktbl[cs]; ! 213: oldc = oldc >> cs; ! 214: bitsleft -= cs; ! 215: /* dbprt(stderr, "code: %d %d %d\n", curstblsize, cs, c); */ ! 216: return(c); ! 217: } ! 218: ! 219: void ! 220: putcode(c) ! 221: int c; ! 222: { ! 223: if (prefix[c] != endcode) { ! 224: putcode(prefix[c]); ! 225: pmap[pmindex] = suffix[c]; ! 226: pmindex++; ! 227: } ! 228: else { ! 229: pmap[pmindex] = suffix[c]; ! 230: pmindex++; ! 231: } ! 232: } ! 233: ! 234: int ! 235: firstof(c) ! 236: int c; ! 237: { ! 238: while (prefix[c] != endcode) c = prefix[c]; ! 239: return(suffix[c]); ! 240: } ! 241: ! 242: void ! 243: writeimage() ! 244: { ! 245: int i, j, k; ! 246: ! 247: dbprt(stderr, "pmindex: %d\n", pmindex); ! 248: fputs("save\n", fp_out); ! 249: fprintf(fp_out, "/codestr %d string def\n", imagewidth); ! 250: if (!gray) { ! 251: fprintf(fp_out, "/colortbl currentfile %d string readhexstring\n", ! 252: maplength*3); ! 253: for (i = 0; i < maplength; i++) puthex(cmap[i], fp_out); ! 254: fputs("\n", fp_out); ! 255: for (i = maplength ; i < maplength*2; i++) puthex(cmap[i], fp_out); ! 256: fputs("\n", fp_out); ! 257: for (i = maplength*2 ; i < maplength*3; i++) puthex(cmap[i], fp_out); ! 258: fputs("\npop def\n", fp_out); ! 259: fprintf(fp_out, "/graytbl currentfile %d string readhexstring\n", ! 260: maplength); ! 261: for (i = 0; i < maplength; i++) puthex(gmap[i], fp_out); ! 262: fputs("\npop def\n", fp_out); ! 263: } ! 264: fprintf(fp_out, "%s %d %d %d %d gifimage\n", ! 265: gray ? "true" : "false", imagewidth, imageheight, ! 266: scrwidth - imageleft - imagewidth, scrheight - imagetop - imageheight); ! 267: if (gray) { ! 268: if (interlaced) { ! 269: int *iltbl; ! 270: ! 271: iltbl = (int *) allocate(imageheight*sizeof(int)); ! 272: j = 0; ! 273: for (i = 0; i < imageheight; i += 8) { ! 274: iltbl[i] = j; ! 275: j += imagewidth; ! 276: } ! 277: dbprt(stderr, "pass1: %d\n", j); ! 278: for (i = 4; i < imageheight; i += 8) { ! 279: iltbl[i] = j; ! 280: j += imagewidth; ! 281: } ! 282: dbprt(stderr, "pass2: %d\n", j); ! 283: for (i = 2; i < imageheight; i += 4) { ! 284: iltbl[i] = j; ! 285: j += imagewidth; ! 286: } ! 287: dbprt(stderr, "pass3: %d\n", j); ! 288: for (i = 1; i < imageheight; i += 2) { ! 289: iltbl[i] = j; ! 290: j += imagewidth; ! 291: } ! 292: dbprt(stderr, "pass4: %d\n", j); ! 293: ! 294: for (i = 0; i < imageheight; i++) { ! 295: k = iltbl[i]; ! 296: for (j = 0; j < imagewidth; j++, k++) ! 297: puthex(gmap[pmap[k]], fp_out); ! 298: fputs("\n", fp_out); ! 299: } ! 300: } ! 301: else { ! 302: for (i = 0, k = 0; i < imageheight; i++) { ! 303: for (j = 0; j < imagewidth; j++, k++) ! 304: puthex(gmap[pmap[k]], fp_out); ! 305: fputs("\n", fp_out); ! 306: } ! 307: } ! 308: } ! 309: else { ! 310: if (interlaced) { ! 311: int *iltbl; ! 312: ! 313: iltbl = (int *) allocate(imageheight*sizeof(int)); ! 314: j = 0; ! 315: for (i = 0; i < imageheight; i += 8) { ! 316: iltbl[i] = j; ! 317: j += imagewidth; ! 318: } ! 319: dbprt(stderr, "pass1: %d\n", j); ! 320: for (i = 4; i < imageheight; i += 8) { ! 321: iltbl[i] = j; ! 322: j += imagewidth; ! 323: } ! 324: dbprt(stderr, "pass2: %d\n", j); ! 325: for (i = 2; i < imageheight; i += 4) { ! 326: iltbl[i] = j; ! 327: j += imagewidth; ! 328: } ! 329: dbprt(stderr, "pass3: %d\n", j); ! 330: for (i = 1; i < imageheight; i += 2) { ! 331: iltbl[i] = j; ! 332: j += imagewidth; ! 333: } ! 334: dbprt(stderr, "pass4: %d\n", j); ! 335: ! 336: for (i = 0; i < imageheight; i++) { ! 337: k = iltbl[i]; ! 338: for (j = 0; j < imagewidth; j++, k++) puthex(pmap[k], fp_out); ! 339: fputs("\n", fp_out); ! 340: } ! 341: } ! 342: else { ! 343: for (i = 0, k = 0; i < imageheight; i++) { ! 344: for (j = 0; j < imagewidth; j++, k++) puthex(pmap[k], fp_out); ! 345: fputs("\n", fp_out); ! 346: } ! 347: } ! 348: } ! 349: fputs("restore\n", fp_out); ! 350: } ! 351: ! 352: void ! 353: readimage() ! 354: { ! 355: int bytecount, zerobytecount = 0; ! 356: int code, oldcode; ! 357: ! 358: fread(ibuf, sizeof(*ibuf), 9, fp_in); ! 359: imageleft = ibuf[0] + 256*ibuf[1]; ! 360: imagetop = ibuf[2] + 256*ibuf[3]; ! 361: imagewidth = ibuf[4] + 256*ibuf[5]; ! 362: imageheight = ibuf[6] + 256*ibuf[7]; ! 363: lcolormap = ibuf[8] & 0200; ! 364: interlaced = ibuf[8] & 0100; ! 365: lbitperpixel = (ibuf[8] & 07) + 1; ! 366: dbprt(stderr, "imageleft: %d\n", imageleft); ! 367: dbprt(stderr, "imagetop: %d\n", imagetop); ! 368: dbprt(stderr, "imagewidth: %d\n", imagewidth); ! 369: dbprt(stderr, "imgaeheight: %d\n", imageheight); ! 370: dbprt(stderr, "lcolormap: %d\n", lcolormap ? 1 : 0); ! 371: dbprt(stderr, "interlaced: %d\n", interlaced ? 1 : 0); ! 372: dbprt(stderr, "lbitperpixel: %d\n", lbitperpixel); ! 373: if (lcolormap) { ! 374: readlcolormap(lbitperpixel); ! 375: cmap = lcmap; ! 376: gmap = lgmap; ! 377: maplength = lmaplength; ! 378: } ! 379: ! 380: dbprt(stderr, "start reading raster data\n"); ! 381: fread(ibuf, sizeof(*ibuf), 1, fp_in); ! 382: codesize = ibuf[0]; ! 383: dbprt(stderr, "codesize: %d\n", codesize); ! 384: pmap = (unsigned char *) allocate(imagewidth*imageheight); ! 385: initstbl(); ! 386: while ((code = getcode()) != endcode) { ! 387: if (code == clearcode) { ! 388: curstblsize = endcode + 1; ! 389: code = getcode(); ! 390: putcode(code); ! 391: oldcode = code; ! 392: } ! 393: else if (code < curstblsize) { ! 394: putcode(code); ! 395: prefix[curstblsize] = oldcode; ! 396: suffix[curstblsize] = firstof(code); ! 397: curstblsize++; ! 398: oldcode = code; ! 399: } ! 400: else { ! 401: if (code != curstblsize) error(FATAL, "code out of order"); ! 402: prefix[curstblsize] = oldcode; ! 403: suffix[curstblsize] = firstof(oldcode); ! 404: curstblsize++; ! 405: putcode(curstblsize-1); ! 406: oldcode = code; ! 407: } ! 408: } ! 409: dbprt(stderr, "finish reading raster data\n"); ! 410: ! 411: /* read the rest of the raster data */ ! 412: do { ! 413: fread(ibuf, sizeof(*ibuf), 1, fp_in); ! 414: bytecount = ibuf[0]; ! 415: dbprt(stderr, "byte count: %d\n", bytecount); ! 416: if (bytecount) fread(ibuf, sizeof(*ibuf), bytecount, fp_in); ! 417: else zerobytecount = 1; ! 418: } while (!zerobytecount); ! 419: ! 420: writeimage(); ! 421: ! 422: if (lcolormap) { ! 423: cmap = gcmap; ! 424: gmap = ggmap; ! 425: maplength = gmaplength; ! 426: free(lcmap); ! 427: free(lgmap); ! 428: } ! 429: } ! 430: ! 431: void ! 432: readextensionblock() ! 433: { ! 434: int functioncode, bytecount, zerobytecount = 0; ! 435: ! 436: fread(ibuf, sizeof(*ibuf), 1, fp_in); ! 437: functioncode = ibuf[0]; ! 438: dbprt(stderr, "function code: %d\n", functioncode); ! 439: do { ! 440: fread(ibuf, sizeof(*ibuf), 1, fp_in); ! 441: bytecount = ibuf[0]; ! 442: dbprt(stderr, "byte count: %d\n", bytecount); ! 443: if (bytecount) fread(ibuf, sizeof(*ibuf), bytecount, fp_in); ! 444: else zerobytecount = 1; ! 445: } while (!zerobytecount); ! 446: } ! 447: ! 448: void ! 449: writebgscr() ! 450: { ! 451: fprintf(fp_out, "%s %d %d\n", PAGE, page, printed+1); ! 452: fputs("/saveobj save def\n", fp_out); ! 453: fprintf(fp_out, "%s: %d %d %d %d\n", ! 454: "%%PageBoundingBox", 0, 0, scrwidth, scrheight); ! 455: if (scrwidth > bburx) bburx = scrwidth; ! 456: if (scrheight > bbury) bbury = scrheight; ! 457: fprintf(fp_out, "%d %d gifscreen\n", scrwidth, scrheight); ! 458: } ! 459: ! 460: void ! 461: writeendscr() ! 462: { ! 463: if ( fp_out == stdout ) printed++; ! 464: fputs("showpage\n", fp_out); ! 465: fputs("saveobj restore\n", fp_out); ! 466: fprintf(fp_out, "%s %d %d\n", ENDPAGE, page, printed); ! 467: } ! 468: ! 469: void ! 470: redirect(pg) ! 471: int pg; /* next page we're printing */ ! 472: { ! 473: static FILE *fp_null = NULL; /* if output is turned off */ ! 474: ! 475: if ( pg >= 0 && in_olist(pg) == ON ) ! 476: fp_out = stdout; ! 477: else if ( (fp_out = fp_null) == NULL ) ! 478: fp_out = fp_null = fopen("/dev/null", "w"); ! 479: ! 480: } ! 481: ! 482: void ! 483: readgif() ! 484: { ! 485: int i, j, k; ! 486: ! 487: for (i = 0, j = 1, k = 0; i < 13; i++) { ! 488: for (; k < j; k++) cstbl[k] = i; ! 489: j *= 2; ! 490: } ! 491: ! 492: fread(ibuf, sizeof(*ibuf), 6, fp_in); ! 493: dbprt(stderr, "%.6s\n", ibuf); ! 494: if (strncmp((char *)ibuf, "GIF87a", 6) != 0) { ! 495: fread(ibuf, sizeof(*ibuf), 122, fp_in); ! 496: fread(ibuf, sizeof(*ibuf), 6, fp_in); ! 497: dbprt(stderr, "%.6s\n", ibuf); ! 498: if (strncmp((char *)ibuf, "GIF87a", 6) != 0) ! 499: error(FATAL, "wrong GIF signature"); ! 500: } ! 501: fread(ibuf, sizeof(*ibuf), 7, fp_in); ! 502: scrwidth = ibuf[0] + 256*ibuf[1]; ! 503: scrheight = ibuf[2] + 256*ibuf[3]; ! 504: gcolormap = ibuf[4] & 0200; ! 505: bitperpixel = (ibuf[4] & 07) + 1; ! 506: background = ibuf[5]; ! 507: dbprt(stderr, "scrwidth: %d\n", scrwidth); ! 508: dbprt(stderr, "scrheight: %d\n", scrheight); ! 509: dbprt(stderr, "gcolormap: %d\n", gcolormap ? 1 : 0); ! 510: dbprt(stderr, "bitperpixel: %d\n", bitperpixel); ! 511: dbprt(stderr, "background: %d\n", background); ! 512: if (ibuf[6] != 0) error(FATAL, "wrong screen descriptor"); ! 513: if (gcolormap) readgcolormap(bitperpixel); ! 514: else setcolormap(bitperpixel); ! 515: ! 516: redirect(++page); ! 517: writebgscr(); ! 518: ! 519: cmap = gcmap; ! 520: gmap = ggmap; ! 521: maplength = gmaplength; ! 522: ! 523: do { ! 524: fread(ibuf, sizeof(*ibuf), 1, fp_in); ! 525: if (ibuf[0] == ',') readimage(); ! 526: else if (ibuf[0] == ';') terminate = 1; ! 527: else if (ibuf[0] == '!') readextensionblock(); ! 528: else ! 529: error(FATAL, "wrong image separator character or wrong GIF terminator"); ! 530: } while (!terminate); ! 531: ! 532: writeendscr(); ! 533: ! 534: free(gcmap); ! 535: free(ggmap); ! 536: } ! 537: ! 538: void ! 539: init_signals() ! 540: { ! 541: ! 542: if ( signal(SIGINT, interrupt) == SIG_IGN ) { ! 543: signal(SIGINT, SIG_IGN); ! 544: signal(SIGQUIT, SIG_IGN); ! 545: signal(SIGHUP, SIG_IGN); ! 546: } ! 547: else { ! 548: signal(SIGHUP, interrupt); ! 549: signal(SIGQUIT, interrupt); ! 550: } ! 551: ! 552: signal(SIGTERM, interrupt); ! 553: } ! 554: ! 555: void ! 556: header() ! 557: { ! 558: int ch; /* return value from getopt() */ ! 559: int old_optind = optind; /* for restoring optind - should be 1 */ ! 560: ! 561: while ( (ch = getopt(argc, argv, optnames)) != EOF ) ! 562: if ( ch == 'L' ) ! 563: prologue = optarg; ! 564: else if ( ch == '?' ) ! 565: error(FATAL, ""); ! 566: ! 567: optind = old_optind; /* get ready for option scanning */ ! 568: ! 569: fprintf(stdout, "%s", CONFORMING); ! 570: fprintf(stdout, "%s %s\n", VERSION, PROGRAMVERSION); ! 571: fprintf(stdout, "%s %s\n", BOUNDINGBOX, ATEND); ! 572: fprintf(stdout, "%s %s\n", PAGES, ATEND); ! 573: fprintf(stdout, "%s", ENDCOMMENTS); ! 574: ! 575: if ( cat(prologue) == FALSE ) ! 576: error(FATAL, "can't read %s", prologue); ! 577: ! 578: fprintf(stdout, "%s", ENDPROLOG); ! 579: fprintf(stdout, "%s", BEGINSETUP); ! 580: fprintf(stdout, "mark\n"); ! 581: ! 582: } ! 583: ! 584: void ! 585: options() ! 586: { ! 587: int ch; /* return value from getopt() */ ! 588: ! 589: while ( (ch = getopt(argc, argv, optnames)) != EOF ) { ! 590: switch ( ch ) { ! 591: ! 592: case 'a': /* aspect ratio */ ! 593: fprintf(stdout, "/aspectratio %s def\n", optarg); ! 594: break; ! 595: ! 596: case 'c': /* copies */ ! 597: copies = atoi(optarg); ! 598: fprintf(stdout, "/#copies %s store\n", optarg); ! 599: break; ! 600: ! 601: case 'f': ! 602: negative = TRUE; ! 603: break; ! 604: ! 605: case 'g': ! 606: gray = TRUE; ! 607: break; ! 608: ! 609: case 'l': ! 610: fprintf(stdout, "/alignment true def\n"); ! 611: break; ! 612: ! 613: case 'm': /* magnification */ ! 614: fprintf(stdout, "/magnification %s def\n", optarg); ! 615: break; ! 616: ! 617: case 'n': /* forms per page */ ! 618: formsperpage = atoi(optarg); ! 619: fprintf(stdout, "%s %s\n", FORMSPERPAGE, optarg); ! 620: fprintf(stdout, "/formsperpage %s def\n", optarg); ! 621: break; ! 622: ! 623: case 'o': /* output page list */ ! 624: out_list(optarg); ! 625: break; ! 626: ! 627: case 'p': /* landscape or portrait mode */ ! 628: if ( *optarg == 'l' ) ! 629: fprintf(stdout, "/landscape true def\n"); ! 630: else fprintf(stdout, "/landscape false def\n"); ! 631: break; ! 632: ! 633: case 'x': /* shift things horizontally */ ! 634: fprintf(stdout, "/xoffset %s def\n", optarg); ! 635: break; ! 636: ! 637: case 'y': /* and vertically on the page */ ! 638: fprintf(stdout, "/yoffset %s def\n", optarg); ! 639: break; ! 640: ! 641: case 'C': /* copy file straight to output */ ! 642: if ( cat(optarg) == FALSE ) ! 643: error(FATAL, "can't read %s", optarg); ! 644: break; ! 645: ! 646: case 'E': /* text font encoding - unnecessary */ ! 647: fontencoding = optarg; ! 648: break; ! 649: ! 650: case 'D': /* debug flag */ ! 651: debug = ON; ! 652: break; ! 653: ! 654: case 'G': ! 655: gammaflag = ON; ! 656: gamma = atof(optarg); ! 657: break; ! 658: ! 659: case 'I': /* ignore FATAL errors */ ! 660: ignore = ON; ! 661: break; ! 662: ! 663: case 'L': /* PostScript prologue file */ ! 664: prologue = optarg; ! 665: break; ! 666: ! 667: case 'P': /* PostScript pass through */ ! 668: fprintf(stdout, "%s\n", optarg); ! 669: break; ! 670: ! 671: case '?': /* don't understand the option */ ! 672: error(FATAL, ""); ! 673: break; ! 674: ! 675: default: /* don't know what to do for ch */ ! 676: error(FATAL, "missing case for option %c\n", ch); ! 677: break; ! 678: ! 679: } ! 680: } ! 681: ! 682: argc -= optind; /* get ready for non-option args */ ! 683: argv += optind; ! 684: } ! 685: ! 686: void ! 687: setup() ! 688: { ! 689: /*setencoding(fontencoding);*/ ! 690: fprintf(stdout, "setup\n"); ! 691: ! 692: if ( formsperpage > 1 ) { /* followed by stuff for multiple pages ! 693: */ ! 694: if ( cat(formfile) == FALSE ) ! 695: error(FATAL, "can't read %s", formfile); ! 696: fprintf(stdout, "%d setupforms\n", formsperpage); ! 697: } /* End if */ ! 698: ! 699: fprintf(stdout, "%s", ENDSETUP); ! 700: ! 701: } ! 702: ! 703: void ! 704: arguments() ! 705: { ! 706: if ( argc < 1 ) { ! 707: fp_in = stdin; ! 708: readgif(); ! 709: } ! 710: else { /* at least one argument is left */ ! 711: while ( argc > 0 ) { ! 712: if ( strcmp(*argv, "-") == 0 ) ! 713: fp_in = stdin; ! 714: else if ( (fp_in = fopen(*argv, "r")) == NULL ) ! 715: error(FATAL, "can't open %s", *argv); ! 716: readgif(); ! 717: if ( fp_in != stdin ) ! 718: fclose(fp_in); ! 719: argc--; ! 720: argv++; ! 721: } ! 722: } ! 723: } ! 724: ! 725: void ! 726: done() ! 727: { ! 728: fprintf(stdout, "%s", TRAILER); ! 729: fprintf(stdout, "done\n"); ! 730: fprintf(stdout, "%s 0 0 %d %d\n", BOUNDINGBOX, bburx, bbury); ! 731: fprintf(stdout, "%s %d\n", PAGES, printed); ! 732: } ! 733: ! 734: main(agc, agv) ! 735: int agc; ! 736: char *agv[]; ! 737: { ! 738: argc = agc; ! 739: argv = agv; ! 740: prog_name = argv[0]; ! 741: ! 742: init_signals(); ! 743: header(); ! 744: options(); ! 745: setup(); ! 746: arguments(); ! 747: done(); ! 748: ! 749: exit(0); ! 750: } ! 751:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.