#include "intlist.h"
#include <string.h>

int inl_sort= 0;

udatum
empty ()
{
  static udatum kkk= 0;

  if (kkk == 0) {
    kkk= ud_alloc ();
    kkk->ptr= NULL;     /* user coding */ /* NO HACE FALTA */
    ud_const(inl_sort,kkk);
  }

  return kkk;
}
udatum
add (t1, t2)
    udatum t1, t2;
{
  udatum r;

  r= ud_alloc();
  r->ino= t2->ino;
  r->ptr= (void*) t1;
  ud_free (int_sort,t2);
  return r;
}
udatum
hd (t1)
    udatum t1;
{
  udatum r;

  r= ud_alloc();
  r->ino= t1->ino;
  ud_free (inl_sort,t1);
  return r;
}
udatum
tl (t1)
    udatum t1;
{
  udatum r;

  r= ud_copy(inl_sort,(udatum) (t1->ptr));
  ud_free (inl_sort,t1);
  return r;
}
udatum
hasany (t1)
    udatum t1;
{
  udatum r;

  if (t1->ptr == NULL)
    r= false ();
  else
    r= true ();
  ud_free (inl_sort,t1);
  return r;
}

void
fintlist (t1)
    udatum t1;
{

  if (t1->ptr != NULL)
    ud_free (inl_sort,(udatum) t1->ptr);
}

int
eqintlist (t1, t2)
    udatum t1, t2;
{
  while (t1->ptr != NULL && t2->ptr != NULL) {
    if (t1->ino != t2->ino)
      return FALSE;
    t1= (udatum) t1->ptr;
    t2= (udatum) t2->ptr;
  }
  if (t1->ptr == NULL && t2->ptr == NULL)
    return TRUE;
  else
    return FALSE;
}
char*
dintlist (t1)
  udatum t1;
{
  static char buf[1024];
  int size;

  for (buf[0]= 0; t1->ptr != NULL; t1= (udatum) t1->ptr)
    (void) sprintf (buf, "%s%d, ", buf, t1->ino);
  size= strlen (buf);
  if (size > 0)
    buf[size-2]= 0;
  return buf;
}
