Home | History | Annotate | Line # | Download | only in common_source
displayq.c revision 1.17
      1  1.17      mrg /*	$NetBSD: displayq.c,v 1.17 1999/12/07 14:54:44 mrg Exp $	*/
      2   1.7      jtc 
      3   1.1      cgd /*
      4   1.4      cgd  * Copyright (c) 1983, 1993
      5   1.4      cgd  *	The Regents of the University of California.  All rights reserved.
      6   1.1      cgd  *
      7   1.1      cgd  * Redistribution and use in source and binary forms, with or without
      8   1.1      cgd  * modification, are permitted provided that the following conditions
      9   1.1      cgd  * are met:
     10   1.1      cgd  * 1. Redistributions of source code must retain the above copyright
     11   1.1      cgd  *    notice, this list of conditions and the following disclaimer.
     12   1.1      cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1      cgd  *    notice, this list of conditions and the following disclaimer in the
     14   1.1      cgd  *    documentation and/or other materials provided with the distribution.
     15   1.1      cgd  * 3. All advertising materials mentioning features or use of this software
     16   1.1      cgd  *    must display the following acknowledgement:
     17   1.1      cgd  *	This product includes software developed by the University of
     18   1.1      cgd  *	California, Berkeley and its contributors.
     19   1.1      cgd  * 4. Neither the name of the University nor the names of its contributors
     20   1.1      cgd  *    may be used to endorse or promote products derived from this software
     21   1.1      cgd  *    without specific prior written permission.
     22   1.1      cgd  *
     23   1.1      cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24   1.1      cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25   1.1      cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26   1.1      cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27   1.1      cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28   1.1      cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29   1.1      cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30   1.1      cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31   1.1      cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32   1.1      cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33   1.1      cgd  * SUCH DAMAGE.
     34   1.1      cgd  */
     35   1.1      cgd 
     36  1.12      mrg #include <sys/cdefs.h>
     37   1.1      cgd #ifndef lint
     38  1.10    mikel #if 0
     39  1.11      mrg static char sccsid[] = "@(#)displayq.c	8.4 (Berkeley) 4/28/95";
     40  1.10    mikel #else
     41  1.17      mrg __RCSID("$NetBSD: displayq.c,v 1.17 1999/12/07 14:54:44 mrg Exp $");
     42  1.10    mikel #endif
     43   1.1      cgd #endif /* not lint */
     44   1.1      cgd 
     45   1.4      cgd #include <sys/param.h>
     46   1.4      cgd #include <sys/stat.h>
     47  1.11      mrg #include <sys/file.h>
     48   1.1      cgd 
     49   1.4      cgd #include <signal.h>
     50   1.4      cgd #include <fcntl.h>
     51   1.4      cgd #include <dirent.h>
     52   1.4      cgd #include <unistd.h>
     53   1.4      cgd #include <stdio.h>
     54   1.4      cgd #include <stdlib.h>
     55   1.4      cgd #include <string.h>
     56   1.4      cgd #include <ctype.h>
     57   1.1      cgd #include "lp.h"
     58   1.4      cgd #include "lp.local.h"
     59   1.1      cgd #include "pathnames.h"
     60   1.1      cgd 
     61   1.4      cgd /*
     62   1.4      cgd  * Routines to display the state of the queue.
     63   1.4      cgd  */
     64   1.1      cgd #define JOBCOL	40		/* column for job # in -l format */
     65   1.1      cgd #define OWNCOL	7		/* start of Owner column in normal */
     66   1.1      cgd #define SIZCOL	62		/* start of Size column in normal */
     67   1.1      cgd 
     68   1.1      cgd /*
     69   1.1      cgd  * Stuff for handling job specifications
     70   1.1      cgd  */
     71   1.1      cgd extern int	requ[];		/* job number of spool entries */
     72   1.1      cgd extern int	requests;	/* # of spool requests */
     73   1.4      cgd extern char    *user[];	        /* users to process */
     74   1.4      cgd extern int	users;		/* # of users in user array */
     75   1.1      cgd 
     76   1.5  hpeyerl extern uid_t	uid, euid;
     77   1.5  hpeyerl 
     78   1.4      cgd static int	col;		/* column on screen */
     79   1.4      cgd static char	current[40];	/* current file being printed */
     80   1.4      cgd static char	file[132];	/* print file name */
     81   1.4      cgd static int	first;		/* first file in ``files'' column? */
     82   1.4      cgd static int	garbage;	/* # of garbage cf files */
     83   1.4      cgd static int	lflag;		/* long output option */
     84   1.4      cgd static int	rank;		/* order to be printed (-1=none, 0=active) */
     85   1.4      cgd static long	totsize;	/* total print job size in bytes */
     86   1.1      cgd 
     87   1.4      cgd static char	*head0 = "Rank   Owner      Job  Files";
     88   1.4      cgd static char	*head1 = "Total Size\n";
     89   1.1      cgd 
     90  1.17      mrg static	void	alarmer __P((int));
     91  1.17      mrg 
     92  1.17      mrg int wait_time = 300;	/* time out after 5 minutes by default */
     93  1.17      mrg 
     94   1.1      cgd /*
     95   1.1      cgd  * Display the current state of the queue. Format = 1 if long format.
     96   1.1      cgd  */
     97   1.4      cgd void
     98   1.1      cgd displayq(format)
     99   1.1      cgd 	int format;
    100   1.1      cgd {
    101  1.12      mrg 	struct queue *q;
    102  1.12      mrg 	int i, nitems, fd, ret;
    103  1.12      mrg 	char *cp;
    104   1.1      cgd 	struct queue **queue;
    105   1.1      cgd 	struct stat statb;
    106   1.1      cgd 	FILE *fp;
    107   1.1      cgd 
    108   1.1      cgd 	lflag = format;
    109   1.1      cgd 	totsize = 0;
    110   1.1      cgd 	rank = -1;
    111   1.4      cgd 	if ((i = cgetent(&bp, printcapdb, printer)) == -2)
    112   1.4      cgd 		fatal("can't open printer description file");
    113   1.4      cgd 	else if (i == -1)
    114   1.1      cgd 		fatal("unknown printer");
    115   1.4      cgd 	else if (i == -3)
    116   1.4      cgd 		fatal("potential reference loop detected in printcap file");
    117   1.4      cgd 	if (cgetstr(bp, "lp", &LP) < 0)
    118   1.1      cgd 		LP = _PATH_DEFDEVLP;
    119   1.4      cgd 	if (cgetstr(bp, "rp", &RP) < 0)
    120   1.1      cgd 		RP = DEFLP;
    121   1.4      cgd 	if (cgetstr(bp, "sd", &SD) < 0)
    122   1.1      cgd 		SD = _PATH_DEFSPOOL;
    123   1.4      cgd 	if (cgetstr(bp,"lo", &LO) < 0)
    124   1.1      cgd 		LO = DEFLOCK;
    125   1.4      cgd 	if (cgetstr(bp, "st", &ST) < 0)
    126   1.1      cgd 		ST = DEFSTAT;
    127   1.4      cgd 	cgetstr(bp, "rm", &RM);
    128  1.10    mikel 	if ((cp = checkremote()) != NULL)
    129   1.1      cgd 		printf("Warning: %s\n", cp);
    130   1.1      cgd 
    131   1.1      cgd 	/*
    132   1.1      cgd 	 * Print out local queue
    133   1.1      cgd 	 * Find all the control files in the spooling directory
    134   1.1      cgd 	 */
    135   1.5  hpeyerl 	seteuid(euid);
    136   1.1      cgd 	if (chdir(SD) < 0)
    137   1.1      cgd 		fatal("cannot chdir to spooling directory");
    138   1.5  hpeyerl 	seteuid(uid);
    139   1.1      cgd 	if ((nitems = getq(&queue)) < 0)
    140   1.1      cgd 		fatal("cannot examine spooling area\n");
    141   1.5  hpeyerl 	seteuid(euid);
    142   1.5  hpeyerl 	ret = stat(LO, &statb);
    143   1.5  hpeyerl 	seteuid(uid);
    144   1.5  hpeyerl 	if (ret >= 0) {
    145   1.1      cgd 		if (statb.st_mode & 0100) {
    146  1.11      mrg 			if (remote)
    147   1.1      cgd 				printf("%s: ", host);
    148   1.1      cgd 			printf("Warning: %s is down: ", printer);
    149   1.5  hpeyerl 			seteuid(euid);
    150   1.1      cgd 			fd = open(ST, O_RDONLY);
    151   1.5  hpeyerl 			seteuid(uid);
    152   1.1      cgd 			if (fd >= 0) {
    153   1.8      mrg 				(void)flock(fd, LOCK_SH);
    154   1.1      cgd 				while ((i = read(fd, line, sizeof(line))) > 0)
    155  1.16      mrg 					(void)fwrite(line, 1, (size_t)i, stdout);
    156   1.8      mrg 				(void)close(fd);	/* unlocks as well */
    157   1.1      cgd 			} else
    158   1.1      cgd 				putchar('\n');
    159   1.1      cgd 		}
    160   1.1      cgd 		if (statb.st_mode & 010) {
    161  1.11      mrg 			if (remote)
    162   1.1      cgd 				printf("%s: ", host);
    163   1.1      cgd 			printf("Warning: %s queue is turned off\n", printer);
    164   1.1      cgd 		}
    165   1.1      cgd 	}
    166   1.1      cgd 
    167   1.1      cgd 	if (nitems) {
    168   1.5  hpeyerl 		seteuid(euid);
    169   1.1      cgd 		fp = fopen(LO, "r");
    170   1.5  hpeyerl 		seteuid(uid);
    171   1.1      cgd 		if (fp == NULL)
    172  1.12      mrg 			nodaemon();
    173   1.1      cgd 		else {
    174   1.1      cgd 			/* get daemon pid */
    175   1.1      cgd 			cp = current;
    176  1.12      mrg 			while ((i = getc(fp)) != EOF && i != '\n')
    177  1.12      mrg 				*cp++ = i;
    178   1.1      cgd 			*cp = '\0';
    179   1.1      cgd 			i = atoi(current);
    180   1.5  hpeyerl 			if (i <= 0) {
    181   1.6       pk 				ret = -1;
    182   1.6       pk 			} else {
    183   1.5  hpeyerl 				seteuid(euid);
    184   1.5  hpeyerl 				ret = kill(i, 0);
    185   1.5  hpeyerl 				seteuid(uid);
    186   1.5  hpeyerl 			}
    187   1.5  hpeyerl 			if (ret < 0) {
    188  1.12      mrg 				nodaemon();
    189   1.6       pk 			} else {
    190   1.1      cgd 				/* read current file name */
    191   1.1      cgd 				cp = current;
    192  1.12      mrg 				while ((i = getc(fp)) != EOF && i != '\n')
    193  1.12      mrg 					*cp++ = i;
    194   1.1      cgd 				*cp = '\0';
    195   1.1      cgd 				/*
    196   1.1      cgd 				 * Print the status file.
    197   1.1      cgd 				 */
    198  1.11      mrg 				if (remote)
    199   1.1      cgd 					printf("%s: ", host);
    200   1.5  hpeyerl 				seteuid(euid);
    201   1.1      cgd 				fd = open(ST, O_RDONLY);
    202   1.5  hpeyerl 				seteuid(uid);
    203   1.1      cgd 				if (fd >= 0) {
    204   1.8      mrg 					(void)flock(fd, LOCK_SH);
    205   1.1      cgd 					while ((i = read(fd, line, sizeof(line))) > 0)
    206  1.16      mrg 						(void)fwrite(line, 1, (size_t)i, stdout);
    207   1.8      mrg 					(void)close(fd);	/* unlocks as well */
    208   1.1      cgd 				} else
    209   1.1      cgd 					putchar('\n');
    210   1.1      cgd 			}
    211   1.8      mrg 			(void)fclose(fp);
    212   1.1      cgd 		}
    213   1.1      cgd 		/*
    214   1.1      cgd 		 * Now, examine the control files and print out the jobs to
    215   1.1      cgd 		 * be done for each user.
    216   1.1      cgd 		 */
    217   1.1      cgd 		if (!lflag)
    218   1.1      cgd 			header();
    219   1.1      cgd 		for (i = 0; i < nitems; i++) {
    220   1.1      cgd 			q = queue[i];
    221   1.1      cgd 			inform(q->q_name);
    222   1.1      cgd 			free(q);
    223   1.1      cgd 		}
    224   1.1      cgd 		free(queue);
    225   1.1      cgd 	}
    226  1.11      mrg 	if (!remote) {
    227   1.1      cgd 		if (nitems == 0)
    228   1.1      cgd 			puts("no entries");
    229   1.1      cgd 		return;
    230   1.1      cgd 	}
    231   1.1      cgd 
    232   1.1      cgd 	/*
    233   1.1      cgd 	 * Print foreign queue
    234   1.1      cgd 	 * Note that a file in transit may show up in either queue.
    235   1.1      cgd 	 */
    236   1.1      cgd 	if (nitems)
    237   1.1      cgd 		putchar('\n');
    238   1.8      mrg 	(void)snprintf(line, sizeof(line), "%c%s", format + '\3', RP);
    239   1.1      cgd 	cp = line;
    240  1.12      mrg 	for (i = 0; i < requests && cp-line+10 < sizeof(line) - 1; i++) {
    241   1.1      cgd 		cp += strlen(cp);
    242  1.16      mrg 		(void)snprintf(cp, (size_t)(line - cp), " %d", requ[i]);
    243   1.1      cgd 	}
    244  1.12      mrg 	for (i = 0; i < users && cp - line + 1 + strlen(user[i]) <
    245  1.12      mrg 	    sizeof(line) - 1; i++) {
    246   1.1      cgd 		cp += strlen(cp);
    247   1.8      mrg 		if (cp - line > sizeof(line) - 1)
    248   1.8      mrg 			break;
    249   1.1      cgd 		*cp++ = ' ';
    250  1.15  frueauf 		if (strlen(user[i]) < (sizeof(line) - (cp - line) - 1))
    251  1.15  frueauf 			(void)strcpy(cp, user[i]);
    252  1.14  frueauf 		else
    253  1.15  frueauf 			(void)strncpy(cp, user[i],
    254  1.15  frueauf 				(sizeof(line) - (cp - line) - 1));
    255   1.1      cgd 	}
    256   1.8      mrg 	(void)strncat(line, "\n", sizeof(line) - strlen(line) - 1);
    257  1.11      mrg 	fd = getport(RM, 0);
    258   1.1      cgd 	if (fd < 0) {
    259   1.1      cgd 		if (from != host)
    260   1.1      cgd 			printf("%s: ", host);
    261   1.8      mrg 		(void)printf("connection to %s is down\n", RM);
    262   1.1      cgd 	}
    263   1.1      cgd 	else {
    264  1.17      mrg 		struct sigaction osa, nsa;
    265  1.17      mrg 
    266   1.1      cgd 		i = strlen(line);
    267  1.16      mrg 		if (write(fd, line, (size_t)i) != i)
    268   1.1      cgd 			fatal("Lost connection");
    269  1.17      mrg 		nsa.sa_handler = alarmer;
    270  1.17      mrg 		sigemptyset(&nsa.sa_mask);
    271  1.17      mrg 		sigaddset(&nsa.sa_mask, SIGALRM);
    272  1.17      mrg 		nsa.sa_flags = 0;
    273  1.17      mrg 		(void)sigaction(SIGALRM, &nsa, &osa);
    274  1.17      mrg 		alarm(wait_time);
    275  1.17      mrg 		while ((i = read(fd, line, sizeof(line))) > 0) {
    276  1.16      mrg 			(void)fwrite(line, 1, (size_t)i, stdout);
    277  1.17      mrg 			alarm(wait_time);
    278  1.17      mrg 		}
    279  1.17      mrg 		alarm(0);
    280  1.17      mrg 		(void)sigaction(SIGALRM, &osa, NULL);
    281   1.8      mrg 		(void)close(fd);
    282   1.1      cgd 	}
    283  1.17      mrg }
    284  1.17      mrg 
    285  1.17      mrg static void
    286  1.17      mrg alarmer(s)
    287  1.17      mrg 	int s;
    288  1.17      mrg {
    289  1.17      mrg 	/* nothing */
    290   1.1      cgd }
    291   1.1      cgd 
    292   1.1      cgd /*
    293   1.1      cgd  * Print a warning message if there is no daemon present.
    294   1.1      cgd  */
    295   1.4      cgd void
    296  1.12      mrg nodaemon()
    297   1.1      cgd {
    298  1.11      mrg 	if (remote)
    299   1.1      cgd 		printf("\n%s: ", host);
    300   1.1      cgd 	puts("Warning: no daemon present");
    301   1.1      cgd 	current[0] = '\0';
    302   1.1      cgd }
    303   1.1      cgd 
    304   1.1      cgd /*
    305   1.1      cgd  * Print the header for the short listing format
    306   1.1      cgd  */
    307   1.4      cgd void
    308   1.1      cgd header()
    309   1.1      cgd {
    310   1.1      cgd 	printf(head0);
    311   1.1      cgd 	col = strlen(head0)+1;
    312   1.1      cgd 	blankfill(SIZCOL);
    313   1.1      cgd 	printf(head1);
    314   1.1      cgd }
    315   1.1      cgd 
    316   1.4      cgd void
    317   1.1      cgd inform(cf)
    318   1.1      cgd 	char *cf;
    319   1.1      cgd {
    320  1.12      mrg 	int j;
    321   1.1      cgd 	FILE *cfp;
    322   1.1      cgd 
    323   1.1      cgd 	/*
    324   1.1      cgd 	 * There's a chance the control file has gone away
    325   1.1      cgd 	 * in the meantime; if this is the case just keep going
    326   1.1      cgd 	 */
    327   1.5  hpeyerl 	seteuid(euid);
    328   1.1      cgd 	if ((cfp = fopen(cf, "r")) == NULL)
    329   1.1      cgd 		return;
    330   1.5  hpeyerl 	seteuid(uid);
    331   1.1      cgd 
    332   1.1      cgd 	if (rank < 0)
    333   1.1      cgd 		rank = 0;
    334  1.11      mrg 	if (remote || garbage || strcmp(cf, current))
    335   1.1      cgd 		rank++;
    336   1.1      cgd 	j = 0;
    337   1.1      cgd 	while (getline(cfp)) {
    338   1.1      cgd 		switch (line[0]) {
    339   1.1      cgd 		case 'P': /* Was this file specified in the user's list? */
    340   1.1      cgd 			if (!inlist(line+1, cf)) {
    341   1.1      cgd 				fclose(cfp);
    342   1.1      cgd 				return;
    343   1.1      cgd 			}
    344   1.1      cgd 			if (lflag) {
    345   1.1      cgd 				printf("\n%s: ", line+1);
    346   1.1      cgd 				col = strlen(line+1) + 2;
    347   1.1      cgd 				prank(rank);
    348   1.1      cgd 				blankfill(JOBCOL);
    349   1.1      cgd 				printf(" [job %s]\n", cf+3);
    350   1.1      cgd 			} else {
    351   1.1      cgd 				col = 0;
    352   1.1      cgd 				prank(rank);
    353   1.1      cgd 				blankfill(OWNCOL);
    354   1.1      cgd 				printf("%-10s %-3d  ", line+1, atoi(cf+3));
    355   1.1      cgd 				col += 16;
    356   1.1      cgd 				first = 1;
    357   1.1      cgd 			}
    358   1.1      cgd 			continue;
    359   1.1      cgd 		default: /* some format specifer and file name? */
    360   1.1      cgd 			if (line[0] < 'a' || line[0] > 'z')
    361   1.1      cgd 				continue;
    362  1.12      mrg 			if (j == 0 || strcmp(file, line+1) != 0) {
    363   1.8      mrg 				(void)strncpy(file, line+1, sizeof(file) - 1);
    364  1.12      mrg 				file[sizeof(file) - 1] = '\0';
    365  1.12      mrg 			}
    366   1.1      cgd 			j++;
    367   1.1      cgd 			continue;
    368   1.1      cgd 		case 'N':
    369   1.1      cgd 			show(line+1, file, j);
    370   1.1      cgd 			file[0] = '\0';
    371   1.1      cgd 			j = 0;
    372   1.1      cgd 		}
    373   1.1      cgd 	}
    374   1.1      cgd 	fclose(cfp);
    375   1.1      cgd 	if (!lflag) {
    376   1.1      cgd 		blankfill(SIZCOL);
    377   1.1      cgd 		printf("%ld bytes\n", totsize);
    378   1.1      cgd 		totsize = 0;
    379   1.1      cgd 	}
    380   1.1      cgd }
    381   1.1      cgd 
    382   1.4      cgd int
    383   1.1      cgd inlist(name, file)
    384   1.1      cgd 	char *name, *file;
    385   1.1      cgd {
    386  1.12      mrg 	int *r, n;
    387  1.12      mrg 	char **u, *cp;
    388   1.1      cgd 
    389   1.1      cgd 	if (users == 0 && requests == 0)
    390   1.1      cgd 		return(1);
    391   1.1      cgd 	/*
    392   1.1      cgd 	 * Check to see if it's in the user list
    393   1.1      cgd 	 */
    394   1.1      cgd 	for (u = user; u < &user[users]; u++)
    395   1.1      cgd 		if (!strcmp(*u, name))
    396   1.1      cgd 			return(1);
    397   1.1      cgd 	/*
    398   1.1      cgd 	 * Check the request list
    399   1.1      cgd 	 */
    400   1.1      cgd 	for (n = 0, cp = file+3; isdigit(*cp); )
    401   1.1      cgd 		n = n * 10 + (*cp++ - '0');
    402   1.1      cgd 	for (r = requ; r < &requ[requests]; r++)
    403   1.1      cgd 		if (*r == n && !strcmp(cp, from))
    404   1.1      cgd 			return(1);
    405   1.1      cgd 	return(0);
    406   1.1      cgd }
    407   1.1      cgd 
    408   1.4      cgd void
    409   1.1      cgd show(nfile, file, copies)
    410  1.12      mrg 	char *nfile, *file;
    411   1.4      cgd 	int copies;
    412   1.1      cgd {
    413   1.1      cgd 	if (strcmp(nfile, " ") == 0)
    414   1.1      cgd 		nfile = "(standard input)";
    415   1.1      cgd 	if (lflag)
    416   1.1      cgd 		ldump(nfile, file, copies);
    417   1.1      cgd 	else
    418   1.1      cgd 		dump(nfile, file, copies);
    419   1.1      cgd }
    420   1.1      cgd 
    421   1.1      cgd /*
    422   1.1      cgd  * Fill the line with blanks to the specified column
    423   1.1      cgd  */
    424   1.4      cgd void
    425   1.1      cgd blankfill(n)
    426  1.12      mrg 	int n;
    427   1.1      cgd {
    428   1.1      cgd 	while (col++ < n)
    429   1.1      cgd 		putchar(' ');
    430   1.1      cgd }
    431   1.1      cgd 
    432   1.1      cgd /*
    433   1.1      cgd  * Give the abbreviated dump of the file names
    434   1.1      cgd  */
    435   1.4      cgd void
    436   1.1      cgd dump(nfile, file, copies)
    437   1.1      cgd 	char *nfile, *file;
    438   1.4      cgd 	int copies;
    439   1.1      cgd {
    440  1.12      mrg 	short n, fill;
    441   1.1      cgd 	struct stat lbuf;
    442   1.1      cgd 
    443   1.1      cgd 	/*
    444   1.1      cgd 	 * Print as many files as will fit
    445   1.1      cgd 	 *  (leaving room for the total size)
    446   1.1      cgd 	 */
    447   1.1      cgd 	 fill = first ? 0 : 2;	/* fill space for ``, '' */
    448   1.1      cgd 	 if (((n = strlen(nfile)) + col + fill) >= SIZCOL-4) {
    449   1.1      cgd 		if (col < SIZCOL) {
    450   1.1      cgd 			printf(" ..."), col += 4;
    451   1.1      cgd 			blankfill(SIZCOL);
    452   1.1      cgd 		}
    453   1.1      cgd 	} else {
    454   1.1      cgd 		if (first)
    455   1.1      cgd 			first = 0;
    456   1.1      cgd 		else
    457   1.1      cgd 			printf(", ");
    458   1.1      cgd 		printf("%s", nfile);
    459   1.1      cgd 		col += n+fill;
    460   1.1      cgd 	}
    461   1.5  hpeyerl 	seteuid(euid);
    462   1.1      cgd 	if (*file && !stat(file, &lbuf))
    463  1.16      mrg 		totsize += copies * (long)lbuf.st_size;
    464   1.5  hpeyerl 	seteuid(uid);
    465   1.1      cgd }
    466   1.1      cgd 
    467   1.1      cgd /*
    468   1.1      cgd  * Print the long info about the file
    469   1.1      cgd  */
    470   1.4      cgd void
    471   1.1      cgd ldump(nfile, file, copies)
    472   1.1      cgd 	char *nfile, *file;
    473   1.4      cgd 	int copies;
    474   1.1      cgd {
    475   1.1      cgd 	struct stat lbuf;
    476   1.1      cgd 
    477   1.1      cgd 	putchar('\t');
    478   1.1      cgd 	if (copies > 1)
    479   1.1      cgd 		printf("%-2d copies of %-19s", copies, nfile);
    480   1.1      cgd 	else
    481   1.1      cgd 		printf("%-32s", nfile);
    482   1.1      cgd 	if (*file && !stat(file, &lbuf))
    483  1.13      mrg 		printf(" %qd bytes", (long long)lbuf.st_size);
    484   1.1      cgd 	else
    485   1.1      cgd 		printf(" ??? bytes");
    486   1.1      cgd 	putchar('\n');
    487   1.1      cgd }
    488   1.1      cgd 
    489   1.1      cgd /*
    490   1.1      cgd  * Print the job's rank in the queue,
    491   1.1      cgd  *   update col for screen management
    492   1.1      cgd  */
    493   1.4      cgd void
    494   1.1      cgd prank(n)
    495   1.4      cgd 	int n;
    496   1.1      cgd {
    497   1.4      cgd 	char rline[100];
    498   1.1      cgd 	static char *r[] = {
    499   1.1      cgd 		"th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th"
    500   1.1      cgd 	};
    501   1.1      cgd 
    502   1.1      cgd 	if (n == 0) {
    503   1.1      cgd 		printf("active");
    504   1.1      cgd 		col += 6;
    505   1.1      cgd 		return;
    506   1.1      cgd 	}
    507   1.1      cgd 	if ((n/10)%10 == 1)
    508   1.4      cgd 		(void)snprintf(rline, sizeof(rline), "%dth", n);
    509   1.1      cgd 	else
    510   1.4      cgd 		(void)snprintf(rline, sizeof(rline), "%d%s", n, r[n%10]);
    511   1.4      cgd 	col += strlen(rline);
    512   1.4      cgd 	printf("%s", rline);
    513   1.1      cgd }
    514