xref: /csrg-svn/usr.sbin/lpr/lpq/lpq.c (revision 34203)
122431Sdist /*
222431Sdist  * Copyright (c) 1983 Regents of the University of California.
3*34203Sbostic  * All rights reserved.
4*34203Sbostic  *
5*34203Sbostic  * Redistribution and use in source and binary forms are permitted
6*34203Sbostic  * provided that this notice is preserved and that due credit is given
7*34203Sbostic  * to the University of California at Berkeley. The name of the University
8*34203Sbostic  * may not be used to endorse or promote products derived from this
9*34203Sbostic  * software without specific prior written permission. This software
10*34203Sbostic  * is provided ``as is'' without express or implied warranty.
1122431Sdist  */
1222431Sdist 
1313953Ssam #ifndef lint
1422431Sdist char copyright[] =
1522431Sdist "@(#) Copyright (c) 1983 Regents of the University of California.\n\
1622431Sdist  All rights reserved.\n";
17*34203Sbostic #endif /* not lint */
1813953Ssam 
1922431Sdist #ifndef lint
20*34203Sbostic static char sccsid[] = "@(#)lpq.c	5.4 (Berkeley) 05/05/88";
21*34203Sbostic #endif /* not lint */
2222431Sdist 
2312108Sralph /*
2412108Sralph  * Spool Queue examination program
2512108Sralph  *
2630994Sbostic  * lpq [-l] [-Pprinter] [user...] [job...]
2712108Sralph  *
2830994Sbostic  * -l long output
2912108Sralph  * -P used to identify printer as per lpr/lprm
3012108Sralph  */
3112108Sralph 
3212108Sralph #include "lp.h"
3312108Sralph 
3412108Sralph char	*user[MAXUSERS];	/* users to process */
3512108Sralph int	users;			/* # of users in user array */
3612108Sralph int	requ[MAXREQUESTS];	/* job number of spool entries */
3712108Sralph int	requests;		/* # of spool requests */
3812108Sralph 
3912108Sralph main(argc, argv)
4030994Sbostic 	register int	argc;
4130994Sbostic 	register char	**argv;
4212108Sralph {
4330994Sbostic 	extern char	*optarg;
4430994Sbostic 	extern int	optind;
4530994Sbostic 	int	ch, lflag;		/* long output option */
4612108Sralph 
4730994Sbostic 	name = *argv;
4830994Sbostic 	if (gethostname(host, sizeof(host))) {
4930994Sbostic 		perror("lpq: gethostname");
5030994Sbostic 		exit(1);
5130994Sbostic 	}
5225495Seric 	openlog("lpd", 0, LOG_LPR);
5312431Sralph 
5430994Sbostic 	lflag = 0;
5530994Sbostic 	while ((ch = getopt(argc, argv, "lP:")) != EOF)
5630994Sbostic 		switch((char)ch) {
5730994Sbostic 		case 'l':			/* long output */
5830994Sbostic 			++lflag;
5930994Sbostic 			break;
6030994Sbostic 		case 'P':		/* printer name */
6130994Sbostic 			printer = optarg;
6230994Sbostic 			break;
6330994Sbostic 		case '?':
6430994Sbostic 		default:
6530994Sbostic 			usage();
6630994Sbostic 		}
6712108Sralph 
6812108Sralph 	if (printer == NULL && (printer = getenv("PRINTER")) == NULL)
6912108Sralph 		printer = DEFLP;
7012108Sralph 
7130994Sbostic 	for (argc -= optind, argv += optind; argc; --argc, ++argv)
7230994Sbostic 		if (isdigit(argv[0][0])) {
7330994Sbostic 			if (requests >= MAXREQUESTS)
7430994Sbostic 				fatal("too many requests");
7530994Sbostic 			requ[requests++] = atoi(*argv);
7612108Sralph 		}
7730994Sbostic 		else {
7830994Sbostic 			if (users >= MAXUSERS)
7930994Sbostic 				fatal("too many users");
8030994Sbostic 			user[users++] = *argv;
8130994Sbostic 		}
8230994Sbostic 
8330994Sbostic 	displayq(lflag);
8416103Sralph 	exit(0);
8512108Sralph }
8612108Sralph 
8712876Sralph static
8812108Sralph usage()
8912108Sralph {
9030994Sbostic 	puts("usage: lpq [-l] [-Pprinter] [user ...] [job ...]");
9112108Sralph 	exit(1);
9212108Sralph }
93