122431Sdist /* 222431Sdist * Copyright (c) 1983 Regents of the University of California. 334203Sbostic * All rights reserved. 434203Sbostic * 5*56125Selan * Redistribution and use in source and binary forms, with or without 6*56125Selan * modification, are permitted provided that the following conditions 7*56125Selan * are met: 8*56125Selan * 1. Redistributions of source code must retain the above copyright 9*56125Selan * notice, this list of conditions and the following disclaimer. 10*56125Selan * 2. Redistributions in binary form must reproduce the above copyright 11*56125Selan * notice, this list of conditions and the following disclaimer in the 12*56125Selan * documentation and/or other materials provided with the distribution. 13*56125Selan * 3. All advertising materials mentioning features or use of this software 14*56125Selan * must display the following acknowledgement: 15*56125Selan * This product includes software developed by the University of 16*56125Selan * California, Berkeley and its contributors. 17*56125Selan * 4. Neither the name of the University nor the names of its contributors 18*56125Selan * may be used to endorse or promote products derived from this software 19*56125Selan * without specific prior written permission. 20*56125Selan * 21*56125Selan * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22*56125Selan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23*56125Selan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24*56125Selan * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25*56125Selan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26*56125Selan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27*56125Selan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28*56125Selan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29*56125Selan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30*56125Selan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31*56125Selan * SUCH DAMAGE. 3222431Sdist */ 3322431Sdist 3413953Ssam #ifndef lint 3522431Sdist char copyright[] = 3622431Sdist "@(#) Copyright (c) 1983 Regents of the University of California.\n\ 3722431Sdist All rights reserved.\n"; 3834203Sbostic #endif /* not lint */ 3913953Ssam 4022431Sdist #ifndef lint 41*56125Selan static char sccsid[] = "@(#)lpq.c 5.9 (Berkeley) 8/6/92"; 4234203Sbostic #endif /* not lint */ 4322431Sdist 4412108Sralph /* 4512108Sralph * Spool Queue examination program 4612108Sralph * 4730994Sbostic * lpq [-l] [-Pprinter] [user...] [job...] 4812108Sralph * 4930994Sbostic * -l long output 5012108Sralph * -P used to identify printer as per lpr/lprm 5112108Sralph */ 5212108Sralph 5355476Sbostic #include <sys/param.h> 5455476Sbostic 5555476Sbostic #include <syslog.h> 5655476Sbostic #include <dirent.h> 5755476Sbostic #include <unistd.h> 5855476Sbostic #include <stdlib.h> 5955476Sbostic #include <stdio.h> 6055476Sbostic #include <ctype.h> 6112108Sralph #include "lp.h" 6255476Sbostic #include "lp.local.h" 6312108Sralph 64*56125Selan int requ[MAXREQUESTS]; /* job number of spool entries */ 65*56125Selan int requests; /* # of spool requests */ 6612108Sralph char *user[MAXUSERS]; /* users to process */ 67*56125Selan int users; /* # of users in user array */ 6812108Sralph 6955476Sbostic void usage __P((void)); 7055476Sbostic 7155476Sbostic int 7212108Sralph main(argc, argv) 7330994Sbostic register int argc; 7430994Sbostic register char **argv; 7512108Sralph { 7630994Sbostic extern char *optarg; 7730994Sbostic extern int optind; 7830994Sbostic int ch, lflag; /* long output option */ 7912108Sralph 8030994Sbostic name = *argv; 8130994Sbostic if (gethostname(host, sizeof(host))) { 8230994Sbostic perror("lpq: gethostname"); 8330994Sbostic exit(1); 8430994Sbostic } 8525495Seric openlog("lpd", 0, LOG_LPR); 8612431Sralph 8730994Sbostic lflag = 0; 8830994Sbostic while ((ch = getopt(argc, argv, "lP:")) != EOF) 8930994Sbostic switch((char)ch) { 9030994Sbostic case 'l': /* long output */ 9130994Sbostic ++lflag; 9230994Sbostic break; 9330994Sbostic case 'P': /* printer name */ 9430994Sbostic printer = optarg; 9530994Sbostic break; 9630994Sbostic case '?': 9730994Sbostic default: 9830994Sbostic usage(); 9930994Sbostic } 10012108Sralph 10112108Sralph if (printer == NULL && (printer = getenv("PRINTER")) == NULL) 10212108Sralph printer = DEFLP; 10312108Sralph 10430994Sbostic for (argc -= optind, argv += optind; argc; --argc, ++argv) 10530994Sbostic if (isdigit(argv[0][0])) { 10630994Sbostic if (requests >= MAXREQUESTS) 10730994Sbostic fatal("too many requests"); 10830994Sbostic requ[requests++] = atoi(*argv); 10912108Sralph } 11030994Sbostic else { 11130994Sbostic if (users >= MAXUSERS) 11230994Sbostic fatal("too many users"); 11330994Sbostic user[users++] = *argv; 11430994Sbostic } 11530994Sbostic 11630994Sbostic displayq(lflag); 11716103Sralph exit(0); 11812108Sralph } 11912108Sralph 12055476Sbostic void 12112108Sralph usage() 12212108Sralph { 12330994Sbostic puts("usage: lpq [-l] [-Pprinter] [user ...] [job ...]"); 12412108Sralph exit(1); 12512108Sralph } 126