Guest User

Untitled

a guest
Jul 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. struct nlist { /* table entry: */
  2. struct nlist *next; /* next entry in chain */
  3. char *name; /* defined name */
  4. char *defn; /* replacement text */
  5. };
  6.  
  7. struct nlist *install(char *name, char *defn) {
  8. struct nlist *np;
  9. unsigned hashval;
  10. if ((np = lookup(name)) == NULL) { /* not found */
  11. np = (struct nlist *) malloc(sizeof(*np));
  12. if (np == NULL || (np->name = strdup(name)) == NULL)
  13. return NULL;
  14. hashval = hash(name);
  15. np->next = hashtab[hashval];
  16. hashtab[hashval] = np;
  17. } else /* already there */
  18. free((void *) np->defn); /*free previous defn */
  19. if ((np->defn = strdup(defn)) == NULL)
  20. return NULL;
  21. return np;
  22. }
  23.  
  24. np->next = hashtab[hashval];
  25. hashtab[hashval] = np;
  26.  
  27. hashtab[hashval] --> original_list
  28.  
  29. hashtab[hashval] --> original_list
  30. np->next --> original_list
  31.  
  32. hashtab[hashval] --> *np
  33. np->next --> original_list
Add Comment
Please, Sign In to add comment