122431Sdist /* 222431Sdist * Copyright (c) 1983 Regents of the University of California. 322431Sdist * All rights reserved. The Berkeley software License Agreement 422431Sdist * specifies the terms and conditions for redistribution. 522431Sdist */ 622431Sdist 713953Ssam #ifndef lint 822431Sdist char copyright[] = 922431Sdist "@(#) Copyright (c) 1983 Regents of the University of California.\n\ 1022431Sdist All rights reserved.\n"; 1122431Sdist #endif not lint 1213953Ssam 1322431Sdist #ifndef lint 14*30994Sbostic static char sccsid[] = "@(#)lpq.c 5.3 (Berkeley) 04/30/87"; 1522431Sdist #endif not lint 1622431Sdist 1712108Sralph /* 1812108Sralph * Spool Queue examination program 1912108Sralph * 20*30994Sbostic * lpq [-l] [-Pprinter] [user...] [job...] 2112108Sralph * 22*30994Sbostic * -l long output 2312108Sralph * -P used to identify printer as per lpr/lprm 2412108Sralph */ 2512108Sralph 2612108Sralph #include "lp.h" 2712108Sralph 2812108Sralph char *user[MAXUSERS]; /* users to process */ 2912108Sralph int users; /* # of users in user array */ 3012108Sralph int requ[MAXREQUESTS]; /* job number of spool entries */ 3112108Sralph int requests; /* # of spool requests */ 3212108Sralph 3312108Sralph main(argc, argv) 34*30994Sbostic register int argc; 35*30994Sbostic register char **argv; 3612108Sralph { 37*30994Sbostic extern char *optarg; 38*30994Sbostic extern int optind; 39*30994Sbostic int ch, lflag; /* long output option */ 4012108Sralph 41*30994Sbostic name = *argv; 42*30994Sbostic if (gethostname(host, sizeof(host))) { 43*30994Sbostic perror("lpq: gethostname"); 44*30994Sbostic exit(1); 45*30994Sbostic } 4625495Seric openlog("lpd", 0, LOG_LPR); 4712431Sralph 48*30994Sbostic lflag = 0; 49*30994Sbostic while ((ch = getopt(argc, argv, "lP:")) != EOF) 50*30994Sbostic switch((char)ch) { 51*30994Sbostic case 'l': /* long output */ 52*30994Sbostic ++lflag; 53*30994Sbostic break; 54*30994Sbostic case 'P': /* printer name */ 55*30994Sbostic printer = optarg; 56*30994Sbostic break; 57*30994Sbostic case '?': 58*30994Sbostic default: 59*30994Sbostic usage(); 60*30994Sbostic } 6112108Sralph 6212108Sralph if (printer == NULL && (printer = getenv("PRINTER")) == NULL) 6312108Sralph printer = DEFLP; 6412108Sralph 65*30994Sbostic for (argc -= optind, argv += optind; argc; --argc, ++argv) 66*30994Sbostic if (isdigit(argv[0][0])) { 67*30994Sbostic if (requests >= MAXREQUESTS) 68*30994Sbostic fatal("too many requests"); 69*30994Sbostic requ[requests++] = atoi(*argv); 7012108Sralph } 71*30994Sbostic else { 72*30994Sbostic if (users >= MAXUSERS) 73*30994Sbostic fatal("too many users"); 74*30994Sbostic user[users++] = *argv; 75*30994Sbostic } 76*30994Sbostic 77*30994Sbostic displayq(lflag); 7816103Sralph exit(0); 7912108Sralph } 8012108Sralph 8112876Sralph static 8212108Sralph usage() 8312108Sralph { 84*30994Sbostic puts("usage: lpq [-l] [-Pprinter] [user ...] [job ...]"); 8512108Sralph exit(1); 8612108Sralph } 87