Annotation of 43BSD/contrib/icon/operators/size.c, revision 1.1.1.1

1.1       root        1: #include "../h/rt.h"
                      2: #include "../h/record.h"
                      3: 
                      4: /*
                      5:  * *x - return size of string or object x.
                      6:  */
                      7: 
                      8: size(nargs, arg1, arg0)
                      9: int nargs;
                     10: struct descrip arg1, arg0;
                     11:    {
                     12:    DclSave
                     13:    char sbuf[MAXSTRING];
                     14: 
                     15:    SetBound;
                     16:    /*
                     17:     * Make sure x isn't null.
                     18:     */
                     19:    DeRef(arg1)
                     20:    if (NULLDESC(arg1))
                     21:       runerr(112, &arg1);
                     22:    if (cvstr(&arg1, sbuf) != NULL) {
                     23:       /*
                     24:        * If x can be converted to a string, return the length of the string
                     25:        *  as the size of x.
                     26:        */
                     27:       arg0.type = D_INTEGER;
                     28:       INTVAL(arg0) = STRLEN(arg1);
                     29:       }
                     30:    else {
                     31:       /*
                     32:        * x isn't a string.  *x for lists and tables is the current size;
                     33:        *  *x for records is the number of fields, and *x for co-expressions
                     34:        *  is the number of results that have been produced.
                     35:        */
                     36:       switch (TYPE(arg1)) {
                     37:          case T_LIST:
                     38:             arg0.type = D_INTEGER;
                     39:             INTVAL(arg0) = BLKLOC(arg1)->list.cursize;
                     40:             break;
                     41: 
                     42:          case T_TABLE:
                     43:             arg0.type = D_INTEGER;
                     44:             INTVAL(arg0) = BLKLOC(arg1)->table.cursize;
                     45:             break;
                     46: #ifdef SETS
                     47:          case T_SET:
                     48:             arg0.type = D_INTEGER;
                     49:             INTVAL(arg0) = BLKLOC(arg1)->set.setsize;
                     50:             break;
                     51: #endif SETS
                     52:          case T_RECORD:
                     53:             arg0.type = D_INTEGER;
                     54:             INTVAL(arg0) = BLKLOC(arg1)->record.recptr->nfields;
                     55:             break;
                     56: 
                     57:          case T_ESTACK:
                     58:             arg0.type = D_INTEGER;
                     59:             INTVAL(arg0) = BLKLOC(arg1)->estack.nresults;
                     60:             break;
                     61: 
                     62:          default:
                     63:             /*
                     64:              * There is no notion of size for this datatype.
                     65:              */
                     66:             runerr(112, &arg1);
                     67:          }
                     68:       }
                     69:    ClearBound;
                     70:    }
                     71: 
                     72: Opblock(size,1,"*")

unix.superglobalmegacorp.com

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