diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-01-19 13:30:00 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-01-19 13:30:00 +0100 |
| commit | e745b5ef655c38c0501d9d5ea1e2fd869ce4f355 (patch) | |
| tree | 3ca4db8993b6c32144ada0bdb568f017230afaca | |
| parent | 4d60f5acb94b555a0f81e4e9a8e358d3bc3898fe (diff) | |
| download | vis-e745b5ef655c38c0501d9d5ea1e2fd869ce4f355.tar.gz vis-e745b5ef655c38c0501d9d5ea1e2fd869ce4f355.tar.xz | |
vis: improve :-command argument tokenizing
Should now handle trailing white spaces.
| -rw-r--r-- | vis-cmds.c | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -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; |
