diff --git a/tools/chop.c b/tools/chop.c new file mode 100644 index 0000000000000000000000000000000000000000..2962f2de30dc7c8b13fb7128d950773845598119 --- /dev/null +++ b/tools/chop.c @@ -0,0 +1,48 @@ +#include <stdio.h> + +#define BUFFERSIZE (1<<21) + +char buffer[BUFFERSIZE]; + +void chop(infile) +char *infile; +{ + FILE *in, *out; + char outfile[1024]; + int count, bytes; + + count = 0; + + in = fopen(infile, "r"); + if (in == NULL) { + perror(infile); + return; + } + + while ((bytes = fread(buffer, 1, BUFFERSIZE, in)) != 0) { + sprintf(outfile, "%s.%d", infile, count++); + out = fopen(outfile, "w+"); + if (out == NULL) { + perror(outfile); + fclose(in); + return; + } + fwrite(buffer, 1, bytes, out); + fclose(out); + } + + fclose(in); +} + +main(argc, argv) +int argc; +char *argv[]; +{ + if (argc < 2) { + fprintf(stderr, "usage: chop file...\n"); + exit(1); + } + + while (*++argv != NULL) + chop(*argv); +}