/* These routines manage the ESD (External Symbol Dictionary).
 *
 * $Log: esd.c,v $
 * Revision 1.2  1997/06/04 01:08:47  david
 * ANSI-fied the program.
 *
 */

#include <stdio.h>
#include <string.h>
#include "esd.h"
#include "list.h"

static char *RcsId = "$Id: esd.c,v 1.2 1997/06/04 01:08:47 david Exp $";

struct esd *list_insert(), *list_data( struct list * );

static struct list *esd_root = NULL; /* Root of ESD in memory */

/* Compare two ESD entries */
int esd_compare( struct esd *ptr1, struct esd *ptr2 )
{
return strcmp( ptr1->name, ptr2->name );
}

char *esd_data( struct esd *ptr )
{
return ptr->name;
}

/* Insert a new entry into the ESD table */
int esdins( char *name, char type, int value )
{
struct esd *temp, *p;
register int not_found = -1; /* Initialize to "Not Found" */

if ( (temp = (struct esd *) malloc( sizeof(struct esd) )) == NULL )
   {
   fprintf( stderr, "esdins: *** Out of Memory ***\n" );
   exit( 1 );
   }

/* Initialize node */
if ( (temp->name = strdup( name )) == NULL )
   {
   fprintf( stderr, "esdins: *** Out of Memory ***\n" );
   exit( 1 );
   }
temp->type = type;
temp->value = value;

if ( (p = list_insert( &esd_root, temp, esd_compare, esd_data )) != NULL )
   {
   xerror( "esdins: Symbol already in ESD Table." );
   free( temp->name );
   free( temp );
   return 1;
   }

return 0; /* No errors */
}

/* Display the ESD Table */
void esddisp(void)
{
struct list *p;
struct esd *temp;

if ( esd_root == NULL )
   return;

printf( "\n" );
printf( "ESD Table\n" );
printf( "---------\n" );

for ( p = esd_root; p != NULL; p = list_next( p ) )
   {
   temp = list_data( p );
   printf( "%s %c %x\n", temp->name, temp->type, temp->value );
   }
}
