Added printing of C and V commands lines; removed printing of B
[unix-history] / usr / src / old / vpr / vpq.c
CommitLineData
36b073d4 1/* vpq.c %G%
c8c4b75c
BJ
2 * Varian and Versatec queue
3 */
4
36b073d4
DH
5static char vpqSCCSid[] = "@(#)vpq.c 1.2\t%G%";
6
c8c4b75c
BJ
7#include <sys/types.h>
8#include <dir.h>
9#include <stat.h>
10#include <stdio.h>
11#include <errno.h>
12#define MAXJOBS 100
13
14struct dir dirent;
15struct stat stbuf;
16int nextflag;
17int linecnt;
18FILE *df;
19FILE *jf;
20char line[100];
21char username[10];
22int cnt;
23extern int errno;
24extern char _sobuf[];
25
26main(argc, argv)
27int argc;
28char **argv;
29{
30 int varian = 1;
31 int versatec = 1;
32
33 setbuf(stdout, _sobuf);
34
35 argc--, argv++;
36 while (argc > 0 && argv[0][0] == '-') {
37 switch (argv[0][1]) {
38
39 case 'W': /* Wide: the versatec. */
40 varian = 0;
41 versatec++;
42 break;
43
44 case 'b':
45 varian++;
46 versatec++;
47 break;
48
49 default:
50 fprintf(stderr, "usage: vpq [ -W ] [ -b ]\n");
51 exit(1);
52 }
53 argc--, argv++;
54 }
55 if (varian)
56 queue("/dev/va0", "Varian", "/usr/spool/vad", "/usr/lib/vad");
57 if (versatec)
58 queue("/dev/vp0", "Versatec", "/usr/spool/vpd", "/usr/lib/vpd");
59 exit(0);
60}
61
62
63queue(device, devname, spooldir, daemon)
64char *device, *devname, *spooldir, *daemon;
65{
66 FILE *vc;
67
68 printf("%s: ", devname);
69 vc = fopen(device, "w");
70 if (vc == NULL) {
71 if (errno == EIO)
72 printf("offline\n");
73 else if (errno == ENXIO)
74 printf("in use\n");
75 else
76 printf("not available\n");
77 } else {
78 printf("ready and idle.\n");
79 fclose(vc);
80 }
81 if (access(daemon, 1))
82 printf("Daemon is disabled.\n");
83 if (chdir(spooldir) < 0) {
84 perror(spooldir);
85 return;
86 }
87oloop:
88 df = fopen(".", "r");
89 if (df == NULL) {
90 perror(spooldir);
91 return;
92 }
93loop:
94 fseek(df, 0l, 0);
95 linecnt = 0;
96 cnt = 0;
97 while (fread(&dirent, sizeof dirent, 1, df) == 1) {
98 if (dirent.d_ino == 0)
99 continue;
100 if (dirent.d_name[0] != 'd')
101 continue;
102 if (dirent.d_name[1] != 'f')
103 continue;
104 if (stat(dirent.d_name, &stbuf) < 0)
105 continue;
106 if (cnt == 0)
107 printf("Owner\t Id Chars Filename\n");
108 cnt++;
109 process();
110 }
111 if (cnt == 0)
112 printf("Queue is empty.\n");
113 printf("\n");
114}
115
116process()
117{
118
119 jf = fopen(dirent.d_name, "r");
120 if (jf == NULL)
121 return;
122 while (getline()) {
123 switch (line[0]) {
124
125 case 'L':
126 strcpy(username, line+1);
127 break;
128
36b073d4
DH
129 case 'C':
130 case 'V':
c8c4b75c
BJ
131 case 'F':
132 case 'G':
133 case 'P':
134 case 'T':
135 if (stat(line+1, &stbuf) < 0)
136 stbuf.st_size = 0;
137 printf("%-10s%5s%8d %s\n", username, dirent.d_name+3,
138 stbuf.st_size, line+1);
139 break;
140 }
141 }
142 fclose(jf);
143}
144
145getline()
146{
147 register int i, c;
148
149 i = 0;
150 while ((c = getc(jf)) != '\n') {
151 if (c <= 0)
152 return(0);
153 if (i < 100)
154 line[i++] = c;
155 }
156 line[i++] = 0;
157 return (1);
158}