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

1.1       root        1: /* Copyright Bell Telephone Laboratories Whippany, N.J.
                      2: 
                      3:  *     ***********************************
                      4:  *     ***********************************
                      5:  *     ************ FOR-NEXT *************
                      6:  *     *** R. B. Drake WH 8C-005 X4163 ***
                      7:  *     **** Fri Aug 24 17:27:09 1979 *****
                      8:  *     ***********************************
                      9:  *     ***********************************
                     10: 
                     11: */
                     12: /*   "@(#) for.c:  V 1.2  3/4/81" */
                     13: 
                     14: #include "bas.h"
                     15: extern int singflg;
                     16: extern int rof;
                     17: extern int singst;
                     18: int bflag,forflg,forcnt,cflag;
                     19: _for()
                     20: {
                     21:        extern int nxt,stpflg;
                     22:        extern char *eoexpr,*ptr,*curptr;
                     23:        char *save,c,*sav1;
                     24:        char nam[5];
                     25:        double  evalx(),final,step,var,round;
                     26:        int i,savno;
                     27:        forflg++; /* mark for in progress for break */
                     28:        for(i=0;(c=expr[i]) != '\15' && c != '\0' && i < 4;i++)
                     29:                nam[i]=c;
                     30:        nam[i]=0;
                     31:        if(!(nam[0] == 'e' && nam[1] == 'v')) /* if not an infinite loop */
                     32:        {
                     33:                step = 1; /* default value for step */
                     34:                let(); /* handle the initial value expression */
                     35:                if(*eoexpr++ != '\004') /* make sure its a to */
                     36:                {
                     37:                        error(inst.thing.linno,9);
                     38:                        forflg=bflag=0;
                     39:                        return(-1);
                     40:                }
                     41:                final=evalx(eoexpr); /*evaluate the "to" expression */
                     42:                if(*eoexpr == '\005') /* see if step is present */
                     43:                {
                     44:                        eoexpr++;
                     45:                        step=evalx(eoexpr);
                     46:                }
                     47:                round=step/2;
                     48:        }
                     49:        if(singflg == 1) /* if single stepping */
                     50:                if(singwt() < 0)
                     51:                {
                     52:                        singflg=stpflg=0;
                     53:                        forflg--;
                     54:                        return(0);
                     55:                }
                     56:        save = ptr;
                     57:        savno = inst.thing.linno;
                     58:        while(fetch(-1,&ptr) == 0 && stpflg == 0)
                     59:        {
                     60:                if(inst.thing.linno == singst)
                     61:                        singflg = 1;
                     62:                if(inst.thing.opcode.lobyte == nxt)
                     63:                {
                     64:                        if(bflag)
                     65:                        {
                     66:                                if(forcnt != 0)
                     67:                                {
                     68:                                        forcnt--;
                     69:                                        continue;
                     70:                                }
                     71:                        }
                     72:                        if(singflg == 1)
                     73:                        {
                     74:                                sav1 = expr;
                     75:                                prin();
                     76:                                expr = sav1;
                     77:                        }
                     78:                        if(strcmp(nam,expr) != 0)
                     79:                        {
                     80:                                ptr=curptr;
                     81:                                forflg--;
                     82:                                return(0);
                     83:                        }
                     84:                        if(cflag) /* if the continue flag is set */
                     85:                        {
                     86:                                if(cflag == 1)
                     87:                                        cflag = 0;
                     88:                                else
                     89:                                {
                     90:                                        cflag--;
                     91:                                        forflg--;
                     92:                                        return(0);
                     93:                                }
                     94:                        }
                     95:                        if(bflag) /* if the break flag is set */
                     96:                        {
                     97:                                bflag--;
                     98:                                forflg--;
                     99:                                return(0);
                    100:                        }
                    101:                        if(!(nam[0] == 'e' && nam[1] == 'v'))
                    102:                        {
                    103:                                getvar(expr,&var);
                    104:                                var += step;
                    105:                                if(step > 0)
                    106:                                {
                    107:                                if(var > final + round) /* if all done */
                    108:                                {
                    109:                                        forflg--;
                    110:                                        return(0);
                    111:                                }
                    112:                                }
                    113:                                else
                    114:                                if(var < final+round)
                    115:                                {
                    116:                                        forflg--;
                    117:                                        return(0);
                    118:                                }
                    119:                                putvar(expr,var);
                    120:                        }
                    121:                        ptr = save;
                    122:                        if(singflg == 1)
                    123:                                if(singwt() < 0)
                    124:                                {
                    125:                                        singflg=stpflg=0;
                    126:                                        forflg--;
                    127:                                        return(0);
                    128:                                }
                    129:                        continue;
                    130:                }
                    131:                if(singflg == 1) /* if single stepping */
                    132:                {
                    133:                        if(singex() < 0)
                    134:                        {
                    135:                        singflg = 0;
                    136:                        forflg--;
                    137:                        return(0);
                    138:                        }
                    139:                }
                    140:                else
                    141:                {
                    142:                        if(bflag || cflag)
                    143:                        {
                    144:                                if(inst.thing.opcode.lobyte == rof) /* if a for */
                    145:                                        forcnt++;
                    146:                                continue;
                    147:                        }
                    148:                        if(bascall(inst.thing.opcode.lobyte) != 0)
                    149:                        {
                    150:                        forflg=0;
                    151:                        return(-1);
                    152:                        }
                    153:                }
                    154:        }
                    155:        forflg--;
                    156:        if(!stpflg)
                    157:        error(savno,48);
                    158:        return(0);
                    159: }
                    160: next()
                    161: {
                    162:        error(inst.thing.linno,18);
                    163:        return(-1);
                    164: }
                    165: brake() /*set the break flag */
                    166: {
                    167:        setflg(&bflag);
                    168:        return(0);
                    169: }
                    170: cont() /* set the continue flag */
                    171: {
                    172:        setflg(&cflag);
                    173:        return(0);
                    174: }
                    175: 
                    176: setflg(flg)
                    177: int *flg;
                    178: {
                    179:        if(forflg == 0) /* if no for in progress */
                    180:        {
                    181:                error(inst.thing.linno,47);
                    182:                return(-1); /* fatal */
                    183:        }
                    184:        if(expr[0] != '\0') /* if there is an expression */
                    185:                *flg = evalx(expr);
                    186:        else
                    187:                *flg = 1;
                    188:        return(0);
                    189: }

unix.superglobalmegacorp.com

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