* Copyright (c) 1983 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
static char sccsid
[] = "@(#)displayq.c 5.1 (Berkeley) 6/6/85";
* Routines to display the state of the queue.
#define JOBCOL 40 /* column for job # in -l format */
#define OWNCOL 7 /* start of Owner column in normal */
#define SIZCOL 62 /* start of Size column in normal */
* Stuff for handling job specifications
extern char *user
[]; /* users to process */
extern int users
; /* # of users in user array */
extern int requ
[]; /* job number of spool entries */
extern int requests
; /* # of spool requests */
int lflag
; /* long output option */
char current
[40]; /* current file being printed */
int garbage
; /* # of garbage cf files */
int rank
; /* order to be printed (-1=none, 0=active) */
long totsize
; /* total print job size in bytes */
int first
; /* first file in ``files'' column? */
int col
; /* column on screen */
int sendtorem
; /* are we sending to a remote? */
char file
[132]; /* print file name */
char *head0
= "Rank Owner Job Files";
char *head1
= "Total Size\n";
* Display the current state of the queue. Format = 1 if long format.
register struct queue
*q
;
register int i
, nitems
, fd
;
if ((i
= pgetent(line
, printer
)) < 0)
fatal("cannot open printer description file");
fatal("unknown printer");
if ((LP
= pgetstr("lp", &bp
)) == NULL
)
if ((RP
= pgetstr("rp", &bp
)) == NULL
)
if ((SD
= pgetstr("sd", &bp
)) == NULL
)
if ((LO
= pgetstr("lo", &bp
)) == NULL
)
if ((ST
= pgetstr("st", &bp
)) == NULL
)
* Figure out whether the local machine is the same as the remote
* machine entry (if it exists). If not, then ignore the local
if (RM
!= (char *) NULL
) {
/* get the standard network name of the local host */
gethostname(name
, sizeof(name
));
name
[sizeof(name
)-1] = '\0';
hp
= gethostbyname(name
);
if (hp
== (struct hostent
*) NULL
) {
printf("unable to get network name for local machine %s\n",
} else strcpy(name
, hp
->h_name
);
/* get the network standard name of RM */
if (hp
== (struct hostent
*) NULL
) {
printf("unable to get hostname for remote machine %s\n",
/* if printer is not on local machine, ignore LP */
if (strcmp(name
, hp
->h_name
) != 0) *LP
= '\0';
* If there is no local printer, then print the queue on
* the remote machine and then what's in the queue here.
* Note that a file in transit may not show up in either queue.
(void) sprintf(line
, "%c%s", format
+ '\3', RP
);
for (i
= 0; i
< requests
; i
++) {
(void) sprintf(cp
, " %d", requ
[i
]);
for (i
= 0; i
< users
; i
++) {
printf("connection to %s is down\n", RM
);
if (write(fd
, line
, i
) != i
)
fatal("Lost connection");
while ((i
= read(fd
, line
, sizeof(line
))) > 0)
(void) fwrite(line
, 1, i
, stdout
);
* Find all the control files in the spooling directory
fatal("cannot chdir to spooling directory");
if ((nitems
= getq(&queue
)) < 0)
fatal("cannot examine spooling area\n");
if (stat(LO
, &statb
) >= 0) {
if ((statb
.st_mode
& 0110) && sendtorem
)
if (statb
.st_mode
& 0100) {
printf("Warning: %s is down: ", printer
);
(void) flock(fd
, LOCK_SH
);
while ((i
= read(fd
, line
, sizeof(line
))) > 0)
(void) fwrite(line
, 1, i
, stdout
);
(void) close(fd
); /* unlocks as well */
if (statb
.st_mode
& 010) {
printf("Warning: %s queue is turned off\n", printer
);
while ((*cp
= getc(fp
)) != EOF
&& *cp
!= '\n')
if (i
<= 0 || kill(i
, 0) < 0)
/* read current file name */
while ((*cp
= getc(fp
)) != EOF
&& *cp
!= '\n')
(void) flock(fd
, LOCK_SH
);
while ((i
= read(fd
, line
, sizeof(line
))) > 0)
(void) fwrite(line
, 1, i
, stdout
);
(void) close(fd
); /* unlocks as well */
* Now, examine the control files and print out the jobs to
for (i
= 0; i
< nitems
; i
++) {
* Print a warning message if there is no daemon present.
printf("Warning: no daemon present\n");
* Print the header for the short listing format
* There's a chance the control file has gone away
* in the meantime; if this is the case just keep going
if ((cfp
= fopen(cf
, "r")) == NULL
)
if (sendtorem
|| garbage
|| strcmp(cf
, current
))
case 'P': /* Was this file specified in the user's list? */
if (!inlist(line
+1, cf
)) {
printf("\n%s: ", line
+1);
col
= strlen(line
+1) + 2;
printf(" [job %s]\n", cf
+3);
printf("%-10s %-3d ", line
+1, atoi(cf
+3));
default: /* some format specifer and file name? */
if (line
[0] < 'a' || line
[0] > 'z')
if (j
== 0 || strcmp(file
, line
+1) != 0)
printf("%D bytes\n", totsize
);
if (users
== 0 && requests
== 0)
* Check to see if it's in the user list
for (u
= user
; u
< &user
[users
]; u
++)
for (n
= 0, cp
= file
+3; isdigit(*cp
); )
n
= n
* 10 + (*cp
++ - '0');
for (r
= requ
; r
< &requ
[requests
]; r
++)
if (*r
== n
&& !strcmp(cp
, from
))
show(nfile
, file
, copies
)
register char *nfile
, *file
;
if (strcmp(nfile
, " ") == 0)
nfile
= "(standard input)";
ldump(nfile
, file
, copies
);
dump(nfile
, file
, copies
);
* Fill the line with blanks to the specified column
* Give the abbreviated dump of the file names
dump(nfile
, file
, copies
)
* Print as many files as will fit
* (leaving room for the total size)
fill
= first
? 0 : 2; /* fill space for ``, '' */
if (((n
= strlen(nfile
)) + col
+ fill
) >= SIZCOL
-4) {
printf(" ..."), col
+= 4;
if (*file
&& !stat(file
, &lbuf
))
totsize
+= copies
* lbuf
.st_size
;
* Print the long info about the file
ldump(nfile
, file
, copies
)
printf("%-2d copies of %-19s", copies
, nfile
);
if (*file
&& !stat(file
, &lbuf
))
printf(" %D bytes", lbuf
.st_size
);
* Print the job's rank in the queue,
* update col for screen management
"th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th"
(void) sprintf(line
, "%dth", n
);
(void) sprintf(line
, "%d%s", n
, r
[n
%10]);