Category : C Source Code
Archive   : TBISON0.ZIP
Filename : SYMTAB.C

 
Output of file : SYMTAB.C contained in archive : TBISON0.ZIP
/* symtab.c Symbol table manager for Bison,
copyright (C) 1984 Bob Corbett and Richard Stallman */


#include
#include
#include "new.h"
#include "symtab.h"
#include "gram.h"


/* 3 calls to temp_allocate */
/* 1 call to free */
/* 1 call to temp_free */


bucket **symtab;
bucket *firstsymbol;
bucket *lastsymbol;



int
hash(key)
char *key;
{
register char *cp;
register int k;

cp = key;
k = 0;
while (*cp)
k = ((k << 1) ^ (*cp++)) & 0x3fff;

return (k % TABSIZE);
}



char *
copys(s)
char *s;
{
register int i;
register char *cp;
register char *result;

i = 1;
for (cp = s; *cp; cp++)
i++;

/* 1st application of allocate */
#ifdef ALLOC_TRACE
fprintf(stderr,"symtab 1 ");
#endif
result = str_allocate(i);
strcpy(result, s);
return (result);
}



tabinit()
{
register int i;

/* 2nd call to allocate via NEW2 */
#ifdef ALLOC_TRACE
fprintf(stderr,"symtab 2 ");
#endif
symtab = TEMPNEW2(TABSIZE, bucket *);

firstsymbol = NULL;
lastsymbol = NULL;
}




bucket *getsym(key)
char *key;
{
register int hashval;
register bucket *bp;
register int found;

#ifdef TRACE
fprintf(stderr," key = %s\n",key);*/
#endif

hashval = hash(key);
bp = symtab[hashval];

found = 0;
while (bp != NULL && found == 0)
{
if (strcmp(key, bp->tag) == 0)
found = 1;
else
bp = bp->link;
}

if (found == 0)
{
nsyms++;

/* 3rd call to allocate via NEW */
#ifdef ALLOC_TRACE
fprintf(stderr,"symtab 3 ");
#endif
bp = TEMPNEW(bucket);
bp->link = symtab[hashval];
bp->next = NULL;
bp->tag = copys(key);
bp->class = SUNKNOWN;

if (firstsymbol == NULL)
{
firstsymbol = bp;
lastsymbol = bp;
}
else
{
lastsymbol->next = bp;
lastsymbol = bp;
}

symtab[hashval] = bp;
}

return (bp);
}



free_symtab()
{
register int i;
register bucket *bp;

#ifdef SMALL_MODEL
for (i = 0; i < TABSIZE; i++)
{
bp = symtab[i];
while (bp)
{
/* only call to free */
#ifdef ALLOC_TRACE
fprintf(stderr,"FREE symtab ");
#endif
FREE(bp);
bp = bp->link;
}
}
#else
#ifdef ALLOC_TRACE
fprintf(stderr,"FREE 1 - 3 ");
#endif
TEMPFREE(symtab);
#endif
}


  3 Responses to “Category : C Source Code
Archive   : TBISON0.ZIP
Filename : SYMTAB.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/