#include "stdio.h" #include "string.h" #include "astring.h" #include "stdlib.h" #include "misc.h" void main(int argc, char *argv[]) { int flag, flatf, helpf, ifilef, error; int i, pos, done, strl; char filein[100], datafile[80]; char command[1000], command2[1000], stat[4], oldstat[4]; char *filelist; helpf = 0; ifilef = 0; error = 0; flatf = 0; if (argc >= 2) { for (i=2; i<=argc; i++) { if (strpos(argv[i-1],"-")==0) { flag = 0; if (strpos(argv[i-1],"f")>0) { flatf = 1; flag=1; } if ((strpos(argv[i-1],"h")>0) || (!flag)) { helpf = 1; printf("usage : \n"); printf("merge_all [-h]\n"); printf(" -h display help\n"); } } else { if (!ifilef) { ifilef = 1; strcpy(filein,argv[i-1]); } } } } if (!helpf) { if (!flatf) { filelist = spawn("ls *.hed"); strcpy(oldstat," "); i = 0; done = 0; while (!done) { pos = strpos(filelist,"\n"); if (pos > 0) { strcpy(datafile,strmid(filelist,0,strpos(filelist,"\n"))); filelist = filelist + strpos(filelist,"\n")+1; strl = strlen(filelist); if (strl < 4) done = 1; } else { done = 1; } printf("file ---%s---\n",datafile); strcpy(stat,strmid(datafile,0,3)); if (strpos(stat,oldstat) > -1) { pos = strpos(datafile,".hed"); strcat(command," "); strcat(command,strmid(datafile,0,pos)); strcat(command2,strmid(datafile,0,pos+1)); strcat(command2,"hed "); strcat(command2,strmid(datafile,0,pos+1)); strcat(command2,"dat ");} else { if (i > 0) { printf("%s\n",command); system(command); printf("%s\n",command2); system(command2); } strcpy(command,"merge_flat "); strcat(command,"-o "); strcat(command,stat); strcat(command," "); pos = strpos(datafile,".hed"); strcat(command,strmid(datafile,0,pos)); strcpy(command2,"/bin/rm "); strcat(command2,strmid(datafile,0,pos+1)); strcat(command2,"hed "); strcat(command2,strmid(datafile,0,pos+1)); strcat(command2,"dat "); } strcpy(oldstat,stat); i++; } printf("%s\n",command); system(command); printf("%s\n",command2); system(command2); } } }