xref: /csrg-svn/contrib/vmsprep/vmsprep.c (revision 31969)
1*31969Sbostic 
2*31969Sbostic #include <stdio.h>
3*31969Sbostic #include <ctype.h>
4*31969Sbostic #include <strings.h>
5*31969Sbostic 
6*31969Sbostic main(argc,argv)
7*31969Sbostic 	int argc;
8*31969Sbostic 	char *argv[];
9*31969Sbostic 
10*31969Sbostic {
11*31969Sbostic 
12*31969Sbostic char cmd[1000];
13*31969Sbostic char *release;
14*31969Sbostic FILE *dirs;
15*31969Sbostic FILE *files;
16*31969Sbostic FILE *mover;
17*31969Sbostic FILE *popen();
18*31969Sbostic FILE *script;
19*31969Sbostic char dirname[1000];
20*31969Sbostic char filename[1000];
21*31969Sbostic char fixedname[1000];
22*31969Sbostic char fixedpath[1000];
23*31969Sbostic char tapename[10];
24*31969Sbostic char *scriptname = "UNPACK.COM";
25*31969Sbostic char *altscript = "/tmp/UNPACK.COMXXXXXX";
26*31969Sbostic char *startname = "AAAAAAAAA";
27*31969Sbostic int i;
28*31969Sbostic int j;
29*31969Sbostic char *k;
30*31969Sbostic int pathlen;
31*31969Sbostic int dot;
32*31969Sbostic int pipeout=0;
33*31969Sbostic 
34*31969Sbostic 	if(argc < 2) usage();
35*31969Sbostic 	if(*argv[1] == '-') {
36*31969Sbostic 		mover = stdout;
37*31969Sbostic 		pipeout=1;
38*31969Sbostic 	} else {
39*31969Sbostic 		mover = fopen("vmsprep.namelist","w");
40*31969Sbostic 	}
41*31969Sbostic 	strcpy(tapename,startname);
42*31969Sbostic 	if(pipeout) {
43*31969Sbostic 		mktemp(altscript);
44*31969Sbostic 		script = fopen(altscript,"w");
45*31969Sbostic 	} else {
46*31969Sbostic 		script = fopen(scriptname,"w");
47*31969Sbostic 	}
48*31969Sbostic 	for(j=1;j<argc;j++) {
49*31969Sbostic 		if(j==1 && *argv[j]=='-') continue;
50*31969Sbostic 		release = argv[j];
51*31969Sbostic 		strcpy(dirname,release);
52*31969Sbostic 		for(k=index(dirname,'/');k;k=index(k+1,'/')) {
53*31969Sbostic 			*k='\0';
54*31969Sbostic 			fprintf(script,"$ CREATE/DIR [.%s] \n",dirname);
55*31969Sbostic 			strcpy(dirname,release);
56*31969Sbostic 		}
57*31969Sbostic 		sprintf(cmd,
58*31969Sbostic 			"find %s \\! \\( -name RCS -o -name \\*,v -o -name SCCS -o -name s.\\* \\) -type d -print\n", release);
59*31969Sbostic 		dirs = popen(cmd,"r");
60*31969Sbostic 		while(!feof(dirs)) {
61*31969Sbostic 			*dirname = NULL;
62*31969Sbostic 			fscanf(dirs," %s ",dirname);
63*31969Sbostic 			if(*dirname == NULL) continue;
64*31969Sbostic 			for(i=0;i<strlen(dirname);i++) {
65*31969Sbostic 				if(dirname[i]=='/') {
66*31969Sbostic 					dirname[i]='.';
67*31969Sbostic 				} else if (dirname[i]=='.') {
68*31969Sbostic 					dirname[i]='Z';
69*31969Sbostic 					fprintf(stderr,"vmsprep: warning - dot in filename illegal-");
70*31969Sbostic 					fprintf(stderr,"dot replaced by 'Z' %s\n",filename);
71*31969Sbostic 				} else if (!(isalpha(dirname[i]) || isdigit(dirname[i]))) {
72*31969Sbostic 					fprintf(stderr," error:  bad character in directory name %s\n",
73*31969Sbostic 							dirname);
74*31969Sbostic 				} else if(islower(dirname[i])) {
75*31969Sbostic 					dirname[i]=toupper(dirname[i]);
76*31969Sbostic 				}
77*31969Sbostic 			}
78*31969Sbostic 			fprintf(script,"$ CREATE/DIR [.%s] \n",dirname);
79*31969Sbostic 		}
80*31969Sbostic 		pclose(dirs);
81*31969Sbostic 
82*31969Sbostic 		sprintf(cmd,
83*31969Sbostic 			"find %s \\! \\( -name RCS -o -name \\*,v -o -name SCCS -o -name s.\\* \\) -type f -print\n", release);
84*31969Sbostic 		files = popen(cmd,"r");
85*31969Sbostic 		while(!feof(files)) {
86*31969Sbostic 			fscanf(files," %s ",filename);
87*31969Sbostic 			if(*filename == NULL) continue;
88*31969Sbostic 			k = rindex(filename,'/') ;
89*31969Sbostic 			if(k != 0) {
90*31969Sbostic 				pathlen = k - filename;
91*31969Sbostic 			} else {
92*31969Sbostic 				pathlen=0;
93*31969Sbostic 				k = filename - 1;
94*31969Sbostic 			}
95*31969Sbostic 			strncpy(fixedpath,filename,pathlen);
96*31969Sbostic 			fixedpath[pathlen]='\0';
97*31969Sbostic 			strcpy(fixedname,k+1);
98*31969Sbostic 			for(i=0;i<pathlen;i++) {
99*31969Sbostic 				if(fixedpath[i]=='/') {
100*31969Sbostic 					fixedpath[i]='.';
101*31969Sbostic 				} else if (fixedpath[i]=='.') {
102*31969Sbostic 					fixedpath[i]='Z';
103*31969Sbostic 				} else if (!(isalpha(fixedpath[i]) || isdigit(fixedpath[i]))) {
104*31969Sbostic 					fprintf(stderr," error:  bad character in file name %s\n",
105*31969Sbostic 							filename);
106*31969Sbostic 				} else if(islower(fixedpath[i])) {
107*31969Sbostic 					fixedpath[i]=toupper(fixedpath[i]);
108*31969Sbostic 				}
109*31969Sbostic 			}
110*31969Sbostic 			for(i=0;i<strlen(fixedname);i++) {
111*31969Sbostic 				if(fixedname[i]=='/') {
112*31969Sbostic 					fixedname[i]='.';
113*31969Sbostic 				} else if (fixedname[i]=='.') {
114*31969Sbostic 					dot++;
115*31969Sbostic 					if(dot != 1) fixedname[i]='Z';
116*31969Sbostic 				} else if (!(isalpha(fixedname[i]) || isdigit(fixedname[i]))) {
117*31969Sbostic 					fprintf(stderr," error:  bad character in file name %s\n",
118*31969Sbostic 							filename);
119*31969Sbostic 					fixedname[i]='Z';
120*31969Sbostic 				} else if(islower(fixedname[i])) {
121*31969Sbostic 					fixedname[i]=toupper(fixedname[i]);
122*31969Sbostic 				}
123*31969Sbostic 			}
124*31969Sbostic 			if(dot >1 )
125*31969Sbostic 				fprintf(stderr,"error:  too many dots in filename %s \n",
126*31969Sbostic 					fixedname);
127*31969Sbostic 			sprintf(cmd,"%s %s.MOV\n", filename,tapename);
128*31969Sbostic 			fprintf(mover,"%s",cmd);
129*31969Sbostic 			if(*fixedpath != NULL) {
130*31969Sbostic 				fprintf(script,"$ RENAME %s.MOV [.%s]%s%s\n",tapename,fixedpath,
131*31969Sbostic 						fixedname,dot==0?".":"");
132*31969Sbostic 			} else {
133*31969Sbostic 				fprintf(script,"$ RENAME %s.MOV []%s%s\n",tapename,fixedname,
134*31969Sbostic 						dot==0?".":"");
135*31969Sbostic 			}
136*31969Sbostic 			dot=0;
137*31969Sbostic 			bumpname(tapename);
138*31969Sbostic 		}
139*31969Sbostic 	pclose(files);
140*31969Sbostic 	}
141*31969Sbostic 	fclose(script);
142*31969Sbostic 	if(pipeout) fprintf(mover,"%s ",altscript);
143*31969Sbostic 	fprintf(mover,"%s\n",scriptname);
144*31969Sbostic 	fclose(mover);
145*31969Sbostic }
146*31969Sbostic 
147*31969Sbostic bumpname(name)
148*31969Sbostic 	char name[10];
149*31969Sbostic 
150*31969Sbostic {
151*31969Sbostic int i;
152*31969Sbostic 	for(i=8;i>=0;i--) {
153*31969Sbostic 		name[i]++;
154*31969Sbostic 		if(name[i] > 'Z') {
155*31969Sbostic 			name[i] = 'A';
156*31969Sbostic 		} else {
157*31969Sbostic 			return;
158*31969Sbostic 		}
159*31969Sbostic 	}
160*31969Sbostic }
161*31969Sbostic usage() {
162*31969Sbostic 	fprintf(stderr,"vmsprep:  usage:  vmsprep dirname [dirname...] \n");
163*31969Sbostic 	exit();
164*31969Sbostic }
165