1*7662Smckusick /* vpq.c 08/06/82 21852Sroot * Varian and Versatec queue 31852Sroot */ 41852Sroot 5*7662Smckusick static char vpqSCCSid[] = "@(#)vpq.c 1.3\t08/06/82"; 62416Shalbert 7*7662Smckusick #include <sys/param.h> 81852Sroot #include <dir.h> 91852Sroot #include <stat.h> 101852Sroot #include <stdio.h> 111852Sroot #include <errno.h> 121852Sroot #define MAXJOBS 100 131852Sroot 141852Sroot struct stat stbuf; 151852Sroot int nextflag; 161852Sroot int linecnt; 171852Sroot FILE *jf; 181852Sroot char line[100]; 191852Sroot char username[10]; 201852Sroot int cnt; 211852Sroot extern int errno; 221852Sroot extern char _sobuf[]; 231852Sroot 241852Sroot main(argc, argv) 251852Sroot int argc; 261852Sroot char **argv; 271852Sroot { 281852Sroot int varian = 1; 291852Sroot int versatec = 1; 301852Sroot 311852Sroot setbuf(stdout, _sobuf); 321852Sroot 331852Sroot argc--, argv++; 341852Sroot while (argc > 0 && argv[0][0] == '-') { 351852Sroot switch (argv[0][1]) { 361852Sroot 371852Sroot case 'W': /* Wide: the versatec. */ 381852Sroot varian = 0; 391852Sroot versatec++; 401852Sroot break; 411852Sroot 421852Sroot case 'b': 431852Sroot varian++; 441852Sroot versatec++; 451852Sroot break; 461852Sroot 471852Sroot default: 481852Sroot fprintf(stderr, "usage: vpq [ -W ] [ -b ]\n"); 491852Sroot exit(1); 501852Sroot } 511852Sroot argc--, argv++; 521852Sroot } 531852Sroot if (varian) 541852Sroot queue("/dev/va0", "Varian", "/usr/spool/vad", "/usr/lib/vad"); 551852Sroot if (versatec) 561852Sroot queue("/dev/vp0", "Versatec", "/usr/spool/vpd", "/usr/lib/vpd"); 571852Sroot exit(0); 581852Sroot } 591852Sroot 601852Sroot 611852Sroot queue(device, devname, spooldir, daemon) 621852Sroot char *device, *devname, *spooldir, *daemon; 631852Sroot { 641852Sroot FILE *vc; 65*7662Smckusick DIR *df; 66*7662Smckusick register struct direct *dirp; 671852Sroot 681852Sroot printf("%s: ", devname); 691852Sroot vc = fopen(device, "w"); 701852Sroot if (vc == NULL) { 711852Sroot if (errno == EIO) 721852Sroot printf("offline\n"); 731852Sroot else if (errno == ENXIO) 741852Sroot printf("in use\n"); 751852Sroot else 761852Sroot printf("not available\n"); 771852Sroot } else { 781852Sroot printf("ready and idle.\n"); 791852Sroot fclose(vc); 801852Sroot } 811852Sroot if (access(daemon, 1)) 821852Sroot printf("Daemon is disabled.\n"); 831852Sroot if (chdir(spooldir) < 0) { 841852Sroot perror(spooldir); 851852Sroot return; 861852Sroot } 87*7662Smckusick df = opendir("."); 881852Sroot if (df == NULL) { 891852Sroot perror(spooldir); 901852Sroot return; 911852Sroot } 921852Sroot linecnt = 0; 931852Sroot cnt = 0; 94*7662Smckusick while ((dirp = readdir(df)) != NULL) { 95*7662Smckusick if (dirp->d_name[0] != 'd') 961852Sroot continue; 97*7662Smckusick if (dirp->d_name[1] != 'f') 981852Sroot continue; 99*7662Smckusick if (stat(dirp->d_name, &stbuf) < 0) 1001852Sroot continue; 1011852Sroot if (cnt == 0) 1021852Sroot printf("Owner\t Id Chars Filename\n"); 1031852Sroot cnt++; 104*7662Smckusick process(dirp); 1051852Sroot } 106*7662Smckusick closedir(df); 1071852Sroot if (cnt == 0) 1081852Sroot printf("Queue is empty.\n"); 1091852Sroot printf("\n"); 1101852Sroot } 1111852Sroot 112*7662Smckusick process(dirp) 113*7662Smckusick register struct direct *dirp; 1141852Sroot { 1151852Sroot 116*7662Smckusick jf = fopen(dirp->d_name, "r"); 1171852Sroot if (jf == NULL) 1181852Sroot return; 1191852Sroot while (getline()) { 1201852Sroot switch (line[0]) { 1211852Sroot 1221852Sroot case 'L': 1231852Sroot strcpy(username, line+1); 1241852Sroot break; 1251852Sroot 1262416Shalbert case 'C': 1272416Shalbert case 'V': 1281852Sroot case 'F': 1291852Sroot case 'G': 1301852Sroot case 'P': 1311852Sroot case 'T': 1321852Sroot if (stat(line+1, &stbuf) < 0) 1331852Sroot stbuf.st_size = 0; 134*7662Smckusick printf("%-10s%5s%8d %s\n", username, 135*7662Smckusick &(dirp->d_name[3]), stbuf.st_size, line+1); 1361852Sroot break; 1371852Sroot } 1381852Sroot } 1391852Sroot fclose(jf); 1401852Sroot } 1411852Sroot 1421852Sroot getline() 1431852Sroot { 1441852Sroot register int i, c; 1451852Sroot 1461852Sroot i = 0; 1471852Sroot while ((c = getc(jf)) != '\n') { 1481852Sroot if (c <= 0) 1491852Sroot return(0); 1501852Sroot if (i < 100) 1511852Sroot line[i++] = c; 1521852Sroot } 1531852Sroot line[i++] = 0; 1541852Sroot return (1); 1551852Sroot } 156