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

1.1       root        1: #
                      2: # include "mcons.c"
                      3: char   ib1[518];
                      4: char   *ibuf   &ib1;
                      5: struct htab    (
                      6:                int     hsiz;
                      7:                int     ssiz;
                      8:                int     nsym;
                      9:                int     curb;
                     10:                int     *hptr;
                     11:                char    *symt;
                     12:                );
                     13: 
                     14: struct htab    itab;
                     15: struct htab    xtab;
                     16: 
                     17: int    ipsp[PTRI];
                     18: char   issp[CHARI];
                     19: search(symbol,length,params,install)
                     20:        char    *symbol;
                     21:        int     length;
                     22:        struct  htab    *params;
                     23:        int     install;
                     24: {
                     25:        char    *sp,*p;
                     26:        int     curb,*hptr,hsiz,nsym,ssiz;
                     27:        char    *symt;
                     28:        auto    h,i,j,k;
                     29: 
                     30:        hptr = params->hptr;
                     31:        hsiz = params->hsiz;
                     32:        symt = params->symt;
                     33:        ssiz = params->ssiz;
                     34:        curb = params->curb;
                     35:        nsym = params->nsym;
                     36: 
                     37:        symbol[length] = '\0';
                     38:        sp = symbol;
                     39: 
                     40:        i = length;
                     41:        h = 1;
                     42:        while(i--)
                     43:                h =* *sp++;
                     44: 
                     45:        if(h == 0100000)h = 1;
                     46:        h = h<0?(-h)%hsiz:h%hsiz;
                     47:        if(h == 0)      h++;
                     48: /*     printf("%s %d\n",symbol,h);     /*DEBUG*/
                     49: 
                     50:        while((p = &symt[hptr[h]]) > symt) {
                     51:                j = length + 1;
                     52:                sp = symbol;
                     53:                while(j--) {
                     54:                        if(*p++ != *sp++)       goto no;
                     55:                }
                     56:                return(*p);
                     57: no:
                     58:                h = (h + h)%hsiz;
                     59:        }
                     60:        if(install) {
                     61:                if(++nsym >= hsiz)      err("too many","symbols");
                     62: 
                     63:                hptr[h] = curb;
                     64:                length++;
                     65:                if((curb + length) >= ssiz)     err("too many","chars");
                     66: 
                     67:                while(length--)
                     68:                        symt[curb++] = *symbol++;
                     69:                symt[curb++] = install;
                     70:                params->curb = curb;
                     71:                params->nsym = nsym;
                     72:        }
                     73:        return(0);
                     74: }
                     75: 
                     76: main(argc,argv)        char **argv; 
                     77: {
                     78: 
                     79:        auto    ifile,ofile,i,c,error,val;
                     80:        char t[20];
                     81: 
                     82:        if(argc != 3)exit();
                     83: 
                     84:        ifile = fopen(argv[1],ibuf);
                     85:        if(ifile < 0)err("open",argv[1]);
                     86: 
                     87:        ofile = creat(argv[2],0644);
                     88:        if(ofile < 0)err("creat",argv[2]);
                     89: 
                     90:        xtab.hptr = &ipsp;
                     91:        xtab.symt = &issp;
                     92:        xtab.hsiz = PTRI;
                     93:        xtab.ssiz = CHARI;
                     94:        xtab.nsym = 0;
                     95:        xtab.curb = 1;
                     96: 
                     97:        i = xtab.hsiz;
                     98:        while(i)xtab.hptr[--i] = 0;
                     99: 
                    100:        i = -1;
                    101:        while((t[++i] = getc(ibuf)) >= 0){
                    102:                if(t[i] == '\n'){
                    103:                        i = search(t,i,&xtab,1);
                    104:                        i = -1;
                    105:                } else {
                    106:                        if(t[i] == '\t') {
                    107:                                val = gen();
                    108:                                search(t,i,&xtab,val);
                    109:                                i = -1;
                    110:                        }
                    111:                }
                    112:        }
                    113: 
                    114: /*     printf("collisions = %d\nsymbols = %d\n",ncol,nsym); /*INSTR*/
                    115:        i = 0100200;
                    116:        error = write(ofile,&i,2);
                    117:        if(error < 0)err("write",argv[2]);
                    118:        i = 2*xtab.hsiz;
                    119:        error = write(ofile,&i,2);
                    120:        if(error < 0)err("write",argv[2]);
                    121:        error = write(ofile,&xtab.ssiz,2);
                    122:        if(error < 0)err("write",argv[2]);
                    123:        error = write(ofile,xtab.hptr,i);
                    124:        if(error < 0)err("write",argv[2]);
                    125:        error = write(ofile,xtab.symt,xtab.ssiz);
                    126:        if(error < 0)err("write",argv[2]);
                    127:        return;
                    128: }
                    129: 
                    130: err(a,b)
                    131:        char    *a,*b;
                    132: {
                    133:        printf("%s %s\n",a,b);
                    134:        exit();
                    135: }
                    136: 
                    137: gen()
                    138: {
                    139:        auto i,v;
                    140: 
                    141:        v = 0;
                    142:        while((i = getc(ibuf)) != -1) {
                    143:                if(i == '\n')   break;
                    144:                v = v*10 + (i - '0');
                    145:        }
                    146:        return(v);
                    147: }
                    148: 

unix.superglobalmegacorp.com

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