vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 9176e80aeb264979382dfaa0887ed2e86a06ddd0 parent 84004298da631b42e8603d46f8a0561e09f63396 Author: Marc André Tanner <mat@brain-dump.org> Date: Tue, 15 Sep 2015 09:37:56 +0200 vis: convert insert verbatim to new input handling code Diffstat:
| M | vis.c | | | 37 | +++++++++++++++++++------------------ |
1 file changed, 19 insertions(+), 18 deletions(-)
diff --git a/vis.c b/vis.c @@ -1249,13 +1249,12 @@ static const char *prompt_backspace(const char *keys, const Arg *arg) { } static const char *insert_verbatim(const char *keys, const Arg *arg) { - int len = 0, count = 0, base; Rune rune = 0; - const char *key = getkey(); - if (!key) - return keys; - char buf[4], type = key[0]; + char buf[4], type = keys[0]; + int len = 0, count = 0, base; switch (type) { + case '\0': + return NULL; case 'o': case 'O': count = 3; @@ -1282,24 +1281,26 @@ static const char *insert_verbatim(const char *keys, const Arg *arg) { break; } - while (count-- > 0) { - key = getkey(); + for (keys++; keys[0] && count > 0; keys++, count--) { int v = 0; - if (!key) - break; - else if (base == 8 && '0' <= key[0] && key[0] <= '7') - v = key[0] - '0'; - else if ((base == 10 || base == 16) && '0' <= key[0] && key[0] <= '9') - v = key[0] - '0'; - else if (base == 16 && 'a' <= key[0] && key[0] <= 'f') - v = 10 + key[0] - 'a'; - else if (base == 16 && 'A' <= key[0] && key[0] <= 'F') - v = 10 + key[0] - 'A'; - else + if (base == 8 && '0' <= keys[0] && keys[0] <= '7') { + v = keys[0] - '0'; + } else if ((base == 10 || base == 16) && '0' <= keys[0] && keys[0] <= '9') { + v = keys[0] - '0'; + } else if (base == 16 && 'a' <= keys[0] && keys[0] <= 'f') { + v = 10 + keys[0] - 'a'; + } else if (base == 16 && 'A' <= keys[0] && keys[0] <= 'F') { + v = 10 + keys[0] - 'A'; + } else { + count = 0; break; + } rune = rune * base + v; } + if (count > 0) + return NULL; + if (type == 'u' || type == 'U') { len = runetochar(buf, &rune); } else {