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

1.1       root        1: /* Copyright Bell Telephone Laboratories Whippany, N.J.
                      2: 
                      3:  *     /////////////////////////////////////
                      4:  *     /////////////////////////////////////
                      5:  *     /////////////// ext$ ////////////////
                      6:  *     /// J. P. Hawkins WH X4610 8C-001 ///
                      7:  *     ///// Tue Feb 17 07:33:14 1981 //////
                      8:  *     /////////////////////////////////////
                      9:  *     /////////////////////////////////////
                     10:  *     @(#) ext.c: V1.3 3/4/81
                     11: 
                     12:  * BASIC ext$(string,pos,len)
                     13:  * return substring of string starting at position pos length len
                     14:  * where string is a string expression and pos and len are
                     15:  * numeric expressions.
                     16:  */
                     17: 
                     18: #include       "bas.h"
                     19: char *ext(args)
                     20: char   args[];
                     21: {
                     22:        double  evalx();
                     23:        char    *prncpy();
                     24:        char    string[80],result[80];
                     25:        char    pos[20],num[20];
                     26:        int     posit,number;
                     27:        char    *holdptr,*sptr;
                     28: 
                     29:        holdptr = args;
                     30:        holdptr=prncpy(result,args)+1; /* get str field and point past ',' */
                     31:        sptr=result;
                     32:        holdptr=prncpy(pos,holdptr)+1; /* get position expr & point past ',' */
                     33:        prncpy(num,holdptr);       /* get size expression */
                     34:        posit = (int)evalx(pos)-1; /* evaluate the position field */
                     35:        number = (int)evalx(num);  /* evaluate the size field */
                     36:        evals(sptr,string);
                     37:        strncpy(result,&string[posit],number); /* put the segment in result */
                     38:        result[number] = '\0';          /* null terminate result */
                     39: 
                     40:        if(posit > strlen(string))
                     41:        {
                     42:                error(inst.thing.linno, 55); /* OUT OF STRING RANGE */
                     43:        }
                     44: 
                     45:        return(result);
                     46: }

unix.superglobalmegacorp.com

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