Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct nlist { /* table entry: */
- struct nlist *next; /* next entry in chain */
- char *name; /* defined name */
- char *defn; /* replacement text */
- };
- struct nlist *install(char *name, char *defn) {
- struct nlist *np;
- unsigned hashval;
- if ((np = lookup(name)) == NULL) { /* not found */
- np = (struct nlist *) malloc(sizeof(*np));
- if (np == NULL || (np->name = strdup(name)) == NULL)
- return NULL;
- hashval = hash(name);
- np->next = hashtab[hashval];
- hashtab[hashval] = np;
- } else /* already there */
- free((void *) np->defn); /*free previous defn */
- if ((np->defn = strdup(defn)) == NULL)
- return NULL;
- return np;
- }
- np->next = hashtab[hashval];
- hashtab[hashval] = np;
- hashtab[hashval] --> original_list
- hashtab[hashval] --> original_list
- np->next --> original_list
- hashtab[hashval] --> *np
- np->next --> original_list
Add Comment
Please, Sign In to add comment