1: #include "../h/rt.h"
   2: 
   3: /*
   4:  * pop(x) - pop an element from beginning of list x.
   5:  */
   6: 
   7: Xpop(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:     * Fail if the list is empty.
  25:     */
  26:    hp = (struct b_list *) BLKLOC(arg1);
  27:    if (hp->cursize <= 0)
  28:       fail();
  29: 
  30:    /*
  31:     * Point bp at the first list block.  If the first block has no
  32:     *  elements in use, point bp at the next list block.
  33:     */
  34:    bp = (struct b_lelem *) BLKLOC(hp->listhead);
  35:    if (bp->nused <= 0) {
  36:       bp = (struct b_lelem *) BLKLOC(bp->listnext);
  37:       BLKLOC(hp->listhead) = (union block *) bp;
  38:       bp->listprev = nulldesc;
  39:       }
  40:    /*
  41:     * Locate first element and assign it to arg0 for return.
  42:     */
  43:    i = bp->first;
  44:    arg0 = bp->lslots[i];
  45:    /*
  46:     * Set bp->first to new first element, or 0 if the block is now
  47:     *  empty.  Decrement the usage count for the block and the size
  48:     *  of the list.
  49:     */
  50:    if (++i >= bp->nelem)
  51:       i = 0;
  52:    bp->first = i;
  53:    bp->nused--;
  54:    hp->cursize--;
  55:    }
  56: 
  57: Procblock(pop,1)

Defined functions

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