From dc611e17c14040fa0530ed28c33919c1aa4a270e Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 28 Jan 2022 19:30:50 -0800 Subject: repl: bug handling comments in plain mode. The is_balanced_line function assumes that comments are terminated by a carriage return, whic his the multi-line convention used by the interactive repl. The plain-mode listener, though, only replaces newlines by carriage returns when returning the complete multi-line input. When invoking the is_balanced_line callback, the newlines are still there, and so comments are not handled properly. Reported by Paul. A. Patience. * linenoise/linenoise.c (linenoise): In plain mode, replace the trailing newline with a carriage return after every physical line input, before that line is passed to the lino->enter_callback (i.e. is_balanced_line). The code to replace newlines with carriage returns at the end is consequently no longer required. --- linenoise/linenoise.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index e8686066..ddb25b0f 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -2581,7 +2581,7 @@ wchar_t *linenoise(lino_t *ls, const wchar_t *prompt) if (plain) { wchar_t *ret = 0; - size_t len = 0, i; + size_t len = 0; const wchar_t *condensed_prompt = prompt + wcslen(prompt); int show_prompt = ls->show_prompt || (noninteractive && isatty(ifd)); @@ -2616,6 +2616,9 @@ wchar_t *linenoise(lino_t *ls, const wchar_t *prompt) wmemcpy(nret + len, ls->data, nlen + 1); ret = nret; len = len + nlen; + + if (len && ret[len-1] == '\n') + ret[len-1] = '\r'; } if (!ls->enter_callback || ls->enter_callback(ret, ls->ce_ctx)) @@ -2625,11 +2628,6 @@ wchar_t *linenoise(lino_t *ls, const wchar_t *prompt) if (ret != 0) { if (len && ret[len - 1] == '\n') ret[len-1] = '\0'; - - for (i = 0; i < len; i++) { - if (ret[i] == '\n') - ret[i] = '\r'; - } } return ret; -- cgit v1.2.3