vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit d99c8253d89bc89e1ad75d39d3c4a3fb2a41d9d3
parent 5670f8fbbabc29cfcd2dbadd5bb196eded3041b6
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Tue, 19 Jan 2016 13:30:00 +0100

vis: improve :-command argument tokenizing

Should now handle trailing white spaces.

Diffstat:
Mvis-cmds.c | 14+++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/vis-cmds.c b/vis-cmds.c @@ -1113,7 +1113,11 @@ bool vis_cmd(Vis *vis, const char *cmdline) { char *line = malloc(len+2); if (!line) return false; - line = strncpy(line, cmdline, len+1); + strncpy(line, cmdline, len+1); + + for (char *end = line + len - 1; end >= line && isspace((unsigned char)*end); end--) + *end = '\0'; + char *name = line; Filerange range = parse_range(vis->win, &name); @@ -1173,8 +1177,12 @@ bool vis_cmd(Vis *vis, const char *cmdline) { } s = NULL; } - if (s && (s = strchr(s, ' '))) - *s++ = '\0'; + if (s) { + while (*s && !isspace((unsigned char)*s)) + s++; + if (*s) + *s++ = '\0'; + } /* strip out a single '!' argument to make ":q !" work */ if (argv[i] && !strcmp(argv[i], "!")) { opt |= CMD_OPT_FORCE;