131969Sbostic
231969Sbostic #include <stdio.h>
331969Sbostic #include <ctype.h>
431969Sbostic #include <strings.h>
531969Sbostic
main(argc,argv)631969Sbostic main(argc,argv)
731969Sbostic int argc;
831969Sbostic char *argv[];
931969Sbostic
1031969Sbostic {
1131969Sbostic
1231969Sbostic char cmd[1000];
1331969Sbostic char *release;
1431969Sbostic FILE *dirs;
1531969Sbostic FILE *files;
1631969Sbostic FILE *mover;
1731969Sbostic FILE *popen();
1831969Sbostic FILE *script;
1931969Sbostic char dirname[1000];
2031969Sbostic char filename[1000];
2131969Sbostic char fixedname[1000];
2231969Sbostic char fixedpath[1000];
2331969Sbostic char tapename[10];
2431969Sbostic char *scriptname = "UNPACK.COM";
2531969Sbostic char *altscript = "/tmp/UNPACK.COMXXXXXX";
2631969Sbostic char *startname = "AAAAAAAAA";
2731969Sbostic int i;
2831969Sbostic int j;
2931969Sbostic char *k;
3031969Sbostic int pathlen;
3131969Sbostic int dot;
3231969Sbostic int pipeout=0;
3331969Sbostic
3431969Sbostic if(argc < 2) usage();
3531969Sbostic if(*argv[1] == '-') {
3631969Sbostic mover = stdout;
3731969Sbostic pipeout=1;
3831969Sbostic } else {
3931969Sbostic mover = fopen("vmsprep.namelist","w");
4031969Sbostic }
4131969Sbostic strcpy(tapename,startname);
4231969Sbostic if(pipeout) {
4331969Sbostic mktemp(altscript);
4431969Sbostic script = fopen(altscript,"w");
4531969Sbostic } else {
4631969Sbostic script = fopen(scriptname,"w");
4731969Sbostic }
4832061Sbostic fprintf(script,"$ SET NOON\n");
4931969Sbostic for(j=1;j<argc;j++) {
5031969Sbostic if(j==1 && *argv[j]=='-') continue;
5131969Sbostic release = argv[j];
5231969Sbostic strcpy(dirname,release);
5331969Sbostic for(k=index(dirname,'/');k;k=index(k+1,'/')) {
5431969Sbostic *k='\0';
5531969Sbostic fprintf(script,"$ CREATE/DIR [.%s] \n",dirname);
5632061Sbostic *k='.';
5731969Sbostic }
5831969Sbostic sprintf(cmd,
5931969Sbostic "find %s \\! \\( -name RCS -o -name \\*,v -o -name SCCS -o -name s.\\* \\) -type d -print\n", release);
6031969Sbostic dirs = popen(cmd,"r");
6131969Sbostic while(!feof(dirs)) {
6231969Sbostic *dirname = NULL;
6331969Sbostic fscanf(dirs," %s ",dirname);
6431969Sbostic if(*dirname == NULL) continue;
6531969Sbostic for(i=0;i<strlen(dirname);i++) {
6631969Sbostic if(dirname[i]=='/') {
6731969Sbostic dirname[i]='.';
6831969Sbostic } else if (dirname[i]=='.') {
6931969Sbostic dirname[i]='Z';
7031969Sbostic fprintf(stderr,"vmsprep: warning - dot in filename illegal-");
7131969Sbostic fprintf(stderr,"dot replaced by 'Z' %s\n",filename);
7231969Sbostic } else if (!(isalpha(dirname[i]) || isdigit(dirname[i]))) {
7331969Sbostic fprintf(stderr," error: bad character in directory name %s\n",
7431969Sbostic dirname);
7531969Sbostic } else if(islower(dirname[i])) {
7631969Sbostic dirname[i]=toupper(dirname[i]);
7731969Sbostic }
7831969Sbostic }
7931969Sbostic fprintf(script,"$ CREATE/DIR [.%s] \n",dirname);
8031969Sbostic }
8131969Sbostic pclose(dirs);
8231969Sbostic
8331969Sbostic sprintf(cmd,
8431969Sbostic "find %s \\! \\( -name RCS -o -name \\*,v -o -name SCCS -o -name s.\\* \\) -type f -print\n", release);
8531969Sbostic files = popen(cmd,"r");
8631969Sbostic while(!feof(files)) {
8731969Sbostic fscanf(files," %s ",filename);
8831969Sbostic if(*filename == NULL) continue;
8931969Sbostic k = rindex(filename,'/') ;
9031969Sbostic if(k != 0) {
9131969Sbostic pathlen = k - filename;
9231969Sbostic } else {
9331969Sbostic pathlen=0;
9431969Sbostic k = filename - 1;
9531969Sbostic }
9631969Sbostic strncpy(fixedpath,filename,pathlen);
9731969Sbostic fixedpath[pathlen]='\0';
9831969Sbostic strcpy(fixedname,k+1);
9931969Sbostic for(i=0;i<pathlen;i++) {
10031969Sbostic if(fixedpath[i]=='/') {
10131969Sbostic fixedpath[i]='.';
10231969Sbostic } else if (fixedpath[i]=='.') {
10331969Sbostic fixedpath[i]='Z';
10431969Sbostic } else if (!(isalpha(fixedpath[i]) || isdigit(fixedpath[i]))) {
10531969Sbostic fprintf(stderr," error: bad character in file name %s\n",
10631969Sbostic filename);
10731969Sbostic } else if(islower(fixedpath[i])) {
10831969Sbostic fixedpath[i]=toupper(fixedpath[i]);
10931969Sbostic }
11031969Sbostic }
111*32599Sbostic dot=0;
11231969Sbostic for(i=0;i<strlen(fixedname);i++) {
11331969Sbostic if(fixedname[i]=='/') {
11431969Sbostic fixedname[i]='.';
11531969Sbostic } else if (fixedname[i]=='.') {
11631969Sbostic dot++;
11731969Sbostic if(dot != 1) fixedname[i]='Z';
11831969Sbostic } else if (!(isalpha(fixedname[i]) || isdigit(fixedname[i]))) {
11931969Sbostic fprintf(stderr," error: bad character in file name %s\n",
12031969Sbostic filename);
12131969Sbostic fixedname[i]='Z';
12231969Sbostic } else if(islower(fixedname[i])) {
12331969Sbostic fixedname[i]=toupper(fixedname[i]);
12431969Sbostic }
12531969Sbostic }
12631969Sbostic if(dot >1 )
12731969Sbostic fprintf(stderr,"error: too many dots in filename %s \n",
12831969Sbostic fixedname);
12931969Sbostic sprintf(cmd,"%s %s.MOV\n", filename,tapename);
13031969Sbostic fprintf(mover,"%s",cmd);
13131969Sbostic if(*fixedpath != NULL) {
13231969Sbostic fprintf(script,"$ RENAME %s.MOV [.%s]%s%s\n",tapename,fixedpath,
13331969Sbostic fixedname,dot==0?".":"");
13431969Sbostic } else {
13531969Sbostic fprintf(script,"$ RENAME %s.MOV []%s%s\n",tapename,fixedname,
13631969Sbostic dot==0?".":"");
13731969Sbostic }
13831969Sbostic dot=0;
13931969Sbostic bumpname(tapename);
14031969Sbostic }
14131969Sbostic pclose(files);
14231969Sbostic }
14331969Sbostic fclose(script);
14431969Sbostic if(pipeout) fprintf(mover,"%s ",altscript);
14531969Sbostic fprintf(mover,"%s\n",scriptname);
14631969Sbostic fclose(mover);
14732594Sbostic return(0);
14831969Sbostic }
14931969Sbostic
bumpname(name)15031969Sbostic bumpname(name)
15131969Sbostic char name[10];
15231969Sbostic
15331969Sbostic {
15431969Sbostic int i;
15531969Sbostic for(i=8;i>=0;i--) {
15631969Sbostic name[i]++;
15731969Sbostic if(name[i] > 'Z') {
15831969Sbostic name[i] = 'A';
15931969Sbostic } else {
16031969Sbostic return;
16131969Sbostic }
16231969Sbostic }
16331969Sbostic }
usage()16431969Sbostic usage() {
16531969Sbostic fprintf(stderr,"vmsprep: usage: vmsprep dirname [dirname...] \n");
16632594Sbostic exit(1);
16731969Sbostic }
168