add Berkeley specific header
[unix-history] / usr / src / old / vfilters / vpf / vpf.c
index c1cdc7d..657afa8 100644 (file)
@@ -1,4 +1,25 @@
-/*     vpf.c   4.2     83/03/17        */
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that this notice is preserved and that due credit is given
+ * to the University of California at Berkeley. The name of the University
+ * may not be used to endorse or promote products derived from this
+ * software without specific prior written permission. This software
+ * is provided ``as is'' without express or implied warranty.
+ */
+
+#ifndef lint
+char copyright[] =
+"@(#) Copyright (c) 1983 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)vpf.c      5.2 (Berkeley) %G%";
+#endif /* not lint */
+
 /*
  * Varian/Versatec printer filter
  */
 /*
  * Varian/Versatec printer filter
  */
 
 #define LINELN 440
 
 
 #define LINELN 440
 
-int    pltmode[] = {VPLOT, 0, 0};
-int    prtmode[] = {VPRINT, 0, 0};
+int    pltmode[] = {VPLOT};
+int    prtmode[] = {VPRINT};
 char   linebuf[LINELN+1];
 char   ovbuf[LINELN];
 int    ov;
 int    lineno;
 int    varian = 1;     /* default is the varian */
 int    width = 132;    /* default line length */
 char   linebuf[LINELN+1];
 char   ovbuf[LINELN];
 int    ov;
 int    lineno;
 int    varian = 1;     /* default is the varian */
 int    width = 132;    /* default line length */
+int    indent = 0;     /* default indent length */
 int    length = 58;    /* 80 for 11" long paper */
 int    npages = 1;
 int    literal;
 int    length = 58;    /* 80 for 11" long paper */
 int    npages = 1;
 int    literal;
@@ -24,23 +46,12 @@ char        *name;          /* user's login name */
 char   *host;          /* user's machine name */
 char   *acctfile;      /* accounting information file */
 
 char   *host;          /* user's machine name */
 char   *acctfile;      /* accounting information file */
 
-onintr()
-{
-       signal(SIGTERM, SIG_IGN);
-       exit(1);
-}
-
-main(argc, argv) 
+main(argc, argv)
        int argc;
        char *argv[];
 {
        register int i;
 
        int argc;
        char *argv[];
 {
        register int i;
 
-       signal(SIGHUP, SIG_IGN);
-       signal(SIGINT, SIG_IGN);
-       signal(SIGQUIT, SIG_IGN);
-       signal(SIGTERM, onintr);
-
        if (argv[0][strlen(argv[0])-1] == 'W') { /* Wide: the versatec. */
                varian = 0;
                width = 440;
        if (argv[0][strlen(argv[0])-1] == 'W') { /* Wide: the versatec. */
                varian = 0;
                width = 440;
@@ -69,6 +80,12 @@ main(argc, argv)
                                length = atoi(&argv[0][2]);
                                break;
 
                                length = atoi(&argv[0][2]);
                                break;
 
+                       case 'i':
+                               if ((i = atoi(&argv[0][2])) >= 0 &&
+                                   i < LINELN - 1)
+                                       indent = i;
+                               break;
+
                        case 'c':       /* Print input without throwing away
                                           control chars and without putting
                                           in page breaks. */
                        case 'c':       /* Print input without throwing away
                                           control chars and without putting
                                           in page breaks. */
@@ -92,35 +109,23 @@ main(argc, argv)
 
 send()
 {
 
 send()
 {
-       register nskipped;
-
        lineno = 0;
        lineno = 0;
-       nskipped = 0;
        while (getline()) {
        while (getline()) {
-               if (!literal && varian && lineno==0 && linebuf[0]==0 && nskipped<3) {
-                       nskipped++;
-                       continue;
-               }
-               if (varian && lineno >= length) {
-                       nskipped = 0;
+               if (varian && !literal && lineno >= length) {
                        putline(1);
                        lineno = 0;
                        putline(1);
                        lineno = 0;
-               } else {
+               } else
                        putline(0);
                        putline(0);
-                       if (literal)    /* Don't make page breaks if -l. */
-                               lineno = 1;
-                       else
-                               lineno++;
-               }
        }
        }
-       if (varian && lineno)
+       if (varian && lineno) {
                putchar('\f');  /* be sure to end on a page boundary */
                putchar('\f');  /* be sure to end on a page boundary */
+               npages++;
+       }
        /*
         * Put out an extra null to ensure varian will get an even
         * number of good characters.
         */
        putchar('\0');
        /*
         * Put out an extra null to ensure varian will get an even
         * number of good characters.
         */
        putchar('\0');
-       npages += (lineno + length - 1) / length;
 }
 
 getline()
 }
 
 getline()
@@ -132,7 +137,7 @@ getline()
                linebuf[col] = ' ';
                ovbuf[col] = 0;
        }
                linebuf[col] = ' ';
                ovbuf[col] = 0;
        }
-       col = 0;
+       col = indent;
        maxcol = 0;
        for (;;) switch (c = getchar()) {
 
        maxcol = 0;
        for (;;) switch (c = getchar()) {
 
@@ -197,11 +202,13 @@ getline()
 
        case '\f':
                /* Fall through, treating a ff as a line break, too... */
 
        case '\f':
                /* Fall through, treating a ff as a line break, too... */
-               lineno = length;
+               lineno = length - 1;
        case '\n':
                if (maxcol > width)
                        maxcol = width;
                linebuf[maxcol] = '\0';
        case '\n':
                if (maxcol > width)
                        maxcol = width;
                linebuf[maxcol] = '\0';
+               if (++lineno % length == 0)
+                       npages++;
                return(1);
 
        case '\b':
                return(1);
 
        case '\b':
@@ -234,10 +241,9 @@ int ff;
                fflush(stdout);
                ioctl(1, VSETSTATE, prtmode);
        }
                fflush(stdout);
                ioctl(1, VSETSTATE, prtmode);
        }
-       if (ff) {
+       if (ff)
                putchar('\f');
                putchar('\f');
-               npages++;
-       } else if (ov == 0)
+       else if (ov == 0)
                putchar('\n');
        if (ferror(stdout))
                exit(1);
                putchar('\n');
        if (ferror(stdout))
                exit(1);