static char *rcsid = "$Header: /sanguine/homes/zeus/Blind-2.48/RCS/List.c,v 2.48 1999/03/14 00:46:08 zeus Exp zeus $";

/*
 * $Log: List.c,v $
 * Revision 2.48  1999/03/14 00:46:08  zeus
 * *** empty log message ***
 *
 */

#define NOTIMEB
#include "common.h"
#include "prototypes.h"
#include "exit.h"
#include "list.h"



void *
alloc (unsigned int bytes)
{
  void *s = malloc (bytes);

  if (s == NULL)
  {
    printf ("Out of memory\n");
    exit (NOMEM);
  }
  memset (s, 0, bytes);
  return s;
}


void
addlist (void *_base, void *_p)
{
  list **base = _base;
  list *p = _p;
  list *q;

  p->next = NULL;
  if (*base)
  {
    for (q = *base; q->next; q = q->next)
      ;
    q->next = p;
  }
  else
    *base = p;
}

void
removelist (void *_base, void *_p)
{
  list **base = _base;
  list *p = _p;
  list *q;

  if (*base == p)
    *base = p->next;
  else
  {
    for (q = *base; q->next != p; q = q->next)
      assert (q != NULL);
    q->next = p->next;
  }
  free (p);
}


void
freelist (void *base)
{
  list *p, *p2;

  p2 = base;
  while (p2)
  {
    p = p2;
    p2 = p2->next;
    free (p);
  }
}

 
unsigned
listlen (void *base)
{
  list *p;
  int i = 0;

  for (p = base; p; p = p->next, i++);
  return i;
}
