Annotation of 42BSD/usr.bin/split.c, revision 1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.