#include #include #include "getch.h" #include "word.h" char scomment(void); int getword(char *word, int lim) { char *w = word; while (isblank(*w = getch()) || *w == '"' || *w == '/') { if (*w == '"') { while ((*w = getch()) != '"' && *w != EOF) ; if (*w == EOF) ungetch(*w); } else if (*w == '/' && !scomment()) { break; } } if (isalpha(*w)) { while ((isalnum(*w) || *w == '_') && --lim > 0) *++w = getch(); ungetch(*w--); } else if (*w == '#') { --lim; do { *++w = getch(); } while (isalpha(*w) && --lim > 0); ungetch(*w--); } *++w = '\0'; return word[0]; } char scomment(void) { char c; switch (c = getch()) { case '/' : while ((c = getch()) != EOF && c != '\n') ; if (c == EOF) ungetch(c); return '/'; case '*' : while ((c = getch()) != EOF && !(c == '*' && (c = getch()) == '/')) if (c == '*') ungetch(c); if (c == EOF) ungetch(c); return '*'; default: ungetch(c); return 0; } }