X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/aaf17c3ef02af149a55ef618ed03dede825047fb..fa32567fe73064d784332e72900f7cb826b88af9:/usr/src/usr.sbin/lpr/filters/lpf.c diff --git a/usr/src/usr.sbin/lpr/filters/lpf.c b/usr/src/usr.sbin/lpr/filters/lpf.c index 0149fd1285..f7ca2241ac 100644 --- a/usr/src/usr.sbin/lpr/filters/lpf.c +++ b/usr/src/usr.sbin/lpr/filters/lpf.c @@ -1,4 +1,14 @@ -/* lpf.c 4.7 83/03/07 +/* + * Copyright (c) 1983 Regents of the University of California. + * All rights reserved. The Berkeley software License Agreement + * specifies the terms and conditions for redistribution. + */ + +#ifndef lint +static char sccsid[] = "@(#)lpf.c 5.1 (Berkeley) %G%"; +#endif not lint + +/* * filter which reads the output of nroff and converts lines * with ^H's to overwritten lines. Thus this works like 'ul' * but is much better: it can handle more than 2 overwrites @@ -6,6 +16,7 @@ * modified by kls to use register references instead of arrays * to try to gain a little speed. */ + #include #include @@ -17,15 +28,16 @@ int maxcol[MAXREP] = {-1}; int lineno; int width = 132; /* default line length */ int length = 66; /* page length */ +int indent; /* indentation length */ int npages = 1; int literal; /* print control characters */ char *name; /* user's login name */ char *host; /* user's machine name */ char *acctfile; /* accounting information file */ -main(argc, argv) -int argc; -char *argv[]; +main(argc, argv) + int argc; + char *argv[]; { register FILE *p = stdin, *o = stdout; register int i, col; @@ -55,6 +67,10 @@ char *argv[]; length = atoi(&cp[2]); break; + case 'i': + indent = atoi(&cp[2]); + break; + case 'c': /* Print control chars */ literal++; break; @@ -67,8 +83,8 @@ char *argv[]; done = 0; while (!done) { - col = 0; - maxrep = 0; + col = indent; + maxrep = -1; linedone = 0; while (!linedone) { switch (ch = getc(p)) { @@ -80,24 +96,22 @@ char *argv[]; case '\f': lineno = length; case '\n': - if (++lineno >= length) { - npages++; - lineno = 0; - } + if (maxrep < 0) + maxrep = 0; linedone = 1; break; case '\b': - if (col-- < 0) - col = 0; + if (--col < indent) + col = indent; break; case '\r': - col = 0; + col = indent; break; case '\t': - col = (col | 07) + 1; + col = ((col - indent) | 07) + indent + 1; break; case '\031': @@ -116,8 +130,10 @@ char *argv[]; } default: - if (col >= width || !literal && ch < ' ') + if (col >= width || !literal && ch < ' ') { + col++; break; + } cp = &buf[0][col]; for (i = 0; i < MAXREP; i++) { if (i > maxrep) @@ -145,6 +161,11 @@ char *argv[]; putc('\r', o); else putc(ch, o); + if (++lineno >= length) { + fflush(o); + npages++; + lineno = 0; + } maxcol[i] = -1; } }