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