BSD 4_4 release
[unix-history] / usr / src / usr.sbin / lpr / common_source / displayq.c
index 5d08267..59d3cc9 100644 (file)
@@ -1,33 +1,58 @@
 /*
 /*
- * Copyright (c) 1983 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1983, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  *
- * Redistribution and use in source and binary forms are permitted provided
- * that: (1) source distributions retain this entire copyright notice and
- * comment, and (2) distributions including binaries display the following
- * acknowledgement:  ``This product includes software developed by the
- * University of California, Berkeley and its contributors'' in the
- * documentation or other materials provided with the distribution and in
- * all advertising materials mentioning features or use of this software.
- * 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * 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
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)displayq.c 5.13 (Berkeley) 6/1/90";
+static char sccsid[] = "@(#)displayq.c 8.1 (Berkeley) 6/6/93";
 #endif /* not lint */
 
 #endif /* not lint */
 
-/*
- * Routines to display the state of the queue.
- */
+#include <sys/param.h>
+#include <sys/stat.h>
 
 
+#include <signal.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
 #include "lp.h"
 #include "lp.h"
+#include "lp.local.h"
 #include "pathnames.h"
 
 #include "pathnames.h"
 
+/*
+ * Routines to display the state of the queue.
+ */
 #define JOBCOL 40              /* column for job # in -l format */
 #define OWNCOL 7               /* start of Owner column in normal */
 #define SIZCOL 62              /* start of Size column in normal */
 #define JOBCOL 40              /* column for job # in -l format */
 #define OWNCOL 7               /* start of Owner column in normal */
 #define SIZCOL 62              /* start of Size column in normal */
@@ -35,26 +60,27 @@ static char sccsid[] = "@(#)displayq.c      5.13 (Berkeley) 6/1/90";
 /*
  * Stuff for handling job specifications
  */
 /*
  * Stuff for handling job specifications
  */
-extern char    *user[];        /* users to process */
-extern int     users;          /* # of users in user array */
 extern int     requ[];         /* job number of spool entries */
 extern int     requests;       /* # of spool requests */
 extern int     requ[];         /* job number of spool entries */
 extern int     requests;       /* # of spool requests */
+extern char    *user[];                /* users to process */
+extern int     users;          /* # of users in user array */
 
 
-int    lflag;          /* long output option */
-char   current[40];    /* current file being printed */
-int    garbage;        /* # of garbage cf files */
-int    rank;           /* order to be printed (-1=none, 0=active) */
-long   totsize;        /* total print job size in bytes */
-int    first;          /* first file in ``files'' column? */
-int    col;            /* column on screen */
-char   file[132];      /* print file name */
+static int     col;            /* column on screen */
+static char    current[40];    /* current file being printed */
+static char    file[132];      /* print file name */
+static int     first;          /* first file in ``files'' column? */
+static int     garbage;        /* # of garbage cf files */
+static int     lflag;          /* long output option */
+static int     rank;           /* order to be printed (-1=none, 0=active) */
+static long    totsize;        /* total print job size in bytes */
 
 
-char   *head0 = "Rank   Owner      Job  Files";
-char   *head1 = "Total Size\n";
+static char    *head0 = "Rank   Owner      Job  Files";
+static char    *head1 = "Total Size\n";
 
 /*
  * Display the current state of the queue. Format = 1 if long format.
  */
 
 /*
  * Display the current state of the queue. Format = 1 if long format.
  */
+void
 displayq(format)
        int format;
 {
 displayq(format)
        int format;
 {
@@ -64,27 +90,27 @@ displayq(format)
        struct queue **queue;
        struct stat statb;
        FILE *fp;
        struct queue **queue;
        struct stat statb;
        FILE *fp;
-       char c;
 
        lflag = format;
        totsize = 0;
        rank = -1;
 
        lflag = format;
        totsize = 0;
        rank = -1;
-
-       if ((i = pgetent(line, printer)) < 0)
-               fatal("cannot open printer description file");
-       else if (i == 0)
+       if ((i = cgetent(&bp, printcapdb, printer)) == -2)
+               fatal("can't open printer description file");
+       else if (i == -1)
                fatal("unknown printer");
                fatal("unknown printer");
-       if ((LP = pgetstr("lp", &bp)) == NULL)
+       else if (i == -3)
+               fatal("potential reference loop detected in printcap file");
+       if (cgetstr(bp, "lp", &LP) < 0)
                LP = _PATH_DEFDEVLP;
                LP = _PATH_DEFDEVLP;
-       if ((RP = pgetstr("rp", &bp)) == NULL)
+       if (cgetstr(bp, "rp", &RP) < 0)
                RP = DEFLP;
                RP = DEFLP;
-       if ((SD = pgetstr("sd", &bp)) == NULL)
+       if (cgetstr(bp, "sd", &SD) < 0)
                SD = _PATH_DEFSPOOL;
                SD = _PATH_DEFSPOOL;
-       if ((LO = pgetstr("lo", &bp)) == NULL)
+       if (cgetstr(bp,"lo", &LO) < 0)
                LO = DEFLOCK;
                LO = DEFLOCK;
-       if ((ST = pgetstr("st", &bp)) == NULL)
+       if (cgetstr(bp, "st", &ST) < 0)
                ST = DEFSTAT;
                ST = DEFSTAT;
-       RM = pgetstr("rm", &bp);
+       cgetstr(bp, "rm", &RM);
        if (cp = checkremote())
                printf("Warning: %s\n", cp);
 
        if (cp = checkremote())
                printf("Warning: %s\n", cp);
 
@@ -208,6 +234,7 @@ displayq(format)
 /*
  * Print a warning message if there is no daemon present.
  */
 /*
  * Print a warning message if there is no daemon present.
  */
+void
 warn()
 {
        if (sendtorem)
 warn()
 {
        if (sendtorem)
@@ -219,6 +246,7 @@ warn()
 /*
  * Print the header for the short listing format
  */
 /*
  * Print the header for the short listing format
  */
+void
 header()
 {
        printf(head0);
 header()
 {
        printf(head0);
@@ -227,11 +255,11 @@ header()
        printf(head1);
 }
 
        printf(head1);
 }
 
+void
 inform(cf)
        char *cf;
 {
 inform(cf)
        char *cf;
 {
-       register int j, k;
-       register char *cp;
+       register int j;
        FILE *cfp;
 
        /*
        FILE *cfp;
 
        /*
@@ -289,6 +317,7 @@ inform(cf)
        }
 }
 
        }
 }
 
+int
 inlist(name, file)
        char *name, *file;
 {
 inlist(name, file)
        char *name, *file;
 {
@@ -314,8 +343,10 @@ inlist(name, file)
        return(0);
 }
 
        return(0);
 }
 
+void
 show(nfile, file, copies)
        register char *nfile, *file;
 show(nfile, file, copies)
        register char *nfile, *file;
+       int copies;
 {
        if (strcmp(nfile, " ") == 0)
                nfile = "(standard input)";
 {
        if (strcmp(nfile, " ") == 0)
                nfile = "(standard input)";
@@ -328,6 +359,7 @@ show(nfile, file, copies)
 /*
  * Fill the line with blanks to the specified column
  */
 /*
  * Fill the line with blanks to the specified column
  */
+void
 blankfill(n)
        register int n;
 {
 blankfill(n)
        register int n;
 {
@@ -338,8 +370,10 @@ blankfill(n)
 /*
  * Give the abbreviated dump of the file names
  */
 /*
  * Give the abbreviated dump of the file names
  */
+void
 dump(nfile, file, copies)
        char *nfile, *file;
 dump(nfile, file, copies)
        char *nfile, *file;
+       int copies;
 {
        register short n, fill;
        struct stat lbuf;
 {
        register short n, fill;
        struct stat lbuf;
@@ -369,8 +403,10 @@ dump(nfile, file, copies)
 /*
  * Print the long info about the file
  */
 /*
  * Print the long info about the file
  */
+void
 ldump(nfile, file, copies)
        char *nfile, *file;
 ldump(nfile, file, copies)
        char *nfile, *file;
+       int copies;
 {
        struct stat lbuf;
 
 {
        struct stat lbuf;
 
@@ -380,7 +416,7 @@ ldump(nfile, file, copies)
        else
                printf("%-32s", nfile);
        if (*file && !stat(file, &lbuf))
        else
                printf("%-32s", nfile);
        if (*file && !stat(file, &lbuf))
-               printf(" %ld bytes", lbuf.st_size);
+               printf(" %qd bytes", lbuf.st_size);
        else
                printf(" ??? bytes");
        putchar('\n');
        else
                printf(" ??? bytes");
        putchar('\n');
@@ -390,9 +426,11 @@ ldump(nfile, file, copies)
  * Print the job's rank in the queue,
  *   update col for screen management
  */
  * Print the job's rank in the queue,
  *   update col for screen management
  */
+void
 prank(n)
 prank(n)
+       int n;
 {
 {
-       char line[100];
+       char rline[100];
        static char *r[] = {
                "th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th"
        };
        static char *r[] = {
                "th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th"
        };
@@ -403,9 +441,9 @@ prank(n)
                return;
        }
        if ((n/10)%10 == 1)
                return;
        }
        if ((n/10)%10 == 1)
-               (void) sprintf(line, "%dth", n);
+               (void)snprintf(rline, sizeof(rline), "%dth", n);
        else
        else
-               (void) sprintf(line, "%d%s", n, r[n%10]);
-       col += strlen(line);
-       printf("%s", line);
+               (void)snprintf(rline, sizeof(rline), "%d%s", n, r[n%10]);
+       col += strlen(rline);
+       printf("%s", rline);
 }
 }