2 * SPDX-License-Identifier: BSD-3-Clause
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
34 static const char copyright[] =
35 "@(#) Copyright (c) 1983, 1993\n\
36 The Regents of the University of California. All rights reserved.\n";
41 static char sccsid[] = "@(#)lpq.c 8.3 (Berkeley) 5/10/95";
45 #include "lp.cdefs.h" /* A cross-platform version of <sys/cdefs.h> */
46 __FBSDID("$FreeBSD$");
49 * Spool Queue examination program
51 * lpq [-a] [-l] [-Pprinter] [user...] [job...]
53 * -a show all non-null queues on the local machine
55 * -P used to identify printer as per lpr/lprm
58 #include <sys/param.h>
70 #include "pathnames.h"
72 int requ[MAXREQUESTS]; /* job number of spool entries */
73 int requests; /* # of spool requests */
74 char *user[MAXUSERS]; /* users to process */
75 int users; /* # of users in user array */
79 static int ckqueue(const struct printer *_pp);
80 static void usage(void);
81 int main(int _argc, char **_argv);
84 main(int argc, char **argv)
88 struct printer myprinter, *pp = &myprinter;
95 if (gethostname(local_host, sizeof(local_host)))
96 err(1, "gethostname");
97 openlog("lpd", 0, LOG_LPR);
100 while ((ch = getopt(argc, argv, "alP:")) != -1)
105 case 'l': /* long output */
108 case 'P': /* printer name */
116 if (!aflag && printer == NULL && (printer = getenv("PRINTER")) == NULL)
119 for (argc -= optind, argv += optind; argc; --argc, ++argv)
120 if (isdigit(argv[0][0])) {
121 if (requests >= MAXREQUESTS)
122 fatal(0, "too many requests");
123 requ[requests++] = atoi(*argv);
126 if (users >= MAXUSERS)
127 fatal(0, "too many users");
128 user[users++] = *argv;
134 more = firstprinter(pp, &status);
138 if (ckqueue(pp) > 0) {
139 printf("%s:\n", pp->printer);
144 more = nextprinter(pp, &status);
148 printf("warning: %s: unresolved "
151 case PCAPERR_SUCCESS:
154 fatal(pp, "%s", pcaperr(status));
156 } while (more && status);
162 status = getprintcap(printer, pp);
164 fatal(pp, "%s", pcaperr(status));
172 ckqueue(const struct printer *pp)
174 register struct dirent *d;
178 spooldir = pp->spool_dir;
179 if ((dirp = opendir(spooldir)) == NULL)
181 while ((d = readdir(dirp)) != NULL) {
182 if (d->d_name[0] != 'c' || d->d_name[1] != 'f')
183 continue; /* daemon control files only */
185 return (1); /* found something */
195 "usage: lpq [-a] [-l] [-Pprinter] [user ...] [job ...]\n");