From cf99d571fb1cb77fbdf2cb84a0890835173b50af Mon Sep 17 00:00:00 2001 From: James Clarke Date: Sat, 29 Aug 2015 11:15:29 +0100 Subject: Fix printk not handling ANSI escape codes * 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 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 24 deletions(-) (limited to 'i386/i386at/kd.c') diff --git a/i386/i386at/kd.c b/i386/i386at/kd.c index 5656e830..9ed3958a 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_esc(ch); splx(o_pri); } if (tp->t_outq.c_cc <= TTLOWAT(tp)) { @@ -1235,6 +1213,43 @@ kd_bellon(void) return; } +/* + * + * 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(): @@ -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; } -- cgit v1.2.3