/* * input: text input routines */ #include #include "tsh.h" static char *prompt; static unsigned char line[200]; #define LINE (line+1) static int ptr, size; snatchline(str) char *str; { if (isatty(fileno(stdin))) { if (egetline(">", str) == EOF) return EOF; strcat(str, "\n"); } else if (!fgets(str, 200, stdin)) return EOF; return 1; } input() { if (ptr >= size) { if (isatty(fileno(stdin))) { if (egetline(prompt, LINE) == EOF) return EOF; strcat(LINE, "\n"); prompt = ">"; } else if (!fgets(LINE, 200, stdin)) return EOF; size = strlen(LINE); ptr = 0; } return LINE[ptr++]; } unput(c) { LINE[--ptr] = c; } eos() { return (ptr >= size); } eof() { return feof(stdin); } flushline() { ptr = size; } reset(pmpt) char *pmpt; { prompt = pmpt; memset(line, 0, 200); ptr = size = 0; }