/* ---------------------- gettoken.c ----------- */ #define GET_H #include "gettoken.h" void skip_line() { int c; while( (c = getchar()) != '\n'); } /* lexikalische Analyse der Kommandozeile */ TOKEN gettoken(char *word) { int c; char * w; enum {NEUTRAL, TWO_GT, GTGT, INWORD, AMP, OR } state = NEUTRAL; w = word; while ((c = getchar()) != EOF) { switch (state) { case NEUTRAL: switch (c) { case '&': state = AMP; continue; case '|': state = OR; continue; case '<': return (T_LT); case '\n': ungetc(c,stdin); return (T_NL); case ' ': case '\t': continue; case '>': state = GTGT; continue; case '2': state = TWO_GT; continue; default: state = INWORD; * w++ = c; continue; } case AMP: if (c == '&') return (T_AND); skip_line(); return (T_AMP); case OR: if (c == '|') return (T_OR); ungetc(c,stdin); return (T_PIPE); case GTGT: if (c == '>') return (T_GTGT); ungetc(c,stdin); return (T_GT); case TWO_GT: if (c == '>') return (T_TWO_GT); *w++ = '2'; ungetc(c,stdin); state = INWORD; continue; case INWORD: switch (c) { case '&': case '|': case '<': case '>': case '\n': case ' ': case '\t': ungetc(c,stdin); * w = '\0'; return (T_WORD); default: * w++ =c; continue; } } } return (T_EOF); }