📄 postgif.c
字号:
cmap = lcmap; gmap = lgmap; maplength = lmaplength; }dbprt(stderr, "start reading raster data\n"); fread(ibuf, sizeof(*ibuf), 1, fp_in); codesize = ibuf[0];dbprt(stderr, "codesize: %d\n", codesize); pmap = (unsigned char *) allocate(imagewidth*imageheight); initstbl(); while ((code = getcode()) != endcode) { if (code == clearcode) { curstblsize = endcode + 1; code = getcode(); putcode(code); oldcode = code; } else if (code < curstblsize) { putcode(code); prefix[curstblsize] = oldcode; suffix[curstblsize] = firstof(code); curstblsize++; oldcode = code; } else { if (code != curstblsize) error(FATAL, "code out of order"); prefix[curstblsize] = oldcode; suffix[curstblsize] = firstof(oldcode); curstblsize++; putcode(curstblsize-1); oldcode = code; } }dbprt(stderr, "finish reading raster data\n"); /* read the rest of the raster data */ do { fread(ibuf, sizeof(*ibuf), 1, fp_in); bytecount = ibuf[0];dbprt(stderr, "byte count: %d\n", bytecount); if (bytecount) fread(ibuf, sizeof(*ibuf), bytecount, fp_in); else zerobytecount = 1; } while (!zerobytecount); writeimage(); if (lcolormap) { cmap = gcmap; gmap = ggmap; maplength = gmaplength; free(lcmap); free(lgmap); }}voidreadextensionblock(){ int functioncode, bytecount, zerobytecount = 0; fread(ibuf, sizeof(*ibuf), 1, fp_in); functioncode = ibuf[0];dbprt(stderr, "function code: %d\n", functioncode); do { fread(ibuf, sizeof(*ibuf), 1, fp_in); bytecount = ibuf[0];dbprt(stderr, "byte count: %d\n", bytecount); if (bytecount) fread(ibuf, sizeof(*ibuf), bytecount, fp_in); else zerobytecount = 1; } while (!zerobytecount);}voidwritebgscr(){ fprintf(fp_out, "%s %d %d\n", PAGE, page, printed+1); fputs("/saveobj save def\n", fp_out); fprintf(fp_out, "%s: %d %d %d %d\n", "%%PageBoundingBox", 0, 0, scrwidth, scrheight); if (scrwidth > bburx) bburx = scrwidth; if (scrheight > bbury) bbury = scrheight; fprintf(fp_out, "%d %d gifscreen\n", scrwidth, scrheight);}voidwriteendscr(){ if ( fp_out == stdout ) printed++; fputs("showpage\n", fp_out); fputs("saveobj restore\n", fp_out); fprintf(fp_out, "%s %d %d\n", ENDPAGE, page, printed);}voidredirect(pg) int pg; /* next page we're printing */{ static FILE *fp_null = NULL; /* if output is turned off */ if ( pg >= 0 && in_olist(pg) == ON ) fp_out = stdout; else if ( (fp_out = fp_null) == NULL ) fp_out = fp_null = fopen("/dev/null", "w");}voidreadgif(){ int i, j, k; for (i = 0, j = 1, k = 0; i < 13; i++) { for (; k < j; k++) cstbl[k] = i; j *= 2; } fread(ibuf, sizeof(*ibuf), 6, fp_in);dbprt(stderr, "%.6s\n", ibuf); if (strncmp((char *)ibuf, "GIF87a", 6) != 0) { fread(ibuf, sizeof(*ibuf), 122, fp_in); fread(ibuf, sizeof(*ibuf), 6, fp_in);dbprt(stderr, "%.6s\n", ibuf); if (strncmp((char *)ibuf, "GIF87a", 6) != 0) error(FATAL, "wrong GIF signature"); } fread(ibuf, sizeof(*ibuf), 7, fp_in); scrwidth = ibuf[0] + 256*ibuf[1]; scrheight = ibuf[2] + 256*ibuf[3]; gcolormap = ibuf[4] & 0200; bitperpixel = (ibuf[4] & 07) + 1; background = ibuf[5];dbprt(stderr, "scrwidth: %d\n", scrwidth);dbprt(stderr, "scrheight: %d\n", scrheight);dbprt(stderr, "gcolormap: %d\n", gcolormap ? 1 : 0);dbprt(stderr, "bitperpixel: %d\n", bitperpixel);dbprt(stderr, "background: %d\n", background); if (ibuf[6] != 0) error(FATAL, "wrong screen descriptor"); if (gcolormap) readgcolormap(bitperpixel); else setcolormap(bitperpixel); redirect(++page); writebgscr(); cmap = gcmap; gmap = ggmap; maplength = gmaplength; do { fread(ibuf, sizeof(*ibuf), 1, fp_in); if (ibuf[0] == ',') readimage(); else if (ibuf[0] == ';') terminate = 1; else if (ibuf[0] == '!') readextensionblock(); else error(FATAL, "wrong image separator character or wrong GIF terminator"); } while (!terminate); writeendscr(); free(gcmap); free(ggmap);}voidinit_signals(){ if ( signal(SIGINT, interrupt) == SIG_IGN ) { signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); signal(SIGHUP, SIG_IGN); } else { signal(SIGHUP, interrupt); signal(SIGQUIT, interrupt); } signal(SIGTERM, interrupt);}voidheader(){ int ch; /* return value from getopt() */ int old_optind = optind; /* for restoring optind - should be 1 */ while ( (ch = getopt(argc, argv, optnames)) != EOF ) if ( ch == 'L' ) prologue = optarg; else if ( ch == '?' ) error(FATAL, ""); optind = old_optind; /* get ready for option scanning */ fprintf(stdout, "%s", CONFORMING); fprintf(stdout, "%s %s\n", VERSION, PROGRAMVERSION); fprintf(stdout, "%s %s\n", BOUNDINGBOX, ATEND); fprintf(stdout, "%s %s\n", PAGES, ATEND); fprintf(stdout, "%s", ENDCOMMENTS); if ( cat(prologue) == FALSE ) error(FATAL, "can't read %s", prologue); fprintf(stdout, "%s", ENDPROLOG); fprintf(stdout, "%s", BEGINSETUP); fprintf(stdout, "mark\n");}voidoptions(){ int ch; /* return value from getopt() */ while ( (ch = getopt(argc, argv, optnames)) != EOF ) { switch ( ch ) { case 'a': /* aspect ratio */ fprintf(stdout, "/aspectratio %s def\n", optarg); break; case 'c': /* copies */ copies = atoi(optarg); fprintf(stdout, "/#copies %s store\n", optarg); break; case 'f': negative = TRUE; break; case 'g': gray = TRUE; break; case 'l': fprintf(stdout, "/alignment true def\n"); break; case 'm': /* magnification */ fprintf(stdout, "/magnification %s def\n", optarg); break; case 'n': /* forms per page */ formsperpage = atoi(optarg); fprintf(stdout, "%s %s\n", FORMSPERPAGE, optarg); fprintf(stdout, "/formsperpage %s def\n", optarg); break; case 'o': /* output page list */ out_list(optarg); break; case 'p': /* landscape or portrait mode */ if ( *optarg == 'l' ) fprintf(stdout, "/landscape true def\n"); else fprintf(stdout, "/landscape false def\n"); break; case 'x': /* shift things horizontally */ fprintf(stdout, "/xoffset %s def\n", optarg); break; case 'y': /* and vertically on the page */ fprintf(stdout, "/yoffset %s def\n", optarg); break; case 'C': /* copy file straight to output */ if ( cat(optarg) == FALSE ) error(FATAL, "can't read %s", optarg); break; case 'E': /* text font encoding - unnecessary */ fontencoding = optarg; break; case 'D': /* debug flag */ debug = ON; break; case 'G': gammaflag = ON; gamma = atof(optarg); break; case 'I': /* ignore FATAL errors */ ignore = ON; break; case 'L': /* PostScript prologue file */ prologue = optarg; break; case 'P': /* PostScript pass through */ fprintf(stdout, "%s\n", optarg); break; case '?': /* don't understand the option */ error(FATAL, ""); break; default: /* don't know what to do for ch */ error(FATAL, "missing case for option %c\n", ch); break; } } argc -= optind; /* get ready for non-option args */ argv += optind;}voidsetup(){ /*setencoding(fontencoding);*/ fprintf(stdout, "setup\n"); if ( formsperpage > 1 ) { /* followed by stuff for multiple pages*/ if ( cat(formfile) == FALSE ) error(FATAL, "can't read %s", formfile); fprintf(stdout, "%d setupforms\n", formsperpage); } /* End if */ fprintf(stdout, "%s", ENDSETUP);}voidarguments(){ if ( argc < 1 ) { fp_in = stdin; readgif(); } else { /* at least one argument is left */ while ( argc > 0 ) { if ( strcmp(*argv, "-") == 0 ) fp_in = stdin; else if ( (fp_in = fopen(*argv, "r")) == NULL ) error(FATAL, "can't open %s", *argv); readgif(); if ( fp_in != stdin ) fclose(fp_in); argc--; argv++; } }}voiddone(){ fprintf(stdout, "%s", TRAILER); fprintf(stdout, "done\n"); fprintf(stdout, "%s 0 0 %d %d\n", BOUNDINGBOX, bburx, bbury); fprintf(stdout, "%s %d\n", PAGES, printed); }main(agc, agv) int agc; char *agv[];{ argc = agc; argv = agv; prog_name = argv[0]; init_signals(); header(); options(); setup(); arguments(); done(); exit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -