Commit | Line | Data |
---|---|---|
d0aeaf5a DF |
1 | /* |
2 | * Copyright (c) 1983 Regents of the University of California. | |
9d85c861 KB |
3 | * All rights reserved. |
4 | * | |
5 | * Redistribution and use in source and binary forms are permitted | |
a399f6c8 KB |
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. | |
d0aeaf5a DF |
16 | */ |
17 | ||
18 | #ifndef lint | |
19 | char copyright[] = | |
20 | "@(#) Copyright (c) 1983 Regents of the University of California.\n\ | |
21 | All rights reserved.\n"; | |
9d85c861 | 22 | #endif /* not lint */ |
d0aeaf5a | 23 | |
5f84f8f0 | 24 | #ifndef lint |
a399f6c8 | 25 | static char sccsid[] = "@(#)lpq.c 5.5 (Berkeley) %G%"; |
9d85c861 | 26 | #endif /* not lint */ |
5f84f8f0 | 27 | |
dd8e3649 RC |
28 | /* |
29 | * Spool Queue examination program | |
30 | * | |
1098f423 | 31 | * lpq [-l] [-Pprinter] [user...] [job...] |
dd8e3649 | 32 | * |
1098f423 | 33 | * -l long output |
dd8e3649 RC |
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 | ||
dd8e3649 | 44 | main(argc, argv) |
1098f423 KB |
45 | register int argc; |
46 | register char **argv; | |
dd8e3649 | 47 | { |
1098f423 KB |
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 | } | |
126fc76f | 57 | openlog("lpd", 0, LOG_LPR); |
4d4caa50 | 58 | |
1098f423 KB |
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(); | |
dd8e3649 | 71 | } |
1098f423 | 72 | |
dd8e3649 RC |
73 | if (printer == NULL && (printer = getenv("PRINTER")) == NULL) |
74 | printer = DEFLP; | |
dd8e3649 | 75 | |
1098f423 KB |
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; | |
dd8e3649 | 86 | } |
1098f423 KB |
87 | |
88 | displayq(lflag); | |
1e7e612e | 89 | exit(0); |
dd8e3649 RC |
90 | } |
91 | ||
54266d1f | 92 | static |
dd8e3649 RC |
93 | usage() |
94 | { | |
1098f423 | 95 | puts("usage: lpq [-l] [-Pprinter] [user ...] [job ...]"); |
dd8e3649 RC |
96 | exit(1); |
97 | } |