1 /* 2 * Copyright (c) 1983 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that the above copyright notice and this paragraph are 7 * duplicated in all such forms and that any documentation, 8 * advertising materials, and other materials related to such 9 * distribution and use acknowledge that the software was developed 10 * by the University of California, Berkeley. The name of the 11 * University may not be used to endorse or promote products derived 12 * from this software without specific prior written permission. 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 */ 17 18 #ifndef lint 19 char copyright[] = 20 "@(#) Copyright (c) 1983 Regents of the University of California.\n\ 21 All rights reserved.\n"; 22 #endif /* not lint */ 23 24 #ifndef lint 25 static char sccsid[] = "@(#)lpq.c 5.5 (Berkeley) 06/30/88"; 26 #endif /* not lint */ 27 28 /* 29 * Spool Queue examination program 30 * 31 * lpq [-l] [-Pprinter] [user...] [job...] 32 * 33 * -l long output 34 * -P used to identify printer as per lpr/lprm 35 */ 36 37 #include "lp.h" 38 39 char *user[MAXUSERS]; /* users to process */ 40 int users; /* # of users in user array */ 41 int requ[MAXREQUESTS]; /* job number of spool entries */ 42 int requests; /* # of spool requests */ 43 44 main(argc, argv) 45 register int argc; 46 register char **argv; 47 { 48 extern char *optarg; 49 extern int optind; 50 int ch, lflag; /* long output option */ 51 52 name = *argv; 53 if (gethostname(host, sizeof(host))) { 54 perror("lpq: gethostname"); 55 exit(1); 56 } 57 openlog("lpd", 0, LOG_LPR); 58 59 lflag = 0; 60 while ((ch = getopt(argc, argv, "lP:")) != EOF) 61 switch((char)ch) { 62 case 'l': /* long output */ 63 ++lflag; 64 break; 65 case 'P': /* printer name */ 66 printer = optarg; 67 break; 68 case '?': 69 default: 70 usage(); 71 } 72 73 if (printer == NULL && (printer = getenv("PRINTER")) == NULL) 74 printer = DEFLP; 75 76 for (argc -= optind, argv += optind; argc; --argc, ++argv) 77 if (isdigit(argv[0][0])) { 78 if (requests >= MAXREQUESTS) 79 fatal("too many requests"); 80 requ[requests++] = atoi(*argv); 81 } 82 else { 83 if (users >= MAXUSERS) 84 fatal("too many users"); 85 user[users++] = *argv; 86 } 87 88 displayq(lflag); 89 exit(0); 90 } 91 92 static 93 usage() 94 { 95 puts("usage: lpq [-l] [-Pprinter] [user ...] [job ...]"); 96 exit(1); 97 } 98