1*12431Sralph /* lpq.c 4.2 83/05/13 */ 212108Sralph /* 312108Sralph * Spool Queue examination program 412108Sralph * 512108Sralph * lpq [+[n]] [-Pprinter] [user...] [job...] 612108Sralph * 712108Sralph * + means continually scan queue until empty 812108Sralph * -P used to identify printer as per lpr/lprm 912108Sralph */ 1012108Sralph 1112108Sralph #include "lp.h" 1212108Sralph 1312108Sralph char *user[MAXUSERS]; /* users to process */ 1412108Sralph int users; /* # of users in user array */ 1512108Sralph int requ[MAXREQUESTS]; /* job number of spool entries */ 1612108Sralph int requests; /* # of spool requests */ 1712108Sralph 1812108Sralph int repeat; /* + flag indicator */ 1912108Sralph int slptime = 30; /* pause between screen refereshes */ 2012108Sralph int lflag; /* long output option */ 2112108Sralph 2212108Sralph /* 2312108Sralph * Termcap stuff for fancy display 2412108Sralph */ 2512108Sralph #ifdef TERMCAP 2612108Sralph struct sgttyb sbuf; 2712108Sralph unsigned ospeed; 2812108Sralph int dumb; /* whether to use capabilities */ 2912108Sralph char PC; /* pad character for output */ 3012108Sralph char *UP; /* up one line */ 3112108Sralph char *BC; /* backspace character, other than \b */ 3212108Sralph char *CM; /* cursor motion */ 3312108Sralph char *CL; /* clear display */ 3412108Sralph char *TI; /* terminal init for CM */ 3512108Sralph char *TE; /* terminal clear for CM */ 3612108Sralph char *SO; /* stand out start */ 3712108Sralph char *SE; /* stand out end */ 3812108Sralph 3912108Sralph char *tgetstr(); 4012108Sralph int putch(); /* for tputs' */ 4112108Sralph #endif 4212108Sralph 4312108Sralph main(argc, argv) 4412108Sralph char *argv[]; 4512108Sralph { 4612108Sralph register char *arg; 4712108Sralph register int n; 4812108Sralph 49*12431Sralph name = argv[0]; 50*12431Sralph gethostname(host, sizeof(host)); 51*12431Sralph 5212108Sralph while (--argc) { 5312108Sralph if ((arg = *++argv)[0] == '+') { 5412108Sralph if (arg[1] != '\0') 5512108Sralph if ((n = atoi(&arg[1])) > 0) 5612108Sralph slptime = n; 5712108Sralph repeat++; 5812108Sralph } else if (arg[0] == '-') 5912108Sralph switch (arg[1]) { 6012108Sralph case 'P': /* printer name */ 6112108Sralph printer = &arg[2]; 6212108Sralph break; 6312108Sralph 6412108Sralph case 'l': /* long output */ 6512108Sralph lflag++; 6612108Sralph break; 6712108Sralph 6812108Sralph default: 6912108Sralph usage(); 7012108Sralph } else { 7112108Sralph if (isdigit(arg[0])) { 7212108Sralph if (requests >= MAXREQUESTS) 7312108Sralph fatal("too many requests"); 7412108Sralph requ[requests++] = atoi(arg); 7512108Sralph } else { 7612108Sralph if (users >= MAXUSERS) 7712108Sralph fatal("too many users"); 7812108Sralph user[users++] = arg; 7912108Sralph } 8012108Sralph } 8112108Sralph } 8212108Sralph if (printer == NULL && (printer = getenv("PRINTER")) == NULL) 8312108Sralph printer = DEFLP; 8412108Sralph #ifdef TERMCAP 8512108Sralph dumb = termcap(); 8612108Sralph #endif 8712108Sralph 8812108Sralph if (repeat) { 8912108Sralph #ifdef TERMCAP 9012108Sralph if (TI) 9112108Sralph tputs(TI, 0, putch); 9212108Sralph #endif 9312108Sralph do { 9412108Sralph #ifdef TERMCAP 9512108Sralph if (!dumb) { 9612108Sralph tputs(CL, 0, putch); 9712108Sralph tputs(tgoto(CM, 0, 0), 0, putch); 9812108Sralph } 9912108Sralph #endif 10012108Sralph if ((n = displayq(lflag)) > 0) 10112108Sralph sleep(slptime); 10212108Sralph } while (n > 0); 10312108Sralph #ifdef TERMCAP 10412108Sralph if (!dumb) { 10512108Sralph standout(stdout, "Hit return to continue"); 10612108Sralph while (getchar() != '\n'); 10712108Sralph if (TE) 10812108Sralph tputs(TE, 0, putch); 10912108Sralph } 11012108Sralph #endif 11112108Sralph } else 11212108Sralph displayq(lflag); 11312108Sralph } 11412108Sralph 11512108Sralph usage() 11612108Sralph { 11712108Sralph printf("usage: lpq [-Pprinter] [-l] [+[n]] [user...] [job...]\n"); 11812108Sralph exit(1); 11912108Sralph } 12012108Sralph 12112108Sralph /* 12212108Sralph * If we have the capability, print this in standout mode 12312108Sralph */ 12412108Sralph standout(f, s, a1, a2) 12512108Sralph FILE *f; 12612108Sralph char *s; 12712108Sralph { 12812108Sralph #ifdef TERMCAP 12912108Sralph if (SO) 13012108Sralph tputs(SO, 0, putch); 13112108Sralph fprintf(f, s, a1, a2); 13212108Sralph if (SO && SE) 13312108Sralph tputs(SE, 0, putch); 13412108Sralph #else 13512108Sralph fprintf(f, s, a1, a2); 13612108Sralph #endif 13712108Sralph } 13812108Sralph 13912108Sralph #ifdef TERMCAP 14012108Sralph char * 14112108Sralph capstrings[] = { 14212108Sralph "bc", "cl", "cm", "so", "se", "ti", "te", "up", 14312108Sralph 0 14412108Sralph }; 14512108Sralph 14612108Sralph char ** 14712108Sralph caps[] = { 14812108Sralph &BC, &CL, &CM, &SO, &SE, &TI, &TE, &UP, 14912108Sralph }; 15012108Sralph 15112108Sralph /* 15212108Sralph * All we need from termcap is to clear screen and 15312108Sralph * position cursor at the top; if these aren't available 15412108Sralph * we say the terminal is dumb and let things scroll 15512108Sralph */ 15612108Sralph termcap() 15712108Sralph { 15812108Sralph char *term, tbuf[BUFSIZ]; 15912108Sralph static char buf[BUFSIZ/2]; 16012108Sralph register short columns; 16112108Sralph char *bp = buf; 16212108Sralph register char **p, ***q, *cp; 16312108Sralph extern int SIZCOL; 16412108Sralph 16512108Sralph ioctl(0, TIOCGETP, (char *)&sbuf); 16612108Sralph ospeed = sbuf.sg_ospeed; 16712108Sralph if ((term = getenv("TERM")) != NULL && tgetent(tbuf, term) > 0) { 16812108Sralph for (p = capstrings, q = caps; *p != NULL; p++, q++) 16912108Sralph **q = tgetstr(*p, &bp); 17012108Sralph if ((cp = tgetstr("pc", &bp)) != NULL) 17112108Sralph PC = *cp; 17212108Sralph if ((columns = tgetnum("co")) >= 0) 17312108Sralph SIZCOL = columns-18; 17412108Sralph } 17512108Sralph return(CL == NULL || CM == NULL); 17612108Sralph } 17712108Sralph 17812108Sralph /* 17912108Sralph * Putchar writearound for tputs 18012108Sralph */ 18112108Sralph putch(c) 18212108Sralph char c; 18312108Sralph { 18412108Sralph putchar(c); 18512108Sralph } 18612108Sralph #endif 187