#include #include #include "getinput.h" #include "hash.h" #define MAXWORD 20 /* maximum word length */ int getdef(char *word, int lim) { int c; char *w = word; while (isspace(c=getch())) putchar(c); if (c != EOF) *w++ = c; if (!isalnum(c)) { *w = '\0'; if (c == '/') { /* comments */ if ((c = getch()) == '*') { while ((c = getch()) != EOF) { if (c == '*') if ((c = getch()) == '/') { strcpy(word, ""); return c; } } } else { ungetch(c); c = '/'; } } return c; } for ( ; --lim > 0; w++) if (!isalnum(*w = getch()) && *w != '_') { ungetch(*w); break; } *w = '\0'; return word[0]; } /* getdef() */ int main(void) { char word[MAXWORD]; char name[MAXWORD]; char defn[MAXWORD]; struct nlist *ent; int cond; while ((cond=getdef(word, MAXWORD)) != EOF) { if (cond == '#') { getdef(word, MAXWORD); if (strcmp(word, "define") == 0) { cond=getdef(word, MAXWORD); if (!isspace(cond)) { strcpy(name, word); cond=getdef(word, MAXWORD); if (!isspace(cond)) { strcpy(defn, word); install(name, defn); } } } } else if ((ent=lookup(word)) != NULL) { printf("%s", ent->defn); } else printf("%s", word); } return 0; }