diff options
author | Curtis McEnroe | 2018-08-20 18:41:23 -0400 |
---|---|---|
committer | Curtis McEnroe | 2018-08-20 18:43:16 -0400 |
commit | 4e4eb0de0f50517e3a2892cddcadfbd75da7152f (patch) | |
tree | cebf2ed9f1cc63b5714e2c9357f8b9ff27f10afc /edit.c | |
parent | afae851319c543118f08b49b1fa804ef31e34267 (diff) |
Add wcsnchr, wcsnrchr, awcsntombs
This eliminates calls to editHead and editTail inside edit.c. Oh god I'm sorry for following libc naming conventions for this stuff.
Diffstat (limited to 'edit.c')
-rw-r--r-- | edit.c | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/edit.c b/edit.c index 8db92fc..782f449 100644 --- a/edit.c +++ b/edit.c @@ -57,15 +57,12 @@ static void right(void) { static void backWord(void) { left(); - editHead(); - wchar_t *word = wcsrchr(line.buf, ' '); - editTail(); + wchar_t *word = wcsnrchr(line.buf, line.ptr - line.buf, L' '); line.ptr = (word ? &word[1] : line.buf); } static void foreWord(void) { right(); - editTail(); - wchar_t *word = wcschr(line.ptr, ' '); + wchar_t *word = wcsnchr(line.ptr, line.end - line.ptr, L' '); line.ptr = (word ? word : line.end); } @@ -108,12 +105,10 @@ static void killForeWord(void) { static char *prefix; static void complete(struct Tag tag) { if (!line.tab) { - editHead(); - line.tab = wcsrchr(line.buf, L' '); + line.tab = wcsnrchr(line.buf, line.ptr - line.buf, L' '); line.tab = (line.tab ? &line.tab[1] : line.buf); - prefix = awcstombs(line.tab); + prefix = awcsntombs(line.tab, line.ptr - line.tab); if (!prefix) err(EX_DATAERR, "awcstombs"); - editTail(); } const char *next = tabNext(tag, prefix); @@ -161,7 +156,7 @@ static void reject(void) { static void enter(struct Tag tag) { if (line.end == line.buf) return; - editTail(); + *line.end = L'\0'; char *str = awcstombs(line.buf); if (!str) err(EX_DATAERR, "awcstombs"); input(tag, str); |