lpq.c revision 1.3
1/*
2 * Copyright (c) 1983, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 *    must display the following acknowledgement:
16 *	This product includes software developed by the University of
17 *	California, Berkeley and its contributors.
18 * 4. Neither the name of the University nor the names of its contributors
19 *    may be used to endorse or promote products derived from this software
20 *    without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35#ifndef lint
36static char copyright[] =
37"@(#) Copyright (c) 1983, 1993\n\
38	The Regents of the University of California.  All rights reserved.\n";
39#endif /* not lint */
40
41#ifndef lint
42static char sccsid[] = "@(#)lpq.c	8.1 (Berkeley) 6/6/93";
43#endif /* not lint */
44
45/*
46 * Spool Queue examination program
47 *
48 * lpq [-l] [-Pprinter] [user...] [job...]
49 *
50 * -l long output
51 * -P used to identify printer as per lpr/lprm
52 */
53
54#include <sys/param.h>
55
56#include <syslog.h>
57#include <dirent.h>
58#include <unistd.h>
59#include <stdlib.h>
60#include <stdio.h>
61#include <ctype.h>
62#include "lp.h"
63#include "lp.local.h"
64
65int	 requ[MAXREQUESTS];	/* job number of spool entries */
66int	 requests;		/* # of spool requests */
67char	*user[MAXUSERS];	/* users to process */
68int	 users;			/* # of users in user array */
69
70void usage __P((void));
71
72int
73main(argc, argv)
74	register int	argc;
75	register char	**argv;
76{
77	extern char	*optarg;
78	extern int	optind;
79	int	ch, lflag;		/* long output option */
80
81	name = *argv;
82	if (gethostname(host, sizeof(host))) {
83		perror("lpq: gethostname");
84		exit(1);
85	}
86	openlog("lpd", 0, LOG_LPR);
87
88	lflag = 0;
89	while ((ch = getopt(argc, argv, "lP:")) != EOF)
90		switch((char)ch) {
91		case 'l':			/* long output */
92			++lflag;
93			break;
94		case 'P':		/* printer name */
95			printer = optarg;
96			break;
97		case '?':
98		default:
99			usage();
100		}
101
102	if (printer == NULL && (printer = getenv("PRINTER")) == NULL)
103		printer = DEFLP;
104
105	for (argc -= optind, argv += optind; argc; --argc, ++argv)
106		if (isdigit(argv[0][0])) {
107			if (requests >= MAXREQUESTS)
108				fatal("too many requests");
109			requ[requests++] = atoi(*argv);
110		}
111		else {
112			if (users >= MAXUSERS)
113				fatal("too many users");
114			user[users++] = *argv;
115		}
116
117	displayq(lflag);
118	exit(0);
119}
120
121void
122usage()
123{
124	puts("usage: lpq [-l] [-Pprinter] [user ...] [job ...]");
125	exit(1);
126}
127