[Qemu-devel] [PATCH v2] console: purge curses bits from console.h

Gerd Hoffmann posted 1 patch 6 years, 6 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20170927103811.19249-1-kraxel@redhat.com
Test checkpatch passed
Test docker passed
Test s390x passed
include/ui/console.h      | 23 ++---------------------
target/unicore32/helper.c |  6 ++++++
ui/curses.c               | 25 ++++++++++++++++++++-----
3 files changed, 28 insertions(+), 26 deletions(-)
[Qemu-devel] [PATCH v2] console: purge curses bits from console.h
Posted by Gerd Hoffmann 6 years, 6 months ago
Handle the translation from vga chars to curses chars in curses_update()
instead of console_write_ch().  Purge any curses support bits from
ui/console.h include file.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 include/ui/console.h      | 23 ++---------------------
 target/unicore32/helper.c |  6 ++++++
 ui/curses.c               | 25 ++++++++++++++++++++-----
 3 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/include/ui/console.h b/include/ui/console.h
index 8024878bae..6966e4bd9d 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -336,29 +336,10 @@ static inline pixman_format_code_t surface_format(DisplaySurface *s)
     return s->format;
 }
 
-#ifdef CONFIG_CURSES
-/* KEY_EVENT is defined in wincon.h and in curses.h. Avoid redefinition. */
-#undef KEY_EVENT
-#include <curses.h>
-#undef KEY_EVENT
-typedef chtype console_ch_t;
-extern chtype vga_to_curses[];
-#else
-typedef unsigned long console_ch_t;
-#endif
+typedef uint32_t console_ch_t;
+
 static inline void console_write_ch(console_ch_t *dest, uint32_t ch)
 {
-    uint8_t c = ch;
-#ifdef CONFIG_CURSES
-    if (vga_to_curses[c]) {
-        ch &= ~(console_ch_t)0xff;
-        ch |= vga_to_curses[c];
-    }
-#else
-    if (c == '\0') {
-        ch |= ' ';
-    }
-#endif
     *dest = ch;
 }
 
diff --git a/target/unicore32/helper.c b/target/unicore32/helper.c
index 309dcd1ae1..3393d2c020 100644
--- a/target/unicore32/helper.c
+++ b/target/unicore32/helper.c
@@ -163,6 +163,12 @@ uint32_t helper_cp0_get(CPUUniCore32State *env, uint32_t creg, uint32_t cop)
 }
 
 #ifdef CONFIG_CURSES
+
+/* KEY_EVENT is defined in wincon.h and in curses.h. Avoid redefinition. */
+#undef KEY_EVENT
+#include <curses.h>
+#undef KEY_EVENT
+
 /*
  * FIXME:
  *     1. curses windows will be blank when switching back
diff --git a/ui/curses.c b/ui/curses.c
index 03cefdf470..85503876c0 100644
--- a/ui/curses.c
+++ b/ui/curses.c
@@ -33,6 +33,11 @@
 #include "ui/input.h"
 #include "sysemu/sysemu.h"
 
+/* KEY_EVENT is defined in wincon.h and in curses.h. Avoid redefinition. */
+#undef KEY_EVENT
+#include <curses.h>
+#undef KEY_EVENT
+
 #define FONT_HEIGHT 16
 #define FONT_WIDTH 8
 
@@ -42,16 +47,26 @@ static WINDOW *screenpad = NULL;
 static int width, height, gwidth, gheight, invalidate;
 static int px, py, sminx, sminy, smaxx, smaxy;
 
-chtype vga_to_curses[256];
+static chtype vga_to_curses[256];
 
 static void curses_update(DisplayChangeListener *dcl,
                           int x, int y, int w, int h)
 {
-    chtype *line;
+    console_ch_t *line;
+    chtype curses_line[width];
 
-    line = ((chtype *) screen) + y * width;
-    for (h += y; y < h; y ++, line += width)
-        mvwaddchnstr(screenpad, y, 0, line, width);
+    line = screen + y * width;
+    for (h += y; y < h; y ++, line += width) {
+        for (x = 0; x < width; x++) {
+            chtype ch = line[x] & 0xff;
+            chtype at = line[x] & ~0xff;
+            if (vga_to_curses[ch]) {
+                ch = vga_to_curses[ch];
+            }
+            curses_line[x] = ch | at;
+        }
+        mvwaddchnstr(screenpad, y, 0, curses_line, width);
+    }
 
     pnoutrefresh(screenpad, py, px, sminy, sminx, smaxy - 1, smaxx - 1);
     refresh();
-- 
2.9.3


Re: [Qemu-devel] [PATCH v2] console: purge curses bits from console.h
Posted by Philippe Mathieu-Daudé 6 years, 6 months ago
Hi Gerd,

On 09/27/2017 07:38 AM, Gerd Hoffmann wrote:
> Handle the translation from vga chars to curses chars in curses_update()
> instead of console_write_ch().  Purge any curses support bits from
> ui/console.h include file.
> 
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>   include/ui/console.h      | 23 ++---------------------
>   target/unicore32/helper.c |  6 ++++++
>   ui/curses.c               | 25 ++++++++++++++++++++-----
>   3 files changed, 28 insertions(+), 26 deletions(-)
> 
> diff --git a/include/ui/console.h b/include/ui/console.h
> index 8024878bae..6966e4bd9d 100644
> --- a/include/ui/console.h
> +++ b/include/ui/console.h
> @@ -336,29 +336,10 @@ static inline pixman_format_code_t surface_format(DisplaySurface *s)
>       return s->format;
>   }
>   
> -#ifdef CONFIG_CURSES
> -/* KEY_EVENT is defined in wincon.h and in curses.h. Avoid redefinition. */
> -#undef KEY_EVENT
> -#include <curses.h>
> -#undef KEY_EVENT
> -typedef chtype console_ch_t;
> -extern chtype vga_to_curses[];
> -#else
> -typedef unsigned long console_ch_t;
> -#endif
> +typedef uint32_t console_ch_t;
> +
>   static inline void console_write_ch(console_ch_t *dest, uint32_t ch)
>   {
> -    uint8_t c = ch;
> -#ifdef CONFIG_CURSES
> -    if (vga_to_curses[c]) {
> -        ch &= ~(console_ch_t)0xff;
> -        ch |= vga_to_curses[c];
> -    }
> -#else
> -    if (c == '\0') {

I can't figure out why this is no more required (curses disabled),
can you enlighten me?

> -        ch |= ' ';
> -    }
> -#endif
>       *dest = ch;
>   }
>   
> diff --git a/target/unicore32/helper.c b/target/unicore32/helper.c
> index 309dcd1ae1..3393d2c020 100644
> --- a/target/unicore32/helper.c
> +++ b/target/unicore32/helper.c
> @@ -163,6 +163,12 @@ uint32_t helper_cp0_get(CPUUniCore32State *env, uint32_t creg, uint32_t cop)
>   }
>   
>   #ifdef CONFIG_CURSES
> +
> +/* KEY_EVENT is defined in wincon.h and in curses.h. Avoid redefinition. */
> +#undef KEY_EVENT
> +#include <curses.h>
> +#undef KEY_EVENT
> +
>   /*
>    * FIXME:
>    *     1. curses windows will be blank when switching back
> diff --git a/ui/curses.c b/ui/curses.c
> index 03cefdf470..85503876c0 100644
> --- a/ui/curses.c
> +++ b/ui/curses.c
> @@ -33,6 +33,11 @@
>   #include "ui/input.h"
>   #include "sysemu/sysemu.h"
>   
> +/* KEY_EVENT is defined in wincon.h and in curses.h. Avoid redefinition. */
> +#undef KEY_EVENT
> +#include <curses.h>
> +#undef KEY_EVENT
> +
>   #define FONT_HEIGHT 16
>   #define FONT_WIDTH 8
>   
> @@ -42,16 +47,26 @@ static WINDOW *screenpad = NULL;
>   static int width, height, gwidth, gheight, invalidate;
>   static int px, py, sminx, sminy, smaxx, smaxy;
>   
> -chtype vga_to_curses[256];
> +static chtype vga_to_curses[256];
>   
>   static void curses_update(DisplayChangeListener *dcl,
>                             int x, int y, int w, int h)
>   {
> -    chtype *line;
> +    console_ch_t *line;
> +    chtype curses_line[width];
>   
> -    line = ((chtype *) screen) + y * width;
> -    for (h += y; y < h; y ++, line += width)
> -        mvwaddchnstr(screenpad, y, 0, line, width);
> +    line = screen + y * width;
> +    for (h += y; y < h; y ++, line += width) {
> +        for (x = 0; x < width; x++) {
> +            chtype ch = line[x] & 0xff;
> +            chtype at = line[x] & ~0xff;
> +            if (vga_to_curses[ch]) {
> +                ch = vga_to_curses[ch];
> +            }
> +            curses_line[x] = ch | at;
> +        }
> +        mvwaddchnstr(screenpad, y, 0, curses_line, width);
> +    }
>   
>       pnoutrefresh(screenpad, py, px, sminy, sminx, smaxy - 1, smaxx - 1);
>       refresh();
>