Annotation of researchv10no/cmd/basic/bite/src/getdims.c, revision 1.1

1.1     ! root        1: /* Copyright Bell Telephone Laboratories Whippany, N.J.
        !             2: 
        !             3:  *     /////////////////////////////////////
        !             4:  *     /////////////////////////////////////
        !             5:  *     ///////////// getdims.c /////////////
        !             6:  *     /// J. P. Hawkins WH X4610 8C-001 ///
        !             7:  *     ///// Sun Aug 26 06:16:54 1979 //////
        !             8:  *     /////////////////////////////////////
        !             9:  *     /////////////////////////////////////
        !            10: 
        !            11:  *
        !            12:  * GET ARRAY PARAMETERS (used by "dim", aputvar and agetvar)
        !            13:  * Pass the array symbol name, the number of dimensions , and
        !            14:  * the value of each dimension in dimlist where dimlist is an array
        !            15:  * of floats. The values returned are integerized.
        !            16:  *
        !            17:  * This routine is used by "dim()", a_getvar(), a_putvar()
        !            18:  *
        !            19:  * This routine could potentially be used for device driver routines
        !            20:  * as a means of getting number of args and the value of each.
        !            21:  */
        !            22: /*   "@(#) getdims.c:  V 1.3  3/4/81" */
        !            23: #include       "bas.h"
        !            24: 
        !            25: getdims(afield,arname,numdim,dimlist)
        !            26: char   afield[];       /* string to be scanned */
        !            27: char   arname[];       /* array name */
        !            28: double *numdim;        /* number of dimensions */
        !            29: double dimlist[];      /* list of dimensions */
        !            30: {
        !            31:        char    expfld[40];     /* expression field */
        !            32:        double  evalx();
        !            33:        double  _int();
        !            34:        double  maxdim;
        !            35:        int     intdim;         /* integer form of number of dimensions */
        !            36: 
        !            37:        register char *ptr;
        !            38:        register        i;
        !            39:        ptr  = afield;  /* get pointer to command argument string */
        !            40:        maxdim = MAXDIM;        /* convert maxdim to double */
        !            41:        i = 0;
        !            42:        while(*ptr != '(' && *ptr != '$' && *ptr != '\0' && i != 2)
        !            43:        {
        !            44:                arname[i++] = *ptr++;   /* copy array symbol name */
        !            45:        }
        !            46: 
        !            47:        arname[i] = '\0';       /* null terminate array name */
        !            48: 
        !            49:        *ptr++;         /* bump past '(' */
        !            50:        /*
        !            51:         * While not at end of string ('\0')
        !            52:         *
        !            53:         * Each field is terminated by a ',' except the last which
        !            54:         * is terminated by a ')' immediatly followed by a '\0'.
        !            55:         *
        !            56:         * CALCULATE NUMBER AND VALUE OF EACH DIMENSION
        !            57:         */
        !            58:        *numdim = 0.0;
        !            59:        i = 0;
        !            60: 
        !            61:        while(1)                /* scan fields */
        !            62:        {
        !            63:                expfld[i++] = *ptr++;   /* copy expression */
        !            64:                if(*ptr == ',' || (*ptr == ')' && *(ptr+1) == '\0'))
        !            65:                {
        !            66:                        *ptr++;         /* bump past field terminator */
        !            67:                        expfld[i] = '\0'; /* null terminate expr */
        !            68:                        i = 0;  /* init expr field pointer */
        !            69:                        /*
        !            70:                         * Evaluate expression and put as dimension
        !            71:                         */
        !            72:                        intdim = *numdim;
        !            73:                        dimlist[intdim] = _int(evalx(expfld));
        !            74:                        if(dimlist[intdim] <= 0.0) 
        !            75:                        {
        !            76:                                error(inst.thing.linno, 28); /* NEG DIM */
        !            77:                                return(-1);
        !            78:                        }
        !            79:                        *numdim += 1.0; /* increment dimension count */
        !            80:                        if(*numdim > maxdim)
        !            81:                        {
        !            82:                                error(inst.thing.linno, 22); /* TOO MANY DIMS */
        !            83:                                return(-1);
        !            84:                        }
        !            85:                }
        !            86:                if(*ptr == '\0') break; /* end of dimension statment */
        !            87:        }
        !            88:        intdim++;       /* bump past last dimension */
        !            89:        dimlist[intdim] = 0.0;  /* null terminate end of list */
        !            90:        return(0);
        !            91: }

unix.superglobalmegacorp.com

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