Add copyright notice
[unix-history] / usr / src / usr.sbin / lpr / filters / lpf.c
index c5380c5..f7ca224 100644 (file)
@@ -1,4 +1,14 @@
-/*             lpf.c   4.10    83/04/29
+/*
+ * 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,18 +28,13 @@ 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 */
 
-onintr()
-{
-       signal(SIGTERM, SIG_IGN);
-       exit(1);
-}
-
 main(argc, argv) 
        int argc;
        char *argv[];
 main(argc, argv) 
        int argc;
        char *argv[];
@@ -39,11 +45,6 @@ main(argc, argv)
        int done, linedone, maxrep;
        char ch, *limit;
 
        int done, linedone, maxrep;
        char ch, *limit;
 
-       signal(SIGHUP, SIG_IGN);
-       signal(SIGINT, SIG_IGN);
-       signal(SIGQUIT, SIG_IGN);
-       signal(SIGTERM, onintr);
-
        while (--argc) {
                if (*(cp = *++argv) == '-') {
                        switch (cp[1]) {
        while (--argc) {
                if (*(cp = *++argv) == '-') {
                        switch (cp[1]) {
@@ -66,6 +67,10 @@ main(argc, 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;
@@ -78,7 +83,7 @@ main(argc, argv)
        done = 0;
        
        while (!done) {
        done = 0;
        
        while (!done) {
-               col = 0;
+               col = indent;
                maxrep = -1;
                linedone = 0;
                while (!linedone) {
                maxrep = -1;
                linedone = 0;
                while (!linedone) {
@@ -97,16 +102,16 @@ main(argc, argv)
                                break;
 
                        case '\b':
                                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':
@@ -125,8 +130,10 @@ main(argc, 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)
@@ -155,6 +162,7 @@ main(argc, argv)
                        else
                                putc(ch, o);
                        if (++lineno >= length) {
                        else
                                putc(ch, o);
                        if (++lineno >= length) {
+                               fflush(o);
                                npages++;
                                lineno = 0;
                        }
                                npages++;
                                lineno = 0;
                        }