bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC] Fix printk not handling ANSI escape codes


From: James Clarke
Subject: [RFC] Fix printk not handling ANSI escape codes
Date: Sat, 29 Aug 2015 11:15:29 +0100

* i386/i386at/kd.c (kdstart): Moved escape sequence handling to new
kd_putc_esc function.
(kd_putc_esc): New function with logic from kdstart.
(kdcnputc): Call kd_putc_esc rather than kd_putc to allow for ANSI
escape codes.
* i386/i386at/kd.h (kd_putc_esc): New function.
---
 i386/i386at/kd.c | 63 +++++++++++++++++++++++++++++++++++---------------------
 i386/i386at/kd.h |  1 +
 2 files changed, 40 insertions(+), 24 deletions(-)

diff --git a/i386/i386at/kd.c b/i386/i386at/kd.c
index 5656e83..52ba0b6 100644
--- a/i386/i386at/kd.c
+++ b/i386/i386at/kd.c
@@ -1059,7 +1059,6 @@ kdstart(struct tty *tp)
 {
        spl_t   o_pri;
        int     ch;
-       unsigned char   c;
 
        if (tp->t_state & TS_TTSTOP)
                return;
@@ -1069,33 +1068,12 @@ kdstart(struct tty *tp)
                        break;
                if ((tp->t_outq.c_cc <= 0) || (ch = getc(&tp->t_outq)) == -1)
                        break;
-               c = ch;
                /*
                 * Drop priority for long screen updates. ttstart() calls us at
                 * spltty.
                 */
                o_pri = splsoftclock();         /* block timeout */
-               if (c == (K_ESC)) {
-                       if (esc_spt == esc_seq) {
-                               *(esc_spt++)=(K_ESC);
-                               *(esc_spt) = '\0';
-                       } else {
-                               kd_putc((K_ESC));
-                               esc_spt = esc_seq;
-                       }
-               } else {
-                       if (esc_spt - esc_seq) {
-                               if (esc_spt - esc_seq > K_MAXESC - 1)
-                                       esc_spt = esc_seq;
-                               else {
-                                       *(esc_spt++) = c;
-                                       *(esc_spt) = '\0';
-                                       kd_parseesc();
-                                     }
-                       } else {
-                               kd_putc(c);
-                       }
-               }
+               kd_putc(ch);
                splx(o_pri);
        }
        if (tp->t_outq.c_cc <= TTLOWAT(tp)) {
@@ -1237,6 +1215,43 @@ kd_bellon(void)
 
 /*
  *
+ * Function kd_putc_esc():
+ *
+ *     This function puts a character on the screen, handling escape
+ *     sequences.
+ *
+ * input       : character to be displayed (or part of an escape code)
+ * output      : character is displayed, or some action is taken
+ *
+ */
+void
+kd_putc_esc(u_char c)
+{
+       if (c == (K_ESC)) {
+               if (esc_spt == esc_seq) {
+                       *(esc_spt++)=(K_ESC);
+                       *(esc_spt) = '\0';
+               } else {
+                       kd_putc((K_ESC));
+                       esc_spt = esc_seq;
+               }
+       } else {
+               if (esc_spt - esc_seq) {
+                       if (esc_spt - esc_seq > K_MAXESC - 1)
+                               esc_spt = esc_seq;
+                       else {
+                               *(esc_spt++) = c;
+                               *(esc_spt) = '\0';
+                               kd_parseesc();
+                       }
+               } else {
+                       kd_putc(c);
+               }
+       }
+}
+
+/*
+ *
  * Function kd_putc():
  *
  *     This function simply puts a character on the screen.  It does some
@@ -2950,7 +2965,7 @@ kdcnputc(dev_t dev, int c)
        /* Note that tab is handled in kd_putc */
        if (c == '\n')
                kd_putc('\r');
-       kd_putc(c);
+       kd_putc_esc(c);
 
        return 0;
 }
diff --git a/i386/i386at/kd.h b/i386/i386at/kd.h
index 0cfed69..60cee7e 100644
--- a/i386/i386at/kd.h
+++ b/i386/i386at/kd.h
@@ -702,6 +702,7 @@ extern void kd_setleds1 (u_char);
 extern void kd_setleds2 (void);
 extern void cnsetleds (u_char);
 extern void kdreboot (void);
+extern void kd_putc_esc (u_char);
 extern void kd_putc (u_char);
 extern void kd_parseesc (void);
 extern void kd_down (void);
-- 
2.5.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]