#include #include #include #include #include "word.h" #include "hash.h" #include "getch.h" #include "def.h" #define MAXWORD 100 static void error(char c, char *s); void skipblanks(void); int endline(char *s, int lim); void getdef(struct nlist *hashtab[], uint32_t hashsize) { char dir[MAXWORD], name[MAXWORD], def[MAXWORD]; skipblanks(); if (!isalpha(getword(dir, MAXWORD))) { error(dir[0], "getdef: expecting a directive after #"); } else if (!strcmp(dir, "define")) { skipblanks(); if (!isalpha(getword(name, MAXWORD))) { error(name[0], "getdef: non-alpha in undef"); } else { if(endline(def, MAXWORD) == MAXWORD) error(def[0], "getdef: incomplete define"); else install(hashtab, hashsize, name, def); } } else if (!strcmp(dir, "undef")) { skipblanks(); if (isalpha(getword(name, MAXWORD))) undef(hashtab, hashsize, name); else error(name[0], "getdef: non-alpha in undef"); } else { error(dir[0], "getdef: directive invalid or not implemented"); } } static void error(char c, char *s) { printf("err: %s\n", s); while (c != EOF && c != '\n') c = getch(); } void skipblanks(void) { char c; while (isblank(c = getch())) ; ungetch(c); } int endline(char *s, int lim) { int i; skipblanks(); for (i = 0; i < lim - 1; ++i) if ((s[i] = getch()) == EOF || s[i] == '\n') break; s[i] = '\0'; return lim - i; }