/********************************************
copyright 1991, Michael D. Brennan
This is a source file for mawk, an implementation of
the AWK programming language.
Mawk is distributed without warranty under the terms of
the GNU General Public License, version 2, 1991.
********************************************/
* Revision 5.1 91/12/05 07:56:05 brennan
{ register unsigned h
= 0 ;
while ( *s
) h
+= h
+ *s
++ ;
static HASHNODE
*PROTO( delete, (char *) ) ;
#define new_HASHNODE() (HASHNODE *) zmalloc(sizeof(HASHNODE))
static HASHNODE
*hash_table
[HASH_PRIME
] ;
* insert -- s is not there and need not be duplicated
* -- used during initialization
{ register HASHNODE
*p
= new_HASHNODE();
p
->link
= hash_table
[h
= hash(s
) % HASH_PRIME
] ;
* find -- s might be there, find it else insert and dup
p
= hash_table
[h
= hash(s
) % HASH_PRIME
] ;
p
->symtab
.type
= ST_NONE
;
p
->symtab
.name
= strcpy(zmalloc( strlen(s
)+1 ), s
) ;
if ( strcmp(p
->symtab
.name
, s
) == 0 ) /* found */
if ( !q
) /* already at the front */
else /* delete from the list */
{ q
->link
= p
->link
; break ; }
/* put p on front of the list */
p
->link
= hash_table
[h
] ;
/* remove a node from the hash table
return a ptr to the node */
static unsigned last_hash
;
static HASHNODE
*delete( s
)
HASHNODE
*q
= (HASHNODE
*) 0 ;
p
= hash_table
[ last_hash
= h
= hash(s
) % HASH_PRIME
] ;
if ( strcmp(p
->symtab
.name
, s
) == 0 ) /* found */
if ( q
) q
->link
= p
->link
;
else hash_table
[h
] = p
->link
;
else { q
= p
; p
= p
->link
; }
#ifdef DEBUG /* we should not ever get here */
/* when processing user functions, global ids which are
replaced by local ids are saved on this list */
static HASHNODE
*save_list
;
/* store a global id on the save list,
return a ptr to the local symtab */
q
->symtab
.type
= ST_LOCAL_NONE
;
q
->symtab
.name
= p
->symtab
.name
;
/* put q in the hash table */
q
->link
= hash_table
[ h
= last_hash
] ;
p
->link
= save_list
; save_list
= p
;
/* restore all global indentifiers */
{ register HASHNODE
*p
, *q
;
q
= save_list
; save_list
= (HASHNODE
*) 0 ;
zfree( delete(p
->symtab
.name
) , sizeof(HASHNODE
) ) ;
p
->link
= hash_table
[h
= last_hash
] ;
/* search the symbol table backwards for the
disassembler. This is slow -- so what
char *reverse_find( type
, ptr
)
static char uk
[] = "unknown" ;
for(i
= 0 ; i
< HASH_PRIME
; i
++)
if ( p
->symtab
.type
== type
)
if ( cp
== p
->symtab
.stval
.cp
)
if ( array
== p
->symtab
.stval
.array
)