1: #include "../h/rt.h"
   2: 
   3: /*
   4:  * push(x,val) - push val onto beginning of list x.
   5:  */
   6: Xpush(nargs, arg2, arg1, arg0)
   7: int nargs;
   8: struct descrip arg2, arg1, arg0;
   9:    {
  10:    register int i;
  11:    register struct b_list *hp;
  12:    register struct b_lelem *bp;
  13:    extern struct b_lelem *alclstb();
  14: 
  15:    /*
  16:     * x must be a list.
  17:     */
  18:    DeRef(arg1)
  19:    DeRef(arg2)
  20:    if (QUAL(arg1) || TYPE(arg1) != T_LIST)
  21:       runerr(108, &arg1);
  22: 
  23:    /*
  24:     * A new list element block might be needed, so ensure space for it.
  25:     */
  26:    hneed(sizeof(struct b_lelem)+LISTBLKSIZE*sizeof(struct descrip));
  27: 
  28:    /*
  29:     * Point hp at the list header block and bp at the first
  30:     * list element block.
  31:     */
  32:    hp = (struct b_list *) BLKLOC(arg1);
  33:    bp = (struct b_lelem *) BLKLOC(hp->listhead);
  34:    /*
  35:     * If the first list element block is full,
  36:     * allocate a new list element block, make it the first list
  37:     *  element block and make it the previous block of the
  38:     *  former first list element block.
  39:     */
  40:    if (bp->nused >= bp->nelem) {
  41:       bp = alclstb(LISTBLKSIZE, 0, 0);
  42:       BLKLOC(hp->listhead)->lelem.listprev.type = D_LELEM;
  43:       BLKLOC(BLKLOC(hp->listhead)->lelem.listprev) = (union block *) bp;
  44:       bp->listnext = hp->listhead;
  45:       BLKLOC(hp->listhead) = (union block *) bp;
  46:       }
  47:    /*
  48:     * Set i to position of new first element and assign val (arg2) to
  49:     *  that element.
  50:     */
  51:    i = bp->first - 1;
  52:    if (i < 0)
  53:       i = bp->nelem - 1;
  54:    bp->lslots[i] = arg2;
  55:    /*
  56:     * Adjust value of location of first element, block usage count,
  57:     *  and current list size.
  58:     */
  59:    bp->first = i;
  60:    bp->nused++;
  61:    hp->cursize++;
  62:    /*
  63:     * Return the list.
  64:     */
  65:    arg0 = arg1;
  66:    }
  67: 
  68: Procblock(push,2)

Defined functions

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