From ad8388547d0b6d0c8cea7403723b1eaca58e18b6 Mon Sep 17 00:00:00 2001 From: Derrick Brashear Date: Thu, 19 Jul 2001 22:51:46 +0000 Subject: [PATCH] lwp-waitkey-lacks-return-for-eof-and-hence-backup-is-unhappy-20010719 just tell the caller if we got an eof and move on with life --- src/bucoord/main.c | 8 ++++++-- src/lwp/waitkey.c | 11 ++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/bucoord/main.c b/src/bucoord/main.c index 371e630b1..cbbae606a 100644 --- a/src/bucoord/main.c +++ b/src/bucoord/main.c @@ -688,13 +688,17 @@ main(argc, argv) /* Iterate on command lines, interpreting user commands (interactive mode) */ while(1) { + int ret; + printf("backup> "); fflush(stdout); - while (LWP_GetLine(lineBuffer, sizeof(lineBuffer)) == 0) + while ((ret = LWP_GetLine(lineBuffer, sizeof(lineBuffer))) == 0) printf("%s: Command line too long\n", whoami); /* line too long */ - + + if (ret == -1) return 0; /* Got EOF */ + if ( !LineIsBlank(lineBuffer) ) { code = cmd_ParseLine(lineBuffer, targv, &targc, MAXV); diff --git a/src/lwp/waitkey.c b/src/lwp/waitkey.c index a6e1bbde7..764ec962c 100644 --- a/src/lwp/waitkey.c +++ b/src/lwp/waitkey.c @@ -98,6 +98,7 @@ int LWP_WaitForKeystroke(int seconds) * Return Value: * n - a whole line has been read.(has n chars) * 0 - buf not big enough. + * -1 - line with only EOF */ int LWP_GetLine(char *linebuf, int len) @@ -111,6 +112,10 @@ int LWP_GetLine(char *linebuf, int len) { 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; @@ -195,15 +200,19 @@ int LWP_WaitForKeystroke(int seconds) * Return Value: * n - a whole line has been read.(has n chars) * 0 - buf not big enough. + * -1 - line with only EOF */ int LWP_GetLine(char *linebuf, int len) { int linelen; + char *s; LWP_WaitForKeystroke(-1); - fgets(linebuf, len, stdin); + s = fgets(linebuf, len, stdin); + if (s == NULL) return -1; + linelen = strlen(linebuf); if (linebuf[linelen-1] != '\n') /* buffer too small */ return 0; -- 2.39.5