Page 1 of 1

shell end of line parsing

Posted: Fri Apr 03, 2020 3:04 pm
by geoffrey.brown
The shell code allows definition of the newline string for output -- SHELL_NEWLINE_STR -- but not on input. The command parser is hardwired to look for '\r' which is an assumption about windows

if (c == '\r') {
chprintf(chp, SHELL_NEWLINE_STR);
#if SHELL_USE_HISTORY == TRUE
save_history(shp, line, p - line);
#endif
*p = 0;
return false;
}

It seems this would be a good place for another "define". I've been bitten by this a few times when working in environments other than windows -- particularly when using programs to communicate with the shell.

Re: shell end of line parsing

Posted: Fri Apr 03, 2020 5:23 pm
by steved
I suppose it depends what you're talking to, but I'd generally expect '\r' as the 'execute' character from a terminal emulator, regardless of the underlying system. A solution I've used is to just swallow any '\n' characters received. Otherwise it gets complicated. (If both characters are received, I've only ever encoutered them in the order \r\n, so you could discard \n only when received immediately following \r; but there's bound to be a system which sends \n\r!)

Sending is harder, since it depends on the receiving system - arguably an option to configure the termination string at run-time would be useful.

Re: shell end of line parsing

Posted: Fri Apr 03, 2020 5:32 pm
by Giovanni
Termination string would be harder than simply defining a char. I agree that a CR is a CR regardless the OS however.

Giovanni

Re: shell end of line parsing

Posted: Fri Jun 12, 2020 6:31 am
by rew
In my version of "the shell" I simply accept both \r and \n as the "now do it" character.

If you configure your terminal program to send \r\n when you hit enter, that's going to give you an empty line/command each time you hit enter. Too bad.