Annotation of researchv10no/cmd/cref/upost.c, revision 1.1

1.1     ! root        1: /*int  mbuf[1024];     /*INSTR*/
        !             2: int    psw     1;
        !             3: int    initf   1;
        !             4: 
        !             5: main(argc, argv)
        !             6:        char    *argv[];
        !             7: {
        !             8:        auto    f,fct,file;
        !             9: 
        !            10:        if(argc < 2) {
        !            11:                printf("Usage: cpost [-d] file1 file2 ...\n");
        !            12:                exit();
        !            13:        }
        !            14: 
        !            15:        if(*argv[1] == '-') {
        !            16:                fct = argv[1][1] - '0';
        !            17:                if((fct < 1) || (fct > 9)) {
        !            18:                        printf("-d: 0 < d < 10\n");
        !            19:                        exit();
        !            20:                }
        !            21:                argv++;
        !            22:                argc--;
        !            23:        } else {
        !            24:                fct = 1;
        !            25:        }
        !            26: 
        !            27:        f = 0;
        !            28:        while(++f < argc) {
        !            29:                file = open(argv[f], 0);
        !            30: 
        !            31:                edl(file, fct);
        !            32: 
        !            33:                close(file);
        !            34:                psw = 0;
        !            35:        }
        !            36:        flsh(0);
        !            37: 
        !            38:        exit();
        !            39: }
        !            40: 
        !            41: int    lno     1;
        !            42: 
        !            43: edl(file)
        !            44: {
        !            45:        auto t,l;
        !            46:        char    static  buf[20],fld[20],line[200];
        !            47:        char    c;
        !            48: field:
        !            49:        t = -1;
        !            50:        while(((buf[++t] = get(file)) != '\t') && (buf[t] != -1))
        !            51:                if(buf[t] == '\0')      goto done;
        !            52: 
        !            53:        if((c = buf[t]) == -1)  c = ' ';
        !            54:        buf[t] = '\0';
        !            55:        if(comp(buf,fld)) {
        !            56:                lno++;
        !            57:                goto junk;
        !            58:        } else {
        !            59:                if(lno == 0) {
        !            60:                        put(0,line,++l);
        !            61:                }
        !            62:                l = copy(buf,line);
        !            63:                copy(buf,fld);
        !            64:                line[--l] = c;
        !            65:                lno = 0;
        !            66:                goto fill;
        !            67:        }
        !            68: 
        !            69: fill:
        !            70:        while((line[++l] = get(file)) != '\n') {
        !            71:                if(line[l] == -1)       line[l] = ' ';
        !            72:                if(line[l] == '\0')     goto done;
        !            73:        }
        !            74: 
        !            75:        goto field;
        !            76: 
        !            77: junk:
        !            78:        while((*line = get(file)) != '\n')
        !            79:                if(*line == '\0')       goto done;
        !            80: 
        !            81:        goto field;
        !            82: 
        !            83: done:
        !            84:        if(lno == 0)
        !            85:                put(0,line,++l);
        !            86:                lno = 1;
        !            87:        return(0);
        !            88: 
        !            89: }
        !            90: 
        !            91: 
        !            92: 
        !            93: gfld(file, buf)
        !            94:        char    *buf;
        !            95: {
        !            96:        char    c;
        !            97: 
        !            98:        buf--;
        !            99:        while(*++buf  = get(file)) {
        !           100:                if((*buf == '\t') || (*buf == '\n')) {
        !           101:                        c = *buf;
        !           102:                        *buf = '\0';
        !           103:                        return(c);
        !           104:                } else {
        !           105:                        continue;
        !           106:                }
        !           107:        }
        !           108:        return('\0');
        !           109: }
        !           110: 
        !           111: copy(a, b)
        !           112:        char    *a,*b;
        !           113: {
        !           114:        char    *c;
        !           115: 
        !           116:        b--;
        !           117:        c = --a;
        !           118:        while(*++b = *++a);
        !           119:        return(a - c);
        !           120: }
        !           121: 
        !           122: comp(a, b)
        !           123:        char    *a, *b;
        !           124: {
        !           125: /*     printf("comp: %s %s\n",a,b); /*DEBUG*/
        !           126:        a--;
        !           127:        b--;
        !           128:        while(*++a == *++b) {
        !           129:                if(*a == '\0')  return(1);
        !           130:        }
        !           131:        return(0);
        !           132: }
        !           133: 
        !           134: 
        !           135: char   buf[512];
        !           136: int    nread   1;
        !           137: 
        !           138: get(ifile) int ifile;
        !           139: {
        !           140: 
        !           141:        char static *ibuf;
        !           142: 
        !           143:        if(--nread){
        !           144:                return(*ibuf++);
        !           145:        }
        !           146: 
        !           147:        if(nread = read(ifile,buf,512)){
        !           148:                if(nread < 0)goto err;
        !           149: 
        !           150:                ibuf = buf;
        !           151:                return(*ibuf++);
        !           152:        }
        !           153: 
        !           154:        nread = 1;
        !           155:        return(0);
        !           156: 
        !           157: err:
        !           158:        nread = 1;
        !           159:        printf("read error\n");
        !           160:        return(0);
        !           161: 
        !           162: }
        !           163: 
        !           164: 
        !           165: int    tp[1]   1;
        !           166: int    optr[4];
        !           167: char   bsp[512];
        !           168: 
        !           169: char   *obuf[1]        bsp;
        !           170: 
        !           171: int    nflush;
        !           172: 
        !           173: put(fil,string,n)
        !           174:        char    *string;
        !           175: {
        !           176:        int     i;
        !           177:        char    *o;
        !           178: 
        !           179: /*printf("%d %c %d\n",fil,*string,n);/*DEBUG*/
        !           180: 
        !           181:        string--;
        !           182: 
        !           183:        if((i = optr[fil] + n - 512) >= 0) {
        !           184:                n =- i;
        !           185:                o = &obuf[fil][optr[fil]] -1;
        !           186:                while(--n >= 0)
        !           187:                        *++o = *++string;
        !           188:                optr[fil] = 512;
        !           189:                flsh(fil);
        !           190:                n = i;
        !           191:        }
        !           192: 
        !           193:        o = &obuf[fil][optr[fil]] - 1;
        !           194:        optr[fil] =+ n;
        !           195: 
        !           196:        while(--n >= 0) {
        !           197:                *++o = *++string;
        !           198:        }
        !           199:        return(0);
        !           200: }
        !           201: 
        !           202: flsh(fil)
        !           203: {
        !           204:        extern  tp[];
        !           205: 
        !           206:        if(optr[fil] <= 0)      return(optr[fil]);
        !           207: 
        !           208:        nflush++;
        !           209:        if(write(tp[fil],obuf[fil],optr[fil]) != optr[fil])
        !           210:                return(-1);
        !           211:        optr[fil] = 0;
        !           212:        return(0);
        !           213: }
        !           214: 

unix.superglobalmegacorp.com

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