xref: /original-bsd/usr.sbin/lpr/lpq/lpq.c (revision 5d3a6356)
1 /*
2  * Copyright (c) 1983 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of California at Berkeley. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  */
12 
13 #ifndef lint
14 char copyright[] =
15 "@(#) Copyright (c) 1983 Regents of the University of California.\n\
16  All rights reserved.\n";
17 #endif /* not lint */
18 
19 #ifndef lint
20 static char sccsid[] = "@(#)lpq.c	5.4 (Berkeley) 05/05/88";
21 #endif /* not lint */
22 
23 /*
24  * Spool Queue examination program
25  *
26  * lpq [-l] [-Pprinter] [user...] [job...]
27  *
28  * -l long output
29  * -P used to identify printer as per lpr/lprm
30  */
31 
32 #include "lp.h"
33 
34 char	*user[MAXUSERS];	/* users to process */
35 int	users;			/* # of users in user array */
36 int	requ[MAXREQUESTS];	/* job number of spool entries */
37 int	requests;		/* # of spool requests */
38 
39 main(argc, argv)
40 	register int	argc;
41 	register char	**argv;
42 {
43 	extern char	*optarg;
44 	extern int	optind;
45 	int	ch, lflag;		/* long output option */
46 
47 	name = *argv;
48 	if (gethostname(host, sizeof(host))) {
49 		perror("lpq: gethostname");
50 		exit(1);
51 	}
52 	openlog("lpd", 0, LOG_LPR);
53 
54 	lflag = 0;
55 	while ((ch = getopt(argc, argv, "lP:")) != EOF)
56 		switch((char)ch) {
57 		case 'l':			/* long output */
58 			++lflag;
59 			break;
60 		case 'P':		/* printer name */
61 			printer = optarg;
62 			break;
63 		case '?':
64 		default:
65 			usage();
66 		}
67 
68 	if (printer == NULL && (printer = getenv("PRINTER")) == NULL)
69 		printer = DEFLP;
70 
71 	for (argc -= optind, argv += optind; argc; --argc, ++argv)
72 		if (isdigit(argv[0][0])) {
73 			if (requests >= MAXREQUESTS)
74 				fatal("too many requests");
75 			requ[requests++] = atoi(*argv);
76 		}
77 		else {
78 			if (users >= MAXUSERS)
79 				fatal("too many users");
80 			user[users++] = *argv;
81 		}
82 
83 	displayq(lflag);
84 	exit(0);
85 }
86 
87 static
88 usage()
89 {
90 	puts("usage: lpq [-l] [-Pprinter] [user ...] [job ...]");
91 	exit(1);
92 }
93