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