/* $Id: listfuncs.c,v 1.4 1998/10/17 13:24:50 fraserm Exp $
   $Log: listfuncs.c,v $
   Revision 1.4  1998/10/17 13:24:50  fraserm
   ANSI-fied the code
   added "-" option to allow futrther options from standard input

   Revision 1.3  1998/03/08 22:44:13  fraserm
   screen refresh by interval timer for xagm
   doesn't sort dictionary unless it has to

   Revision 1.2  1996/09/12 14:20:56  fraser
   add module version printing

 * Revision 1.1  1996/09/12  13:18:54  fraser
 * Initial revision
 *
*/
/* listfuncs.c: list manipulating functions for agm
*/

char listfuncs_RCSid[] = "$Revision: 1.4 $";

#include "agm.h"

void destroy_list (struct wnode *ls, struct wnode *le)
{
  struct wnode *loop = ls, *last;

  while (loop != NULL) {
    last = loop;
    loop = loop->next;
    free (last);
  }
}

int addword (char *word, struct wnode **ls, struct wnode **le)
{
  struct wnode *new;

  if ((new = (struct wnode *) malloc (sizeof (struct wnode))) == NULL) {
    return -1;
  }
  new->word = word;
  new->next = NULL;
  if (*ls == NULL) {
    *ls = *le = new;
  }
  else {
    if (strcmp ((*le)->word, new->word) >= 0) { /* if the new word is lexically
						   less than or equal to the
						   current last in the list,
						   set the "we must sort"
						   flag */
      must_sort = TRUE;
    }
    (*le)->next = new;
    *le = new;
  }
  return 0;
}
