summaryrefslogtreecommitdiffstats
path: root/cpukit/libcsupport
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2017-02-23 14:04:24 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2017-02-28 09:05:47 +0100
commit5244d31ef7d7a5d5034672fe17107a058c9de867 (patch)
treefea9226bee257013eef0eb036577c7579cd45097 /cpukit/libcsupport
parenttermios09: Test output post processing (diff)
downloadrtems-5244d31ef7d7a5d5034672fe17107a058c9de867.tar.bz2
termios: Simplify oproc()
Call rtems_termios_puts() only once. Adjust column in one place.
Diffstat (limited to 'cpukit/libcsupport')
-rw-r--r--cpukit/libcsupport/src/termios.c55
1 files changed, 36 insertions, 19 deletions
diff --git a/cpukit/libcsupport/src/termios.c b/cpukit/libcsupport/src/termios.c
index f5bf493966..e5bfeaa236 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