diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-11-06 17:04:40 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-11-06 17:04:40 -0600 |
commit | db67dd9481c27cd71deb658c55f4a6d980cd7b77 (patch) | |
tree | c89ab8efaae31f9be170c96d4651551f1538187c /apps/interpreters | |
parent | f96eabc250fc5e157bd669399e1cf4938e0b58a0 (diff) | |
download | nuttx-db67dd9481c27cd71deb658c55f4a6d980cd7b77.tar.gz nuttx-db67dd9481c27cd71deb658c55f4a6d980cd7b77.tar.bz2 nuttx-db67dd9481c27cd71deb658c55f4a6d980cd7b77.zip |
BAS: Add logic to handle serial consoles that end lines with CR, LF, CR&LF, or CR|LF
Diffstat (limited to 'apps/interpreters')
-rw-r--r-- | apps/interpreters/bas/fs.c | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/apps/interpreters/bas/fs.c b/apps/interpreters/bas/fs.c index cea05db56..81425630d 100644 --- a/apps/interpreters/bas/fs.c +++ b/apps/interpreters/bas/fs.c @@ -285,15 +285,21 @@ static int edit(int chn, int onl) #else if ((f->inCapacity + 1) < sizeof(f->inBuf)) { - /* Ignore carriage returns that may accompany a CRLF sequence. - * REVISIT: Some environments may have other line termination rules - */ +#ifdef CONFIG_EOL_IS_BOTH_CRLF + /* Ignore carriage returns that may accompany a CRLF sequence. */ if (ch != '\r') +#endif { /* Is this a new line character */ +#ifdef CONFIG_EOL_IS_CR + if (ch != '\r') +#elif defined(CONFIG_EOL_IS_LF) if (ch != '\n') +#elif defined(CONFIG_EOL_IS_EITHER_CRLF) + if (ch != '\n' && ch != '\r' ) +#endif { /* No.. escape control characters other than newline and * carriage return @@ -313,11 +319,26 @@ static int edit(int chn, int onl) } } - /* Echo the newline (or not) */ + /* It is a newline */ - else if (onl) + else { - FS_putChar(chn, '\n'); + /* Echo the newline (or not). We always use newline + * termination when talking to the host. + */ + + if (onl) + { + FS_putChar(chn, '\n'); + } + +#if defined(CONFIG_EOL_IS_CR) || defined(CONFIG_EOL_IS_EITHER_CRLF) + /* If the host is talking to us with CR line terminations, + * switch to use LF internally. + */ + + ch = '\n'; +#endif } f->inBuf[f->inCapacity++] = ch; |