# 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
** 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;
+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;
{
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);
setupterm();
/* print the appropriate files */
- if (argc < 2)
+ if (argc < 1)
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();
}
copyfile()
{
- char buf[200];
- register char *p;
- extern char *index();
-
- while (fgets(buf, sizeof buf, stdin) != NULL)
{
p = index(buf, '\n');
if (p == NULL)
}
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()
{
+ /* output trailing formfeed */
+ if (FormFeedFollowing)
+ fputs("\r\f", stdout);
+
+ /* disconnect printer */
resetmodes();
exit(0);
}
resetmodes()
{
stty(1, &tbuf);
+ if (SysLinePid > 0)
+ kill(SysLinePid, SIGCONT);
}