xref: /csrg-svn/old/vpr/vpq.c (revision 2416)
1*2416Shalbert /* vpq.c		02/12/81
21852Sroot  * Varian and Versatec queue
31852Sroot  */
41852Sroot 
5*2416Shalbert static char vpqSCCSid[] = "@(#)vpq.c	1.2\t02/12/81";
6*2416Shalbert 
71852Sroot #include <sys/types.h>
81852Sroot #include <dir.h>
91852Sroot #include <stat.h>
101852Sroot #include <stdio.h>
111852Sroot #include <errno.h>
121852Sroot #define	MAXJOBS 100
131852Sroot 
141852Sroot struct	dir dirent;
151852Sroot struct	stat stbuf;
161852Sroot int	nextflag;
171852Sroot int	linecnt;
181852Sroot FILE	*df;
191852Sroot FILE	*jf;
201852Sroot char	line[100];
211852Sroot char	username[10];
221852Sroot int	cnt;
231852Sroot extern	int errno;
241852Sroot extern	char _sobuf[];
251852Sroot 
261852Sroot main(argc, argv)
271852Sroot int argc;
281852Sroot char **argv;
291852Sroot {
301852Sroot 	int varian = 1;
311852Sroot 	int versatec = 1;
321852Sroot 
331852Sroot 	setbuf(stdout, _sobuf);
341852Sroot 
351852Sroot 	argc--, argv++;
361852Sroot 	while (argc > 0 && argv[0][0] == '-') {
371852Sroot 		switch (argv[0][1]) {
381852Sroot 
391852Sroot 		case 'W':		/* Wide: the versatec. */
401852Sroot 			varian = 0;
411852Sroot 			versatec++;
421852Sroot 			break;
431852Sroot 
441852Sroot 		case 'b':
451852Sroot 			varian++;
461852Sroot 			versatec++;
471852Sroot 			break;
481852Sroot 
491852Sroot 		default:
501852Sroot 			fprintf(stderr, "usage: vpq [ -W ] [ -b ]\n");
511852Sroot 			exit(1);
521852Sroot 		}
531852Sroot 		argc--, argv++;
541852Sroot 	}
551852Sroot 	if (varian)
561852Sroot 		queue("/dev/va0", "Varian", "/usr/spool/vad", "/usr/lib/vad");
571852Sroot 	if (versatec)
581852Sroot 		queue("/dev/vp0", "Versatec", "/usr/spool/vpd", "/usr/lib/vpd");
591852Sroot 	exit(0);
601852Sroot }
611852Sroot 
621852Sroot 
631852Sroot queue(device, devname, spooldir, daemon)
641852Sroot char *device, *devname, *spooldir, *daemon;
651852Sroot {
661852Sroot 	FILE *vc;
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 	}
871852Sroot oloop:
881852Sroot 	df = fopen(".", "r");
891852Sroot 	if (df == NULL) {
901852Sroot 		perror(spooldir);
911852Sroot 		return;
921852Sroot 	}
931852Sroot loop:
941852Sroot 	fseek(df, 0l, 0);
951852Sroot 	linecnt = 0;
961852Sroot 	cnt = 0;
971852Sroot 	while (fread(&dirent, sizeof dirent, 1, df) == 1) {
981852Sroot 		if (dirent.d_ino == 0)
991852Sroot 			continue;
1001852Sroot 		if (dirent.d_name[0] != 'd')
1011852Sroot 			continue;
1021852Sroot 		if (dirent.d_name[1] != 'f')
1031852Sroot 			continue;
1041852Sroot 		if (stat(dirent.d_name, &stbuf) < 0)
1051852Sroot 			continue;
1061852Sroot 		if (cnt == 0)
1071852Sroot 			printf("Owner\t  Id      Chars  Filename\n");
1081852Sroot 		cnt++;
1091852Sroot 		process();
1101852Sroot 	}
1111852Sroot 	if (cnt == 0)
1121852Sroot 		printf("Queue is empty.\n");
1131852Sroot 	printf("\n");
1141852Sroot }
1151852Sroot 
1161852Sroot process()
1171852Sroot {
1181852Sroot 
1191852Sroot 	jf = fopen(dirent.d_name, "r");
1201852Sroot 	if (jf == NULL)
1211852Sroot 		return;
1221852Sroot 	while (getline()) {
1231852Sroot 		switch (line[0]) {
1241852Sroot 
1251852Sroot 		case 'L':
1261852Sroot 			strcpy(username, line+1);
1271852Sroot 			break;
1281852Sroot 
129*2416Shalbert 		case 'C':
130*2416Shalbert 		case 'V':
1311852Sroot 		case 'F':
1321852Sroot 		case 'G':
1331852Sroot 		case 'P':
1341852Sroot 		case 'T':
1351852Sroot 			if (stat(line+1, &stbuf) < 0)
1361852Sroot 				stbuf.st_size = 0;
1371852Sroot 			printf("%-10s%5s%8d  %s\n", username, dirent.d_name+3,
1381852Sroot 			    stbuf.st_size, line+1);
1391852Sroot 			break;
1401852Sroot 		}
1411852Sroot 	}
1421852Sroot 	fclose(jf);
1431852Sroot }
1441852Sroot 
1451852Sroot getline()
1461852Sroot {
1471852Sroot 	register int i, c;
1481852Sroot 
1491852Sroot 	i = 0;
1501852Sroot 	while ((c = getc(jf)) != '\n') {
1511852Sroot 		if (c <= 0)
1521852Sroot 			return(0);
1531852Sroot 		if (i < 100)
1541852Sroot 			line[i++] = c;
1551852Sroot 	}
1561852Sroot 	line[i++] = 0;
1571852Sroot 	return (1);
1581852Sroot }
159