Add copyright notice
[unix-history] / usr / src / usr.sbin / lpr / filters / lpf.c
index 0149fd1..f7ca224 100644 (file)
@@ -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
  *     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.
  */
  *     modified by kls to use register references instead of arrays
  *     to try to gain a little speed.
  */
+
 #include <stdio.h>
 #include <signal.h>
 
 #include <stdio.h>
 #include <signal.h>
 
@@ -17,15 +28,16 @@ int maxcol[MAXREP] = {-1};
 int    lineno;
 int    width = 132;    /* default line length */
 int    length = 66;    /* page length */
 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 */
 
 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;
 {
        register FILE *p = stdin, *o = stdout;
        register int i, col;
@@ -55,6 +67,10 @@ char *argv[];
                                length = atoi(&cp[2]);
                                break;
 
                                length = atoi(&cp[2]);
                                break;
 
+                       case 'i':
+                               indent = atoi(&cp[2]);
+                               break;
+
                        case 'c':       /* Print control chars */
                                literal++;
                                break;
                        case 'c':       /* Print control chars */
                                literal++;
                                break;
@@ -67,8 +83,8 @@ char *argv[];
        done = 0;
        
        while (!done) {
        done = 0;
        
        while (!done) {
-               col = 0;
-               maxrep = 0;
+               col = indent;
+               maxrep = -1;
                linedone = 0;
                while (!linedone) {
                        switch (ch = getc(p)) {
                linedone = 0;
                while (!linedone) {
                        switch (ch = getc(p)) {
@@ -80,24 +96,22 @@ char *argv[];
                        case '\f':
                                lineno = length;
                        case '\n':
                        case '\f':
                                lineno = length;
                        case '\n':
-                               if (++lineno >= length) {
-                                       npages++;
-                                       lineno = 0;
-                               }
+                               if (maxrep < 0)
+                                       maxrep = 0;
                                linedone = 1;
                                break;
 
                        case '\b':
                                linedone = 1;
                                break;
 
                        case '\b':
-                               if (col-- < 0)
-                                       col = 0;
+                               if (--col < indent)
+                                       col = indent;
                                break;
 
                        case '\r':
                                break;
 
                        case '\r':
-                               col = 0;
+                               col = indent;
                                break;
 
                        case '\t':
                                break;
 
                        case '\t':
-                               col = (col | 07) + 1;
+                               col = ((col - indent) | 07) + indent + 1;
                                break;
 
                        case '\031':
                                break;
 
                        case '\031':
@@ -116,8 +130,10 @@ char *argv[];
                                }
 
                        default:
                                }
 
                        default:
-                               if (col >= width || !literal && ch < ' ')
+                               if (col >= width || !literal && ch < ' ') {
+                                       col++;
                                        break;
                                        break;
+                               }
                                cp = &buf[0][col];
                                for (i = 0; i < MAXREP; i++) {
                                        if (i > maxrep)
                                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);
                                putc('\r', o);
                        else
                                putc(ch, o);
+                       if (++lineno >= length) {
+                               fflush(o);
+                               npages++;
+                               lineno = 0;
+                       }
                        maxcol[i] = -1;
                }
        }
                        maxcol[i] = -1;
                }
        }