xref: /csrg-svn/old/vpr/vprm.c (revision 1854)
1*1854Sroot #include <sys/types.h>
2*1854Sroot #include <dir.h>
3*1854Sroot #include <stat.h>
4*1854Sroot #include <stdio.h>
5*1854Sroot 
6*1854Sroot char	line[128];
7*1854Sroot int	linel;
8*1854Sroot int	wide;
9*1854Sroot char	*spooldir;
10*1854Sroot FILE	*df;
11*1854Sroot FILE	*dfb;
12*1854Sroot extern	char _sobuf[];
13*1854Sroot 
14*1854Sroot main(argc, argv)
15*1854Sroot 	int argc;
16*1854Sroot 	char *argv[];
17*1854Sroot {
18*1854Sroot 	register int i;
19*1854Sroot 	register char *ap, *cp;
20*1854Sroot 	int cnt;
21*1854Sroot 	int oldargc;
22*1854Sroot 	char **oldargv;
23*1854Sroot 
24*1854Sroot 	setbuf(stdout, _sobuf);
25*1854Sroot 	argc--, argv++;
26*1854Sroot 	if (argc == 0) {
27*1854Sroot 		fprintf(stderr, "usage: vprm [ id ... ] [ filename ... ] [ user ... ]\n");
28*1854Sroot 		exit(1);
29*1854Sroot 	}
30*1854Sroot 
31*1854Sroot 
32*1854Sroot 	oldargc = argc; oldargv = argv;
33*1854Sroot 
34*1854Sroot 	printf("Varian - ");
35*1854Sroot 	if (chdir("/usr/spool/vad") < 0)
36*1854Sroot 		perror("/usr/spool/vad");
37*1854Sroot 	else {
38*1854Sroot 		df = fopen(".", "r");
39*1854Sroot 		if (df == NULL)
40*1854Sroot 			perror("/usr/spool/vad");
41*1854Sroot 		else do {
42*1854Sroot 			clobber(*oldargv++);
43*1854Sroot 		} while (--oldargc);
44*1854Sroot 	}
45*1854Sroot 
46*1854Sroot 	printf("Versatec - ");
47*1854Sroot 	if (chdir("/usr/spool/vpd") < 0)
48*1854Sroot 		perror("/usr/spool/vpd");
49*1854Sroot 	else {
50*1854Sroot 		df = fopen(".", "r");
51*1854Sroot 		if (df == NULL)
52*1854Sroot 			perror("/usr/spool/vpd");
53*1854Sroot 		else do {
54*1854Sroot 			clobber(*argv++);
55*1854Sroot 		} while (--argc);
56*1854Sroot 	}
57*1854Sroot }
58*1854Sroot 
59*1854Sroot clobber(cp)
60*1854Sroot 	char *cp;
61*1854Sroot {
62*1854Sroot 	struct dir dirent;
63*1854Sroot 	int did = 0;
64*1854Sroot 
65*1854Sroot 	rewind(df);
66*1854Sroot 	while (fread(&dirent, sizeof dirent, 1, df) == 1) {
67*1854Sroot 		if (dirent.d_ino == 0)
68*1854Sroot 			continue;
69*1854Sroot 		if (dirent.d_name[0] != 'd' || dirent.d_name[1] != 'f')
70*1854Sroot 			continue;
71*1854Sroot 		if (dirent.d_name[7] == 0 || dirent.d_name[8] != 0)
72*1854Sroot 			continue;
73*1854Sroot 		if (chkclob(cp, dirent.d_name)) {
74*1854Sroot 			did++;
75*1854Sroot 			printf("removing %s\n", dirent.d_name+3);
76*1854Sroot 			unlink(dirent.d_name);
77*1854Sroot 			dirent.d_name[0] = 'c'; unlink(dirent.d_name);
78*1854Sroot 			dirent.d_name[2] = 'b'; unlink(dirent.d_name);
79*1854Sroot 			dirent.d_name[2] = 'a';
80*1854Sroot 			dirent.d_name[0] = 'l'; unlink(dirent.d_name);
81*1854Sroot 			dirent.d_name[0] = 't'; unlink(dirent.d_name);
82*1854Sroot 			dirent.d_name[0] = 'd';
83*1854Sroot 		}
84*1854Sroot 	}
85*1854Sroot 	if (did == 0)
86*1854Sroot 		printf("%s: nothing to remove\n", cp);
87*1854Sroot }
88*1854Sroot 
89*1854Sroot chkclob(pattern, file)
90*1854Sroot 	char *pattern, *file;
91*1854Sroot {
92*1854Sroot 	register char *id = pattern;
93*1854Sroot 
94*1854Sroot 	/*
95*1854Sroot 	 * Quick check for matching id
96*1854Sroot 	 */
97*1854Sroot 	if (any(id[0], "cd") && id[1] == 'f' && id[2] == 'a')
98*1854Sroot 		id += 3;
99*1854Sroot 	if (strcmp(file+3, id) == 0)
100*1854Sroot 		return (1);
101*1854Sroot 	/*
102*1854Sroot 	 * Now check for matching filename 'B', 'F' or id 'L'
103*1854Sroot 	 */
104*1854Sroot 	dfb = fopen(file, "r");
105*1854Sroot 	if (dfb == NULL)
106*1854Sroot 		return (0);
107*1854Sroot 	while (getline()) switch (line[0]) {
108*1854Sroot 
109*1854Sroot 	case 'L':
110*1854Sroot 	case 'B':
111*1854Sroot 	case 'F':
112*1854Sroot 	case 'T':
113*1854Sroot 		if (strcmp(line+1, pattern) == 0) {
114*1854Sroot 			fclose(dfb);
115*1854Sroot 			return (1);
116*1854Sroot 		}
117*1854Sroot 		continue;
118*1854Sroot 	}
119*1854Sroot 	fclose(dfb);
120*1854Sroot 	return (0);
121*1854Sroot }
122*1854Sroot 
123*1854Sroot any(c, cp)
124*1854Sroot 	char c;
125*1854Sroot 	register char *cp;
126*1854Sroot {
127*1854Sroot 
128*1854Sroot 	while (*cp)
129*1854Sroot 		if (c == *cp++)
130*1854Sroot 			return (1);
131*1854Sroot 	return (0);
132*1854Sroot }
133*1854Sroot 
134*1854Sroot getline()
135*1854Sroot {
136*1854Sroot 	register int i, c;
137*1854Sroot 
138*1854Sroot 	i = 0;
139*1854Sroot 	while ((c = getc(dfb)) != '\n') {
140*1854Sroot 		if (c <= 0)
141*1854Sroot 			return(0);
142*1854Sroot 		if (i < 100)
143*1854Sroot 			line[i++] = c;
144*1854Sroot 	}
145*1854Sroot 	line[i++] = 0;
146*1854Sroot 	return (1);
147*1854Sroot }
148