1 /* 2 * Copyright (c) 1983 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 char copyright[] = 10 "@(#) Copyright (c) 1983 Regents of the University of California.\n\ 11 All rights reserved.\n"; 12 #endif /* not lint */ 13 14 #ifndef lint 15 static char sccsid[] = "@(#)lpq.c 5.8 (Berkeley) 07/21/92"; 16 #endif /* not lint */ 17 18 /* 19 * Spool Queue examination program 20 * 21 * lpq [-l] [-Pprinter] [user...] [job...] 22 * 23 * -l long output 24 * -P used to identify printer as per lpr/lprm 25 */ 26 27 #include <sys/param.h> 28 29 #include <syslog.h> 30 #include <dirent.h> 31 #include <unistd.h> 32 #include <stdlib.h> 33 #include <stdio.h> 34 #include <ctype.h> 35 #include "lp.h" 36 #include "lp.local.h" 37 38 char *user[MAXUSERS]; /* users to process */ 39 int users; /* # of users in user array */ 40 int requ[MAXREQUESTS]; /* job number of spool entries */ 41 int requests; /* # of spool requests */ 42 43 void usage __P((void)); 44 45 int 46 main(argc, argv) 47 register int argc; 48 register char **argv; 49 { 50 extern char *optarg; 51 extern int optind; 52 int ch, lflag; /* long output option */ 53 54 name = *argv; 55 if (gethostname(host, sizeof(host))) { 56 perror("lpq: gethostname"); 57 exit(1); 58 } 59 openlog("lpd", 0, LOG_LPR); 60 61 lflag = 0; 62 while ((ch = getopt(argc, argv, "lP:")) != EOF) 63 switch((char)ch) { 64 case 'l': /* long output */ 65 ++lflag; 66 break; 67 case 'P': /* printer name */ 68 printer = optarg; 69 break; 70 case '?': 71 default: 72 usage(); 73 } 74 75 if (printer == NULL && (printer = getenv("PRINTER")) == NULL) 76 printer = DEFLP; 77 78 for (argc -= optind, argv += optind; argc; --argc, ++argv) 79 if (isdigit(argv[0][0])) { 80 if (requests >= MAXREQUESTS) 81 fatal("too many requests"); 82 requ[requests++] = atoi(*argv); 83 } 84 else { 85 if (users >= MAXUSERS) 86 fatal("too many users"); 87 user[users++] = *argv; 88 } 89 90 displayq(lflag); 91 exit(0); 92 } 93 94 void 95 usage() 96 { 97 puts("usage: lpq [-l] [-Pprinter] [user ...] [job ...]"); 98 exit(1); 99 } 100