tex: backslash as escape character in file names - neatvi - [fork] simple vi-ty… | |
git clone git://src.adamsgaard.dk/neatvi | |
Log | |
Files | |
Refs | |
README | |
--- | |
commit cfcaaf89225f9e1f28dffa447668a4b2437f4586 | |
parent 3a4ce478980b560dd436c5fd93e867b1adb35c6a | |
Author: Ali Gholami Rudi <[email protected]> | |
Date: Wed, 4 Nov 2015 22:53:44 +0330 | |
ex: backslash as escape character in file names | |
Reported by yoelion at github. | |
Diffstat: | |
M ex.c | 16 ++++++++++++++-- | |
1 file changed, 14 insertions(+), 2 deletions(-) | |
--- | |
diff --git a/ex.c b/ex.c | |
t@@ -154,8 +154,11 @@ static char *ex_arg(char *s, char *arg) | |
s = ex_cmd(s, arg); | |
while (isspace((unsigned char) *s)) | |
s++; | |
- while (*s && !isspace((unsigned char) *s)) | |
+ while (*s && !isspace((unsigned char) *s)) { | |
+ if (*s == '\\' && s[1]) | |
+ s++; | |
*arg++ = *s++; | |
+ } | |
*arg = '\0'; | |
return s; | |
} | |
t@@ -852,7 +855,16 @@ void ex(void) | |
int ex_init(char **files) | |
{ | |
char cmd[EXLEN]; | |
- snprintf(cmd, sizeof(cmd), "e %s", files[0] ? files[0] : ""); | |
+ char *s = cmd; | |
+ char *r = files[0] ? files[0] : ""; | |
+ *s++ = 'e'; | |
+ *s++ = ' '; | |
+ while (*r && s + 2 < cmd + sizeof(cmd)) { | |
+ if (*r == ' ') | |
+ *s++ = '\\'; | |
+ *s++ = *r++; | |
+ } | |
+ *s = '\0'; | |
if (ec_edit(cmd)) | |
return 1; | |
if (getenv("EXINIT")) |