date and time created 88/07/21 17:35:50 by marc
[unix-history] / usr / src / local / local.cmd / cpr.c
index 071e1b2..81eae98 100644 (file)
@@ -2,7 +2,7 @@
 # include <sgtty.h>
 # include <signal.h>
 
 # include <sgtty.h>
 # include <signal.h>
 
-static char    SccsId[] =      "@(#)cpr.c      1.1.1.1         %G%";
+static char    SccsId[] =      "@(#)cpr.c      1.8             %G%";
 
 /*
 **  CPR -- print on concept 108
 
 /*
 **  CPR -- print on concept 108
@@ -12,10 +12,22 @@ static char SccsId[] =      "@(#)cpr.c      1.1.1.1         %G%";
 **     models in the Concept 100 series also.
 **
 **     Usage:
 **     models in the Concept 100 series also.
 **
 **     Usage:
-**             cpr [file ...]
+**             cpr [-f] [file ...]
+**
+**     Flags:
+**             -f      form feed following to print.
 */
 
 */
 
+#define LINELEN        132                     /* carriage width */
+
+typedef char   bool;
+#define TRUE   1
+#define FALSE  0
+
 struct sgttyb  tbuf;
 struct sgttyb  tbuf;
+int            SysLinePid;             /* pid of sysline process */
+bool           FormFeedFollowing;      /* print form feed following print */
+bool           EchoDuringPrint;        /* echo on terminal while printing */
 
 main(argc, argv)
        int argc;
 
 main(argc, argv)
        int argc;
@@ -23,6 +35,30 @@ main(argc, argv)
 {
        register char *p;
        extern cleanterm();
 {
        register char *p;
        extern cleanterm();
+       extern char *getenv();
+
+       /* arrange to stop the sysline program during printing */
+       p = getenv("SYSLINE");
+       if (p != NULL)
+               SysLinePid = atoi(p);
+
+       /* process arguments */
+       while (--argc > 0)
+       {
+               p = *++argv;
+               if (*p != '-')
+                       break;
+               switch (*++p)
+               {
+                 case 'f':
+                       FormFeedFollowing = TRUE;
+                       break;
+
+                 case 'e':
+                       EchoDuringPrint = TRUE;
+                       break;
+               }
+       }
 
        /* be nice on interrupts, etc. */
        signal(SIGINT, cleanterm);
 
        /* be nice on interrupts, etc. */
        signal(SIGINT, cleanterm);
@@ -31,14 +67,15 @@ main(argc, argv)
        setupterm();
 
        /* print the appropriate files */
        setupterm();
 
        /* print the appropriate files */
-       if (argc < 2)
+       if (argc < 1)
                copyfile();
        else
        {
                copyfile();
        else
        {
-               while (--argc > 0)
+               while (argc-- > 0)
                {
                {
-                       if (freopen(*++argv, "r", stdin) == NULL)
-                               perror(*argv);
+                       p = *argv++;
+                       if (freopen(p, "r", stdin) == NULL)
+                               perror(p);
                        else
                                copyfile();
                }
                        else
                                copyfile();
                }
@@ -50,11 +87,6 @@ main(argc, argv)
 
 copyfile()
 {
 
 copyfile()
 {
-       char buf[200];
-       register char *p;
-       extern char *index();
-
-       while (fgets(buf, sizeof buf, stdin) != NULL)
        {
                p = index(buf, '\n');
                if (p == NULL)
        {
                p = index(buf, '\n');
                if (p == NULL)
@@ -81,13 +113,18 @@ setupterm()
        }
        oldflags = tbuf.sg_flags;
        tbuf.sg_flags &= ~ECHO;
        }
        oldflags = tbuf.sg_flags;
        tbuf.sg_flags &= ~ECHO;
-       tbuf.sg_flags |= CBREAK;
+       tbuf.sg_flags |= CBREAK | XTABS;
        stty(1, &tbuf);
        tbuf.sg_flags = oldflags;
 }
 
 cleanterm()
 {
        stty(1, &tbuf);
        tbuf.sg_flags = oldflags;
 }
 
 cleanterm()
 {
+       /* output trailing formfeed */
+       if (FormFeedFollowing)
+               fputs("\r\f", stdout);
+
+       /* disconnect printer */
        resetmodes();
        exit(0);
 }
        resetmodes();
        exit(0);
 }
@@ -105,4 +142,6 @@ getack()
 resetmodes()
 {
        stty(1, &tbuf);
 resetmodes()
 {
        stty(1, &tbuf);
+       if (SysLinePid > 0)
+               kill(SysLinePid, SIGCONT);
 }
 }