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