diff options
author | hoek <hoek@FreeBSD.org> | 1999-12-26 03:03:04 +0000 |
---|---|---|
committer | hoek <hoek@FreeBSD.org> | 1999-12-26 03:03:04 +0000 |
commit | 131789d30dfc5c184457f6ca4f3a9dbcf645e743 (patch) | |
tree | 3556bb1606d6fad278ea6c4f620407d4ccdae931 /usr.bin | |
parent | 0bf78e4bac60a0b4869939a26f56d6ce791d1c53 (diff) | |
download | FreeBSD-src-131789d30dfc5c184457f6ca4f3a9dbcf645e743.zip FreeBSD-src-131789d30dfc5c184457f6ca4f3a9dbcf645e743.tar.gz |
Allow excessive backspacing to correctly abort an input (most significantly
a search string input).
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/more/command.c | 10 | ||||
-rw-r--r-- | usr.bin/more/ncommand.c | 24 |
2 files changed, 22 insertions, 12 deletions
diff --git a/usr.bin/more/command.c b/usr.bin/more/command.c index 92b860a..1e7c988 100644 --- a/usr.bin/more/command.c +++ b/usr.bin/more/command.c @@ -99,8 +99,10 @@ biggetinputhack() /* * Read a line of input from the terminal. Reads at most bufsiz - 1 characters * and places them in buffer buf. They are NUL-terminated. Prints the - * temporary prompt prompt. + * temporary prompt prompt. Returns true if the user aborted the input and + * returns false otherwise. */ +int getinput(prompt, buf, bufsiz) const char *prompt; char *buf; @@ -117,18 +119,18 @@ getinput(prompt, buf, bufsiz) c = getcc(); if (c == '\n') { *bufcur = '\0'; - return; + return 0; } if (c == READ_INTR || cmd_char(c, buf, &bufcur, buf + bufsiz - 1)) { /* input cancelled */ if (bufsiz) *buf = '\0'; - return; + return 1; } if (biggetinputhack_f) { biggetinputhack_f = 0; *bufcur = '\0'; - return; + return 0; } } } diff --git a/usr.bin/more/ncommand.c b/usr.bin/more/ncommand.c index 13c22f6..9a84d89 100644 --- a/usr.bin/more/ncommand.c +++ b/usr.bin/more/ncommand.c @@ -916,7 +916,8 @@ cusercom(cident, args) char buf[125]; /* XXX should avoid static buffer... */ ENDPARSE; - getinput("Command: ", buf, sizeof(buf)); + if (getinput("Command: ", buf, sizeof(buf))) + return args; /* abort the command */ if (command(buf)) return NULL; @@ -1192,7 +1193,10 @@ caskfile(cident, args) char buf[MAXPATHLEN + 1]; ENDPARSE; - getinput("Examine: ", buf, sizeof(buf)); + if (getinput("Examine: ", buf, sizeof(buf))) + return args; /* abort */ + /* Abort is different from a "" answer in that "" causes the current + * file to be re-opened. */ /* XXX should modify this() or edit() to handle lists of file, ie. * the type of lists that I get if I try to glob("*") */ (void)edit(glob(buf)); @@ -1297,6 +1301,7 @@ csearch(cident, args) enum { FORW=0, BACK=1 } direction; static enum { NOINVERT=0, INVERT=1 } sense; long N; + int abrt; ARGTOG(direction, 6, "forw", "back", "forward", "backward", "forwards", "backwards"); @@ -1313,25 +1318,25 @@ csearch(cident, args) case MAGICASKSEARCH: biggetinputhack(); /* It's magic, boys */ if (direction == FORW) - getinput("Search: /", buf, 2); + abrt = getinput("Search: /", buf, 2); else - getinput("Search: ?", buf, 2); + abrt = getinput("Search: ?", buf, 2); switch (*buf) { case '!': /* Magic */ if (direction == FORW) - getinput("Search: !/", buf, sizeof(buf)); + abrt = getinput("Search: !/", buf, sizeof(buf)); else - getinput("Search: !?", buf, sizeof(buf)); + abrt = getinput("Search: !?", buf, sizeof(buf)); sense = INVERT; break; default: /* No magic */ ungetcc(*buf); if (direction == FORW) - getinput("Search: /", buf, sizeof(buf)); + abrt = getinput("Search: /", buf, sizeof(buf)); else - getinput("Search: ?", buf, sizeof(buf)); + abrt = getinput("Search: ?", buf, sizeof(buf)); case '\0': sense = NOINVERT; break; @@ -1345,6 +1350,9 @@ csearch(cident, args) break; } + if (abrt) + return args; + if (cident == SEARCH || cident == MAGICASKSEARCH) { settog("_ls_direction", direction, 2, "forw", "back"); settog("_ls_sense", sense, 2, "noinvert", "invert"); |