[rtems commit] termios: Simplify oproc()
Sebastian Huber
sebh at rtems.org
Tue Feb 28 08:43:40 UTC 2017
Module: rtems
Branch: master
Commit: 5244d31ef7d7a5d5034672fe17107a058c9de867
Changeset: http://git.rtems.org/rtems/commit/?id=5244d31ef7d7a5d5034672fe17107a058c9de867
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Thu Feb 23 14:04:24 2017 +0100
termios: Simplify oproc()
Call rtems_termios_puts() only once. Adjust column in one place.
---
cpukit/libcsupport/src/termios.c | 55 +++++++++++++++++++++++-------------
testsuites/libtests/termios09/init.c | 9 +++---
2 files changed, 41 insertions(+), 23 deletions(-)
diff --git a/cpukit/libcsupport/src/termios.c b/cpukit/libcsupport/src/termios.c
index f5bf493..e5bfeaa 100644
--- a/cpukit/libcsupport/src/termios.c
+++ b/cpukit/libcsupport/src/termios.c
@@ -1098,55 +1098,72 @@ rtems_termios_puts (
static void
oproc (unsigned char c, struct rtems_termios_tty *tty)
{
- int i;
+ char buf[8];
+ size_t len;
+
+ buf[0] = c;
+ len = 1;
if (tty->termios.c_oflag & OPOST) {
+ int oldColumn = tty->column;
+ int columnAdj = 0;
+
switch (c) {
case '\n':
if (tty->termios.c_oflag & ONLRET)
- tty->column = 0;
+ columnAdj = -oldColumn;
if (tty->termios.c_oflag & ONLCR) {
- rtems_termios_puts ("\r", 1, tty);
- tty->column = 0;
+ columnAdj = -oldColumn;
+ buf[0] = '\r';
+ buf[1] = c;
+ len = 2;
}
break;
case '\r':
- if ((tty->termios.c_oflag & ONOCR) && (tty->column == 0))
+ if ((tty->termios.c_oflag & ONOCR) && (oldColumn == 0))
return;
if (tty->termios.c_oflag & OCRNL) {
- c = '\n';
+ buf[0] = '\n';
if (tty->termios.c_oflag & ONLRET)
- tty->column = 0;
- break;
+ columnAdj = -oldColumn;
+ } else {
+ columnAdj = -oldColumn;
}
- tty->column = 0;
break;
case '\t':
- i = 8 - (tty->column & 7);
+ columnAdj = 8 - (oldColumn & 7);
if ((tty->termios.c_oflag & TABDLY) == XTABS) {
- tty->column += i;
- rtems_termios_puts ( " ", i, tty);
- return;
+ int i;
+
+ len = (size_t) columnAdj;
+
+ for (i = 0; i < columnAdj; ++i) {
+ buf[i] = ' ';
+ }
}
- tty->column += i;
break;
case '\b':
- if (tty->column > 0)
- tty->column--;
+ if (oldColumn > 0)
+ columnAdj = -1;
break;
default:
- if (tty->termios.c_oflag & OLCUC)
+ if (tty->termios.c_oflag & OLCUC) {
c = toupper(c);
+ buf[0] = c;
+ }
if (!iscntrl(c))
- tty->column++;
+ columnAdj = 1;
break;
}
+
+ tty->column = oldColumn + columnAdj;
}
- rtems_termios_puts (&c, 1, tty);
+
+ rtems_termios_puts (buf, len, tty);
}
static uint32_t
diff --git a/testsuites/libtests/termios09/init.c b/testsuites/libtests/termios09/init.c
index 2e40ebf..58a23ea 100644
--- a/testsuites/libtests/termios09/init.c
+++ b/testsuites/libtests/termios09/init.c
@@ -575,10 +575,11 @@ static void flush_output(test_context *ctx, size_t i)
{
if (i == INTERRUPT) {
device_context *dev = &ctx->devices[i];
+ int left;
- while (dev->output_pending != 0) {
- rtems_termios_dequeue_characters(dev->tty, dev->output_pending);
- }
+ do {
+ left = rtems_termios_dequeue_characters(dev->tty, dev->output_pending);
+ } while (left > 0);
}
}
@@ -586,7 +587,7 @@ static void clear_output(test_context *ctx, size_t i)
{
device_context *dev = &ctx->devices[i];
- dev->output_pending = 0;
+ flush_output(ctx, i);
dev->output_count = 0;
memset(&dev->output_buf, 0, OUTPUT_BUFFER_SIZE);
}
More information about the vc
mailing list