ide_sym.c 1.27 KB
/*
 * ide_sym - Symbol table manager for ide
 *
 * This is a simple hashed symbol table.
 *
 */

#include "ide.h"

sym_t *symhash[HASHSIZE];

unsigned
makehash(s)
char *s;
{
	unsigned int h = 0;

	while ( *s )
		h = (h << 1) + *s++;
	
	return h % HASHSIZE;
}

sym_t *
findsym(s)
char *s;
{
	sym_t *psym;

	for ( psym = symhash[makehash(s)]; psym; psym = psym->sym_hlink )
		if ( *psym->sym_name == *s && !strcmp( psym->sym_name, s))
			return psym;
	
	return 0;
}

addsym(psym)
sym_t *psym;
{
	int h = makehash(psym->sym_name);

	psym->sym_hlink = symhash[h];
	symhash[h] = psym;

	psym->sym_flags |= SYM_INTABLE;

	return 0;
}
/*ARGSUSED*/
_dodumpsym(argc,argv)
{
	int i;
	sym_t *psym;

	for ( i = 0; i < HASHSIZE; i++ )
		for ( psym = symhash[i]; psym; psym = psym->sym_hlink ) {
			printf( "%s: ", psym->sym_name );
			switch( psym->sym_type ) {
				case SYM_VAR:
					if ( psym->sym_basetype == SYM_INT )
					      printf("\t%d\n", psym->sym_i);
					else
					if ( psym->sym_basetype == SYM_STR )
					      printf("\t\"%s\"\n",psym->sym_s);
					break;
				case SYM_CMD:
					if ( psym->sym_flags & SYM_UDEF )
					      printf("user defined command\n");
					else
					      printf("built in command\n");
					break;
				default:
					printf("type %d\n",psym->sym_type);
					break;
				}
			}
}