[PATCH 4/8] termios: Ignore newline early if desired
Sebastian Huber
sebastian.huber at embedded-brains.de
Thu Feb 23 14:45:36 UTC 2017
In case newline characters should be ignored in the input (IGNCR), then
drop them early before they reach the raw input buffer. This makes it
easier to calculate the content size of the raw input buffer.
---
cpukit/libcsupport/src/termios.c | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/cpukit/libcsupport/src/termios.c b/cpukit/libcsupport/src/termios.c
index c52f0e5..dccdfd7 100644
--- a/cpukit/libcsupport/src/termios.c
+++ b/cpukit/libcsupport/src/termios.c
@@ -1295,12 +1295,11 @@ iproc (unsigned char c, struct rtems_termios_tty *tty)
c = tolower (c);
if (c == '\r') {
- if (tty->termios.c_iflag & IGNCR)
- return 0;
if (tty->termios.c_iflag & ICRNL)
c = '\n';
- } else if ((c == '\n') && (tty->termios.c_iflag & INLCR)) {
- c = '\r';
+ } else if (c == '\n') {
+ if (tty->termios.c_iflag & INLCR)
+ c = '\r';
}
if ((c != '\0') && (tty->termios.c_lflag & ICANON)) {
@@ -1366,6 +1365,16 @@ siproc (unsigned char c, struct rtems_termios_tty *tty)
return i;
}
+static int
+siprocPoll (unsigned char c, rtems_termios_tty *tty)
+{
+ if (c == '\r' && (tty->termios.c_iflag & IGNCR) != 0) {
+ return 0;
+ }
+
+ return siproc (c, tty);
+}
+
/*
* Fill the input buffer by polling the device
*/
@@ -1380,7 +1389,7 @@ fillBufferPoll (struct rtems_termios_tty *tty)
if (n < 0) {
rtems_task_wake_after (1);
} else {
- if (siproc (n, tty))
+ if (siprocPoll (n, tty))
break;
}
}
@@ -1408,7 +1417,7 @@ fillBufferPoll (struct rtems_termios_tty *tty)
}
rtems_task_wake_after (1);
} else {
- siproc (n, tty);
+ siprocPoll (n, tty);
if (tty->ccount >= tty->termios.c_cc[VMIN])
break;
if (tty->termios.c_cc[VMIN] && tty->termios.c_cc[VTIME])
@@ -1637,6 +1646,10 @@ rtems_termios_enqueue_raw_characters (void *ttyp, const char *buf, int len)
unsigned int oldTail;
unsigned int newTail;
+ if (c == '\r' && (tty->termios.c_iflag & IGNCR) != 0) {
+ continue;
+ }
+
rtems_termios_device_lock_acquire (ctx, &lock_context);
head = tty->rawInBuf.Head;
--
1.8.4.5
More information about the devel
mailing list