displayq.c (68401) | displayq.c (78146) |
---|---|
1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 22 unchanged lines hidden (view full) --- 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint 35/* 36static char sccsid[] = "@(#)displayq.c 8.4 (Berkeley) 4/28/95"; 37*/ 38static const char rcsid[] = | 1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 22 unchanged lines hidden (view full) --- 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint 35/* 36static char sccsid[] = "@(#)displayq.c 8.4 (Berkeley) 4/28/95"; 37*/ 38static const char rcsid[] = |
39 "$FreeBSD: head/usr.sbin/lpr/common_source/displayq.c 68401 2000-11-06 19:36:38Z gad $"; | 39 "$FreeBSD: head/usr.sbin/lpr/common_source/displayq.c 78146 2001-06-12 16:38:20Z gad $"; |
40#endif /* not lint */ 41 42#include <sys/param.h> 43#include <sys/stat.h> 44 45#include <ctype.h> 46#include <dirent.h> 47#include <errno.h> --- 28 unchanged lines hidden (view full) --- 76static char current[40]; /* current file being printed */ 77static char file[132]; /* print file name */ 78static int first; /* first file in ``files'' column? */ 79static int garbage; /* # of garbage cf files */ 80static int lflag; /* long output option */ 81static int rank; /* order to be printed (-1=none, 0=active) */ 82static long totsize; /* total print job size in bytes */ 83 | 40#endif /* not lint */ 41 42#include <sys/param.h> 43#include <sys/stat.h> 44 45#include <ctype.h> 46#include <dirent.h> 47#include <errno.h> --- 28 unchanged lines hidden (view full) --- 76static char current[40]; /* current file being printed */ 77static char file[132]; /* print file name */ 78static int first; /* first file in ``files'' column? */ 79static int garbage; /* # of garbage cf files */ 80static int lflag; /* long output option */ 81static int rank; /* order to be printed (-1=none, 0=active) */ 82static long totsize; /* total print job size in bytes */ 83 |
84static char *head0 = "Rank Owner Job Files"; 85static char *head1 = "Total Size\n"; | 84static const char *head0 = "Rank Owner Job Files"; 85static const char *head1 = "Total Size\n"; |
86 | 86 |
87static void alarmhandler __P((int)); 88static void warn __P((const struct printer *pp)); | 87static void alarmhandler(int _signo); 88static void warn(const struct printer *_pp); |
89 90/* 91 * Display the current state of the queue. Format = 1 if long format. 92 */ 93void | 89 90/* 91 * Display the current state of the queue. Format = 1 if long format. 92 */ 93void |
94displayq(pp, format) 95 struct printer *pp; 96 int format; | 94displayq(struct printer *pp, int format) |
97{ 98 register struct jobqueue *q; 99 register int i, nitems, fd, ret; 100 register char *cp; 101 struct jobqueue **queue; 102 struct stat statb; 103 FILE *fp; 104 void (*savealrm)(int); --- 148 unchanged lines hidden (view full) --- 253 (void) close(fd); 254 } 255} 256 257/* 258 * Print a warning message if there is no daemon present. 259 */ 260static void | 95{ 96 register struct jobqueue *q; 97 register int i, nitems, fd, ret; 98 register char *cp; 99 struct jobqueue **queue; 100 struct stat statb; 101 FILE *fp; 102 void (*savealrm)(int); --- 148 unchanged lines hidden (view full) --- 251 (void) close(fd); 252 } 253} 254 255/* 256 * Print a warning message if there is no daemon present. 257 */ 258static void |
261warn(pp) 262 const struct printer *pp; | 259warn(const struct printer *pp) |
263{ 264 if (pp->remote) 265 printf("%s: ", host); 266 puts("Warning: no daemon present"); 267 current[0] = '\0'; 268} 269 270/* 271 * Print the header for the short listing format 272 */ 273void | 260{ 261 if (pp->remote) 262 printf("%s: ", host); 263 puts("Warning: no daemon present"); 264 current[0] = '\0'; 265} 266 267/* 268 * Print the header for the short listing format 269 */ 270void |
274header() | 271header(void) |
275{ 276 printf(head0); 277 col = strlen(head0)+1; 278 blankfill(SIZCOL); 279 printf(head1); 280} 281 282void | 272{ 273 printf(head0); 274 col = strlen(head0)+1; 275 blankfill(SIZCOL); 276 printf(head1); 277} 278 279void |
283inform(pp, cf) 284 const struct printer *pp; 285 char *cf; | 280inform(const struct printer *pp, char *cf) |
286{ 287 register int copycnt; 288 char savedname[MAXPATHLEN+1]; 289 FILE *cfp; 290 291 /* 292 * There's a chance the control file has gone away 293 * in the meantime; if this is the case just keep going --- 83 unchanged lines hidden (view full) --- 377 if (!lflag) { 378 blankfill(SIZCOL); 379 printf("%ld bytes\n", totsize); 380 totsize = 0; 381 } 382} 383 384int | 281{ 282 register int copycnt; 283 char savedname[MAXPATHLEN+1]; 284 FILE *cfp; 285 286 /* 287 * There's a chance the control file has gone away 288 * in the meantime; if this is the case just keep going --- 83 unchanged lines hidden (view full) --- 372 if (!lflag) { 373 blankfill(SIZCOL); 374 printf("%ld bytes\n", totsize); 375 totsize = 0; 376 } 377} 378 379int |
385inlist(name, file) 386 char *name, *file; | 380inlist(char *uname, char *cfile) |
387{ 388 register int *r, n; 389 register char **u, *cp; 390 391 if (users == 0 && requests == 0) 392 return(1); 393 /* 394 * Check to see if it's in the user list 395 */ 396 for (u = user; u < &user[users]; u++) | 381{ 382 register int *r, n; 383 register char **u, *cp; 384 385 if (users == 0 && requests == 0) 386 return(1); 387 /* 388 * Check to see if it's in the user list 389 */ 390 for (u = user; u < &user[users]; u++) |
397 if (!strcmp(*u, name)) | 391 if (!strcmp(*u, uname)) |
398 return(1); 399 /* 400 * Check the request list 401 */ | 392 return(1); 393 /* 394 * Check the request list 395 */ |
402 for (n = 0, cp = file+3; isdigit(*cp); ) | 396 for (n = 0, cp = cfile+3; isdigit(*cp); ) |
403 n = n * 10 + (*cp++ - '0'); 404 for (r = requ; r < &requ[requests]; r++) 405 if (*r == n && !strcmp(cp, from)) 406 return(1); 407 return(0); 408} 409 410void | 397 n = n * 10 + (*cp++ - '0'); 398 for (r = requ; r < &requ[requests]; r++) 399 if (*r == n && !strcmp(cp, from)) 400 return(1); 401 return(0); 402} 403 404void |
411show(nfile, file, copies) 412 register char *nfile, *file; 413 int copies; | 405show(const char *nfile, const char *datafile, int copies) |
414{ 415 if (strcmp(nfile, " ") == 0) 416 nfile = "(standard input)"; 417 if (lflag) | 406{ 407 if (strcmp(nfile, " ") == 0) 408 nfile = "(standard input)"; 409 if (lflag) |
418 ldump(nfile, file, copies); | 410 ldump(nfile, datafile, copies); |
419 else | 411 else |
420 dump(nfile, file, copies); | 412 dump(nfile, datafile, copies); |
421} 422 423/* 424 * Fill the line with blanks to the specified column 425 */ 426void | 413} 414 415/* 416 * Fill the line with blanks to the specified column 417 */ 418void |
427blankfill(n) 428 register int n; | 419blankfill(int tocol) |
429{ | 420{ |
430 while (col++ < n) | 421 while (col++ < tocol) |
431 putchar(' '); 432} 433 434/* 435 * Give the abbreviated dump of the file names 436 */ 437void | 422 putchar(' '); 423} 424 425/* 426 * Give the abbreviated dump of the file names 427 */ 428void |
438dump(nfile, file, copies) 439 char *nfile, *file; 440 int copies; | 429dump(const char *nfile, const char *datafile, int copies) |
441{ 442 struct stat lbuf; 443 const char etctmpl[] = ", ..."; 444 char etc[sizeof(etctmpl)]; 445 char *lastsep; 446 short fill, nlen; 447 short rem, remetc; 448 --- 34 unchanged lines hidden (view full) --- 483 if (!first) 484 printf(", "); 485 printf("%s", nfile); 486 col += nlen + fill; 487 } 488 first = 0; 489 490 seteuid(euid); | 430{ 431 struct stat lbuf; 432 const char etctmpl[] = ", ..."; 433 char etc[sizeof(etctmpl)]; 434 char *lastsep; 435 short fill, nlen; 436 short rem, remetc; 437 --- 34 unchanged lines hidden (view full) --- 472 if (!first) 473 printf(", "); 474 printf("%s", nfile); 475 col += nlen + fill; 476 } 477 first = 0; 478 479 seteuid(euid); |
491 if (*file && !stat(file, &lbuf)) | 480 if (*datafile && !stat(datafile, &lbuf)) |
492 totsize += copies * lbuf.st_size; 493 seteuid(uid); 494} 495 496/* 497 * Print the long info about the file 498 */ 499void | 481 totsize += copies * lbuf.st_size; 482 seteuid(uid); 483} 484 485/* 486 * Print the long info about the file 487 */ 488void |
500ldump(nfile, file, copies) 501 char *nfile, *file; 502 int copies; | 489ldump(const char *nfile, const char *datafile, int copies) |
503{ 504 struct stat lbuf; 505 506 putchar('\t'); 507 if (copies > 1) 508 printf("%-2d copies of %-19s", copies, nfile); 509 else 510 printf("%-32s", nfile); | 490{ 491 struct stat lbuf; 492 493 putchar('\t'); 494 if (copies > 1) 495 printf("%-2d copies of %-19s", copies, nfile); 496 else 497 printf("%-32s", nfile); |
511 if (*file && !stat(file, &lbuf)) | 498 if (*datafile && !stat(datafile, &lbuf)) |
512 printf(" %qd bytes", (long long) lbuf.st_size); 513 else 514 printf(" ??? bytes"); 515 putchar('\n'); 516} 517 518/* 519 * Print the job's rank in the queue, 520 * update col for screen management 521 */ 522void | 499 printf(" %qd bytes", (long long) lbuf.st_size); 500 else 501 printf(" ??? bytes"); 502 putchar('\n'); 503} 504 505/* 506 * Print the job's rank in the queue, 507 * update col for screen management 508 */ 509void |
523prank(n) 524 int n; | 510prank(int n) |
525{ 526 char rline[100]; | 511{ 512 char rline[100]; |
527 static char *r[] = { | 513 static const char *r[] = { |
528 "th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th" 529 }; 530 531 if (n == 0) { 532 printf("active"); 533 col += 6; 534 return; 535 } 536 if ((n/10)%10 == 1) 537 (void)snprintf(rline, sizeof(rline), "%dth", n); 538 else 539 (void)snprintf(rline, sizeof(rline), "%d%s", n, r[n%10]); 540 col += strlen(rline); 541 printf("%s", rline); 542} 543 544void | 514 "th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th" 515 }; 516 517 if (n == 0) { 518 printf("active"); 519 col += 6; 520 return; 521 } 522 if ((n/10)%10 == 1) 523 (void)snprintf(rline, sizeof(rline), "%dth", n); 524 else 525 (void)snprintf(rline, sizeof(rline), "%d%s", n, r[n%10]); 526 col += strlen(rline); 527 printf("%s", rline); 528} 529 530void |
545alarmhandler(signo) 546 int signo; | 531alarmhandler(int signo __unused) |
547{ | 532{ |
548 /* ignored */ | 533 /* the signal is ignored */ 534 /* (the '__unused' is just to avoid a compile-time warning) */ |
549} | 535} |