From 295e0813ce2c31aebd3ac4f71e46305acd85d61c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Diego=20Aur=C3=A9lio=20Mesquita?= Date: Wed, 23 May 2018 22:18:06 -0300 Subject: [PATCH] Allow double quotes to be used when defining text binding on .nanorc. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marco Diego Aurélio Mesquita --- src/rcfile.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/rcfile.c b/src/rcfile.c index 2e7c2ab..aaba523 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -344,6 +344,26 @@ bool is_universal(void (*func)(void)) func == do_tab || func == do_enter || func == do_verbatim_input); } +/* Normalizes a string by replacing \" by " and \\ by \ . */ +char *normalize(char *string) +{ + size_t len = strlen(string); + char *ret = (char*)malloc(len); + int d_pos, s_pos; + + for (d_pos = 0, s_pos = 0; s_pos < len; s_pos++) { + if (string[s_pos] == '\\' && + (string[s_pos + 1] == '\\' || string[s_pos + 1] == '"')) { + s_pos++; + } + + ret[d_pos++] = string[s_pos]; + } + + ret[d_pos] = '\0'; + return ret; +} + /* Bind or unbind a key combo, to or from a function. */ void parse_binding(char *ptr, bool dobind) { @@ -418,7 +438,7 @@ void parse_binding(char *ptr, bool dobind) if (*funcptr == '"') { newsc = nmalloc(sizeof(sc)); newsc->func = (functionptrtype)implant; - newsc->expansion = mallocstrcpy(NULL, funcptr + 1); + newsc->expansion = normalize(funcptr + 1); #ifndef NANO_TINY newsc->toggle = 0; #endif -- 2.7.4