Annotation of researchv10no/cmd/cref/crpost.c, revision 1.1.1.1

1.1       root        1: /*int  mbuf[1024];     /*INSTR*/
                      2: int    ig      100;
                      3: int    esw;
                      4: int    initf   1;
                      5: char   ssp[270];
                      6: char   *sym[9] {ssp,
                      7:                ssp + 30,
                      8:                ssp + 60,
                      9:                ssp + 90,
                     10:                ssp + 120,
                     11:                ssp + 150,
                     12:                ssp + 180,
                     13:                ssp + 210,
                     14:                ssp + 240
                     15:                };
                     16: 
                     17: main(argc, argv)
                     18:        char    *argv[];
                     19: {
                     20:        auto    f,fct,file,i;
                     21: 
                     22:        if(argc < 2) {
                     23:                printf("Usage: crpost [-d] file1 file2 ...\n");
                     24:                exit();
                     25:        }
                     26: 
                     27:        if(argv[1][0] == '-') {
                     28:                if(argv[1][1] == 'E') {
                     29:                        fct = argv[1][2] - '0';
                     30:                        esw = 1;
                     31:                        goto on;
                     32:                }
                     33:                fct = argv[1][1] - '0';
                     34:                if((fct < 1) || (fct > 9)) {
                     35:                        printf("-d: 0 < d < 10\n");
                     36:                        exit();
                     37:                }
                     38:                if(argv[1][2] == 'x') {
                     39:                        ig = fct-1;
                     40:                }
                     41: on:
                     42: printf("%s ", argv[1]);
                     43:                argv++;
                     44:                argc--;
                     45:        } else {
                     46:                fct = 3;
                     47:        }
                     48: 
                     49:        f = 0;
                     50:        while(++f < argc) {
                     51:                file = open(argv[f], 0);
                     52: 
                     53:                edf(file, fct);
                     54: 
                     55:                close(file);
                     56:        }
                     57: printf("\n");
                     58:        flsh(1);
                     59: 
                     60:        exit();
                     61: }
                     62: 
                     63: int    lno     1;
                     64: 
                     65: edf(file, fct)
                     66: {
                     67:        auto    i,j,l;
                     68:        extern  lno,etext;
                     69:        char    brk,*buf,bufsp[150],line[150];
                     70:        char extern     *sym[];
                     71: 
                     72: /*     monitor(&main,&etext,&mbuf,1024);       /*INSTR*/
                     73:        for(i = 0; i < fct; i++)
                     74:                *sym[i] = 0200;
                     75: fields:
                     76:        l = -1;
                     77:        buf = &bufsp;
                     78: 
                     79:        for(i = 0; i < fct; ++i) {
                     80:                buf--;
                     81: 
                     82: swt:
                     83: 
                     84:                switch(*++buf = get(file)) {
                     85: 
                     86:                        default:
                     87:                                if(esw && *buf >= 'A' && *buf <= 'Z'
                     88:                                        && i == 0)
                     89:                                        *buf =| 040;
                     90:                                goto swt;
                     91: 
                     92:                        case -1:
                     93:                                *buf = ' ';
                     94:                        case '\t':
                     95:                                if(i == ig)     continue;
                     96:                                brk = *buf;
                     97:                                *buf = '\0';
                     98:                                buf = &bufsp;
                     99:                                if(comp(buf, sym[i])) {
                    100:                                        if(esw && i == 0) {
                    101:                                                line[0] = line[1] = '\t';
                    102:                                                l = 1;
                    103:                                                goto rest;
                    104:                                        }
                    105:                                        line[++l] = '\t';
                    106:                                        continue;
                    107:                                } else {
                    108:                                        copy(buf, sym[i]);
                    109:                                        l =+ copy(buf, &line[++l]);
                    110:                                        line[--l] = brk;
                    111:                                        if(l < 8 && esw && i == 0)
                    112:                                                line[++l] = '\t';
                    113:                                        j = i;
                    114:                                        while(++j < fct)
                    115:                                                *sym[j] = 0200;
                    116:                                        continue;
                    117:                                }
                    118: 
                    119:                        case '\n':
                    120:                                lno++;
                    121:                                brk = *buf;
                    122:                                *buf = '\0';
                    123:                                buf = &bufsp;
                    124:                                if(comp(buf, sym[i])) {
                    125:                                        goto fields;
                    126:                                } else {
                    127:                                        copy(buf, sym[i]);
                    128:                                        l =+ copy(buf, &line[++l]);
                    129:                                        line[--l] = '\n';
                    130:                                        j = i;
                    131:                                        while(++j < fct)
                    132:                                                *sym[j] = 0;
                    133:                                        goto out;
                    134:                                }
                    135: 
                    136:                        case '\0':
                    137:                                goto fexit;
                    138:                }
                    139:        }
                    140: 
                    141: rest:
                    142:        while((line[++l] = get(file)) != '\n')
                    143:                if(line[l] == '\0')     goto fexit;
                    144: 
                    145:        lno++;
                    146: out:
                    147:        if(*line != '\t') {
                    148:                put(1,"\n",1);
                    149:                lno++;
                    150:        }
                    151: 
                    152:        put(1,line,++l);
                    153: 
                    154:        goto fields;
                    155: 
                    156: fexit:
                    157: /*     monitor(0);     /*INSTR*/
                    158:        return(0);
                    159: 
                    160: }
                    161: 
                    162: 
                    163: copy(a, b)
                    164:        char    *a,*b;
                    165: {
                    166:        char    *c;
                    167: 
                    168:        b--;
                    169:        c = --a;
                    170:        while(*++b = *++a);
                    171:        return(a - c);
                    172: }
                    173: 
                    174: comp(a, b)
                    175:        char    *a, *b;
                    176: {
                    177: /*     printf("comp: %s %s\n",a,b); /*DEBUG*/
                    178:        a--;
                    179:        b--;
                    180:        while(*++a == *++b) {
                    181:                if(*a == '\0')  return(1);
                    182:        }
                    183:        return(0);
                    184: }
                    185: 
                    186: 
                    187: char   buf[512];
                    188: int    nread   1;
                    189: 
                    190: get(ifile) int ifile;
                    191: {
                    192: 
                    193:        char static *ibuf;
                    194: 
                    195:        if(--nread){
                    196:                return(*ibuf++);
                    197:        }
                    198: 
                    199:        if(nread = read(ifile,buf,512)){
                    200:                if(nread < 0)goto err;
                    201: 
                    202:                ibuf = buf;
                    203:                return(*ibuf++);
                    204:        }
                    205: 
                    206:        nread = 1;
                    207:        return(0);
                    208: 
                    209: err:
                    210:        nread = 1;
                    211:        printf("read error\n");
                    212:        return(0);
                    213: 
                    214: }
                    215: 
                    216: int    optr;
                    217: char   bsp[512];
                    218: 
                    219: char   *obuf   bsp;
                    220: 
                    221: int    nflush;
                    222: 
                    223: put(fil, string, n)
                    224:        char    *string;
                    225: {
                    226:        register int    i;
                    227:        register char   *o;
                    228: 
                    229: /*printf("%d %c %d\n",fil,*string,n);/*DEBUG*/
                    230: 
                    231:        string--;
                    232: 
                    233:        if((i = optr + n - 512) >= 0) {
                    234:                n =- i;
                    235:                o = &obuf[optr] -1;
                    236:                while(--n >= 0)
                    237:                        *++o = *++string;
                    238:                optr = 512;
                    239:                flsh(fil);
                    240:                n = i;
                    241:        }
                    242: 
                    243:        o = &obuf[optr] - 1;
                    244:        optr =+ n;
                    245: 
                    246:        while(--n >= 0) {
                    247:                *++o = *++string;
                    248:        }
                    249:        return(0);
                    250: }
                    251: 
                    252: flsh(fil)
                    253: {
                    254: 
                    255:        if(optr <= 0)   return(optr);
                    256: 
                    257:        nflush++;
                    258:        if(write(fil,  obuf, optr) != optr)
                    259:                return(-1);
                    260:        optr = 0;
                    261:        return(0);
                    262: }
                    263: 

unix.superglobalmegacorp.com

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