int LWP_GetResponseKey(int seconds, char *key) { int rc; if (key == NULL) return 0; /* need space to store char */ fflush(stdin); /* flush all existing data and start anew */ rc = LWP_WaitForKeystroke(seconds); if (rc == 0) { /* time ran out */ *key = 0; return rc; } /* now read the char. */ #ifdef AFS_NT40_ENV *key = getche(); /* get char and echo it to screen */ #else *key = (char)getchar(); #endif return rc; }
int LWP_GetLine(char *linebuf, int len) { int linelen; char *s; LWP_WaitForKeystroke(-1); s = fgets(linebuf, len, stdin); if (s == NULL) return -1; linelen = strlen(linebuf); if (linebuf[linelen - 1] != '\n') /* buffer too small */ return 0; else return linelen; }
int LWP_GetLine(char *linebuf, int len) { int cnt = 0; int ch = 0; fflush(stdin); /* loop until a new line has been entered */ while (ch != '\r' && cnt < len - 1) { LWP_WaitForKeystroke(-1); ch = getch(); if ((ch == EOF) && (cnt == 0)) return -1; if (ch == '\b') { /* print and throw away a backspace */ if (!cnt) /* if we are at the start of the line don't bspace */ continue; /* print a space to delete char and move cursor back */ printf("\b \b"); cnt--; } else { putchar(ch); linebuf[cnt++] = ch; } } if (ch == '\r') { /* got a cr. translate to nl */ linebuf[cnt - 1] = '\n'; linebuf[cnt] = '\0'; putchar('\n'); return cnt; } else { /* buffer too small */ linebuf[cnt] = '\0'; return 0; } }
void main(int ac, char **av) { int delay = 0; int iters = 0; int inter = 0; int line = 0; int i; PROCESS dotpid; int rc; for (i = 1; i < ac; i++) { if (!strcmp("-delay", av[i])) { if (++i >= ac) { printf("Missing delay time for -delay option.\n"); } delay = atoi(av[i]); if (delay < 0) { printf("Delay must be at least 0 seconds.\n"); Usage(); } } else if (!strcmp("-iters", av[i])) { if (++i >= ac) { printf("Missing iteration count for -iters option.\n"); } iters = atoi(av[i]); if (iters < 0) { printf("Number of iterations must be at least 0.\n"); Usage(); } } else if (!strcmp("-nobuf", av[i])) { rc = setvbuf(stdin, NULL, _IONBF, 0); if (rc < 0) { perror("Setting -nobuf for stdin"); } } else if (!strcmp("-inter", av[i])) { inter = 1; } else if (!strcmp("-line", av[i])) { line = 1; } else Usage(); } IOMGR_Initialize(); LWP_CreateProcess(DotWriter, 32000, LWP_NORMAL_PRIORITY, (char *)0, "DotWriter", &dotpid); if (inter) { interTest(); exit(1); } if (line) { lineTest(); exit(1); } if (delay == 0) { delay = -1; /* Means wait indefinitely. */ } for (; iters >= 0; iters--) { waitingForAnswer = 1; LWP_NoYieldSignal(&waitingForAnswer); rc = LWP_WaitForKeystroke(delay); waitingForAnswer = 0; if (rc) { printf("\n'%c'\n", getchar()); printf("Flushing remaining input.\n"); while (LWP_WaitForKeystroke(0)) { printf("'%c'\n", getchar()); } } else { printf("\nNo data available on this iteration.\n"); } } }