10b561052SJoerg Wunsch /* 20b561052SJoerg Wunsch * Copyright (c) 1983, 1993 30b561052SJoerg Wunsch * The Regents of the University of California. All rights reserved. 40b561052SJoerg Wunsch * 50b561052SJoerg Wunsch * Redistribution and use in source and binary forms, with or without 60b561052SJoerg Wunsch * modification, are permitted provided that the following conditions 70b561052SJoerg Wunsch * are met: 80b561052SJoerg Wunsch * 1. Redistributions of source code must retain the above copyright 90b561052SJoerg Wunsch * notice, this list of conditions and the following disclaimer. 100b561052SJoerg Wunsch * 2. Redistributions in binary form must reproduce the above copyright 110b561052SJoerg Wunsch * notice, this list of conditions and the following disclaimer in the 120b561052SJoerg Wunsch * documentation and/or other materials provided with the distribution. 130b561052SJoerg Wunsch * 3. All advertising materials mentioning features or use of this software 140b561052SJoerg Wunsch * must display the following acknowledgement: 150b561052SJoerg Wunsch * This product includes software developed by the University of 160b561052SJoerg Wunsch * California, Berkeley and its contributors. 170b561052SJoerg Wunsch * 4. Neither the name of the University nor the names of its contributors 180b561052SJoerg Wunsch * may be used to endorse or promote products derived from this software 190b561052SJoerg Wunsch * without specific prior written permission. 200b561052SJoerg Wunsch * 210b561052SJoerg Wunsch * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 220b561052SJoerg Wunsch * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 230b561052SJoerg Wunsch * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 240b561052SJoerg Wunsch * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 250b561052SJoerg Wunsch * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 260b561052SJoerg Wunsch * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 270b561052SJoerg Wunsch * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 280b561052SJoerg Wunsch * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 290b561052SJoerg Wunsch * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 300b561052SJoerg Wunsch * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 310b561052SJoerg Wunsch * SUCH DAMAGE. 320b561052SJoerg Wunsch */ 330b561052SJoerg Wunsch 340b561052SJoerg Wunsch #ifndef lint 354a1a0dbeSGarrett Wollman /* 365458e2f4SJoerg Wunsch static char sccsid[] = "@(#)displayq.c 8.4 (Berkeley) 4/28/95"; 374a1a0dbeSGarrett Wollman */ 384a1a0dbeSGarrett Wollman static const char rcsid[] = 394a1a0dbeSGarrett Wollman "$Id$"; 400b561052SJoerg Wunsch #endif /* not lint */ 410b561052SJoerg Wunsch 420b561052SJoerg Wunsch #include <sys/param.h> 430b561052SJoerg Wunsch #include <sys/stat.h> 440b561052SJoerg Wunsch 454a1a0dbeSGarrett Wollman #include <ctype.h> 460b561052SJoerg Wunsch #include <dirent.h> 474a1a0dbeSGarrett Wollman #include <errno.h> 484a1a0dbeSGarrett Wollman #include <fcntl.h> 494a1a0dbeSGarrett Wollman #include <signal.h> 500b561052SJoerg Wunsch #include <stdio.h> 510b561052SJoerg Wunsch #include <stdlib.h> 520b561052SJoerg Wunsch #include <string.h> 534a1a0dbeSGarrett Wollman #define psignal foil_gcc_psignal 544a1a0dbeSGarrett Wollman #define sys_siglist foil_gcc_siglist 554a1a0dbeSGarrett Wollman #include <unistd.h> 564a1a0dbeSGarrett Wollman #undef psignal 574a1a0dbeSGarrett Wollman #undef sys_siglist 584a1a0dbeSGarrett Wollman 590b561052SJoerg Wunsch #include "lp.h" 600b561052SJoerg Wunsch #include "lp.local.h" 610b561052SJoerg Wunsch #include "pathnames.h" 620b561052SJoerg Wunsch 630b561052SJoerg Wunsch /* 640b561052SJoerg Wunsch * Routines to display the state of the queue. 650b561052SJoerg Wunsch */ 660b561052SJoerg Wunsch #define JOBCOL 40 /* column for job # in -l format */ 670b561052SJoerg Wunsch #define OWNCOL 7 /* start of Owner column in normal */ 680b561052SJoerg Wunsch #define SIZCOL 62 /* start of Size column in normal */ 690b561052SJoerg Wunsch 700b561052SJoerg Wunsch /* 710b561052SJoerg Wunsch * Stuff for handling job specifications 720b561052SJoerg Wunsch */ 73360d4ad5SWarner Losh extern uid_t uid, euid; 74360d4ad5SWarner Losh 750b561052SJoerg Wunsch static int col; /* column on screen */ 760b561052SJoerg Wunsch static char current[40]; /* current file being printed */ 770b561052SJoerg Wunsch static char file[132]; /* print file name */ 780b561052SJoerg Wunsch static int first; /* first file in ``files'' column? */ 790b561052SJoerg Wunsch static int garbage; /* # of garbage cf files */ 800b561052SJoerg Wunsch static int lflag; /* long output option */ 810b561052SJoerg Wunsch static int rank; /* order to be printed (-1=none, 0=active) */ 820b561052SJoerg Wunsch static long totsize; /* total print job size in bytes */ 830b561052SJoerg Wunsch 840b561052SJoerg Wunsch static char *head0 = "Rank Owner Job Files"; 850b561052SJoerg Wunsch static char *head1 = "Total Size\n"; 860b561052SJoerg Wunsch 87334a9508SJoerg Wunsch static void alarmhandler __P((int)); 884a1a0dbeSGarrett Wollman static void warn __P((const struct printer *pp)); 89334a9508SJoerg Wunsch 900b561052SJoerg Wunsch /* 910b561052SJoerg Wunsch * Display the current state of the queue. Format = 1 if long format. 920b561052SJoerg Wunsch */ 930b561052SJoerg Wunsch void 944a1a0dbeSGarrett Wollman displayq(pp, format) 954a1a0dbeSGarrett Wollman struct printer *pp; 960b561052SJoerg Wunsch int format; 970b561052SJoerg Wunsch { 980b561052SJoerg Wunsch register struct queue *q; 99360d4ad5SWarner Losh register int i, nitems, fd, ret; 1000b561052SJoerg Wunsch register char *cp; 1010b561052SJoerg Wunsch struct queue **queue; 1020b561052SJoerg Wunsch struct stat statb; 1030b561052SJoerg Wunsch FILE *fp; 104334a9508SJoerg Wunsch void (*savealrm)(int); 1050b561052SJoerg Wunsch 1060b561052SJoerg Wunsch lflag = format; 1070b561052SJoerg Wunsch totsize = 0; 1080b561052SJoerg Wunsch rank = -1; 1094a1a0dbeSGarrett Wollman 1104a1a0dbeSGarrett Wollman if ((cp = checkremote(pp))) { 1110b561052SJoerg Wunsch printf("Warning: %s\n", cp); 1124a1a0dbeSGarrett Wollman free(cp); 1134a1a0dbeSGarrett Wollman } 1140b561052SJoerg Wunsch 1150b561052SJoerg Wunsch /* 1160b561052SJoerg Wunsch * Print out local queue 1170b561052SJoerg Wunsch * Find all the control files in the spooling directory 1180b561052SJoerg Wunsch */ 119360d4ad5SWarner Losh seteuid(euid); 1204a1a0dbeSGarrett Wollman if (chdir(pp->spool_dir) < 0) 1214a1a0dbeSGarrett Wollman fatal(pp, "cannot chdir to spooling directory: %s", 1224a1a0dbeSGarrett Wollman strerror(errno)); 123360d4ad5SWarner Losh seteuid(uid); 1244a1a0dbeSGarrett Wollman if ((nitems = getq(pp, &queue)) < 0) 1254a1a0dbeSGarrett Wollman fatal(pp, "cannot examine spooling area\n"); 126360d4ad5SWarner Losh seteuid(euid); 1274a1a0dbeSGarrett Wollman ret = stat(pp->lock_file, &statb); 128360d4ad5SWarner Losh seteuid(uid); 129360d4ad5SWarner Losh if (ret >= 0) { 1304a1a0dbeSGarrett Wollman if (statb.st_mode & LFM_PRINT_DIS) { 1314a1a0dbeSGarrett Wollman if (pp->remote) 1320b561052SJoerg Wunsch printf("%s: ", host); 1334a1a0dbeSGarrett Wollman printf("Warning: %s is down: ", pp->printer); 134360d4ad5SWarner Losh seteuid(euid); 1354a1a0dbeSGarrett Wollman fd = open(pp->status_file, O_RDONLY|O_SHLOCK); 136360d4ad5SWarner Losh seteuid(uid); 1370b561052SJoerg Wunsch if (fd >= 0) { 1380b561052SJoerg Wunsch while ((i = read(fd, line, sizeof(line))) > 0) 1390b561052SJoerg Wunsch (void) fwrite(line, 1, i, stdout); 1400b561052SJoerg Wunsch (void) close(fd); /* unlocks as well */ 1410b561052SJoerg Wunsch } else 1420b561052SJoerg Wunsch putchar('\n'); 1430b561052SJoerg Wunsch } 1444a1a0dbeSGarrett Wollman if (statb.st_mode & LFM_QUEUE_DIS) { 1454a1a0dbeSGarrett Wollman if (pp->remote) 1460b561052SJoerg Wunsch printf("%s: ", host); 1474a1a0dbeSGarrett Wollman printf("Warning: %s queue is turned off\n", 1484a1a0dbeSGarrett Wollman pp->printer); 1490b561052SJoerg Wunsch } 1500b561052SJoerg Wunsch } 1510b561052SJoerg Wunsch 1520b561052SJoerg Wunsch if (nitems) { 153360d4ad5SWarner Losh seteuid(euid); 1544a1a0dbeSGarrett Wollman fp = fopen(pp->lock_file, "r"); 155360d4ad5SWarner Losh seteuid(uid); 1560b561052SJoerg Wunsch if (fp == NULL) 1574a1a0dbeSGarrett Wollman warn(pp); 1580b561052SJoerg Wunsch else { 1590b561052SJoerg Wunsch /* get daemon pid */ 1600b561052SJoerg Wunsch cp = current; 1615458e2f4SJoerg Wunsch while ((i = getc(fp)) != EOF && i != '\n') 1625458e2f4SJoerg Wunsch *cp++ = i; 1630b561052SJoerg Wunsch *cp = '\0'; 1640b561052SJoerg Wunsch i = atoi(current); 165360d4ad5SWarner Losh if (i <= 0) { 166360d4ad5SWarner Losh ret = -1; 167360d4ad5SWarner Losh } else { 168360d4ad5SWarner Losh seteuid(euid); 169360d4ad5SWarner Losh ret = kill(i, 0); 170360d4ad5SWarner Losh seteuid(uid); 171360d4ad5SWarner Losh } 172360d4ad5SWarner Losh if (ret < 0) { 1734a1a0dbeSGarrett Wollman warn(pp); 174360d4ad5SWarner Losh } else { 1750b561052SJoerg Wunsch /* read current file name */ 1760b561052SJoerg Wunsch cp = current; 1775458e2f4SJoerg Wunsch while ((i = getc(fp)) != EOF && i != '\n') 1785458e2f4SJoerg Wunsch *cp++ = i; 1790b561052SJoerg Wunsch *cp = '\0'; 1800b561052SJoerg Wunsch /* 1810b561052SJoerg Wunsch * Print the status file. 1820b561052SJoerg Wunsch */ 1834a1a0dbeSGarrett Wollman if (pp->remote) 1840b561052SJoerg Wunsch printf("%s: ", host); 185360d4ad5SWarner Losh seteuid(euid); 1864a1a0dbeSGarrett Wollman fd = open(pp->status_file, O_RDONLY|O_SHLOCK); 187360d4ad5SWarner Losh seteuid(uid); 1880b561052SJoerg Wunsch if (fd >= 0) { 1894a1a0dbeSGarrett Wollman while ((i = read(fd, line, 1904a1a0dbeSGarrett Wollman sizeof(line))) > 0) 1914a1a0dbeSGarrett Wollman fwrite(line, 1, i, stdout); 1924a1a0dbeSGarrett Wollman close(fd); /* unlocks as well */ 1930b561052SJoerg Wunsch } else 1940b561052SJoerg Wunsch putchar('\n'); 1950b561052SJoerg Wunsch } 1960b561052SJoerg Wunsch (void) fclose(fp); 1970b561052SJoerg Wunsch } 1980b561052SJoerg Wunsch /* 1990b561052SJoerg Wunsch * Now, examine the control files and print out the jobs to 2000b561052SJoerg Wunsch * be done for each user. 2010b561052SJoerg Wunsch */ 2020b561052SJoerg Wunsch if (!lflag) 2030b561052SJoerg Wunsch header(); 2040b561052SJoerg Wunsch for (i = 0; i < nitems; i++) { 2050b561052SJoerg Wunsch q = queue[i]; 2064a1a0dbeSGarrett Wollman inform(pp, q->q_name); 2070b561052SJoerg Wunsch free(q); 2080b561052SJoerg Wunsch } 2090b561052SJoerg Wunsch free(queue); 2100b561052SJoerg Wunsch } 2114a1a0dbeSGarrett Wollman if (!pp->remote) { 2120b561052SJoerg Wunsch if (nitems == 0) 2130b561052SJoerg Wunsch puts("no entries"); 2140b561052SJoerg Wunsch return; 2150b561052SJoerg Wunsch } 2160b561052SJoerg Wunsch 2170b561052SJoerg Wunsch /* 2180b561052SJoerg Wunsch * Print foreign queue 2190b561052SJoerg Wunsch * Note that a file in transit may show up in either queue. 2200b561052SJoerg Wunsch */ 2210b561052SJoerg Wunsch if (nitems) 2220b561052SJoerg Wunsch putchar('\n'); 2234a1a0dbeSGarrett Wollman (void) snprintf(line, sizeof(line), "%c%s", format ? '\4' : '\3', 2244a1a0dbeSGarrett Wollman pp->remote_queue); 2250b561052SJoerg Wunsch cp = line; 2266ee8b269SWarner Losh for (i = 0; i < requests && cp-line+10 < sizeof(line) - 1; i++) { 2270b561052SJoerg Wunsch cp += strlen(cp); 2280b561052SJoerg Wunsch (void) sprintf(cp, " %d", requ[i]); 2290b561052SJoerg Wunsch } 230d583a7c3SWarner Losh for (i = 0; i < users && cp - line + 1 + strlen(user[i]) < 2316ee8b269SWarner Losh sizeof(line) - 1; i++) { 2320b561052SJoerg Wunsch cp += strlen(cp); 2330b561052SJoerg Wunsch *cp++ = ' '; 2340b561052SJoerg Wunsch (void) strcpy(cp, user[i]); 2350b561052SJoerg Wunsch } 2360b561052SJoerg Wunsch strcat(line, "\n"); 237334a9508SJoerg Wunsch savealrm = signal(SIGALRM, alarmhandler); 2384a1a0dbeSGarrett Wollman alarm(pp->conn_timeout); 2394a1a0dbeSGarrett Wollman fd = getport(pp, pp->remote_host, 0); 2406d0727f4SJoerg Wunsch alarm(0); 241334a9508SJoerg Wunsch (void)signal(SIGALRM, savealrm); 2420b561052SJoerg Wunsch if (fd < 0) { 2430b561052SJoerg Wunsch if (from != host) 2440b561052SJoerg Wunsch printf("%s: ", host); 2454a1a0dbeSGarrett Wollman printf("connection to %s is down\n", pp->remote_host); 2460b561052SJoerg Wunsch } 2470b561052SJoerg Wunsch else { 2480b561052SJoerg Wunsch i = strlen(line); 2490b561052SJoerg Wunsch if (write(fd, line, i) != i) 2504a1a0dbeSGarrett Wollman fatal(pp, "Lost connection"); 2510b561052SJoerg Wunsch while ((i = read(fd, line, sizeof(line))) > 0) 2520b561052SJoerg Wunsch (void) fwrite(line, 1, i, stdout); 2530b561052SJoerg Wunsch (void) close(fd); 2540b561052SJoerg Wunsch } 2550b561052SJoerg Wunsch } 2560b561052SJoerg Wunsch 2570b561052SJoerg Wunsch /* 2580b561052SJoerg Wunsch * Print a warning message if there is no daemon present. 2590b561052SJoerg Wunsch */ 26036d0e2a3SJoerg Wunsch static void 2614a1a0dbeSGarrett Wollman warn(pp) 2624a1a0dbeSGarrett Wollman const struct printer *pp; 2630b561052SJoerg Wunsch { 2644a1a0dbeSGarrett Wollman if (pp->remote) 26528185a19SJoerg Wunsch printf("%s: ", host); 2660b561052SJoerg Wunsch puts("Warning: no daemon present"); 2670b561052SJoerg Wunsch current[0] = '\0'; 2680b561052SJoerg Wunsch } 2690b561052SJoerg Wunsch 2700b561052SJoerg Wunsch /* 2710b561052SJoerg Wunsch * Print the header for the short listing format 2720b561052SJoerg Wunsch */ 2730b561052SJoerg Wunsch void 2740b561052SJoerg Wunsch header() 2750b561052SJoerg Wunsch { 2760b561052SJoerg Wunsch printf(head0); 2770b561052SJoerg Wunsch col = strlen(head0)+1; 2780b561052SJoerg Wunsch blankfill(SIZCOL); 2790b561052SJoerg Wunsch printf(head1); 2800b561052SJoerg Wunsch } 2810b561052SJoerg Wunsch 2820b561052SJoerg Wunsch void 2834a1a0dbeSGarrett Wollman inform(pp, cf) 2844a1a0dbeSGarrett Wollman const struct printer *pp; 2850b561052SJoerg Wunsch char *cf; 2860b561052SJoerg Wunsch { 2870b561052SJoerg Wunsch register int j; 2880b561052SJoerg Wunsch FILE *cfp; 2890b561052SJoerg Wunsch 2900b561052SJoerg Wunsch /* 2910b561052SJoerg Wunsch * There's a chance the control file has gone away 2920b561052SJoerg Wunsch * in the meantime; if this is the case just keep going 2930b561052SJoerg Wunsch */ 294360d4ad5SWarner Losh seteuid(euid); 2950b561052SJoerg Wunsch if ((cfp = fopen(cf, "r")) == NULL) 2960b561052SJoerg Wunsch return; 297360d4ad5SWarner Losh seteuid(uid); 2980b561052SJoerg Wunsch 2990b561052SJoerg Wunsch if (rank < 0) 3000b561052SJoerg Wunsch rank = 0; 3014a1a0dbeSGarrett Wollman if (pp->remote || garbage || strcmp(cf, current)) 3020b561052SJoerg Wunsch rank++; 3030b561052SJoerg Wunsch j = 0; 3040b561052SJoerg Wunsch while (getline(cfp)) { 3050b561052SJoerg Wunsch switch (line[0]) { 3060b561052SJoerg Wunsch case 'P': /* Was this file specified in the user's list? */ 3070b561052SJoerg Wunsch if (!inlist(line+1, cf)) { 3080b561052SJoerg Wunsch fclose(cfp); 3090b561052SJoerg Wunsch return; 3100b561052SJoerg Wunsch } 3110b561052SJoerg Wunsch if (lflag) { 3120b561052SJoerg Wunsch printf("\n%s: ", line+1); 3130b561052SJoerg Wunsch col = strlen(line+1) + 2; 3140b561052SJoerg Wunsch prank(rank); 3150b561052SJoerg Wunsch blankfill(JOBCOL); 3160b561052SJoerg Wunsch printf(" [job %s]\n", cf+3); 3170b561052SJoerg Wunsch } else { 3180b561052SJoerg Wunsch col = 0; 3190b561052SJoerg Wunsch prank(rank); 3200b561052SJoerg Wunsch blankfill(OWNCOL); 3210b561052SJoerg Wunsch printf("%-10s %-3d ", line+1, atoi(cf+3)); 3220b561052SJoerg Wunsch col += 16; 3230b561052SJoerg Wunsch first = 1; 3240b561052SJoerg Wunsch } 3250b561052SJoerg Wunsch continue; 3260b561052SJoerg Wunsch default: /* some format specifer and file name? */ 3270b561052SJoerg Wunsch if (line[0] < 'a' || line[0] > 'z') 3280b561052SJoerg Wunsch continue; 329d583a7c3SWarner Losh if (j == 0 || strcmp(file, line+1) != 0) { 330d583a7c3SWarner Losh (void) strncpy(file, line+1, sizeof(file) - 1); 331d583a7c3SWarner Losh file[sizeof(file) - 1] = '\0'; 332d583a7c3SWarner Losh } 3330b561052SJoerg Wunsch j++; 3340b561052SJoerg Wunsch continue; 3350b561052SJoerg Wunsch case 'N': 3360b561052SJoerg Wunsch show(line+1, file, j); 3370b561052SJoerg Wunsch file[0] = '\0'; 3380b561052SJoerg Wunsch j = 0; 3390b561052SJoerg Wunsch } 3400b561052SJoerg Wunsch } 3410b561052SJoerg Wunsch fclose(cfp); 3420b561052SJoerg Wunsch if (!lflag) { 3430b561052SJoerg Wunsch blankfill(SIZCOL); 3440b561052SJoerg Wunsch printf("%ld bytes\n", totsize); 3450b561052SJoerg Wunsch totsize = 0; 3460b561052SJoerg Wunsch } 3470b561052SJoerg Wunsch } 3480b561052SJoerg Wunsch 3490b561052SJoerg Wunsch int 3500b561052SJoerg Wunsch inlist(name, file) 3510b561052SJoerg Wunsch char *name, *file; 3520b561052SJoerg Wunsch { 3530b561052SJoerg Wunsch register int *r, n; 3540b561052SJoerg Wunsch register char **u, *cp; 3550b561052SJoerg Wunsch 3560b561052SJoerg Wunsch if (users == 0 && requests == 0) 3570b561052SJoerg Wunsch return(1); 3580b561052SJoerg Wunsch /* 3590b561052SJoerg Wunsch * Check to see if it's in the user list 3600b561052SJoerg Wunsch */ 3610b561052SJoerg Wunsch for (u = user; u < &user[users]; u++) 3620b561052SJoerg Wunsch if (!strcmp(*u, name)) 3630b561052SJoerg Wunsch return(1); 3640b561052SJoerg Wunsch /* 3650b561052SJoerg Wunsch * Check the request list 3660b561052SJoerg Wunsch */ 3670b561052SJoerg Wunsch for (n = 0, cp = file+3; isdigit(*cp); ) 3680b561052SJoerg Wunsch n = n * 10 + (*cp++ - '0'); 3690b561052SJoerg Wunsch for (r = requ; r < &requ[requests]; r++) 3700b561052SJoerg Wunsch if (*r == n && !strcmp(cp, from)) 3710b561052SJoerg Wunsch return(1); 3720b561052SJoerg Wunsch return(0); 3730b561052SJoerg Wunsch } 3740b561052SJoerg Wunsch 3750b561052SJoerg Wunsch void 3760b561052SJoerg Wunsch show(nfile, file, copies) 3770b561052SJoerg Wunsch register char *nfile, *file; 3780b561052SJoerg Wunsch int copies; 3790b561052SJoerg Wunsch { 3800b561052SJoerg Wunsch if (strcmp(nfile, " ") == 0) 3810b561052SJoerg Wunsch nfile = "(standard input)"; 3820b561052SJoerg Wunsch if (lflag) 3830b561052SJoerg Wunsch ldump(nfile, file, copies); 3840b561052SJoerg Wunsch else 3850b561052SJoerg Wunsch dump(nfile, file, copies); 3860b561052SJoerg Wunsch } 3870b561052SJoerg Wunsch 3880b561052SJoerg Wunsch /* 3890b561052SJoerg Wunsch * Fill the line with blanks to the specified column 3900b561052SJoerg Wunsch */ 3910b561052SJoerg Wunsch void 3920b561052SJoerg Wunsch blankfill(n) 3930b561052SJoerg Wunsch register int n; 3940b561052SJoerg Wunsch { 3950b561052SJoerg Wunsch while (col++ < n) 3960b561052SJoerg Wunsch putchar(' '); 3970b561052SJoerg Wunsch } 3980b561052SJoerg Wunsch 3990b561052SJoerg Wunsch /* 4000b561052SJoerg Wunsch * Give the abbreviated dump of the file names 4010b561052SJoerg Wunsch */ 4020b561052SJoerg Wunsch void 4030b561052SJoerg Wunsch dump(nfile, file, copies) 4040b561052SJoerg Wunsch char *nfile, *file; 4050b561052SJoerg Wunsch int copies; 4060b561052SJoerg Wunsch { 4070b561052SJoerg Wunsch register short n, fill; 4080b561052SJoerg Wunsch struct stat lbuf; 4090b561052SJoerg Wunsch 4100b561052SJoerg Wunsch /* 4110b561052SJoerg Wunsch * Print as many files as will fit 4120b561052SJoerg Wunsch * (leaving room for the total size) 4130b561052SJoerg Wunsch */ 4140b561052SJoerg Wunsch fill = first ? 0 : 2; /* fill space for ``, '' */ 4150b561052SJoerg Wunsch if (((n = strlen(nfile)) + col + fill) >= SIZCOL-4) { 4160b561052SJoerg Wunsch if (col < SIZCOL) { 4170b561052SJoerg Wunsch printf(" ..."), col += 4; 4180b561052SJoerg Wunsch blankfill(SIZCOL); 4190b561052SJoerg Wunsch } 4200b561052SJoerg Wunsch } else { 4210b561052SJoerg Wunsch if (first) 4220b561052SJoerg Wunsch first = 0; 4230b561052SJoerg Wunsch else 4240b561052SJoerg Wunsch printf(", "); 4250b561052SJoerg Wunsch printf("%s", nfile); 4260b561052SJoerg Wunsch col += n+fill; 4270b561052SJoerg Wunsch } 428360d4ad5SWarner Losh seteuid(euid); 4290b561052SJoerg Wunsch if (*file && !stat(file, &lbuf)) 4300b561052SJoerg Wunsch totsize += copies * lbuf.st_size; 431360d4ad5SWarner Losh seteuid(uid); 4320b561052SJoerg Wunsch } 4330b561052SJoerg Wunsch 4340b561052SJoerg Wunsch /* 4350b561052SJoerg Wunsch * Print the long info about the file 4360b561052SJoerg Wunsch */ 4370b561052SJoerg Wunsch void 4380b561052SJoerg Wunsch ldump(nfile, file, copies) 4390b561052SJoerg Wunsch char *nfile, *file; 4400b561052SJoerg Wunsch int copies; 4410b561052SJoerg Wunsch { 4420b561052SJoerg Wunsch struct stat lbuf; 4430b561052SJoerg Wunsch 4440b561052SJoerg Wunsch putchar('\t'); 4450b561052SJoerg Wunsch if (copies > 1) 4460b561052SJoerg Wunsch printf("%-2d copies of %-19s", copies, nfile); 4470b561052SJoerg Wunsch else 4480b561052SJoerg Wunsch printf("%-32s", nfile); 4490b561052SJoerg Wunsch if (*file && !stat(file, &lbuf)) 4504ebd2ee4SJoerg Wunsch printf(" %qd bytes", lbuf.st_size); 4510b561052SJoerg Wunsch else 4520b561052SJoerg Wunsch printf(" ??? bytes"); 4530b561052SJoerg Wunsch putchar('\n'); 4540b561052SJoerg Wunsch } 4550b561052SJoerg Wunsch 4560b561052SJoerg Wunsch /* 4570b561052SJoerg Wunsch * Print the job's rank in the queue, 4580b561052SJoerg Wunsch * update col for screen management 4590b561052SJoerg Wunsch */ 4600b561052SJoerg Wunsch void 4610b561052SJoerg Wunsch prank(n) 4620b561052SJoerg Wunsch int n; 4630b561052SJoerg Wunsch { 4640b561052SJoerg Wunsch char rline[100]; 4650b561052SJoerg Wunsch static char *r[] = { 4660b561052SJoerg Wunsch "th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th" 4670b561052SJoerg Wunsch }; 4680b561052SJoerg Wunsch 4690b561052SJoerg Wunsch if (n == 0) { 4700b561052SJoerg Wunsch printf("active"); 4710b561052SJoerg Wunsch col += 6; 4720b561052SJoerg Wunsch return; 4730b561052SJoerg Wunsch } 4740b561052SJoerg Wunsch if ((n/10)%10 == 1) 4750b561052SJoerg Wunsch (void)snprintf(rline, sizeof(rline), "%dth", n); 4760b561052SJoerg Wunsch else 4770b561052SJoerg Wunsch (void)snprintf(rline, sizeof(rline), "%d%s", n, r[n%10]); 4780b561052SJoerg Wunsch col += strlen(rline); 4790b561052SJoerg Wunsch printf("%s", rline); 4800b561052SJoerg Wunsch } 481334a9508SJoerg Wunsch 482334a9508SJoerg Wunsch void 483334a9508SJoerg Wunsch alarmhandler(signo) 484334a9508SJoerg Wunsch int signo; 485334a9508SJoerg Wunsch { 486334a9508SJoerg Wunsch /* ignored */ 487334a9508SJoerg Wunsch } 488