1
/* $OpenBSD: lpq.c,v 1.7 1997/01/17 16:12:44 millert 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. All advertising materials mentioning features or use of this software
17
* must display the following acknowledgement:
18
* This product includes software developed by the University of
19
* California, Berkeley and its contributors.
20
* 4. Neither the name of the University nor the names of its contributors
21
* may be used to endorse or promote products derived from this software
22
* without specific prior written permission.
24
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38
static char copyright[] =
39
"@(#) Copyright (c) 1983, 1993\n\
40
The Regents of the University of California. All rights reserved.\n";
45
static char sccsid[] = "@(#)lpq.c 8.3 (Berkeley) 5/10/95";
47
static char rcsid[] = "$OpenBSD: lpq.c,v 1.7 1997/01/17 16:12:44 millert Exp $";
52
* Spool Queue examination program
54
* lpq [-a] [-l] [-Pprinter] [user...] [job...]
56
* -a show all non-null queues on the local machine
58
* -P used to identify printer as per lpr/lprm
61
#include <sys/param.h>
71
#include "pathnames.h"
73
int requ[MAXREQUESTS]; /* job number of spool entries */
74
int requests; /* # of spool requests */
75
char *user[MAXUSERS]; /* users to process */
76
int users; /* # of users in user array */
80
static int ckqueue __P((char *));
81
void usage __P((void));
97
if (gethostname(host, sizeof(host))) {
98
perror("lpq: gethostname");
101
openlog("lpd", 0, LOG_LPR);
104
while ((ch = getopt(argc, argv, "alP:")) != -1)
109
case 'l': /* long output */
112
case 'P': /* printer name */
120
if (!aflag && printer == NULL) {
124
if ((p = getenv("PRINTER")) != NULL)
128
for (argc -= optind, argv += optind; argc; --argc, ++argv)
129
if (isdigit(argv[0][0])) {
130
if (requests >= MAXREQUESTS)
131
fatal("too many requests");
132
requ[requests++] = atoi(*argv);
135
if (users >= MAXUSERS)
136
fatal("too many users");
137
user[users++] = *argv;
141
while (cgetnext(&buf, printcapdb) > 0) {
142
if (ckqueue(buf) <= 0) {
144
continue; /* no jobs */
146
for (cp = buf; *cp; cp++)
147
if (*cp == '|' || *cp == ':') {
152
printf("%s:\n", printer);
166
register struct dirent *d;
170
if (cgetstr(cap, "sd", &spooldir) == -1)
171
spooldir = _PATH_DEFSPOOL;
172
if ((dirp = opendir(spooldir)) == NULL)
174
while ((d = readdir(dirp)) != NULL) {
175
if (d->d_name[0] != 'c' || d->d_name[1] != 'f')
176
continue; /* daemon control files only */
178
return (1); /* found something */
187
puts("usage: lpq [-a] [-l] [-Pprinter] [user ...] [job ...]");