1: #include "../h/rt.h"
   2: 
   3: /*
   4:  * list(n,x) - create a list of size n, with initial value x.
   5:  */
   6: 
   7: Xlist(nargs, arg2, arg1, arg0)
   8: int nargs;
   9: struct descrip arg2, arg1, arg0;
  10:    {
  11:    register int i, size;
  12:    register struct b_lelem *bp;
  13:    register struct b_list *hp;
  14:    int nelem;
  15:    extern struct b_list *alclist();
  16:    extern struct b_lelem *alclstb();
  17: 
  18:    defshort(&arg1, 0);  /* Size defaults to 0 */
  19:    DeRef(arg2)
  20: 
  21:    nelem = size = INTVAL(arg1);
  22:    /*
  23:     * Ensure that the size is positive and that the list element block will
  24:     *  have at least LISTBLKSIZE element slots.
  25:     */
  26:    if (size < 0)
  27:       runerr(205, &arg1);
  28:    if (nelem < LISTBLKSIZE)
  29:       nelem = LISTBLKSIZE;
  30: 
  31:    /*
  32:     * Ensure space for a list header block, and a list element block
  33:     * with nelem element slots.
  34:     */
  35:    hneed(sizeof(struct b_list) + sizeof(struct b_lelem) +
  36:          nelem * sizeof(struct descrip));
  37: 
  38:    /*
  39:     * Allocate the list header block and a list element block.
  40:     *  Note that nelem is not equivalent to size
  41:     *  because nelem is the number of elements in the list element
  42:     *  block while size is the number of elements in the
  43:     *  list.
  44:     */
  45:    hp = alclist(size);
  46:    bp = alclstb(nelem, 0, size);
  47:    hp->listhead.type = hp->listtail.type = D_LELEM;
  48:    BLKLOC(hp->listhead) = BLKLOC(hp->listtail) = (union block *) bp;
  49:    /*
  50:     * Initialize each list element.
  51:     */
  52:    for (i = 0; i < size; i++)
  53:       bp->lslots[i] = arg2;
  54:    /*
  55:     * Return the new list.
  56:     */
  57:    arg0.type = D_LIST;
  58:    BLKLOC(arg0) = (union block *) hp;
  59:    }
  60: 
  61: Procblock(list,2)

Defined functions

Xlist defined in line 7; never used
Last modified: 1984-11-18
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 864
Valid CSS Valid XHTML 1.0 Strict