#include #include #include #include #include #include #ifndef PATH_SEP # define PATH_SEP '/' #endif #ifdef MYGETOPT char getopt( int argc, char *argv[], char *format ); #endif #ifdef _BSD_ extern char *sys_errlist[]; # define raise(s) kill(getpid(),(s)) # define strerror(e) sys_errlist[(e)] #endif static char __ident[] = "@(#)(c)SPDsoft, Fri Jul 28, 1995"; #define VERS_STR ((char*)&__ident[4]) void usage(void); extern int errno; char *app; void usage(void) { fprintf(stderr,"Use: %s [-h] [-f n0] -t n1 file\n", app); fprintf(stderr,"%s: -h : This text\n", app); fprintf(stderr,"%s: -f : First number (default 0)\n", app); fprintf(stderr,"%s: -t : Last number\n", app); fprintf(stderr,"%s: file: Output\n", app); exit(0); } main( int argc, char *argv[]) { int theFile; int opt; int Verbose=0; int i,r; int n0=0, n1=0; FILE *f, *g; char fname[MAXPATHLEN]; char buffer[1024]; extern char *optarg; extern int optind,opterr; if ((app = strrchr(argv[0], PATH_SEP)) != NULL) app = app+1; else app = argv[0]; while ( (opt=getopt(argc,argv,"hf:t:v")) != EOF ) { switch(opt) { case 'v': printf("%s:%s\n",app,VERS_STR); Verbose=1; break; case 'f': n0 = (unsigned int) atoi(optarg); break; case 't': n1 = (unsigned int) atoi(optarg); break; case 'h': default: usage(); break; } } if ((argc-optind)!=1) usage(); theFile=optind; if ( NULL == ( f = fopen(argv[theFile],"wb"))) fprintf(stderr,"%s: can't open %s (%s)\n", app, argv[theFile],strerror(errno)); else { if (Verbose) fprintf(stderr,"%s: open %s\n", app,argv[theFile]); for(i=n0; i<=n1; i++) { sprintf(fname,"%s.%03d",argv[theFile],i); if ( NULL == ( g = fopen(fname,"rb"))) { fprintf(stderr,"%s: can't open %s (%s)\n", app, fname,strerror(errno)); break; } else { if (Verbose) fprintf(stderr,"%s: open %s\n", app,fname); while(!feof(g)) { r = (int) fread(buffer,1,1024,g); fwrite(buffer,1,r,f); } fclose(g); } } fclose( f ); } }