1*1101Sbill static char *sccsid = "@(#)split.c 4.1 (Berkeley) 10/01/80"; 2*1101Sbill #include <stdio.h> 3*1101Sbill 4*1101Sbill unsigned count = 1000; 5*1101Sbill int fnumber; 6*1101Sbill char fname[100]; 7*1101Sbill char *ifil; 8*1101Sbill char *ofil; 9*1101Sbill FILE *is; 10*1101Sbill FILE *os; 11*1101Sbill 12*1101Sbill main(argc, argv) 13*1101Sbill char *argv[]; 14*1101Sbill { 15*1101Sbill register i, c, f; 16*1101Sbill int iflg = 0; 17*1101Sbill 18*1101Sbill for(i=1; i<argc; i++) 19*1101Sbill if(argv[i][0] == '-') 20*1101Sbill switch(argv[i][1]) { 21*1101Sbill 22*1101Sbill case '\0': 23*1101Sbill iflg = 1; 24*1101Sbill continue; 25*1101Sbill 26*1101Sbill case '0': 27*1101Sbill case '1': 28*1101Sbill case '2': 29*1101Sbill case '3': 30*1101Sbill case '4': 31*1101Sbill case '5': 32*1101Sbill case '6': 33*1101Sbill case '7': 34*1101Sbill case '8': 35*1101Sbill case '9': 36*1101Sbill count = atoi(argv[i]+1); 37*1101Sbill continue; 38*1101Sbill } 39*1101Sbill else if(iflg) 40*1101Sbill ofil = argv[i]; 41*1101Sbill else { 42*1101Sbill ifil = argv[i]; 43*1101Sbill iflg = 2; 44*1101Sbill } 45*1101Sbill if(iflg != 2) 46*1101Sbill is = stdin; 47*1101Sbill else 48*1101Sbill if((is=fopen(ifil,"r")) == NULL) { 49*1101Sbill fprintf(stderr,"cannot open input\n"); 50*1101Sbill exit(1); 51*1101Sbill } 52*1101Sbill if(ofil == 0) 53*1101Sbill ofil = "x"; 54*1101Sbill 55*1101Sbill loop: 56*1101Sbill f = 1; 57*1101Sbill for(i=0; i<count; i++) 58*1101Sbill do { 59*1101Sbill c = getc(is); 60*1101Sbill if(c == EOF) { 61*1101Sbill if(f == 0) 62*1101Sbill fclose(os); 63*1101Sbill exit(0); 64*1101Sbill } 65*1101Sbill if(f) { 66*1101Sbill for(f=0; ofil[f]; f++) 67*1101Sbill fname[f] = ofil[f]; 68*1101Sbill fname[f++] = fnumber/26 + 'a'; 69*1101Sbill fname[f++] = fnumber%26 + 'a'; 70*1101Sbill fname[f] = '\0'; 71*1101Sbill fnumber++; 72*1101Sbill if((os=fopen(fname,"w")) == NULL) { 73*1101Sbill fprintf(stderr,"Cannot create output\n"); 74*1101Sbill exit(1); 75*1101Sbill } 76*1101Sbill f = 0; 77*1101Sbill } 78*1101Sbill putc(c, os); 79*1101Sbill } while(c != '\n'); 80*1101Sbill fclose(os); 81*1101Sbill goto loop; 82*1101Sbill } 83