1 /* $NetBSD: lpq.c,v 1.18 2008/07/21 13:36:58 lukem Exp $ */
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/cdefs.h>
35 __COPYRIGHT("@(#) Copyright (c) 1983, 1993\
36 The Regents of the University of California. All rights reserved.");
38 static char sccsid
[] = "@(#)lpq.c 8.3 (Berkeley) 5/10/95";
40 __RCSID("$NetBSD: lpq.c,v 1.18 2008/07/21 13:36:58 lukem Exp $");
45 * Spool Queue examination program
47 * lpq [-a] [-l] [-Pprinter] [user...] [job...]
49 * -a show all non-null queues on the local machine
51 * -P used to identify printer as per lpr/lprm
54 #include <sys/param.h>
66 #include "pathnames.h"
68 int requ
[MAXREQUESTS
]; /* job number of spool entries */
69 int requests
; /* # of spool requests */
70 char *user
[MAXUSERS
]; /* users to process */
71 int users
; /* # of users in user array */
74 static void usage(void) __dead
;
77 main(int argc
, char *argv
[])
86 if (gethostname(host
, sizeof(host
)))
87 err(1, "lpq: gethostname");
88 host
[sizeof(host
) - 1] = '\0';
89 openlog("lpd", 0, LOG_LPR
);
92 while ((ch
= getopt(argc
, argv
, "alP:w:")) != -1)
97 case 'l': /* long output */
100 case 'P': /* printer name */
104 wait_time
= atoi(optarg
);
106 errx(1, "wait time must be postive: %s",
109 warnx("warning: wait time less than 30 seconds");
116 if (!aflag
&& printer
== NULL
&& (printer
= getenv("PRINTER")) == NULL
)
119 for (argc
-= optind
, argv
+= optind
; argc
; --argc
, ++argv
)
120 if (isdigit((unsigned char)argv
[0][0])) {
121 if (requests
>= MAXREQUESTS
)
122 fatal("too many requests");
123 requ
[requests
++] = atoi(*argv
);
126 if (users
>= MAXUSERS
)
127 fatal("too many users");
128 user
[users
++] = *argv
;
132 while (cgetnext(&buf
, printcapdb
) > 0) {
133 if (ckqueue(buf
) <= 0) {
135 continue; /* no jobs */
137 for (cp
= buf
; *cp
; cp
++)
138 if (*cp
== '|' || *cp
== ':') {
143 printf("%s:\n", printer
);
156 (void)fprintf(stderr
, "Usage: %s [-a] [-l] [-Pprinter] [-w maxwait] [user ...] [job ...]\n", getprogname());