Annotation of 43BSD/usr.lib/lpr/lpq.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1983 Regents of the University of California.
                      3:  * All rights reserved.  The Berkeley software License Agreement
                      4:  * specifies the terms and conditions for redistribution.
                      5:  */
                      6: 
                      7: #ifndef lint
                      8: char copyright[] =
                      9: "@(#) Copyright (c) 1983 Regents of the University of California.\n\
                     10:  All rights reserved.\n";
                     11: #endif not lint
                     12: 
                     13: #ifndef lint
                     14: static char sccsid[] = "@(#)lpq.c      5.2 (Berkeley) 11/17/85";
                     15: #endif not lint
                     16: 
                     17: /*
                     18:  * Spool Queue examination program
                     19:  *
                     20:  * lpq [+[n]] [-Pprinter] [user...] [job...]
                     21:  *
                     22:  * + means continually scan queue until empty
                     23:  * -P used to identify printer as per lpr/lprm
                     24:  */
                     25: 
                     26: #include "lp.h"
                     27: 
                     28: char   *user[MAXUSERS];        /* users to process */
                     29: int    users;                  /* # of users in user array */
                     30: int    requ[MAXREQUESTS];      /* job number of spool entries */
                     31: int    requests;               /* # of spool requests */
                     32: 
                     33: static int     repeat;         /* + flag indicator */
                     34: static int     slptime = 30;   /* pause between screen refereshes */
                     35: static int     lflag;          /* long output option */
                     36: 
                     37: /*
                     38:  * Termcap stuff for fancy display
                     39:  */
                     40: #ifdef TERMCAP
                     41: struct sgttyb sbuf;
                     42: static unsigned ospeed;
                     43: static int     dumb;           /* whether to use capabilities */
                     44: static char    PC;             /* pad character for output */
                     45: static char    *UP;            /* up one line */
                     46: static char    *BC;            /* backspace character, other than \b */
                     47: static char    *CM;            /* cursor motion */
                     48: static char    *CL;            /* clear display */
                     49: static char    *TI;            /* terminal init for CM */
                     50: static char    *TE;            /* terminal clear for CM */
                     51: static char    *SO;            /* stand out start */
                     52: static char    *SE;            /* stand out end */
                     53: 
                     54: char   *tgetstr();
                     55: int    putch();                /* for tputs' */
                     56: #endif
                     57: 
                     58: main(argc, argv)
                     59:        char *argv[];
                     60: {
                     61:        register char *arg;
                     62:        register int n;
                     63: 
                     64:        name = argv[0];
                     65:        gethostname(host, sizeof(host));
                     66:        openlog("lpd", 0, LOG_LPR);
                     67: 
                     68:        while (--argc) {
                     69:                if ((arg = *++argv)[0] == '+') {
                     70:                        if (arg[1] != '\0')
                     71:                                if ((n = atoi(&arg[1])) > 0)
                     72:                                        slptime = n;
                     73:                        repeat++;
                     74:                } else if (arg[0] == '-')
                     75:                        switch (arg[1]) {
                     76:                        case 'P':               /* printer name */
                     77:                                if (arg[2])
                     78:                                        printer = &arg[2];
                     79:                                else if (argc > 1) {
                     80:                                        argc--;
                     81:                                        printer = *++argv;
                     82:                                }
                     83:                                break;
                     84: 
                     85:                        case 'l':               /* long output */
                     86:                                lflag++;
                     87:                                break;
                     88: 
                     89:                        default:
                     90:                                usage();
                     91:                } else {
                     92:                        if (isdigit(arg[0])) {
                     93:                                if (requests >= MAXREQUESTS)
                     94:                                        fatal("too many requests");
                     95:                                requ[requests++] = atoi(arg);
                     96:                        } else {
                     97:                                if (users >= MAXUSERS)
                     98:                                        fatal("too many users");
                     99:                                user[users++] = arg;
                    100:                        }
                    101:                }
                    102:        }
                    103:        if (printer == NULL && (printer = getenv("PRINTER")) == NULL)
                    104:                printer = DEFLP;
                    105: #ifdef TERMCAP
                    106:        dumb = termcap();
                    107: #endif
                    108: 
                    109:        if (repeat) {
                    110: #ifdef TERMCAP
                    111:                if (TI)
                    112:                        tputs(TI, 0, putch);
                    113: #endif
                    114:                do {
                    115: #ifdef TERMCAP
                    116:                        if (!dumb) {
                    117:                                tputs(CL, 0, putch);
                    118:                                tputs(tgoto(CM, 0, 0), 0, putch);
                    119:                        }
                    120: #endif
                    121:                        if ((n = displayq(lflag)) > 0)
                    122:                                sleep(slptime);
                    123:                } while (n > 0);
                    124: #ifdef TERMCAP
                    125:                if (!dumb) {
                    126:                        standout(stdout, "Hit return to continue");
                    127:                        while (getchar() != '\n');
                    128:                        if (TE)
                    129:                                tputs(TE, 0, putch);
                    130:                }
                    131: #endif
                    132:        } else
                    133:                displayq(lflag);
                    134:        exit(0);
                    135: }
                    136: 
                    137: static
                    138: usage()
                    139: {
                    140:        printf("usage: lpq [-Pprinter] [-l] [+[n]] [user...] [job...]\n");
                    141:        exit(1);
                    142: }
                    143: 
                    144: /*
                    145:  * If we have the capability, print this in standout mode
                    146:  */
                    147: static
                    148: standout(f, s, a1, a2)
                    149:        FILE *f;
                    150:        char *s;
                    151: {
                    152: #ifdef TERMCAP
                    153:        if (SO)
                    154:                tputs(SO, 0, putch);
                    155:        fprintf(f, s, a1, a2);
                    156:        if (SO && SE)
                    157:                tputs(SE, 0, putch);
                    158: #else
                    159:        fprintf(f, s, a1, a2);
                    160: #endif
                    161: }
                    162: 
                    163: #ifdef TERMCAP
                    164: static char *
                    165: capstrings[] = {
                    166:        "bc", "cl", "cm", "so", "se", "ti", "te", "up",
                    167:        0
                    168: };
                    169: 
                    170: static char **
                    171: caps[] = {
                    172:        &BC, &CL, &CM, &SO, &SE, &TI, &TE, &UP,
                    173: };
                    174: 
                    175: /*
                    176:  * All we need from termcap is to clear screen and
                    177:  *   position cursor at the top; if these aren't available
                    178:  *   we say the terminal is dumb and let things scroll
                    179:  */
                    180: static
                    181: termcap()
                    182: {
                    183:        char *term, tbuf[BUFSIZ];
                    184:        static char buf[BUFSIZ/2];
                    185:        register short columns;
                    186:        char *bp = buf;
                    187:        register char **p, ***q, *cp;
                    188: 
                    189:        ioctl(0, TIOCGETP, (char *)&sbuf);
                    190:        ospeed = sbuf.sg_ospeed;
                    191:        if ((term = getenv("TERM")) != NULL && tgetent(tbuf, term) > 0) {
                    192:                for (p = capstrings, q = caps; *p != NULL; p++, q++)
                    193:                        **q = tgetstr(*p, &bp);
                    194:                if ((cp = tgetstr("pc", &bp)) != NULL)
                    195:                        PC = *cp;
                    196:        }
                    197:        return(CL == NULL || CM == NULL);
                    198: }
                    199: 
                    200: /*
                    201:  * Putchar writearound for tputs
                    202:  */
                    203: static
                    204: putch(c)
                    205:        char c;
                    206: {
                    207:        putchar(c);
                    208: }
                    209: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.