1: #include "../h/rt.h"
   2: 
   3: /*
   4:  * put(x,val) - put val onto end of list x.
   5:  */
   6: Xput(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 last list element block.
  30:     */
  31:    hp = (struct b_list *) BLKLOC(arg1);
  32:    bp = (struct b_lelem *) BLKLOC(hp->listtail);
  33: 
  34:    /*
  35:     * If the last list element block is full,
  36:     *  allocate a new list element block, make it the first list
  37:     *  element block and it make it the next block of the
  38:     *  former last list element block.
  39:     */
  40:    if (bp->nused >= bp->nelem) {
  41:       bp = alclstb(LISTBLKSIZE, 0, 0);
  42:       BLKLOC(hp->listtail)->lelem.listnext.type = D_LELEM;
  43:       BLKLOC(BLKLOC(hp->listtail)->lelem.listnext) = (union block *) bp;
  44:       bp->listprev = hp->listtail;
  45:       BLKLOC(hp->listtail) = (union block *) bp;
  46:       }
  47:    /*
  48:     * Set i to position of new last element and assign val (arg2) to
  49:     *  that element.
  50:     */
  51:    i = bp->first + bp->nused;
  52:    if (i >= bp->nelem)
  53:       i -= bp->nelem;
  54:    bp->lslots[i] = arg2;
  55:    /*
  56:     * Adjust block usage count and current list size.
  57:     */
  58:    bp->nused++;
  59:    hp->cursize++;
  60:    /*
  61:     * Return the list.
  62:     */
  63:    arg0 = arg1;
  64:    }
  65: 
  66: Procblock(put,2)

Defined functions

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