| 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 | |
| 13 | #ifndef lint |
| 14 | static char sccsid[] = "@(#)lpq.c 5.3 (Berkeley) %G%"; |
| 15 | #endif not lint |
| 16 | |
| 17 | /* |
| 18 | * Spool Queue examination program |
| 19 | * |
| 20 | * lpq [-l] [-Pprinter] [user...] [job...] |
| 21 | * |
| 22 | * -l long output |
| 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 | |
| 33 | main(argc, argv) |
| 34 | register int argc; |
| 35 | register char **argv; |
| 36 | { |
| 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 | } |
| 46 | openlog("lpd", 0, LOG_LPR); |
| 47 | |
| 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(); |
| 60 | } |
| 61 | |
| 62 | if (printer == NULL && (printer = getenv("PRINTER")) == NULL) |
| 63 | printer = DEFLP; |
| 64 | |
| 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; |
| 75 | } |
| 76 | |
| 77 | displayq(lflag); |
| 78 | exit(0); |
| 79 | } |
| 80 | |
| 81 | static |
| 82 | usage() |
| 83 | { |
| 84 | puts("usage: lpq [-l] [-Pprinter] [user ...] [job ...]"); |
| 85 | exit(1); |
| 86 | } |