xref: /csrg-svn/usr.sbin/lpr/lpq/lpq.c (revision 61845)
122431Sdist /*
2*61845Sbostic  * Copyright (c) 1983, 1993
3*61845Sbostic  *	The Regents of the University of California.  All rights reserved.
434203Sbostic  *
556125Selan  *
656252Selan  * %sccs.include.redist.c%
722431Sdist  */
822431Sdist 
913953Ssam #ifndef lint
1056266Selan static char copyright[] =
11*61845Sbostic "@(#) Copyright (c) 1983, 1993\n\
12*61845Sbostic 	The Regents of the University of California.  All rights reserved.\n";
1334203Sbostic #endif /* not lint */
1413953Ssam 
1522431Sdist #ifndef lint
16*61845Sbostic static char sccsid[] = "@(#)lpq.c	8.1 (Berkeley) 06/06/93";
1734203Sbostic #endif /* not lint */
1822431Sdist 
1912108Sralph /*
2012108Sralph  * Spool Queue examination program
2112108Sralph  *
2230994Sbostic  * lpq [-l] [-Pprinter] [user...] [job...]
2312108Sralph  *
2430994Sbostic  * -l long output
2512108Sralph  * -P used to identify printer as per lpr/lprm
2612108Sralph  */
2712108Sralph 
2855476Sbostic #include <sys/param.h>
2955476Sbostic 
3055476Sbostic #include <syslog.h>
3155476Sbostic #include <dirent.h>
3255476Sbostic #include <unistd.h>
3355476Sbostic #include <stdlib.h>
3455476Sbostic #include <stdio.h>
3555476Sbostic #include <ctype.h>
3612108Sralph #include "lp.h"
3755476Sbostic #include "lp.local.h"
3812108Sralph 
3956125Selan int	 requ[MAXREQUESTS];	/* job number of spool entries */
4056125Selan int	 requests;		/* # of spool requests */
4112108Sralph char	*user[MAXUSERS];	/* users to process */
4256125Selan int	 users;			/* # of users in user array */
4312108Sralph 
4455476Sbostic void usage __P((void));
4555476Sbostic 
4655476Sbostic int
4712108Sralph main(argc, argv)
4830994Sbostic 	register int	argc;
4930994Sbostic 	register char	**argv;
5012108Sralph {
5130994Sbostic 	extern char	*optarg;
5230994Sbostic 	extern int	optind;
5330994Sbostic 	int	ch, lflag;		/* long output option */
5412108Sralph 
5530994Sbostic 	name = *argv;
5630994Sbostic 	if (gethostname(host, sizeof(host))) {
5730994Sbostic 		perror("lpq: gethostname");
5830994Sbostic 		exit(1);
5930994Sbostic 	}
6025495Seric 	openlog("lpd", 0, LOG_LPR);
6112431Sralph 
6230994Sbostic 	lflag = 0;
6330994Sbostic 	while ((ch = getopt(argc, argv, "lP:")) != EOF)
6430994Sbostic 		switch((char)ch) {
6530994Sbostic 		case 'l':			/* long output */
6630994Sbostic 			++lflag;
6730994Sbostic 			break;
6830994Sbostic 		case 'P':		/* printer name */
6930994Sbostic 			printer = optarg;
7030994Sbostic 			break;
7130994Sbostic 		case '?':
7230994Sbostic 		default:
7330994Sbostic 			usage();
7430994Sbostic 		}
7512108Sralph 
7612108Sralph 	if (printer == NULL && (printer = getenv("PRINTER")) == NULL)
7712108Sralph 		printer = DEFLP;
7812108Sralph 
7930994Sbostic 	for (argc -= optind, argv += optind; argc; --argc, ++argv)
8030994Sbostic 		if (isdigit(argv[0][0])) {
8130994Sbostic 			if (requests >= MAXREQUESTS)
8230994Sbostic 				fatal("too many requests");
8330994Sbostic 			requ[requests++] = atoi(*argv);
8412108Sralph 		}
8530994Sbostic 		else {
8630994Sbostic 			if (users >= MAXUSERS)
8730994Sbostic 				fatal("too many users");
8830994Sbostic 			user[users++] = *argv;
8930994Sbostic 		}
9030994Sbostic 
9130994Sbostic 	displayq(lflag);
9216103Sralph 	exit(0);
9312108Sralph }
9412108Sralph 
9555476Sbostic void
9612108Sralph usage()
9712108Sralph {
9830994Sbostic 	puts("usage: lpq [-l] [-Pprinter] [user ...] [job ...]");
9912108Sralph 	exit(1);
10012108Sralph }
101