1: /* $Header$ */
   2: 
   3: /*
   4:  * Author: Peter J. Nicklin
   5:  */
   6: 
   7: /*
   8:  * slpop() removes the (nkey+1)th item from list slist, if item matches key.
   9:  * If key is null, the item is removed regardless. Keys are numbered
  10:  * from 0 starting at the head of the list. Integer YES is returned if a
  11:  * key was popped, otherwise NO.
  12:  */
  13: #include "macro.h"
  14: #include "null.h"
  15: #include "slist.h"
  16: #include "yesno.h"
  17: 
  18: slpop(key, nkey, slist)
  19:     char *key;          /* key string */
  20:     int nkey;           /* number of key to be removed */
  21:     SLIST *slist;           /* pointer to list head block */
  22: {
  23:     SLBLK *curblk;          /* current list block */
  24:     SLBLK *nxtblk;          /* next list block */
  25:     SLBLK *prvblk;          /* previous list block */
  26: 
  27:     if (nkey < 1)
  28:         {
  29:         /* first block is a special case */
  30:         if (slist->head == NULL)
  31:             goto nopop;
  32:         else if (key != NULL && !EQUAL(slist->head->key, key))
  33:             goto nopop;
  34:         else    {
  35:             nxtblk = slist->head->next;
  36:             free(slist->head->key);
  37:             free((char *) slist->head);
  38:             slist->head = nxtblk;
  39:             slist->nk--;
  40:             }
  41:         if (slist->head == NULL)
  42:             slist->tail = NULL;
  43:         }
  44:     else    {
  45:         /* remainder of list */
  46:         if (slist->head == NULL)
  47:             goto nopop;
  48:         else    {
  49:             prvblk = slist->head;
  50:             curblk = slist->head->next;
  51:             while (curblk != NULL && --nkey > 0)
  52:                 {
  53:                 prvblk = curblk;
  54:                 curblk = curblk->next;
  55:                 }
  56:             if (curblk == NULL)
  57:                 goto nopop;
  58:             else if (key != NULL && !EQUAL(curblk->key, key))
  59:                 goto nopop;
  60:             else    {
  61:                 if (curblk == slist->tail)
  62:                     slist->tail = prvblk;
  63:                 prvblk->next = curblk->next;
  64:                 free(curblk->key);
  65:                 free((char *) curblk);
  66:                 slist->nk--;
  67:                 }
  68:             }
  69:         }
  70:     return(YES);
  71: 
  72: nopop:  return(NO);
  73: }

Defined functions

slpop defined in line 18; never used
Last modified: 1985-07-03
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 538
Valid CSS Valid XHTML 1.0 Strict