home *** CD-ROM | disk | FTP | other *** search
- /*
- * LOOKUP.C
- *
- * Purpose: demonstrates calling NDP C function
- * from NDP Pascal program
- * Copyright (C) MicroWay, Inc 1989
- *
- */
-
- #include <stdio.h>
- #include <string.h>
-
- #define STSIZE 200
- #define NAMESIZE 30
- #define NOTKNOWN 0
-
- typedef struct SYMBOL {
- char name [NAMESIZE];
- int symtype;
- struct SYMBOL *nextsym;
- };
-
- extern struct SYMBOL *symtable[];
-
- struct SYMBOL *lookup (identifier)
- char *identifier;
-
- {
- struct SYMBOL *p;
- int hashval;
- register char *pi; /* pointer to identifier */
-
- pi = identifier; /* into register for speed */
-
- hashval = 0;
- while (*pi) /* sum all chars in string */
- hashval += *pi++;
-
- /* index is sum modulo size of array */
- p = symtable [hashval % STSIZE];
-
- while (p != NULL) {
- if (strcmp (p->name,identifier) == 0)
- return (p);
- else
- p = p->nextsym;
- }
- return (NULL);
-
- } /* end of lookup */
-
-
- struct SYMBOL *install(identifier)
- char *identifier;
-
- {
- struct SYMBOL *p;
- int hashval;
- register char *pi; /* pointer to identifier */
-
- pi = identifier; /* into register for speed */
-
- hashval = 0;
- while (*pi) /* sum all chars in string */
- hashval += *pi++;
- hashval %= STSIZE; /* index is sum modulo size of array */
-
- p = (struct SYMBOL *) malloc (sizeof (struct SYMBOL));
- strcpy (p->name, identifier);
-
- p->symtype = NOTKNOWN; /* at first, type is not known */
-
- /* insert new symbol table entry at head of linked list */
- p->nextsym = symtable [hashval];
- symtable [hashval] = p;
-
- return (p);
-
- } /* end of install */
-