aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-01-19 13:30:00 +0100
committerMarc André Tanner <mat@brain-dump.org>2016-01-19 13:30:00 +0100
commite745b5ef655c38c0501d9d5ea1e2fd869ce4f355 (patch)
tree3ca4db8993b6c32144ada0bdb568f017230afaca
parent4d60f5acb94b555a0f81e4e9a8e358d3bc3898fe (diff)
downloadvis-e745b5ef655c38c0501d9d5ea1e2fd869ce4f355.tar.gz
vis-e745b5ef655c38c0501d9d5ea1e2fd869ce4f355.tar.xz
vis: improve :-command argument tokenizing
Should now handle trailing white spaces.
-rw-r--r--vis-cmds.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/vis-cmds.c b/vis-cmds.c
index 22c81ce..03d3c87 100644
--- 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;