ide_sym.c
1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* 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;
}
}
}