xref: /csrg-svn/old/vpr/vpq.c (revision 32589)
1*32589Sbostic /* vpq.c		11/04/87
21852Sroot  * Varian and Versatec queue
31852Sroot  */
41852Sroot 
5*32589Sbostic static char vpqSCCSid[] = "@(#)vpq.c	1.4\t11/04/87";
62416Shalbert 
77662Smckusick #include <sys/param.h>
8*32589Sbostic #include <sys/dir.h>
9*32589Sbostic #include <sys/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 
main(argc,argv)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 
queue(device,devname,spooldir,daemon)611852Sroot queue(device, devname, spooldir, daemon)
621852Sroot char *device, *devname, *spooldir, *daemon;
631852Sroot {
641852Sroot 	FILE *vc;
657662Smckusick 	DIR *df;
667662Smckusick 	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 	}
877662Smckusick 	df = opendir(".");
881852Sroot 	if (df == NULL) {
891852Sroot 		perror(spooldir);
901852Sroot 		return;
911852Sroot 	}
921852Sroot 	linecnt = 0;
931852Sroot 	cnt = 0;
947662Smckusick 	while ((dirp = readdir(df)) != NULL) {
957662Smckusick 		if (dirp->d_name[0] != 'd')
961852Sroot 			continue;
977662Smckusick 		if (dirp->d_name[1] != 'f')
981852Sroot 			continue;
997662Smckusick 		if (stat(dirp->d_name, &stbuf) < 0)
1001852Sroot 			continue;
1011852Sroot 		if (cnt == 0)
1021852Sroot 			printf("Owner\t  Id      Chars  Filename\n");
1031852Sroot 		cnt++;
1047662Smckusick 		process(dirp);
1051852Sroot 	}
1067662Smckusick 	closedir(df);
1071852Sroot 	if (cnt == 0)
1081852Sroot 		printf("Queue is empty.\n");
1091852Sroot 	printf("\n");
1101852Sroot }
1111852Sroot 
process(dirp)1127662Smckusick process(dirp)
1137662Smckusick 	register struct direct *dirp;
1141852Sroot {
1151852Sroot 
1167662Smckusick 	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;
1347662Smckusick 			printf("%-10s%5s%8d  %s\n", username,
1357662Smckusick 			    &(dirp->d_name[3]), stbuf.st_size, line+1);
1361852Sroot 			break;
1371852Sroot 		}
1381852Sroot 	}
1391852Sroot 	fclose(jf);
1401852Sroot }
1411852Sroot 
getline()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