BSD 4_4 release
[unix-history] / usr / src / old / vfilters / vcat / vcat.c
index 7276722..b612267 100644 (file)
@@ -1,18 +1,56 @@
-/*     vcat.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, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#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[] = "@(#)vcat.c     5.6 (Berkeley) 2/15/91";
+#endif /* not lint */
+
 /*
  * Cat Simulator for Versatec and Varian
  */ 
 
 /*
  * Cat Simulator for Versatec and Varian
  */ 
 
-#include <errno.h>
-#include <signal.h>
 #include <stdio.h>
 #include <stdio.h>
-#include <sgtty.h>
-#include <pwd.h>
 #include <sys/vcmd.h>
 #include <vfont.h>
 
 #include <sys/vcmd.h>
 #include <vfont.h>
 
-int    prtmode[] = {VPRINT, 0, 0};
-int    pltmode[] = {VPLOT, 0, 0};
+int    prtmode[] = {VPRINT};
+int    pltmode[] = {VPLOT};
 
 #define DISPATCHSIZE           256     /* must be a power of two */
 #define CHARMASK               (DISPATCHSIZE-1)
 
 #define DISPATCHSIZE           256     /* must be a power of two */
 #define CHARMASK               (DISPATCHSIZE-1)
@@ -27,16 +65,10 @@ int pltmode[] = {VPLOT, 0, 0};
 #define CONVERT(n)             (n*(200./432.))
 #define RECONVERT(n)           (n*(432./200.))
 
 #define CONVERT(n)             (n*(200./432.))
 #define RECONVERT(n)           (n*(432./200.))
 
-#define VA_RASTER_LENGTH       2112
-#define VP_RASTER_LENGTH       7040
-#define VA_BYTES_PER_LINE      (VA_RASTER_LENGTH/8)
-#define VP_BYTES_PER_LINE      (VP_RASTER_LENGTH/8)
 #define NLINES                 110
 #define NLINES                 110
-#define VA_BUFFER_SIZE         (NLINES*VA_BYTES_PER_LINE)
-#define VP_BUFFER_SIZE         (NLINES*VP_BYTES_PER_LINE)
 
 
-char   buffer[VP_BUFFER_SIZE]; /* Big line buffers  */
-char   *buf0p = &buffer[0];    /* Zero origin in circular buffer  */
+char   buffer[NLINES * 880];   /* Big enough for versatec */
+char   *buf0p = &buffer[0];    /* Zero origin in circular buffer */
 
 char   *calloc();
 char   *nalloc();
 
 char   *calloc();
 char   *nalloc();
@@ -77,16 +109,13 @@ struct point_sizes {
        0, 0
 };
 
        0, 0
 };
 
-#define VA_FFLINES     2200
-#define VP_FFLINES     650
-#define VP_EOTLINES    1400
-
 int    lines;
 
 int    lines;
 
-int    vc = 1;         /* varian/versatec output file descriptor */
-int    varian;         /* 0 for versatec, 1 for varian. */
-int    BYTES_PER_LINE; /* VA_BYTES_PER_LINE or VP_BYTES_PER_LINE. */
-int    BUFFER_SIZE;    /* VA_BUFFER_SIZE or VP_BUFFER_SIZE. */
+int    vc = 1;                 /* varian/versatec output file descriptor */
+int    varian;                 /* 0 for versatec, 1 for varian. */
+int    BYTES_PER_LINE = 880;   /* number of bytes per raster line. */
+int    PAGE_LINES = 2400;      /* number of raster lines per page. */
+int    BUFFER_SIZE = NLINES * 880;     /* buffer size. */
 int    cfnum = -1;
 int    cpsize = 10;
 int    cfont = 1;
 int    cfnum = -1;
 int    cpsize = 10;
 int    cfont = 1;
@@ -322,7 +351,7 @@ char spectab[128] = {
        '{',    /*{*/
        '}',    /*}*/
        '\'',   /*' acute accent*/
        '{',    /*{*/
        '}',    /*}*/
        '\'',   /*' acute accent*/
-       '\`',   /*` grave accent*/
+       '`',    /*` grave accent*/
        '^',    /*^*/
        '#',    /*sharp*/
        '\036', /*left hand*/
        '^',    /*^*/
        '#',    /*sharp*/
        '\036', /*left hand*/
@@ -341,48 +370,26 @@ char spectab[128] = {
        '8'     /*section mark*/
 };
 
        '8'     /*section mark*/
 };
 
-
-onintr()
-{
-       signal(SIGINT, SIG_IGN);
-       signal(SIGHUP, SIG_IGN);
-       signal(SIGTERM, SIG_IGN);
-       exit(1);
-}
-
 main(argc, argv) 
        int argc;
        char *argv[];
 {
 main(argc, argv) 
        int argc;
        char *argv[];
 {
-       char *namearg;
-       char *hostarg;
-       char *acctfile;
-
-       if (signal(SIGINT, SIG_IGN) == SIG_DFL) {
-               signal(SIGPIPE, SIG_IGN);
-               signal(SIGINT, onintr);
-               signal(SIGHUP, onintr);
-       } else
-               signal(SIGHUP, SIG_IGN);
-       if (signal(SIGTERM, SIG_IGN) == SIG_DFL)
-               signal(SIGTERM, onintr);
-
-       varian = 1;     /* Default is the varian */
-       namearg = NULL;
-       hostarg = NULL;
-       acctfile = NULL;
-       BYTES_PER_LINE = VA_BYTES_PER_LINE;
-       BUFFER_SIZE = VA_BUFFER_SIZE;
-
-       if (argv[0][strlen(argv[0])-1] == 'W') { /* Wide: the versatec. */
-               varian = 0;
-               BYTES_PER_LINE = VP_BYTES_PER_LINE;
-               BUFFER_SIZE = VP_BUFFER_SIZE;
-       }
+       char *namearg = NULL;
+       char *hostarg = NULL;
+       char *acctfile = NULL;
 
        while (--argc) {
                if (*(*++argv) == '-')
                        switch (argv[0][1]) {
 
        while (--argc) {
                if (*(*++argv) == '-')
                        switch (argv[0][1]) {
+                       case 'x':
+                               BYTES_PER_LINE = atoi(&argv[0][2]) / 8;
+                               BUFFER_SIZE = NLINES * BYTES_PER_LINE;
+                               varian = BYTES_PER_LINE == 264;
+                               break;
+
+                       case 'y':
+                               PAGE_LINES = atoi(&argv[0][2]);
+                               break;
 
                        case 'n':
                                if (argc > 1) {
 
                        case 'n':
                                if (argc > 1) {
@@ -397,10 +404,6 @@ main(argc, argv)
                                        hostarg = *++argv;
                                }
                                break;
                                        hostarg = *++argv;
                                }
                                break;
-
-                       default:
-                               fprintf(stderr, "usage: vcat[W] [-n name] [-h host] [accounting file]\n");
-                               exit(2);
                        }
                else
                        acctfile = *argv;
                        }
                else
                        acctfile = *argv;
@@ -430,7 +433,7 @@ readrm()
                        exit(2);
                }
        cp = fnbuf;
                        exit(2);
                }
        cp = fnbuf;
-       for (i = 0; i < 4; i++) {
+       for (i = 0; i < MAXF; i++) {
                fontname[i] = cp;
                while (read(rmfd, &c, 1) == 1 && c != '\n')
                        *cp++ = c;
                fontname[i] = cp;
                while (read(rmfd, &c, 1) == 1 && c != '\n')
                        *cp++ = c;
@@ -586,7 +589,7 @@ findsize(code)
                code = -code;
        esc += code;
        last_ssize = psp->stupid_code;
                code = -code;
        esc += code;
        last_ssize = psp->stupid_code;
-       return (psp->real_code);
+       return(psp->real_code);
 }
 
 account(who, from, acctfile)
 }
 
 account(who, from, acctfile)
@@ -599,10 +602,10 @@ account(who, from, acctfile)
        if (access(acctfile, 02) || (a = fopen(acctfile, "a")) == NULL)
                return;
        /*
        if (access(acctfile, 02) || (a = fopen(acctfile, "a")) == NULL)
                return;
        /*
-        * Varian accounting is done by 11 inch pages;
+        * Varian accounting is done by 8.5 inch pages;
         * Versatec accounting is by the (12 inch) foot.
         */
         * Versatec accounting is by the (12 inch) foot.
         */
-       fprintf(a, "t%6.2f\t", (lines / 200.0) / (varian ? 11.0 : 12.0));
+       fprintf(a, "t%6.2f\t", (double)lines / (double)PAGE_LINES);
        if (from != NULL)
                fprintf(a, "%s:", from);
        fprintf(a, "%s\n", who);
        if (from != NULL)
                fprintf(a, "%s:", from);
        fprintf(a, "%s\n", who);
@@ -638,7 +641,7 @@ loadfont(fnum, size)
                        dispatch = &fontdes[i].disp[0];
                        bits = fontdes[i].bits;
                        cfont = i;
                        dispatch = &fontdes[i].disp[0];
                        bits = fontdes[i].bits;
                        cfont = i;
-                       return (0);
+                       return(0);
                }
        if (fnum < 0 || fnum >= MAXF) {
                fprintf(stderr, "vcat: Internal error: illegal font\n");
                }
        if (fnum < 0 || fnum >= MAXF) {
                fprintf(stderr, "vcat: Internal error: illegal font\n");
@@ -647,7 +650,7 @@ loadfont(fnum, size)
        nfontnum = fnum;
        npsize = size;
        fontwanted++;
        nfontnum = fnum;
        npsize = size;
        fontwanted++;
-       return (0);
+       return(0);
 }
 
 
 }
 
 
@@ -664,9 +667,10 @@ getfont()
        sprintf(cbuf, "%s.%d", fontname[fnum], size);
        font = open(cbuf, 0);
        if (font == -1) {
        sprintf(cbuf, "%s.%d", fontname[fnum], size);
        font = open(cbuf, 0);
        if (font == -1) {
+               fprintf(stderr, "vcat: ");
                perror(cbuf);
                fontwanted = 0;
                perror(cbuf);
                fontwanted = 0;
-               return (-1);
+               return(-1);
        }
        if (read(font, &header, sizeof header)!=sizeof header || header.magic!=0436)
                fprintf(stderr, "vcat: %s: Bad font file", cbuf);
        }
        if (read(font, &header, sizeof header)!=sizeof header || header.magic!=0436)
                fprintf(stderr, "vcat: %s: Bad font file", cbuf);
@@ -695,7 +699,7 @@ getfont()
                                fontdes[cfont].disp = (struct dispatch *) d;
                                dispatch = &fontdes[cfont].disp[0];
                                fontwanted = 0;
                                fontdes[cfont].disp = (struct dispatch *) d;
                                dispatch = &fontdes[cfont].disp[0];
                                fontwanted = 0;
-                               return (0);
+                               return(0);
                        }
                }
        }
                        }
                }
        }
@@ -704,7 +708,7 @@ getfont()
        return(-1);
 }
 
        return(-1);
 }
 
-int lastloaded = -1;
+int lastloaded = -1;
 
 relfont()
 {
 
 relfont()
 {
@@ -723,7 +727,7 @@ relfont()
        if ((int)fontdes[newfont].bits != -1 && fontdes[newfont].bits != 0)
                nfree(fontdes[newfont].bits);
        fontdes[newfont].bits = 0;
        if ((int)fontdes[newfont].bits != -1 && fontdes[newfont].bits != 0)
                nfree(fontdes[newfont].bits);
        fontdes[newfont].bits = 0;
-       return (newfont);
+       return(newfont);
 }
 
 char *
 }
 
 char *
@@ -805,9 +809,9 @@ outc(code)
                        scanp += scanp_inc+count;
                        addr += count;
                }
                        scanp += scanp_inc+count;
                        addr += count;
                }
-               return (1);
+               return(1);
        }
        }
-       return (0);
+       return(0);
 }
 
 slop_lines(nlines)
 }
 
 slop_lines(nlines)
@@ -820,7 +824,7 @@ slop_lines(nlines)
        if (rlines < nlines) {
                if (write(vc, buf0p, BYTES_PER_LINE * rlines) < 0)
                        exit(1);
        if (rlines < nlines) {
                if (write(vc, buf0p, BYTES_PER_LINE * rlines) < 0)
                        exit(1);
-               clear(buf0p, rlines * BYTES_PER_LINE);
+               bzero(buf0p, rlines * BYTES_PER_LINE);
                buf0p = buffer;
                nlines -= rlines;
                xpos -= rlines;
                buf0p = buffer;
                nlines -= rlines;
                xpos -= rlines;
@@ -828,7 +832,7 @@ slop_lines(nlines)
        }
        if (write(vc, buf0p, BYTES_PER_LINE * nlines) < 0)
                exit(1);
        }
        if (write(vc, buf0p, BYTES_PER_LINE * nlines) < 0)
                exit(1);
-       clear(buf0p, BYTES_PER_LINE * nlines);
+       bzero(buf0p, BYTES_PER_LINE * nlines);
        buf0p += BYTES_PER_LINE * nlines;
        if (buf0p >= &buffer[BUFFER_SIZE])
                buf0p -= BUFFER_SIZE;
        buf0p += BYTES_PER_LINE * nlines;
        if (buf0p >= &buffer[BUFFER_SIZE])
                buf0p -= BUFFER_SIZE;
@@ -837,14 +841,6 @@ slop_lines(nlines)
        /* ioctl(vc, VSETSTATE, pltmode);  WHY? */
 }
 
        /* ioctl(vc, VSETSTATE, pltmode);  WHY? */
 }
 
-/*ARGSUSED*/
-clear(lp, nbytes)
-       int *lp;
-       int nbytes;
-{
-       asm("movc5 $0,(sp),$0,8(ap),*4(ap)");
-}
-
 char *
 nalloc(i, j)
        int i, j;
 char *
 nalloc(i, j)
        int i, j;