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