X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/95f51977ddc18faa2e212f30c00a39540b39f325..ca67e7b465996afb3821d6a075c4dc6a7f0f5d52:/usr/src/usr.lib/lpr/lpq.c diff --git a/usr/src/usr.lib/lpr/lpq.c b/usr/src/usr.lib/lpr/lpq.c index aada12576a..a2fe7e40bc 100644 --- a/usr/src/usr.lib/lpr/lpq.c +++ b/usr/src/usr.lib/lpr/lpq.c @@ -1,25 +1,36 @@ /* * Copyright (c) 1983 Regents of the University of California. - * All rights reserved. The Berkeley software License Agreement - * specifies the terms and conditions for redistribution. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that the above copyright notice and this paragraph are + * duplicated in all such forms and that any documentation, + * advertising materials, and other materials related to such + * distribution and use acknowledge that the software was developed + * by the University of California, Berkeley. The name of the + * University may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #ifndef lint char copyright[] = "@(#) Copyright (c) 1983 Regents of the University of California.\n\ All rights reserved.\n"; -#endif not lint +#endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)lpq.c 5.2 (Berkeley) 11/17/85"; -#endif not lint +static char sccsid[] = "@(#)lpq.c 5.5 (Berkeley) 6/30/88"; +#endif /* not lint */ /* * Spool Queue examination program * - * lpq [+[n]] [-Pprinter] [user...] [job...] + * lpq [-l] [-Pprinter] [user...] [job...] * - * + means continually scan queue until empty + * -l long output * -P used to identify printer as per lpr/lprm */ @@ -30,180 +41,57 @@ int users; /* # of users in user array */ int requ[MAXREQUESTS]; /* job number of spool entries */ int requests; /* # of spool requests */ -static int repeat; /* + flag indicator */ -static int slptime = 30; /* pause between screen refereshes */ -static int lflag; /* long output option */ - -/* - * Termcap stuff for fancy display - */ -#ifdef TERMCAP -struct sgttyb sbuf; -static unsigned ospeed; -static int dumb; /* whether to use capabilities */ -static char PC; /* pad character for output */ -static char *UP; /* up one line */ -static char *BC; /* backspace character, other than \b */ -static char *CM; /* cursor motion */ -static char *CL; /* clear display */ -static char *TI; /* terminal init for CM */ -static char *TE; /* terminal clear for CM */ -static char *SO; /* stand out start */ -static char *SE; /* stand out end */ - -char *tgetstr(); -int putch(); /* for tputs' */ -#endif - main(argc, argv) - char *argv[]; + register int argc; + register char **argv; { - register char *arg; - register int n; - - name = argv[0]; - gethostname(host, sizeof(host)); + extern char *optarg; + extern int optind; + int ch, lflag; /* long output option */ + + name = *argv; + if (gethostname(host, sizeof(host))) { + perror("lpq: gethostname"); + exit(1); + } openlog("lpd", 0, LOG_LPR); - while (--argc) { - if ((arg = *++argv)[0] == '+') { - if (arg[1] != '\0') - if ((n = atoi(&arg[1])) > 0) - slptime = n; - repeat++; - } else if (arg[0] == '-') - switch (arg[1]) { - case 'P': /* printer name */ - if (arg[2]) - printer = &arg[2]; - else if (argc > 1) { - argc--; - printer = *++argv; - } - break; - - case 'l': /* long output */ - lflag++; - break; - - default: - usage(); - } else { - if (isdigit(arg[0])) { - if (requests >= MAXREQUESTS) - fatal("too many requests"); - requ[requests++] = atoi(arg); - } else { - if (users >= MAXUSERS) - fatal("too many users"); - user[users++] = arg; - } + lflag = 0; + while ((ch = getopt(argc, argv, "lP:")) != EOF) + switch((char)ch) { + case 'l': /* long output */ + ++lflag; + break; + case 'P': /* printer name */ + printer = optarg; + break; + case '?': + default: + usage(); } - } + if (printer == NULL && (printer = getenv("PRINTER")) == NULL) printer = DEFLP; -#ifdef TERMCAP - dumb = termcap(); -#endif - if (repeat) { -#ifdef TERMCAP - if (TI) - tputs(TI, 0, putch); -#endif - do { -#ifdef TERMCAP - if (!dumb) { - tputs(CL, 0, putch); - tputs(tgoto(CM, 0, 0), 0, putch); - } -#endif - if ((n = displayq(lflag)) > 0) - sleep(slptime); - } while (n > 0); -#ifdef TERMCAP - if (!dumb) { - standout(stdout, "Hit return to continue"); - while (getchar() != '\n'); - if (TE) - tputs(TE, 0, putch); + for (argc -= optind, argv += optind; argc; --argc, ++argv) + if (isdigit(argv[0][0])) { + if (requests >= MAXREQUESTS) + fatal("too many requests"); + requ[requests++] = atoi(*argv); } -#endif - } else - displayq(lflag); + else { + if (users >= MAXUSERS) + fatal("too many users"); + user[users++] = *argv; + } + + displayq(lflag); exit(0); } static usage() { - printf("usage: lpq [-Pprinter] [-l] [+[n]] [user...] [job...]\n"); + puts("usage: lpq [-l] [-Pprinter] [user ...] [job ...]"); exit(1); } - -/* - * If we have the capability, print this in standout mode - */ -static -standout(f, s, a1, a2) - FILE *f; - char *s; -{ -#ifdef TERMCAP - if (SO) - tputs(SO, 0, putch); - fprintf(f, s, a1, a2); - if (SO && SE) - tputs(SE, 0, putch); -#else - fprintf(f, s, a1, a2); -#endif -} - -#ifdef TERMCAP -static char * -capstrings[] = { - "bc", "cl", "cm", "so", "se", "ti", "te", "up", - 0 -}; - -static char ** -caps[] = { - &BC, &CL, &CM, &SO, &SE, &TI, &TE, &UP, -}; - -/* - * All we need from termcap is to clear screen and - * position cursor at the top; if these aren't available - * we say the terminal is dumb and let things scroll - */ -static -termcap() -{ - char *term, tbuf[BUFSIZ]; - static char buf[BUFSIZ/2]; - register short columns; - char *bp = buf; - register char **p, ***q, *cp; - - ioctl(0, TIOCGETP, (char *)&sbuf); - ospeed = sbuf.sg_ospeed; - if ((term = getenv("TERM")) != NULL && tgetent(tbuf, term) > 0) { - for (p = capstrings, q = caps; *p != NULL; p++, q++) - **q = tgetstr(*p, &bp); - if ((cp = tgetstr("pc", &bp)) != NULL) - PC = *cp; - } - return(CL == NULL || CM == NULL); -} - -/* - * Putchar writearound for tputs - */ -static -putch(c) - char c; -{ - putchar(c); -} -#endif