From 0c581075c55fe3c7839fdc293282a9544280bfab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Wed, 24 Sep 2014 09:02:53 +0200 Subject: 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. --- config.def.h | 28 ++++++++++++++-------------- vis.c | 13 +++++++++++++ 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/config.def.h b/config.def.h index 097dfb5..993f2a0 100644 --- a/config.def.h +++ b/config.def.h @@ -47,20 +47,20 @@ enum { /* command recognized at the ':'-prompt. tested top to bottom, first match wins. */ static Command cmds[] = { - { "^[0-9]+$", cmd_gotoline }, - { "^e(dit)?!?$", cmd_edit }, - { "^o(pen)?$", cmd_open }, - { "^qa(ll)?!?$", cmd_qall }, - { "^q(quit)?!?$", cmd_quit }, - { "^r(ead)?$", cmd_read }, - { "^sav(as)?$", cmd_saveas }, - { "^set$", cmd_set }, - { "^sp(lit)?$", cmd_split }, - { "^s(ubstitute)?$", cmd_substitute }, - { "^v(split)?$", cmd_vsplit }, - { "^wq!?$", cmd_wq }, - { "^w(rite)?$", cmd_write }, - { /* array terminator */ }, + { "^[0-9]+$", cmd_gotoline, false }, + { "^e(dit)?!?$", cmd_edit, false }, + { "^o(pen)?$", cmd_open, false }, + { "^qa(ll)?!?$", cmd_qall, false }, + { "^q(quit)?!?$", cmd_quit, false }, + { "^r(ead)?$", cmd_read, false }, + { "^sav(as)?$", cmd_saveas, false }, + { "^set$", cmd_set, true }, + { "^sp(lit)?$", cmd_split, false }, + { "^s(ubstitute)?$", cmd_substitute, false }, + { "^v(split)?$", cmd_vsplit, false }, + { "^wq!?$", cmd_wq, false }, + { "^w(rite)?$", cmd_write, false }, + { /* array terminator */ }, }; /* draw a statubar, do whatever you want with win->statuswin curses window */ 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'; } -- cgit v1.2.3