home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume22 / queuer / part02 / showqueue.c < prev   
C/C++ Source or Header  |  1990-06-07  |  2KB  |  99 lines

  1. /* Copyright 1990  The President and Fellows of Harvard University
  2.  
  3. Permission to use, copy, modify, and distribute this program for any
  4. purpose and without fee is hereby granted, provided that this
  5. copyright and permission notice appear on all copies and supporting
  6. documentation, the name of Harvard University not be used in advertising
  7. or publicity pertaining to distribution of the program, or to results
  8. derived from its use, without specific prior written permission, and notice
  9. be given in supporting documentation that copying and distribution is by
  10. permission of Harvard University.  Harvard University makes no
  11. representations about the suitability of this software for any purpose.
  12. It is provided "as is" without express or implied warranty.    */
  13.  
  14.  
  15. /* showqueue.c - Dan Lanciani '85 */
  16.  
  17. #include <stdio.h>
  18. #include <sys/types.h>
  19. #include <sys/stat.h>
  20.  
  21. #include "queue.h"
  22.  
  23. showqueue(s)
  24. {
  25.     struct stat statb;
  26.     char buf[BUFSIZ], tbuf[BUFSIZ], lhost[BUFSIZ];
  27.     register FILE *n, *m, *l;
  28.     register int i, c, oneonly = 0;
  29.  
  30.     gethostname(lhost, BUFSIZ);
  31.     for(i = 0; i < 3; i++)
  32.         dup2(s, i);
  33.     getstr(s, buf);
  34.     if(s > 2)
  35.         close(s);
  36.     if(*buf) {
  37.         oneonly++;
  38.         goto onlyone;
  39.     }
  40.     if(!(n = fopen(QUEUES, "r"))) {
  41.         fprintf(stderr, "No QUEUES file\n");
  42.         exit(1);
  43.     }
  44.  
  45.     while(fgets(buf, sizeof(buf), n)) {
  46.         buf[strlen(buf)-1] = '\0';
  47.     onlyone:
  48.         printf("Queue: %s, Host: %s\n", buf, lhost);
  49.         sprintf(tbuf, "%s/%s", SPOOLDIR, buf);
  50.         if(m = fopen(tbuf, "r")) {
  51.             printf("Pid\t\tState\tUser\tHost\tCommand\n");
  52.             while(fgets(buf, sizeof(buf), m)) {
  53.                 buf[strlen(buf)-1] = '\0';
  54.                 i = atoi(buf);
  55.                 sprintf(tbuf, "%s/%s", SPOOLDIR, buf);
  56.                 if(l = fopen(tbuf, "r")) {
  57.                     fgetstr(l, buf);
  58.                     fgetstr(l, buf);
  59.                     if(atol(buf))
  60.                         printf("%-16ld", atol(buf));
  61.                     else
  62.                         printf("%-16d", i);
  63.                     if(!fstat(fileno(l), &statb) &&
  64.                         (statb.st_mode&0111))
  65.                         printf("RUN\t");
  66.                     else
  67.                         printf("WAIT\t");
  68.                     fgetstr(l, buf);
  69.                     c = atoi(buf);
  70.                     for(i = 0; i < c; i++)
  71.                         fgetstr(l, buf);
  72.                     fgetstr(l, buf);
  73.                     printf("%s\t", buf);
  74.                     rewind(l);
  75.                     fgetstr(l, buf);
  76.                     printf("%s\t", buf);
  77.                     fgetstr(l, buf);
  78.                     fgetstr(l, buf);
  79.                     c = atoi(buf);
  80.                     for(i = 0; i < c; i++) {
  81.                         fgetstr(l, buf);
  82.                         printf("%s ", buf);
  83.                     }
  84.                     fclose(l);
  85.                     printf("\n");
  86.                 }
  87.             }
  88.             printf("\n");
  89.             fclose(m);
  90.         }
  91.         else
  92.             printf("Warning:  File missing\n\n");
  93.         fflush(stdout);
  94.         if(oneonly)
  95.             exit(0);
  96.     }
  97.     fclose(n);
  98. }
  99.