xref: /original-bsd/usr.sbin/lpr/lpq/lpq.c (revision c3e32dec)
1 /*
2  * Copyright (c) 1983, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  *
6  * %sccs.include.redist.c%
7  */
8 
9 #ifndef lint
10 static char copyright[] =
11 "@(#) Copyright (c) 1983, 1993\n\
12 	The Regents of the University of California.  All rights reserved.\n";
13 #endif /* not lint */
14 
15 #ifndef lint
16 static char sccsid[] = "@(#)lpq.c	8.1 (Berkeley) 06/06/93";
17 #endif /* not lint */
18 
19 /*
20  * Spool Queue examination program
21  *
22  * lpq [-l] [-Pprinter] [user...] [job...]
23  *
24  * -l long output
25  * -P used to identify printer as per lpr/lprm
26  */
27 
28 #include <sys/param.h>
29 
30 #include <syslog.h>
31 #include <dirent.h>
32 #include <unistd.h>
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <ctype.h>
36 #include "lp.h"
37 #include "lp.local.h"
38 
39 int	 requ[MAXREQUESTS];	/* job number of spool entries */
40 int	 requests;		/* # of spool requests */
41 char	*user[MAXUSERS];	/* users to process */
42 int	 users;			/* # of users in user array */
43 
44 void usage __P((void));
45 
46 int
47 main(argc, argv)
48 	register int	argc;
49 	register char	**argv;
50 {
51 	extern char	*optarg;
52 	extern int	optind;
53 	int	ch, lflag;		/* long output option */
54 
55 	name = *argv;
56 	if (gethostname(host, sizeof(host))) {
57 		perror("lpq: gethostname");
58 		exit(1);
59 	}
60 	openlog("lpd", 0, LOG_LPR);
61 
62 	lflag = 0;
63 	while ((ch = getopt(argc, argv, "lP:")) != EOF)
64 		switch((char)ch) {
65 		case 'l':			/* long output */
66 			++lflag;
67 			break;
68 		case 'P':		/* printer name */
69 			printer = optarg;
70 			break;
71 		case '?':
72 		default:
73 			usage();
74 		}
75 
76 	if (printer == NULL && (printer = getenv("PRINTER")) == NULL)
77 		printer = DEFLP;
78 
79 	for (argc -= optind, argv += optind; argc; --argc, ++argv)
80 		if (isdigit(argv[0][0])) {
81 			if (requests >= MAXREQUESTS)
82 				fatal("too many requests");
83 			requ[requests++] = atoi(*argv);
84 		}
85 		else {
86 			if (users >= MAXUSERS)
87 				fatal("too many users");
88 			user[users++] = *argv;
89 		}
90 
91 	displayq(lflag);
92 	exit(0);
93 }
94 
95 void
96 usage()
97 {
98 	puts("usage: lpq [-l] [-Pprinter] [user ...] [job ...]");
99 	exit(1);
100 }
101