add USL's copyright notice
[unix-history] / usr / src / usr.sbin / lpr / common_source / common.c
index 0b77e0c..aabffb5 100644 (file)
@@ -1,83 +1,97 @@
 /*
 /*
- * 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.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
  *
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, 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'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * %sccs.include.redist.c%
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)common.c   5.5 (Berkeley) %G%";
+static char sccsid[] = "@(#)common.c   8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
+#include <sys/param.h>
+#include <sys/stat.h>
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+
+#include <dirent.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "lp.h"
+#include "pathnames.h"
+
 /*
  * Routines and data common to all the line printer functions.
  */
 
 /*
  * Routines and data common to all the line printer functions.
  */
 
-#include "lp.h"
-
-int    DU;             /* daeomon user-id */
-int    MX;             /* maximum number of blocks to copy */
-int    MC;             /* maximum number of copies allowed */
-char   *LP;            /* line printer device name */
-char   *RM;            /* remote machine name */
-char   *RP;            /* remote printer name */
-char   *LO;            /* lock file name */
-char   *ST;            /* status file name */
-char   *SD;            /* spool directory */
 char   *AF;            /* accounting file */
 char   *AF;            /* accounting file */
+long    BR;            /* baud rate if lp is a tty */
+char   *CF;            /* name of cifplot filter (per job) */
+char   *DF;            /* name of tex filter (per job) */
+long    DU;            /* daeomon user-id */
+long    FC;            /* flags to clear if lp is a tty */
+char   *FF;            /* form feed string */
+long    FS;            /* flags to set if lp is a tty */
+char   *GF;            /* name of graph(1G) filter (per job) */
+long    HL;            /* print header last */
+char   *IF;            /* name of input filter (created per job) */
 char   *LF;            /* log file for error messages */
 char   *LF;            /* log file for error messages */
+char   *LO;            /* lock file name */
+char   *LP;            /* line printer device name */
+long    MC;            /* maximum number of copies allowed */
+long    MX;            /* maximum number of blocks to copy */
+char   *NF;            /* name of ditroff filter (per job) */
 char   *OF;            /* name of output filter (created once) */
 char   *OF;            /* name of output filter (created once) */
-char   *IF;            /* name of input filter (created per job) */
+char   *PF;            /* name of vrast filter (per job) */
+long    PL;            /* page length */
+long    PW;            /* page width */
+long    PX;            /* page width in pixels */
+long    PY;            /* page length in pixels */
 char   *RF;            /* name of fortran text filter (per job) */
 char   *RF;            /* name of fortran text filter (per job) */
+char    *RG;           /* resricted group */
+char   *RM;            /* remote machine name */
+char   *RP;            /* remote printer name */
+long    RS;            /* restricted to those with local accounts */
+long    RW;            /* open LP for reading and writing */
+long    SB;            /* short banner instead of normal header */
+long    SC;            /* suppress multiple copies */
+char   *SD;            /* spool directory */
+long    SF;            /* suppress FF on each print job */
+long    SH;            /* suppress header page */
+char   *ST;            /* status file name */
 char   *TF;            /* name of troff filter (per job) */
 char   *TF;            /* name of troff filter (per job) */
-char   *NF;            /* name of ditroff filter (per job) */
-char   *DF;            /* name of tex filter (per job) */
-char   *GF;            /* name of graph(1G) filter (per job) */
-char   *VF;            /* name of vplot filter (per job) */
-char   *CF;            /* name of cifplot filter (per job) */
-char   *PF;            /* name of vrast filter (per job) */
-char   *FF;            /* form feed string */
 char   *TR;            /* trailer string to be output when Q empties */
 char   *TR;            /* trailer string to be output when Q empties */
-short  SC;             /* suppress multiple copies */
-short  SF;             /* suppress FF on each print job */
-short  SH;             /* suppress header page */
-short  SB;             /* short banner instead of normal header */
-short  HL;             /* print header last */
-short  RW;             /* open LP for reading and writing */
-short  PW;             /* page width */
-short  PL;             /* page length */
-short  PX;             /* page width in pixels */
-short  PY;             /* page length in pixels */
-short  BR;             /* baud rate if lp is a tty */
-int    FC;             /* flags to clear if lp is a tty */
-int    FS;             /* flags to set if lp is a tty */
-int    XC;             /* flags to clear for local mode */
-int    XS;             /* flags to set for local mode */
-short  RS;             /* restricted to those with local accounts */
+char   *VF;            /* name of vplot filter (per job) */
+long    XC;            /* flags to clear for local mode */
+long    XS;            /* flags to set for local mode */
 
 char   line[BUFSIZ];
 
 char   line[BUFSIZ];
-char   pbuf[BUFSIZ/2]; /* buffer for printcap strings */
-char   *bp = pbuf;     /* pointer into pbuf for pgetent() */
+char   *bp;            /* pointer into printcap buffer. */
 char   *name;          /* program name */
 char   *printer;       /* printer name */
 char   *name;          /* program name */
 char   *printer;       /* printer name */
-char   host[32];       /* host machine name */
+                       /* host machine name */
+char   host[MAXHOSTNAMELEN];
 char   *from = host;   /* client's machine name */
 int    sendtorem;      /* are we sending to a remote? */
 char   *from = host;   /* client's machine name */
 int    sendtorem;      /* are we sending to a remote? */
+char   *printcapdb[2] = { _PATH_PRINTCAP, 0 };
+
+static int compar __P((const void *, const void *));
 
 /*
  * Create a connection to the remote printer server.
  * Most of this code comes from rcmd.c.
  */
 
 /*
  * Create a connection to the remote printer server.
  * Most of this code comes from rcmd.c.
  */
+int
 getport(rhost)
        char *rhost;
 {
 getport(rhost)
        char *rhost;
 {
@@ -110,7 +124,7 @@ retry:
        s = rresvport(&lport);
        if (s < 0)
                return(-1);
        s = rresvport(&lport);
        if (s < 0)
                return(-1);
-       if (connect(s, (caddr_t)&sin, sizeof(sin)) < 0) {
+       if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
                err = errno;
                (void) close(s);
                errno = err;
                err = errno;
                (void) close(s);
                errno = err;
@@ -133,6 +147,7 @@ retry:
  *  new-line to null and leaves it in line.
  * Returns 0 at EOF or the number of characters read.
  */
  *  new-line to null and leaves it in line.
  * Returns 0 at EOF or the number of characters read.
  */
+int
 getline(cfp)
        FILE *cfp;
 {
 getline(cfp)
        FILE *cfp;
 {
@@ -162,15 +177,16 @@ getline(cfp)
  * creation time.
  * Return the number of entries and a pointer to the list.
  */
  * creation time.
  * Return the number of entries and a pointer to the list.
  */
+int
 getq(namelist)
        struct queue *(*namelist[]);
 {
 getq(namelist)
        struct queue *(*namelist[]);
 {
-       register struct direct *d;
+       register struct dirent *d;
        register struct queue *q, **queue;
        register int nitems;
        struct stat stbuf;
        register struct queue *q, **queue;
        register int nitems;
        struct stat stbuf;
-       int arraysz, compar();
        DIR *dirp;
        DIR *dirp;
+       int arraysz;
 
        if ((dirp = opendir(SD)) == NULL)
                return(-1);
 
        if ((dirp = opendir(SD)) == NULL)
                return(-1);
@@ -223,13 +239,13 @@ errdone:
 /*
  * Compare modification times.
  */
 /*
  * Compare modification times.
  */
-static
+static int
 compar(p1, p2)
 compar(p1, p2)
-       register struct queue **p1, **p2;
+       const void *p1, *p2;
 {
 {
-       if ((*p1)->q_time < (*p2)->q_time)
+       if ((*(struct queue **)p1)->q_time < (*(struct queue **)p2)->q_time)
                return(-1);
                return(-1);
-       if ((*p1)->q_time > (*p2)->q_time)
+       if ((*(struct queue **)p1)->q_time > (*(struct queue **)p2)->q_time)
                return(1);
        return(0);
 }
                return(1);
        return(0);
 }
@@ -252,7 +268,7 @@ checkremote()
                name[sizeof(name)-1] = '\0';
                hp = gethostbyname(name);
                if (hp == (struct hostent *) NULL) {
                name[sizeof(name)-1] = '\0';
                hp = gethostbyname(name);
                if (hp == (struct hostent *) NULL) {
-                   (void) sprintf(errbuf,
+                   (void) snprintf(errbuf, sizeof(errbuf),
                        "unable to get official name for local machine %s",
                        name);
                    return errbuf;
                        "unable to get official name for local machine %s",
                        name);
                    return errbuf;
@@ -261,7 +277,7 @@ checkremote()
                /* get the official name of RM */
                hp = gethostbyname(RM);
                if (hp == (struct hostent *) NULL) {
                /* get the official name of RM */
                hp = gethostbyname(RM);
                if (hp == (struct hostent *) NULL) {
-                   (void) sprintf(errbuf,
+                   (void) snprintf(errbuf, sizeof(errbuf),
                        "unable to get official name for remote machine %s",
                        RM);
                    return errbuf;
                        "unable to get official name for remote machine %s",
                        RM);
                    return errbuf;
@@ -277,16 +293,34 @@ checkremote()
        return (char *)0;
 }
 
        return (char *)0;
 }
 
-/*VARARGS1*/
-fatal(msg, a1, a2, a3)
+#if __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+
+void
+#if __STDC__
+fatal(const char *msg, ...)
+#else
+fatal(msg, va_alist)
        char *msg;
        char *msg;
+        va_dcl
+#endif
 {
 {
+       va_list ap;
+#if __STDC__
+       va_start(ap, msg);
+#else
+       va_start(ap);
+#endif
        if (from != host)
        if (from != host)
-               printf("%s: ", host);
-       printf("%s: ", name);
+               (void)printf("%s: ", host);
+       (void)printf("%s: ", name);
        if (printer)
        if (printer)
-               printf("%s: ", printer);
-       printf(msg, a1, a2, a3);
-       putchar('\n');
+               (void)printf("%s: ", printer);
+       (void)vprintf(msg, ap);
+       va_end(ap);
+       (void)putchar('\n');
        exit(1);
 }
        exit(1);
 }