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.
shell end of line parsing
Moderators: RoccoMarco, lbednarz, tfAteba
-
geoffrey.brown
- Posts: 122
- Joined: Thu May 07, 2015 9:47 pm
- Has thanked: 3 times
- Been thanked: 18 times
Re: shell end of line parsing
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.
Sending is harder, since it depends on the receiving system - arguably an option to configure the termination string at run-time would be useful.
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: shell end of line parsing
Termination string would be harder than simply defining a char. I agree that a CR is a CR regardless the OS however.
Giovanni
Giovanni
Re: shell end of line parsing
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.
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.