shell end of line parsing

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
geoffrey.brown
Posts: 122
Joined: Thu May 07, 2015 9:47 pm
Has thanked: 3 times
Been thanked: 18 times

shell end of line parsing

Post 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.
steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

Re: shell end of line parsing

Post 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.
User avatar
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

Post 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
rew
Posts: 383
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 14 times

Re: shell end of line parsing

Post 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.
Post Reply