Commit | Line | Data |
---|---|---|
d0aeaf5a | 1 | /* |
ad787160 C |
2 | * Copyright (c) 1983, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
9d85c861 | 4 | * |
853a196e | 5 | * |
ad787160 C |
6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions | |
8 | * are met: | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * 2. Redistributions in binary form must reproduce the above copyright | |
12 | * notice, this list of conditions and the following disclaimer in the | |
13 | * documentation and/or other materials provided with the distribution. | |
14 | * 3. All advertising materials mentioning features or use of this software | |
15 | * must display the following acknowledgement: | |
16 | * This product includes software developed by the University of | |
17 | * California, Berkeley and its contributors. | |
18 | * 4. Neither the name of the University nor the names of its contributors | |
19 | * may be used to endorse or promote products derived from this software | |
20 | * without specific prior written permission. | |
21 | * | |
22 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
32 | * SUCH DAMAGE. | |
d0aeaf5a DF |
33 | */ |
34 | ||
35 | #ifndef lint | |
63fd8427 | 36 | static char copyright[] = |
ad787160 C |
37 | "@(#) Copyright (c) 1983, 1993\n\ |
38 | The Regents of the University of California. All rights reserved.\n"; | |
9d85c861 | 39 | #endif /* not lint */ |
d0aeaf5a | 40 | |
5f84f8f0 | 41 | #ifndef lint |
ad787160 | 42 | static char sccsid[] = "@(#)lpq.c 8.1 (Berkeley) 6/6/93"; |
9d85c861 | 43 | #endif /* not lint */ |
5f84f8f0 | 44 | |
dd8e3649 RC |
45 | /* |
46 | * Spool Queue examination program | |
47 | * | |
1098f423 | 48 | * lpq [-l] [-Pprinter] [user...] [job...] |
dd8e3649 | 49 | * |
1098f423 | 50 | * -l long output |
dd8e3649 RC |
51 | * -P used to identify printer as per lpr/lprm |
52 | */ | |
53 | ||
6ce2d98b KB |
54 | #include <sys/param.h> |
55 | ||
56 | #include <syslog.h> | |
57 | #include <dirent.h> | |
58 | #include <unistd.h> | |
59 | #include <stdlib.h> | |
60 | #include <stdio.h> | |
61 | #include <ctype.h> | |
dd8e3649 | 62 | #include "lp.h" |
6ce2d98b | 63 | #include "lp.local.h" |
dd8e3649 | 64 | |
853a196e EA |
65 | int requ[MAXREQUESTS]; /* job number of spool entries */ |
66 | int requests; /* # of spool requests */ | |
dd8e3649 | 67 | char *user[MAXUSERS]; /* users to process */ |
853a196e | 68 | int users; /* # of users in user array */ |
dd8e3649 | 69 | |
6ce2d98b | 70 | void usage __P((void)); |
dd8e3649 | 71 | |
6ce2d98b | 72 | int |
dd8e3649 | 73 | main(argc, argv) |
1098f423 KB |
74 | register int argc; |
75 | register char **argv; | |
dd8e3649 | 76 | { |
1098f423 KB |
77 | extern char *optarg; |
78 | extern int optind; | |
79 | int ch, lflag; /* long output option */ | |
80 | ||
81 | name = *argv; | |
82 | if (gethostname(host, sizeof(host))) { | |
83 | perror("lpq: gethostname"); | |
84 | exit(1); | |
85 | } | |
126fc76f | 86 | openlog("lpd", 0, LOG_LPR); |
4d4caa50 | 87 | |
1098f423 KB |
88 | lflag = 0; |
89 | while ((ch = getopt(argc, argv, "lP:")) != EOF) | |
90 | switch((char)ch) { | |
91 | case 'l': /* long output */ | |
92 | ++lflag; | |
93 | break; | |
94 | case 'P': /* printer name */ | |
95 | printer = optarg; | |
96 | break; | |
97 | case '?': | |
98 | default: | |
99 | usage(); | |
dd8e3649 | 100 | } |
1098f423 | 101 | |
dd8e3649 RC |
102 | if (printer == NULL && (printer = getenv("PRINTER")) == NULL) |
103 | printer = DEFLP; | |
dd8e3649 | 104 | |
1098f423 KB |
105 | for (argc -= optind, argv += optind; argc; --argc, ++argv) |
106 | if (isdigit(argv[0][0])) { | |
107 | if (requests >= MAXREQUESTS) | |
108 | fatal("too many requests"); | |
109 | requ[requests++] = atoi(*argv); | |
110 | } | |
111 | else { | |
112 | if (users >= MAXUSERS) | |
113 | fatal("too many users"); | |
114 | user[users++] = *argv; | |
dd8e3649 | 115 | } |
1098f423 KB |
116 | |
117 | displayq(lflag); | |
1e7e612e | 118 | exit(0); |
dd8e3649 RC |
119 | } |
120 | ||
6ce2d98b | 121 | void |
dd8e3649 RC |
122 | usage() |
123 | { | |
1098f423 | 124 | puts("usage: lpq [-l] [-Pprinter] [user ...] [job ...]"); |
dd8e3649 RC |
125 | exit(1); |
126 | } |