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

1.1       root        1: /* Copyright Bell Telephone Laboratories Whippany, N.J.
                      2: 
                      3:  *     /////////////////////////////////////
                      4:  *     /////////////////////////////////////
                      5:  *     //////////// UNTILCOD.C /////////////
                      6:  *     /// J. P. Hawkins WH X4610 8C-001 ///
                      7:  *     ///// Mon Sep 17 23:06:13 1979 //////
                      8:  *     /////////////////////////////////////
                      9:  *     /////////////////////////////////////
                     10: 
                     11:  * Either execute or skip command lines until specified code (endcod)
                     12:  * is reached.
                     13:  * If execflg = 1 then execute the command lines,
                     14:  * If execflg = 0 then skip over the command lines.
                     15:  * This routine terminates if:
                     16:  *     endcod is encountered
                     17:  *     end of text is encountered
                     18:  *     error is encountered
                     19:  *
                     20:  * This routine is used for the structured "if" for skipping
                     21:  * or executing until the "else" or "endif" is encountered.
                     22:  */
                     23: /*   "@(#) untilcod.c:  V 1.1  12/21/80" */
                     24: 
                     25: #include       "bas.h"
                     26: extern int bflag,cflag;                /* break & continue flag */
                     27: extern int esle,fidne;         /* else and endif codes */
                     28: extern int _togo;              /* "goto" code */
                     29:        int     endfcnt;        /* nest count */
                     30: extern int _fi;
                     31: 
                     32: untilcod(endcod,execflg)
                     33: int    endcod;         /* termination code */
                     34: int    execflg;        /* execution flag */
                     35: {
                     36:        extern int stpflg;      /* stop flag */
                     37:        extern char *ptr;
                     38: 
                     39:        if(bflag || cflag)      /* if break flag on */
                     40:        {
                     41:                endfcnt = 0;    /* clean up nest count */
                     42:                return(0);      /* UNRAVEL */
                     43:        }
                     44:        while(fetch(-1,&ptr) == 0 && stpflg == 0)
                     45:        {
                     46:                /*
                     47:                 * ALWAYS terminate if endif encountered and nest = 0
                     48:                 */
                     49:                if(inst.thing.opcode.lobyte == fidne && endfcnt == 0)
                     50:                        break;
                     51:                if(execflg)     /* EXECUTION PART */
                     52:                {
                     53:                        if(inst.thing.opcode.lobyte == _togo)
                     54:                        {
                     55:                                error(inst.thing.linno, 46); /* GOTO NOT ALLOW */
                     56:                                return(-1);
                     57:                        }
                     58:                        /*
                     59:                         * IF TERMINATION CODE REACHED
                     60:                         */
                     61:                        if(inst.thing.opcode.lobyte == endcod)
                     62:                                break;          /*    break out */
                     63:                        if(bascall(inst.thing.opcode.lobyte) != 0)
                     64:                        {
                     65:                                return(-1);
                     66:                        }
                     67:                        if(bflag || cflag)      /* if break got set */
                     68:                        {
                     69:                                endfcnt = 0; /* zero nest count */
                     70:                                return(0);      /* UNRAVEL */
                     71:                        }
                     72:                }
                     73:                else    /* NON EXECUTION PART */
                     74:                {
                     75:                        if(inst.thing.opcode.lobyte == fidne && endfcnt > 0)
                     76:                        {
                     77:                                endfcnt--; /* dec endif nest count */
                     78:                                continue; /* not last "if" when just 0 */
                     79:                        }
                     80:                        else if(inst.thing.opcode.lobyte == _fi)
                     81:                        {
                     82:                                endfcnt++;
                     83:                        }
                     84:                        if(inst.thing.opcode.lobyte == endcod && endfcnt == 0)
                     85:                                break;
                     86:                }
                     87:        }
                     88:        return(0);
                     89: }

unix.superglobalmegacorp.com

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