#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] [-n] kb file\n", app); fprintf(stderr,"%s: -h : This text\n", app); fprintf(stderr,"%s: -n : kbytes\n", app); exit(0); } main( int argc, char *argv[]) { int theFile; int opt; int Verbose=0; int out_n; int i,r; FILE *f, *g; char fname[MAXPATHLEN]; unsigned int size=1350; 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,"hn:v")) != EOF ) { switch(opt) { case 'v': printf("%s:%s\n",app,VERS_STR); Verbose=1; break; case 'n': size = (unsigned int) atoi(optarg); break; case 'h': default: usage(); break; } } if ((argc-optind)<1) usage(); for( theFile=optind; theFile < argc ; theFile ++) { out_n = 0; if ( NULL == ( f = fopen(argv[theFile],"rb"))) 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]); while( !feof (f)) { sprintf(fname,"%s.%03d",argv[theFile],out_n++); if ( NULL == ( g = fopen(fname,"wb"))) { 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); for( i=0; i