122431Sdist /* 222431Sdist * Copyright (c) 1983 Regents of the University of California. 334203Sbostic * All rights reserved. 434203Sbostic * 542802Sbostic * %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*55476Sbostic static char sccsid[] = "@(#)lpq.c 5.8 (Berkeley) 07/21/92"; 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 27*55476Sbostic #include <sys/param.h> 28*55476Sbostic 29*55476Sbostic #include <syslog.h> 30*55476Sbostic #include <dirent.h> 31*55476Sbostic #include <unistd.h> 32*55476Sbostic #include <stdlib.h> 33*55476Sbostic #include <stdio.h> 34*55476Sbostic #include <ctype.h> 3512108Sralph #include "lp.h" 36*55476Sbostic #include "lp.local.h" 3712108Sralph 3812108Sralph char *user[MAXUSERS]; /* users to process */ 3912108Sralph int users; /* # of users in user array */ 4012108Sralph int requ[MAXREQUESTS]; /* job number of spool entries */ 4112108Sralph int requests; /* # of spool requests */ 4212108Sralph 43*55476Sbostic void usage __P((void)); 44*55476Sbostic 45*55476Sbostic int 4612108Sralph main(argc, argv) 4730994Sbostic register int argc; 4830994Sbostic register char **argv; 4912108Sralph { 5030994Sbostic extern char *optarg; 5130994Sbostic extern int optind; 5230994Sbostic int ch, lflag; /* long output option */ 5312108Sralph 5430994Sbostic name = *argv; 5530994Sbostic if (gethostname(host, sizeof(host))) { 5630994Sbostic perror("lpq: gethostname"); 5730994Sbostic exit(1); 5830994Sbostic } 5925495Seric openlog("lpd", 0, LOG_LPR); 6012431Sralph 6130994Sbostic lflag = 0; 6230994Sbostic while ((ch = getopt(argc, argv, "lP:")) != EOF) 6330994Sbostic switch((char)ch) { 6430994Sbostic case 'l': /* long output */ 6530994Sbostic ++lflag; 6630994Sbostic break; 6730994Sbostic case 'P': /* printer name */ 6830994Sbostic printer = optarg; 6930994Sbostic break; 7030994Sbostic case '?': 7130994Sbostic default: 7230994Sbostic usage(); 7330994Sbostic } 7412108Sralph 7512108Sralph if (printer == NULL && (printer = getenv("PRINTER")) == NULL) 7612108Sralph printer = DEFLP; 7712108Sralph 7830994Sbostic for (argc -= optind, argv += optind; argc; --argc, ++argv) 7930994Sbostic if (isdigit(argv[0][0])) { 8030994Sbostic if (requests >= MAXREQUESTS) 8130994Sbostic fatal("too many requests"); 8230994Sbostic requ[requests++] = atoi(*argv); 8312108Sralph } 8430994Sbostic else { 8530994Sbostic if (users >= MAXUSERS) 8630994Sbostic fatal("too many users"); 8730994Sbostic user[users++] = *argv; 8830994Sbostic } 8930994Sbostic 9030994Sbostic displayq(lflag); 9116103Sralph exit(0); 9212108Sralph } 9312108Sralph 94*55476Sbostic void 9512108Sralph usage() 9612108Sralph { 9730994Sbostic puts("usage: lpq [-l] [-Pprinter] [user ...] [job ...]"); 9812108Sralph exit(1); 9912108Sralph } 100