📄 ln03rof.c
字号:
cpi = 17; lpi = length / 10.0; } } else { /* orientation is landscape */ if (length <= 88) { cpi = 13; lpi = length / 7.5; } else { cpi = 19; lpi = length / 7.5; } }}is_ps()/* Is this a PostScript Document ? */{ register char *ps=POSTSCRIPT_MN; register int c; while (*ps) { if ((c=getchar()) == EOF) exit(0); *sp++ = c; /* put in buffer */ if (c != *ps++) { *sp = NULL ; /* null terminate buffer */ sp = spbuf; return NULL ; } } *sp = NULL ; /* null terminate buffer */ sp=spbuf; return PS;}ps_end(stat)int stat;{ putchar ('\n'); putchar(PS_EOF); exit(stat);}main(argc, argv) int argc; char *argv[];{ register int i, c, ch; register char *cp; FILE *af; register enum font_encoding_e font_encoding=fe_Adobe; char *arg0; /* pointer to name filter was called by */ int prolog_sent=0; char *font_family=DEFAULT_FONT_FAMILY; lineno = 0; indent = 0; arg0 = strrchr(argv[0], '/'); if (!arg0) { arg0 = argv[0]; } else { arg0 += 1; /* Step past the / */ } if (strcmp(arg0, LN03ROF_DECMCS) == 0) { font_encoding = fe_DECMCS; setlocale(LC_CTYPE,"ENG_GB.MCS"); } else if (strcmp(arg0, LN03ROF_ISOLATIN1) == 0) { font_encoding = fe_ISOlatin1; setlocale(LC_CTYPE,"ENG_GB.8859"); } strcpy (orientation, "portrait"); while (--argc) { if (*(cp = *++argv) == '-') { switch (cp[1]) { case 'n': /* collect login name */ argc--; name = *++argv; break; case 'h': /* collect host name */ argc--; host = *++argv; break; case 'w': /* collect page width */ if ((i = atoi(&cp[2])) > 0 && i <= MAXWIDTH){ width = i; } if (width > 80) { /* switch to landscape mode */ strcpy (orientation, "landscape"); } break; case 'l': /* collect page length */ length = atoi(&cp[2]); break; case 'i': /* collect indent */ indent = atoi(&cp[2]); break; case 'c': /* print control chars */ literal++; break; } } else acctfile = cp; } if (is_ps()==PS){ send_ps (); /* send postscript file and then exit */ } /*========================================================================*/ /* * load the PostScript function definitions * Since its not a PostScript document */ init(); /* initialize prolog variables */ cc = indent; for (i = 0; i <= cc; buf[i++] = ' '); /* Initialize buf to blanks */ while ((c = spgetchar()) != EOF) { if (!prolog_sent) { send_encoding_and_prolog(font_family, font_encoding); puts("soj"); prolog_sent++; } /* Print literal characters otherwise ignore them */ if ( literal && is_7or8_bit(c) && (c != '\n')) { if (is_7bit_cntrl (c)) { if (c == '\177') { buf[cc++] = '^'; buf[cc++] = '?'; } else { buf[cc++] = '^'; ch = c + '@'; if (ch == '\\' || ch == '[' || ch == ']') buf[cc++] = '\\'; buf[cc++] = ch; } } else { /* its 8 bit */ if ((unsigned)c < (unsigned)'\240') { buf[cc++] = 'M'; buf[cc++] = '-'; ch = (c & 0177) + '@'; if (ch == '\\' || ch == '[' || ch == ']') buf[cc++] = '\\'; buf[cc++] = ch; } else { buf[cc++] = '\\'; buf[cc++] = 064 + ( (unsigned)c >> 6); /* WHY? */ buf[cc++] = 060 + ( ((unsigned)c >> 3) & 07); buf[cc++] = 060 + ( (unsigned)c & 07); } } } else { /* Supress control characters */ switch (c) { case ('\n'): flush_buf(1); puts("nl"); break; case ('\f'): flush_buf(1); puts("ff"); npages++; break; case ('\r'): flush_buf(1); puts("cr"); break; case ('\b'): flush_buf(0); puts("bsp"); break; case ('\t'): flush_buf(0); puts("tab"); break; case (ESC): flush_buf(0); c = spgetchar (); if (c == '9') /* move partial line down */ puts("pld"); else if (c == '8') /* move partial line up */ puts("plu"); else if (c == '7') /* move a full line up */ puts("flu"); else printf ("(%c) show", c); break; case ('\031'): /* * lpd needs to use a different filter * to print data so stop what we are * doing and lpd will restart us later. * This is executed when this filter is * used as the "of" as specified in * /etc/printcap */ if ((c = spgetchar()) == '\1') { puts("eoj"); putchar(PS_EOF); fflush(stdout); kill(getpid(), SIGSTOP); /* sleeeeep */ prolog_sent = 0; break; } else { ungetc(c, stdin); c = '\031'; } break; case ('\\'): case ('('): case (')'): if (cc >= (sizeof(buf) - 2)) flush_buf(1); buf[cc++] = '\\'; /* fall through into default code */ default: if(isprint(c)) { buf[cc++] = c; if (cc >= (sizeof(buf) - 1)) flush_buf(1); } break; } /* end switch */ } /* end else supress control characters */ } /* end while not done */ flush_buf(1); /* * execute "end-of-job" function */ if (prolog_sent) { printf("eoj\n"); } if (name && acctfile && access(acctfile, 02) >= 0 && (af = fopen(acctfile, "a")) != NULL) { fprintf(af, "%7.2f\t%s:%s\n", (float)npages, host, name); } ps_end(0);}put_text(text_block)char **text_block;{ register char *p; while(p = *text_block++) { if (*p != '%') /* do not send comments */ fprintf(stdout,"%s\n", p); }}set_and_scale_font()/* * Set font and scaling */{ double spsize, /* The size of one blank space */ lfsize, /* The size of a line feed */ fontsize; /* The size of the font */ spsize = (1.0 / cpi) * 72.0; lfsize = (1.0 / lpi) * 72.0; fontsize = spsize / MSIZE; /* re-initialize prolog variables */ fprintf (stdout, "\n"); fprintf (stdout, "%s\n", orientation); fprintf (stdout, "%4.2f in top-m\n", topmargin); fprintf (stdout, "%4.2f in bot-m\n", bottommargin); fprintf (stdout, "%4.2f in left-m\n", leftmargin); fprintf (stdout, "/lfsize %4.2f def\n", lfsize); fprintf (stdout, "/spsize %4.2f def\n", spsize); fprintf (stdout, "/%s findfont %4.2f scalefont setfont\n", fontname, fontsize); fprintf (stdout, "\n");}can_print (c)int c;/* * Returns true if it is a printable 7 or 8 bit character * A newline, carriage return or a tab */{ return (((unsigned)c >= (unsigned)'\040' && (unsigned)c <= (unsigned)'\176') || ((unsigned)c >= (unsigned)'\240' && (unsigned)c <= (unsigned)'\375') || ((unsigned)c == (unsigned)'\012') || ((unsigned)c == (unsigned)'\011') || ((unsigned)c == (unsigned)'\015'));}send_ps ()/* * The document is already formatted in PostScript, so we'll pass it * straight through, but remove most control characters. * */{ register int c; while ((c = spgetchar()) != EOF) { if (can_print(c)) { putchar (c); } } ps_end(0);}flush_buf(entire_line)int entire_line;/* * Flushes the output buffer to the printer (if it is not empty). * If entire line is flushed then cc is reset to indent, otherwise * only part of the line is being flushed so cc is reset to 0. * */{int i; if (cc != 0) { buf[cc] = NULL; printf("(%s) s ", buf); if (++lineno == length) { lineno = 0; npages ++; } for (i = 0; i <= cc; buf[i++] = ' '); if (entire_line) cc = indent; else cc = 0; }}/* Sends the appropriate PS prolog based on value of font_encoding */send_encoding_and_prolog(font_family, font_encoding)char *font_family;enum font_encoding_e font_encoding;{ sprintf(fontname, "%s%s", font_family, font_suffix[(int)font_encoding]); /* * We need to output the magic %! here because * put_text() strips all comments */ fprintf (stdout, "%%!\n"); put_text(font_encoding_prolog[(int)font_encoding]); if (font_encoding != fe_Adobe) put_text(findfont_prolog); put_text(prolog); set_and_scale_font();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -