From 1c2fad53308a2b3c43a6b6039be4b559ebcd6d3c Mon Sep 17 00:00:00 2001 From: devsaurus Date: Sun, 22 Nov 2015 13:00:40 +0100 Subject: [PATCH] re-add detection of CR as newline --- app/lua/lua.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/lua/lua.c b/app/lua/lua.c index 6de0c00d..c66f35ee 100644 --- a/app/lua/lua.c +++ b/app/lua/lua.c @@ -541,6 +541,7 @@ extern bool uart0_echo; extern bool run_input; extern uint16_t need_len; extern int16_t end_char; +static char last_nl_char = '\0'; static bool readline(lua_Load *load){ // NODE_DBG("readline() is called.\n"); bool need_dojob = false; @@ -549,11 +550,18 @@ static bool readline(lua_Load *load){ { if(run_input) { - /* skip CR key */ - if (ch == '\r') + char tmp_last_nl_char = last_nl_char; + // reset marker, will be finally set below when newline is processed + last_nl_char = '\0'; + + /* handle CR & LF characters + filters second char of LF&CR (\n\r) or CR&LF (\r\n) sequences */ + if ((ch == '\r' && tmp_last_nl_char == '\n') || // \n\r sequence -> skip \r + (ch == '\n' && tmp_last_nl_char == '\r')) // \r\n sequence -> skip \n { continue; } + /* backspace key */ else if (ch == 0x7f || ch == 0x08) { @@ -578,8 +586,10 @@ static bool readline(lua_Load *load){ // } /* end of line */ - if (ch == '\n') + if (ch == '\r' || ch == '\n') { + last_nl_char = ch; + load->line[load->line_position] = 0; if(uart0_echo) uart_putc('\n'); uart_on_data_cb(load->line, load->line_position);