[PATCH 6/8] termios: Simplify oproc()

Sebastian Huber sebastian.huber at embedded-brains.de
Thu Feb 23 14:45:38 UTC 2017


Call rtems_termios_puts() only once.  Adjust column in one place.
---
 cpukit/libcsupport/src/termios.c | 57 ++++++++++++++++++++++++++--------------
 1 file changed, 38 insertions(+), 19 deletions(-)

diff --git a/cpukit/libcsupport/src/termios.c b/cpukit/libcsupport/src/termios.c
index 18fe269..4fd98a5 100644
--- a/cpukit/libcsupport/src/termios.c
+++ b/cpukit/libcsupport/src/termios.c
@@ -1098,55 +1098,74 @@ rtems_termios_puts (
 static void
 oproc (unsigned char c, struct rtems_termios_tty *tty)
 {
-  int  i;
+  char buf[8];
+  size_t len;
+  int oldColumn;
+  int columnAdj;
+  int i;
+
+  buf[0] = c;
+  len = 1;
+  oldColumn = tty->column;
+  columnAdj = 0;
 
   if (tty->termios.c_oflag & OPOST) {
     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;
+        buf[0] = '\r';
+        buf[1] = c;
+        len = 2;
+        columnAdj = -oldColumn;
       }
       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);
+      i = 8 - (oldColumn & 7);
       if ((tty->termios.c_oflag & TABDLY) == XTABS) {
-        tty->column += i;
-        rtems_termios_puts ( "        ",  i, tty);
-        return;
+        int j;
+
+        for (j = 0; j < i; ++j) {
+          buf[j] = ' ';
+        }
+
+        len = (size_t) i;
       }
-      tty->column += i;
+      columnAdj = 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;
     }
   }
-  rtems_termios_puts (&c, 1, tty);
+
+  tty->column = oldColumn + columnAdj;
+  rtems_termios_puts (buf, len, tty);
 }
 
 static uint32_t
-- 
1.8.4.5




More information about the devel mailing list