1: #include "../h/rt.h"
   2: 
   3: /*
   4:  * get(x) - get an element from end of list x.
   5:  * Identical to  pop(x).
   6:  */
   7: 
   8: Xget(nargs, arg1, arg0)
   9: int nargs;
  10: struct descrip arg1, arg0;
  11:    {
  12:    register int i;
  13:    register struct b_list *hp;
  14:    register struct b_lelem *bp;
  15:    extern struct b_lelem *alclstb();
  16: 
  17:    /*
  18:     * x must be a list.
  19:     */
  20:    DeRef(arg1)
  21:    if (QUAL(arg1) || TYPE(arg1) != T_LIST)
  22:       runerr(108, &arg1);
  23: 
  24:    /*
  25:     * Fail if the list is empty.
  26:     */
  27:    hp = (struct b_list *) BLKLOC(arg1);
  28:    if (hp->cursize <= 0)
  29:       fail();
  30: 
  31:    /*
  32:     * Point bp at the first list block.  If the first block has no
  33:     *  elements in use, point bp at the next list block.
  34:     */
  35:    bp = (struct b_lelem *) BLKLOC(hp->listhead);
  36:    if (bp->nused <= 0) {
  37:       bp = (struct b_lelem *) BLKLOC(bp->listnext);
  38:       BLKLOC(hp->listhead) = (union block *) bp;
  39:       bp->listprev = nulldesc;
  40:       }
  41:    /*
  42:     * Locate first element and assign it to arg0 for return.
  43:     */
  44:    i = bp->first;
  45:    arg0 = bp->lslots[i];
  46:    /*
  47:     * Set bp->first to new first element, or 0 if the block is now
  48:     *  empty.  Decrement the usage count for the block and the size
  49:     *  of the list.
  50:     */
  51:    if (++i >= bp->nelem)
  52:       i = 0;
  53:    bp->first = i;
  54:    bp->nused--;
  55:    hp->cursize--;
  56:    }
  57: 
  58: Procblock(get,1)

Defined functions

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