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

1.1       root        1: /* Copyright Bell Telephone Laboratories Whippany, N.J.
                      2: 
                      3:  *     ***********************************************
                      4:  *     ***********************************************
                      5:  *     *** READ INFORMATION FROM 'data' STATEMENTS ***
                      6:  *     ********* R. B. Drake WH 8C-005 X4163 *********
                      7:  *     ********** Sun Aug 26 11:19:29 1979 ***********
                      8:  *     ***********************************************
                      9:  *     ***********************************************
                     10:  * "read" locates the next item of information in a 'data' sttement
                     11:  * and places it in variables defined by a list following the read
                     12:  * command.
                     13: 
                     14: */
                     15: /*   "@(#) read.c:  V 1.4  3/4/81" */
                     16: 
                     17: #include "bas.h"
                     18: static char *daptr;
                     19: static char *itmptr;
                     20: extern int atad;
                     21: double evalx();
                     22: char *prncpy();
                     23: int arflg;
                     24: getnext()
                     25: {
                     26:        while(fetch(-1, &daptr) == 0)
                     27:        {
                     28:                if(inst.thing.opcode.lobyte == atad)
                     29:                {
                     30:                        itmptr = expr;
                     31:                        return(0);
                     32:                }
                     33:        }
                     34:        error(inst.thing.linno,33);
                     35:        return(-1);
                     36: }
                     37: __read()
                     38: {
                     39:        char *ptr;
                     40:        int flg;
                     41: #ifdef STRINGS
                     42:        char    *savptr;
                     43:        char    field[40];
                     44:        char    result[80];
                     45: #endif
                     46:        char ascop[80],ascno[80];
                     47:        ptr = expr;
                     48:        if(daptr == 0)
                     49:        {
                     50:                if(fetch(0, &daptr) != 0)
                     51:                {
                     52:                        error(inst.thing.linno,33);
                     53:                        return(0);
                     54:                }
                     55:                if(inst.thing.opcode.lobyte == atad)
                     56:                        itmptr = expr;
                     57:                else
                     58:                if(getnext() < 0)
                     59:                        return(0);
                     60:        }
                     61:        while(1)
                     62:        {
                     63:                flg = 0;
                     64:                ptr = prncpy(ascop,ptr);
                     65:                if(arflg == 1)
                     66:                        flg = 1;
                     67:                switch(*itmptr)
                     68:                {
                     69:                        case '\0':
                     70:                                if(getnext() < 0)
                     71:                                        return(0);
                     72:                                break;
                     73:                        case ',':
                     74:                                itmptr++;
                     75:                                if(*itmptr == '\0')
                     76:                                        if(getnext() < 0)
                     77:                                                return(0);
                     78:                }
                     79:                itmptr = prncpy(ascno,itmptr);
                     80: #ifdef STRINGS
                     81:                savptr = ascno;
                     82:                if(class(&savptr,field) < STCLASS)
                     83:                {
                     84: #endif
                     85:                        if(flg==1)
                     86:                                aputvar(ascop,evalx(ascno));
                     87:                        else
                     88:                                putvar(ascop,evalx(ascno));
                     89: #ifdef STRINGS
                     90:                }
                     91:                else
                     92:                {
                     93:                        evals(ascno,result);
                     94:                        savptr=ascop;
                     95:                        if(class(&savptr,field) == SACLASS)
                     96:                                saputvar(field,result);
                     97:                        else
                     98:                                sputvar(field,result);
                     99:                }
                    100: #endif
                    101:                if(*ptr++ == '\0')
                    102:                        return(0);
                    103:        }
                    104: }
                    105: restore()
                    106: {
                    107:        daptr = 0;
                    108:        return(0);
                    109: }
                    110: char *prncpy(to,from)
                    111: char register *to,*from;
                    112: {
                    113:        int prncnt,i;
                    114:        prncnt = 0;
                    115:        arflg = 0;
                    116:        for(i=0;*from != '\0';i++)
                    117:        {
                    118:                if(*from == ',' && prncnt == 0) break;
                    119:                to[i] = *from++;
                    120:                switch(to[i])
                    121:                {
                    122:                        case '(':
                    123:                                prncnt += 1;
                    124:                                arflg = 1;
                    125:                                break;
                    126:                        case ')':
                    127:                                prncnt -= 1;
                    128:                }
                    129:        }
                    130:        to[i] = '\0';
                    131:        return(from);
                    132: }

unix.superglobalmegacorp.com

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