aboutsummaryrefslogtreecommitdiff
path: root/vis.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2014-09-24 09:02:53 +0200
committerMarc André Tanner <mat@brain-dump.org>2014-09-24 09:02:53 +0200
commit0c581075c55fe3c7839fdc293282a9544280bfab (patch)
treeb5fe531adb1f63f4871202976bc966a34c7c7463 /vis.c
parentf26e811bb073297ac1ca753c2c3cb746af07b9bf (diff)
downloadvis-0c581075c55fe3c7839fdc293282a9544280bfab.tar.gz
vis-0c581075c55fe3c7839fdc293282a9544280bfab.tar.xz
Handle filenames with spaces
Before :w foo bar would create 2 files whereas now 1 file named "foo bar" will be created. Longterm such ambigious command arguments should be given surrounded with quotes.
Diffstat (limited to 'vis.c')
-rw-r--r--vis.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/vis.c b/vis.c
index d444377..a04b6f7 100644
--- a/vis.c
+++ b/vis.c
@@ -137,6 +137,9 @@ typedef struct { /* command definitions for the ':'-prom
bool (*cmd)(const char *argv[]); /* command logic called with a NULL terminated array
* of arguments. argv[0] will be the command name,
* as matched by the regex. */
+ bool args; /* whether argv should be populated with words
+ * separated by spaces. if false, argv[1] will
+ * contain the remaining command line unmodified */
regex_t regex; /* compiled form of the pattern in 'name' */
} Command;
@@ -1260,7 +1263,17 @@ static bool exec_command(char *cmdline) {
for (int i = 1; i < LENGTH(argv); i++) {
while (s && *s && *s == ' ')
s++;
+ if (s && !*s)
+ s = NULL;
argv[i] = s;
+ if (!cmd->args) {
+ /* remove trailing spaces */
+ if (s) {
+ while (*s) s++;
+ while (*(--s) == ' ') *s = '\0';
+ }
+ s = NULL;
+ }
if (s && (s = strchr(s, ' ')))
*s++ = '\0';
}