📄 et2ps.c
字号:
} } return(rc);}/* * a keyword has been matched in the input stream, so it's time to * process the associated operation. the key value + 1 is passed in. * if the key is negative, it represents turning an attribute off, e.g. /bold. * if it's positive, it represents turning an attribute on, e.g. italic. * some keywords don't have an off attribute, e.g. there's no /nl. if one of * these is encountered, the "off" is silently ignored. */#define AttrOff (key < 0)voidcontrolOutput( int key ){ int k = abs(key)-1; switch(k) { /* <nl> */ case K_NL: newline(); break; /* <bold> */ case K_BOLD: if AttrOff g.mask &= ~BOLD; else g.mask |= BOLD; break; /* <italic */ case K_ITALIC: if AttrOff g.mask &= ~ITALIC; else g.mask |= ITALIC; break; /* <fixed> */ case K_FIXED: if AttrOff g.mask &= ~FIXED; else g.mask |= FIXED; break; /* <underline> */ case K_UNDERLINE: if AttrOff g.underline = 0; else g.underline = 1; break; /* <center> */ case K_CENTER: if (g.atMargin == 0) { newline(); } if AttrOff { popJustify(CENTER); printf("/JU %i def\n", g.justify); } else { pushJustify(CENTER); printf("/JU %i def\n", g.justify); } break; /* <flushleft> */ case K_FL: if (g.atMargin == 0) { newline(); } if AttrOff { popJustify(L_JUST); printf("/JU %i def\n", g.justify); } else { pushJustify(L_JUST); printf("/JU %i def\n", g.justify); } break; /* <flushright> */ case K_FR: if (g.atMargin == 0) { newline(); } if AttrOff { popJustify(R_JUST); printf("/JU %i def\n", g.justify); } else { pushJustify(R_JUST); printf("/JU %i def\n", g.justify); } break; /* <flushboth> */ case K_FB: if (g.atMargin == 0) { newline(); } if AttrOff { popJustify(F_JUST); printf("/JU %i def\n", g.justify); } else { pushJustify(F_JUST); printf("/JU %i def\n", g.justify); } break; /* <nofill> */ case K_NOFILL: if (g.atMargin == 0) { newline(); } if AttrOff { popJustify(L_JUST); printf("/JU %i def\n", g.justify); } else { pushJustify(L_JUST); printf("/JU %i def\n", g.justify); } break; /* <indent> */ case K_INDENT: if AttrOff { if(g.atMargin) puts("DLM\n"); else puts("DDLM\n"); } else { if(g.atMargin) puts("ILM\n"); else puts("DILM\n"); } break; /* <indentright> */ case K_INDENTR: if AttrOff { if(g.atMargin) puts("DRM\n"); else puts("DDRM\n"); } else { if(g.atMargin) puts("IRM\n"); else puts("DIRM\n"); } break; /* <param> */ case K_PARAM: if AttrOff g.suppress = 0; else g.suppress = 1; break; /* <bigger> */ case K_BIGGER: if AttrOff g.fs -=2; else g.fs +=2; g.ffs = g.fs; break; /* <smaller> */ case K_SMALLER: if AttrOff g.fs +=2; else g.fs -=2; g.ffs = g.fs; break; /* <excerpt> */ case K_EXCERPT: if (g.atMargin == 0) { newline(); } if AttrOff { puts("DLM"); toggleFont(0); } else { puts("ILM"); toggleFont(1); } break; default: fprintf(stderr, "INVALID KEYWORD\n"); } g.c = 0; g.keyword = 0;}/* * subroutine: process a line break. * this is called when 2 consecutive newline characters are found, * or when justification mode is changed. */voidnewline(){ printf("NL\n"); g.atMargin = 1;}/* * push justification attributes onto a stack. this allows nesting, for * example, of <flushleft>, <flushright>, <flushboth>, and <center>. */voidpushJustify( int justify ){ jstack[g.jstack] = g.justify; if (++g.jstack >= MAXJSTACK) { fprintf(stderr, "Internal error, justify stack overflow\n"); exit(1); } g.justify = justify;}/* * pop justification attributes off a stack. this allows nesting, for * example, of <flushleft>, <flushright>, <flushboth>, and <center>. */voidpopJustify( int justify ){ if (g.justify != justify) { fprintf(stderr, "Warning: Incorrect nesting of justification, output may be weird.\n"); } if (--g.jstack < 0) { fprintf(stderr, "Internal error, justify stack underflow\n"); exit(1); } g.justify = jstack[g.jstack];}/* * subroutine: toggle the main font between Helvetica and TimesRoman, based * on the "alt" parameter. alt=true means set the alternate font, * alt=false means set the main font. * * the default main font is Helvetica, and the alternate is TimesRoman. * the polarity can be reversed by command line switch, which sets the * main font to TimesRoman and the alternate font to Helvetica. */voidtoggleFont( int alt ){ char buff[256]; if (alt ^ g.altFont) { strcpy(buff, "(Times-Roman) cvlit /f1 exch def "); strcat(buff, "(Times-Bold) cvlit /f1b exch def "); strcat(buff, "(Times-Italic) cvlit /f1i exch def "); strcat(buff, "(Times-BoldItalic) cvlit /f1bi exch def "); } else { strcpy(buff, "(Helvetica) cvlit /f1 exch def "); strcat(buff, "(Helvetica-Bold) cvlit /f1b exch def "); strcat(buff, "(Helvetica-Oblique) cvlit /f1i exch def "); strcat(buff, "(Helvetica-BoldOblique) cvlit /f1bi exch def "); } puts( buff );}/* * subroutine: fold alphabetic characters to upper case * note: VERY dependant on ASCII encoding */voidfoldLow( char *x ){ for ( ; *x != '>'; x++ ) { if ( ( *x >= 'A' ) && ( *x <= 'Z' ) ) x[0] = (char)((int)(x[0]) + 32); }}/* * Output PostScript prolog code * * The main body of the prolog is read from a static data structure, which * contains the pagination macros. The data structure is in prolog.h, * which is built by the Perl program mkincl. The source for the prolog is * paginate.ps. This is a "stripped" version of the PostScript code. The * human-readable source is in paginate.ps.verbose. This latter file is the * one which should be edited if PostScript code changes are required. The * Perl program pstrip converts paginate.ps.verbose to paginate.ps. The * purpose for doing all this is to make the program self contained, rather * than require shipping an extra file with it, containing the PostScript code. */static time_t tloc;voidprolog(){ char *c = &pscode[0]; if(g.prolog) { puts("%!PS"); puts("%Copyright (c) 1996 H&L Software, Inc."); puts("%All rights reserved"); puts("%%BeginProlog"); /* * copy the PostScript macros from the static data * structure to standard output. */ while( *c != (char) NULL ) { putchar((int) *c++); } puts("\n%%EndProlog\n%%BeginSetup"); /* * set flag for drawing box (or not) around each page */ if(g.box) puts("/BOX true def\nDB % draw box for first page"); else puts("/BOX false def"); /* * set flag for running header (or not) */ if(g.hdr) { puts("/HDR true def\n/PG 1 def"); time(&tloc); printf("/MSG (Message converted on %s) def\n", ctime(&tloc)); puts("PH % print header for first page"); } else puts("/HDR false def"); /* * define short-hand literal names for fonts */ if (g.altFont) { strcpy(buff, "(Times-Roman) cvlit /f1 exch def "); strcat(buff, "(Times-Bold) cvlit /f1b exch def "); strcat(buff, "(Times-Italic) cvlit /f1i exch def "); strcat(buff, "(Times-BoldItalic) cvlit /f1bi exch def "); } else { strcpy(buff, "(Helvetica) cvlit /f1 exch def "); strcat(buff, "(Helvetica-Bold) cvlit /f1b exch def "); strcat(buff, "(Helvetica-Oblique) cvlit /f1i exch def "); strcat(buff, "(Helvetica-BoldOblique) cvlit /f1bi exch def "); } strcat(buff, "(Courier) cvlit /f2 exch def "); strcat(buff, "(Courier-Bold) cvlit /f2b exch def "); strcat(buff, "(Courier-Oblique) cvlit /f2i exch def "); strcat(buff, "(Courier-BoldOblique) cvlit /f2bi exch def\n"); puts( buff ); /* * set the page margins *//*** to override the stuff in the PostScript prolog, this is the place ***/ puts("%%EndSetup"); }}/* * wrap up the PostScript output */voidepilog(){ /* * if text in the buffer, dump it out */ if (g.atMargin == 0) tokenOutput(buff); /* * cause final "showpage" */ puts("/BOX false def\n/HDR false def"); puts("NP"); puts("%%EOF");}/* * this routine parses command line flags and arguments */intgetArgs( int argc, char **argv ){ int c; int fs; int rc = 0; extern char *optarg; extern int optind; int opterr = 0; /* * get program name (for error msgs) and directory name (for * finding PostScript prolog file. */ g.n = baseName( g.n, argv[0] ); g.d = dirName( g.d, argv[0] ); /* * parse arguments */ while ((c=getopt(argc, argv, "bpts:h?")) != EOF) switch(c) { /* * 'b' flag causes a box to be drawn around the margins * on each page. */ case 'b': g.box = 1; break; /* * 'p' flag suppresses pre-pending the PostScript prolog * to the output. this is useful when debugging, using * the program as a filter for standard input and * interactively writing conversions to standard output. */ case 'p': g.prolog = 0; break; /* * 't' flag changes default font to "Times", * rather than "Helvetica." */ case 't': g.altFont = 1; break; /* * 'u' flag causes unrecognized MIME tags to be shown * in the output. useful for debugging. */ case 'u': g.showTags = 1; break; /* * 's' flag followed by an integer overrides the * default font size (10 pt) */ case 's': fs = atoi(optarg); if(errno) perror(g.n); if(fs > 0 && fs < 36) { g.fs = fs; g.ffs = fs; } break; /* * 'h' flag causes printing of running headers */ case 'h': g.hdr = 1; break; case '?': opterr++; break; } if(opterr) { showHelp(); rc = 1; } /* * discard command line arguments */ for ( ; optind < argc; optind++) { fprintf(stderr, "%s: Unrecognized parameter: %s\n", g.n, argv[optind]); rc = 1; } return(rc);}/* * get program name, for error messages * simulate the "basename()" function, so as to avoid using libgen, * since not always available. */char *baseName( char *n, char *a ){ extern char *strrchr( const char *, int); n = strrchr(a, (int)'/'); if( n == NULL) n = a; else ++n; return(n);}char *dirName( char *n, char *a ){ char *end; extern char *strrchr( const char *, int); end = strrchr(a, (int)'/'); if( end != NULL ) { strncpy(n, a, (int)(end-a+1)); n[(int)(end-a+1)] = (char)NULL; } else n[0] = (char)NULL; return(n);}/* * display some help text */voidshowHelp(){ fprintf(stderr,"usage: %s [-b] [-p] [-t] [-h] [-s nn]\n",g.n); fprintf(stderr,"\nThe -b flag causes a box to be drawn along the page margins.\n"); fprintf(stderr,"\nThe -p flag suppresses output of the PostScript prolog code, an option probably only useful for debugging.\n"); fprintf(stderr,"\nThe -t flag changes the default font from Helvetica to Times-Roman.\n"); fprintf(stderr,"\nThe -h flag causes running headers to be printed on each page.\n"); fprintf(stderr,"\nThe -s flag changes the default font size from 10 pt to the value of \"nn\", up to a maximum of 36 pt.\n"); fprintf(stderr,"\nThe -u flag causes unrecognized MIME tags to be shown in the output.\n");}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -