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

Defined functions

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