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

1.1       root        1: /* Copyright Bell Telephone Laboratories Whippany, N.J.
                      2: 
                      3:  *     /////////////////////////////////////
                      4:  *     /////////////////////////////////////
                      5:  *     ////////////// print.c //////////////
                      6:  *     /// J. P. Hawkins WH X4610 8C-001 ///
                      7:  *     ///// Fri Aug 24 17:02:55 1979 //////
                      8:  *     /////////////////////////////////////
                      9:  *     /////////////////////////////////////
                     10:  *
                     11: 
                     12:  *
                     13:  * BASIC Print Command
                     14:  *
                     15:  * MOD,J.P.Hawkins,3-FEB-81 to handle string variables
                     16:  */
                     17: /*   "@(#) print.c:  V 1.5  5/6/81" */
                     18: #include       "bas.h"
                     19: #define NMFIELD 5      /* number of print fields */
                     20: #define        PSIZE   80      /* max print columns */
                     21: /*
                     22: #define skip00() {while(*ptext == ' ' || *ptext == '\t') *ptext++;}
                     23: */
                     24: #define        skip00()        {}      /* skip00 does nothing */
                     25: static int     contin = 1;     /* line continuation flag initted
                     26:                                    to no continuation */
                     27: extern struct FILTBL filtbl[];
                     28: #ifdef TEST
                     29: char   busaddr[2];     /* IBV11 bus address (one char term by null) */
                     30: buspr()
                     31: {
                     32:        char    *ptr;
                     33: 
                     34:        ptr = expr;     /* point to beginning of string */
                     35: 
                     36:        if(*ptr++ != '\'')
                     37:        {
                     38:                error(inst.thing.linno, 100); /* MISSING ' DELIM */
                     39:                return(-1);
                     40:        }
                     41: 
                     42:        busaddr[0] = *ptr++;    /* next char is buss address */
                     43:        busaddr[1] = '\0';      /* null terminate */
                     44: 
                     45:        expr = ptr;             /* make prguts start at current pointer */
                     46:        prguts(1);              /* call prguts with buslfg on */
                     47: }
                     48: #endif
                     49: 
                     50: __print()
                     51: {
                     52:        prguts(0);
                     53: }
                     54: 
                     55: /*
                     56:  *
                     57:  * GUTS TO NORMAL PRINT AND IEEE BUS OUTPUT
                     58:  */
                     59: prguts(busflg)
                     60: int    busflg;         /* true if talking to IBV11 bus */
                     61: {
                     62: #ifdef STRINGS
                     63:        char    *savptr;
                     64:        char    field[80];
                     65: #endif
                     66:        int     tvalue;         /* tab value */
                     67:        int     fildes;         /* file designator for BASIC */
                     68:        double  value;          /* evaluated floating point value */
                     69:        double  evalx();        /* expression avaluator */
                     70:        char    pbuild[PSIZE];  /* print string build area */
                     71:        char    numbuf[80];     /* number text storage */
                     72:        register i;             /* build txtbuf index */
                     73:        int n;                  /* number txtbuf index */
                     74:        int     fd;             /* file descriptor */
                     75:        char *ptext;            /* input text pointer */
                     76:        fd = 1;                 /* init fd to 1 for normal print */
                     77:        ptext = expr;           /* point to beginning of text area */
                     78: 
                     79:        i = 0;
                     80: 
                     81: if(!(busflg))
                     82: {
                     83:        if(*ptext == '_' && (*(ptext+1) >= '0' && *(ptext+1) <= '8'))
                     84:        {
                     85:                *ptext++;
                     86:                fildes = *ptext - '1';  /* get BASIC file designator */
                     87:                fd = filtbl[fildes].fildes;
                     88:                *ptext++;
                     89:                if(filtbl[fildes].mode != 'w')  /* file must be open
                     90:                                                     for writing */
                     91:                {
                     92:                        error(inst.thing.linno, 36); /* FILE NOT OPEN FOR WRITE */
                     93:                        return(-1);
                     94:                }
                     95:        }
                     96: }
                     97:        if(*ptext == '\0')      /* if line empty */
                     98:                contin = 1;     /* force newline */
                     99: 
                    100:        while(*ptext != '\0')
                    101:        {
                    102:                skip00();       /* skip blanks and tabs */
                    103:                if(equal(ptext,"tab"))  /* if "tab" function */
                    104:                {
                    105:                        contin = 1;
                    106:                        ptext += 3;     /* skip "tab" string */
                    107:                        if(*ptext != '(')
                    108:                        {
                    109:                                error(inst.thing.linno, 30);
                    110:                                return(-1);
                    111:                        }
                    112:                        else
                    113:                        {
                    114:                                n = 0;
                    115:                                cpyprn(numbuf,&ptext,&n); /* get expr */
                    116:                                numbuf[n] = '\0';
                    117:                                value = evalx(numbuf);
                    118:                                if(value < 0.0) value = 0.0;
                    119:                                tvalue = value;
                    120:                                while((i < tvalue) && (i < PSIZE-2))
                    121:                                        pbuild[i++] = ' ';
                    122:                        }
                    123:                }
                    124:                else if(*ptext == '"')  /* if string delimiter */
                    125:                {
                    126:                        contin = 1;     /* flip to no line continuation */
                    127:                        *ptext++;       /* bump past delimiter */
                    128:                        while(*ptext != '"' && *ptext != '\0')
                    129:                        {
                    130:                                if(i > PSIZE-2) i = PSIZE-2;
                    131:                                pbuild[i++] = *ptext++; /* copy text
                    132:                                                        into build area */
                    133:                        }
                    134:                        if(*ptext == '\0') /* if null before end quote */
                    135:                        {
                    136:                                error(inst.thing.linno, 11); /* error */
                    137:                                return(-1);
                    138:                        }
                    139:                        else if(i >= PSIZE-2)
                    140:                        {
                    141:                                i = PSIZE-2; /* truncate line at line limit */
                    142:                        }
                    143:                        else;
                    144: 
                    145:                        *ptext++;       /* bump past end delim */
                    146:                        skip00();       /* skip blanks and tabs */
                    147:                }
                    148:                else if(*ptext == ',' || *ptext == ';')
                    149:                {
                    150:                                pbuild[i++] = ' ';
                    151:                }
                    152:                else
                    153:                {
                    154:                        contin = 1;     /* flip to no line continuation */
                    155:                        n = 0;
                    156:                        while(*ptext != ';' && *ptext != ',' && *ptext != '\0')
                    157:                        {
                    158:                                /*
                    159:                                 * SKIP EVERYTHING ENCLOSED IN BALANCED ()
                    160:                                 * This is so commas in array specs
                    161:                                 * ARENT interpreted as print delims
                    162:                                 */
                    163:                                if(*ptext == '(')
                    164:                                {
                    165:                                        cpyprn(numbuf,&ptext,&n);
                    166:                                }
                    167:                                else
                    168:                                {
                    169:                                        numbuf[n++] = *ptext++;
                    170:                                }
                    171:                        }
                    172:                        numbuf[n] = '\0';       /* null terminate expr */
                    173: #ifdef STRINGS
                    174:                        savptr=numbuf;
                    175:                        if(class(&savptr,field) < STCLASS)
                    176:                        {
                    177: #endif
                    178:                                value = evalx(numbuf); /* eval the expr. */
                    179:                                /*
                    180:                                * PRECEDE POS. NUMS WITH A BLANK
                    181:                                * IF NOT A BUS CALL
                    182:                                */
                    183:                                if(busflg == 0)
                    184:                                        if(value>=0.0) pbuild[i++] = ' ';
                    185: 
                    186:                                sprintf(numbuf,"%g", value); /* conv to ascii */
                    187: #ifdef STRINGS
                    188:                        }
                    189:                        else
                    190:                        {
                    191:                                evals(numbuf,numbuf);
                    192:                        }
                    193: #endif
                    194:                        n=0;
                    195:                        while(numbuf[n] != '\0' && i < PSIZE-2)
                    196:                        {
                    197:                                pbuild[i++] = numbuf[n++];
                    198:                        }
                    199:                        if(i >= PSIZE-2)
                    200:                        {
                    201:                                i = PSIZE-2; /* truncate line */
                    202:                        }
                    203:                }
                    204:                switch(*ptext)
                    205:                {
                    206:                        case ';':
                    207:                                contin = 0; /* turn on line continuation */
                    208:                                *ptext++;       /* bump past delim */
                    209:                                break;
                    210:                        case ',':
                    211:                                contin = 0; /* turn on line continuation */
                    212:                                /*
                    213:                                 * this is a modulo count to
                    214:                                 * set up field seperation
                    215:                                 */
                    216:                                while((i%(PSIZE/NMFIELD)) && i < PSIZE-2)
                    217:                                        pbuild[i++] = ' '; /* blank fill */
                    218:                                *ptext++;
                    219:                                break;
                    220:                        case '\0':
                    221:                                break;
                    222:                        default:
                    223:                                error(inst.thing.linno, 13); /* missing delim */
                    224:                                return(0);
                    225:                                /* bad news */
                    226:                                break;
                    227:                }
                    228:                skip00();       /* skip spaces and tabs */
                    229:        }
                    230:        if(contin && !(busflg)) /* if continuation off
                    231:                                    and not a bus command */
                    232:        {
                    233:                if(i >= PSIZE-2)
                    234:                        i = PSIZE-2; /* truncate line at maximum */
                    235:                pbuild[i++] = '\n'; /* put in "newline" char */
                    236:        }
                    237: 
                    238:        pbuild[i] = '\0';       /* null term string */
                    239:        /*
                    240:         * write to terminal if fd = 1 otherwise write to file
                    241:         */
                    242: #ifdef TEST
                    243:        if(busflg)
                    244:        {
                    245:                ibs(busaddr,pbuild);
                    246:                return(0);
                    247:        }
                    248: #endif
                    249: 
                    250:        if(fd == 1)
                    251:                printf("%s",pbuild);    /* PRINT OUT THE LINE */
                    252:        else
                    253:                write(fd, pbuild, i);
                    254:        return(0);
                    255: }
                    256: /*
                    257:  *
                    258:  * /// COPY CHARS WITHIN BALANCED PARENS TO NUMBUF ///
                    259:  */
                    260: cpyprn(numbuf,txtptr,n)
                    261: char   numbuf[];
                    262: char   **txtptr;
                    263: int    *n;
                    264: {
                    265:        int     pcnt;
                    266: 
                    267:        pcnt = 1;
                    268:        numbuf[(*n)++] = *(*txtptr)++;
                    269:        while(pcnt>0 && **txtptr != '\0')
                    270:        {
                    271:                switch(**txtptr)
                    272:                {
                    273:                        case '(':
                    274:                                pcnt += 1;
                    275:                                break;
                    276:                        case ')':
                    277:                                pcnt -= 1;
                    278:                                break;
                    279:                        default:
                    280:                                break;
                    281:                }
                    282:                numbuf[(*n)++] = *(*txtptr)++;
                    283:        }
                    284: }

unix.superglobalmegacorp.com

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