Annotation of researchv10no/cmd/basic/bite/src/reseq.c, revision 1.1.1.1

1.1       root        1: /* Copyright Bell Telephone Laboratories Whippany, N.J.
                      2: 
                      3:  *     ***********************************
                      4:  *     ***********************************
                      5:  *     ***** LINE NUMBER RESEQUENCER *****
                      6:  *     *** R. B. Drake WH 8C-005 X4163 ***
                      7:  *     **** Sun Aug 26 11:23:45 1979 *****
                      8:  *     ***********************************
                      9:  *     ***********************************
                     10: 
                     11: */
                     12: /*   "@(#) reseq.c:  V 1.1  12/21/80" */
                     13: 
                     14: /* resequence the program buffer */
                     15: #include "bas.h"
                     16: extern int no;
                     17: extern char temp[];
                     18: extern char *endob;
                     19: extern int _fi,_togo,subog;
                     20: extern int tsil,tospgo;
                     21: extern int start,finish;
                     22: extern char _string[];
                     23:        static struct REFP
                     24:                {
                     25:                        int whoref;
                     26:                        int refwhat;
                     27:                        int newref;
                     28:                } *refptr,*savit;
                     29:        static int newnum;
                     30: breseq(begin,end)
                     31: int begin,end;
                     32: {
                     33:        FILE *fopen(),*fp;
                     34:        char *lin,*from,*to,*lp,*ptr,*prncpy(),*hold;
                     35: #ifdef LSX
                     36:        static char nam[] = {"/tmp/tmp.b"};
                     37: #endif
                     38: #ifndef LSX
                     39:        static char nam[] = {"tmp.b"};
                     40: #endif
                     41:        int i;
                     42:        lnpars(); /* get start and finish. finish will be increment */
                     43:        if(start==0) start=10;
                     44:        if(finish==0 || finish == 32767) finish = 10;
                     45:        expunge();
                     46:        refptr = (struct REFP *)endob;
                     47:        newnum=0;
                     48:        if(fetch(0,&lbdptr) < 0) /* get first line */
                     49:        {
                     50:                error(0,5);
                     51:                return(-1);
                     52:        }
                     53:        if(inst.thing.linno < begin || inst.thing.linno > end)
                     54:        --newnum;
                     55:        check(begin,end); /* if it references a line#, record it */
                     56:        while(fetch(-1,&lbdptr) == 0) /* search the remaining lines */
                     57:        {
                     58:                if(inst.thing.linno >= begin && inst.thing.linno <= end)
                     59:                newnum++;
                     60:                check(begin,end);
                     61:        }
                     62:        fetch(begin,&lbdptr);
                     63:                replace();
                     64:        clear();
                     65:        while(fetch(-1,&lbdptr) != -1)
                     66:        {
                     67:                if(inst.thing.linno > end) break;
                     68:                replace();
                     69:        }
                     70:        update();
                     71:        if(begin != 0)
                     72:        {
                     73:                fp=fopen(nam,"w");
                     74:                fetch(0,&lbdptr);
                     75:                        outit(fp);
                     76:                while(fetch(-1,&lbdptr) == 0)
                     77:                        outit(fp);
                     78:                fclose(fp);
                     79:                onew();
                     80:                fp=fopen(nam,"r");
                     81:                while(bed(fp) == 0);
                     82:                fclose(fp);
                     83: #ifndef LSX
                     84:                unlink(nam);
                     85: #endif
                     86:        }
                     87:        while(refptr != (struct REFP *)endob)
                     88:        {
                     89:        fetch(refptr->whoref,&lbdptr);
                     90:        lin = expand();
                     91:        if(refptr->refwhat < 0)
                     92:        {
                     93:        strcpy(temp,lin); /* put line refrences into temp */
                     94:        ptr=_string;
                     95:        lp=temp;
                     96:        i= -1*refptr->refwhat;
                     97:        while(1)
                     98:        {
                     99:                hold=prncpy(ptr,lp);
                    100:                if(atoi(ptr) == i) break;
                    101:                if(*hold != ',') break;
                    102:                lp= ++hold;
                    103:        }
                    104:        sprintf(ptr,"%d",refptr->newref);
                    105:        from= temp;
                    106:        to=lin;
                    107:        while(*from != '\0')
                    108:        {
                    109:                if(from == lp)
                    110:                {
                    111:                        while(*from != ',' && *from != '\0')
                    112:                                from++;
                    113:                        while(*ptr != '\0')
                    114:                                *to++ = *ptr++;
                    115:                }
                    116:                else
                    117:                        *to++ = *from++;
                    118:        }
                    119:        *to = '\0';
                    120:        sprintf(_string,"%d %s %s\n",inst.thing.linno,decode(inst.thing.opcode.lobyte),linbuf);
                    121:        bed((FILE *)0);
                    122:        }
                    123:        else
                    124:                error(refptr->whoref,0);
                    125:        refptr++;
                    126:        }
                    127:        return(0);
                    128: }
                    129: check(begin,end)
                    130: int begin,end;
                    131: {
                    132:        char *lin;
                    133:        int oldlin;
                    134:        char buffer[80];
                    135:        if(cklist(inst.thing.opcode.lobyte))
                    136:        {
                    137:                lin = expand();
                    138:                if(!num(*lin)) return(0);
                    139:                while(*lin != '\0')
                    140:                {
                    141:                        lin = prncpy(buffer,lin);
                    142:                        oldlin=atoi(buffer);
                    143:                        if(oldlin < begin || oldlin > end) return(0);
                    144:                        --refptr;
                    145:                        if(inst.thing.linno >= begin && inst.thing.linno <= end)
                    146:                        refptr->whoref = start + newnum * finish;
                    147:                        else refptr->whoref = inst.thing.linno;
                    148:                        refptr->refwhat = oldlin;
                    149:                        if(*lin == '\0') break;
                    150:                        lin++;
                    151:                }
                    152:        }
                    153:        return(0);
                    154: }
                    155: cklist(code)
                    156: int code;
                    157: {
                    158:        int i;
                    159:        static int *list[] =
                    160:                { &_fi,
                    161:                &_togo,
                    162:                &subog,
                    163:                &tsil,
                    164:                &no,
                    165:                &tospgo,
                    166:                0 };
                    167:        for(i=0;list[i] != 0;i++)
                    168:        {
                    169:                if(code == *list[i])
                    170:                return(1);
                    171:        }
                    172:        return(0);
                    173: }
                    174: replace()
                    175: {
                    176:        local.thing.linno=start;
                    177:        start += finish;
                    178:        *curptr++ = local.byte[0];
                    179:        *curptr++ = local.byte[1];
                    180:        savit = refptr;
                    181:        while(refptr != (struct REFP *)endob)
                    182:        {
                    183:                if(inst.thing.linno == refptr->refwhat)
                    184:                {
                    185:                        refptr->refwhat *= -1;
                    186:                        refptr->newref = local.thing.linno;
                    187:                }
                    188:                refptr++;
                    189:        }
                    190:        refptr=savit;
                    191:        return(0);
                    192: }
                    193: reseq()
                    194: {
                    195:        breseq(0,32767);
                    196: }
                    197: mov()
                    198: {
                    199:        extern char *expr;
                    200:        char *prncpy(),ary[6];
                    201:        int begin,end;
                    202:        expr=prncpy(ary,expr);
                    203:        if(*expr++ != ',')
                    204:        {
                    205:                error(0,42);
                    206:                return(0);
                    207:        }
                    208:        begin=atoi(ary);
                    209:        expr=prncpy(ary,expr);
                    210:        if(*expr++ != ',')
                    211:        {
                    212:                error(0,42);
                    213:                return(0);
                    214:        }
                    215:        end=atoi(ary);
                    216:        breseq(begin,end);
                    217:        return 0;
                    218: }

unix.superglobalmegacorp.com

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