xref: /csrg-svn/usr.sbin/lpr/lpq/lpq.c (revision 42802)
122431Sdist /*
222431Sdist  * Copyright (c) 1983 Regents of the University of California.
334203Sbostic  * All rights reserved.
434203Sbostic  *
5*42802Sbostic  * %sccs.include.redist.c%
622431Sdist  */
722431Sdist 
813953Ssam #ifndef lint
922431Sdist char copyright[] =
1022431Sdist "@(#) Copyright (c) 1983 Regents of the University of California.\n\
1122431Sdist  All rights reserved.\n";
1234203Sbostic #endif /* not lint */
1313953Ssam 
1422431Sdist #ifndef lint
15*42802Sbostic static char sccsid[] = "@(#)lpq.c	5.6 (Berkeley) 06/01/90";
1634203Sbostic #endif /* not lint */
1722431Sdist 
1812108Sralph /*
1912108Sralph  * Spool Queue examination program
2012108Sralph  *
2130994Sbostic  * lpq [-l] [-Pprinter] [user...] [job...]
2212108Sralph  *
2330994Sbostic  * -l long output
2412108Sralph  * -P used to identify printer as per lpr/lprm
2512108Sralph  */
2612108Sralph 
2712108Sralph #include "lp.h"
2812108Sralph 
2912108Sralph char	*user[MAXUSERS];	/* users to process */
3012108Sralph int	users;			/* # of users in user array */
3112108Sralph int	requ[MAXREQUESTS];	/* job number of spool entries */
3212108Sralph int	requests;		/* # of spool requests */
3312108Sralph 
3412108Sralph main(argc, argv)
3530994Sbostic 	register int	argc;
3630994Sbostic 	register char	**argv;
3712108Sralph {
3830994Sbostic 	extern char	*optarg;
3930994Sbostic 	extern int	optind;
4030994Sbostic 	int	ch, lflag;		/* long output option */
4112108Sralph 
4230994Sbostic 	name = *argv;
4330994Sbostic 	if (gethostname(host, sizeof(host))) {
4430994Sbostic 		perror("lpq: gethostname");
4530994Sbostic 		exit(1);
4630994Sbostic 	}
4725495Seric 	openlog("lpd", 0, LOG_LPR);
4812431Sralph 
4930994Sbostic 	lflag = 0;
5030994Sbostic 	while ((ch = getopt(argc, argv, "lP:")) != EOF)
5130994Sbostic 		switch((char)ch) {
5230994Sbostic 		case 'l':			/* long output */
5330994Sbostic 			++lflag;
5430994Sbostic 			break;
5530994Sbostic 		case 'P':		/* printer name */
5630994Sbostic 			printer = optarg;
5730994Sbostic 			break;
5830994Sbostic 		case '?':
5930994Sbostic 		default:
6030994Sbostic 			usage();
6130994Sbostic 		}
6212108Sralph 
6312108Sralph 	if (printer == NULL && (printer = getenv("PRINTER")) == NULL)
6412108Sralph 		printer = DEFLP;
6512108Sralph 
6630994Sbostic 	for (argc -= optind, argv += optind; argc; --argc, ++argv)
6730994Sbostic 		if (isdigit(argv[0][0])) {
6830994Sbostic 			if (requests >= MAXREQUESTS)
6930994Sbostic 				fatal("too many requests");
7030994Sbostic 			requ[requests++] = atoi(*argv);
7112108Sralph 		}
7230994Sbostic 		else {
7330994Sbostic 			if (users >= MAXUSERS)
7430994Sbostic 				fatal("too many users");
7530994Sbostic 			user[users++] = *argv;
7630994Sbostic 		}
7730994Sbostic 
7830994Sbostic 	displayq(lflag);
7916103Sralph 	exit(0);
8012108Sralph }
8112108Sralph 
8212876Sralph static
8312108Sralph usage()
8412108Sralph {
8530994Sbostic 	puts("usage: lpq [-l] [-Pprinter] [user ...] [job ...]");
8612108Sralph 	exit(1);
8712108Sralph }
88