/* ttyin process response from /dev/tty from kernighan and pike, page 185 */ #include int ttyin() { char buf[BUFSIZ]; FILE *efopen(); static FILE *tty = NULL; if (tty == NULL) tty = efopen("/dev/tty", "r"); for (;;) { if (fgets(buf, BUFSIZ, tty) == NULL || buf[0] == 'q') { exit(0); } else if (buf[0] == '!') { system(buf + 1); /* possible bug here */ printf("!\n"); } else /*ordinary line*/ { return buf[0]; } } }