public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/4] [gdb/tui] Remove default entries in TUI translation tables
@ 2023-06-23 11:15 Tom de Vries
  2023-06-23 11:15 ` [PATCH 2/4] [gdb/tui] Introduce translate_acs Tom de Vries
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Tom de Vries @ 2023-06-23 11:15 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

The TUI translation tables contain default entries at the end:
...
static struct tui_translate tui_border_kind_translate_hline[] = {
  { "space",    ' ' },
  { "ascii",    '-' },
  { "acs",      -1 },
  { 0, 0 },
  { "ascii",    '-' }
};
...

A simpler way of implementing this would be to to declare the first (or last)
entry the default, but in fact these default entries are not used.

Make this explicit by removing the default entries, and asserting in translate
that an entry will always be found.

Tested on x86_64-linux.
---
 gdb/tui/tui-win.c | 31 ++++++++++---------------------
 1 file changed, 10 insertions(+), 21 deletions(-)

diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index 7d58a2db251..fe80df468fa 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -116,8 +116,7 @@ struct tui_translate
 };
 
 /* Translation table for border-mode variables.
-   The list of values must be terminated by a NULL.
-   After the NULL value, an entry defines the default.  */
+   The list of values must be terminated by a NULL.  */
 static struct tui_translate tui_border_mode_translate[] = {
   { "normal",		A_NORMAL },
   { "standout",		A_STANDOUT },
@@ -126,8 +125,7 @@ static struct tui_translate tui_border_mode_translate[] = {
   { "half-standout",	A_DIM | A_STANDOUT },
   { "bold",		A_BOLD },
   { "bold-standout",	A_BOLD | A_STANDOUT },
-  { 0, 0 },
-  { "normal",		A_NORMAL }
+  { 0, 0 }
 };
 
 /* Translation tables for border-kind, one for each border
@@ -138,48 +136,42 @@ static struct tui_translate tui_border_kind_translate_vline[] = {
   { "space",    ' ' },
   { "ascii",    '|' },
   { "acs",      -1 },
-  { 0, 0 },
-  { "ascii",    '|' }
+  { 0, 0 }
 };
 
 static struct tui_translate tui_border_kind_translate_hline[] = {
   { "space",    ' ' },
   { "ascii",    '-' },
   { "acs",      -1 },
-  { 0, 0 },
-  { "ascii",    '-' }
+  { 0, 0 }
 };
 
 static struct tui_translate tui_border_kind_translate_ulcorner[] = {
   { "space",    ' ' },
   { "ascii",    '+' },
   { "acs",      -1 },
-  { 0, 0 },
-  { "ascii",    '+' }
+  { 0, 0 }
 };
 
 static struct tui_translate tui_border_kind_translate_urcorner[] = {
   { "space",    ' ' },
   { "ascii",    '+' },
   { "acs",      -1 },
-  { 0, 0 },
-  { "ascii",    '+' }
+  { 0, 0 }
 };
 
 static struct tui_translate tui_border_kind_translate_llcorner[] = {
   { "space",    ' ' },
   { "ascii",    '+' },
   { "acs",      -1 },
-  { 0, 0 },
-  { "ascii",    '+' }
+  { 0, 0 }
 };
 
 static struct tui_translate tui_border_kind_translate_lrcorner[] = {
   { "space",    ' ' },
   { "ascii",    '+' },
   { "acs",      -1 },
-  { 0, 0 },
-  { "ascii",    '+' }
+  { 0, 0 }
 };
 
 
@@ -257,8 +249,7 @@ chtype tui_border_lrcorner;
 int tui_border_attrs;
 int tui_active_border_attrs;
 
-/* Identify the item in the translation table.
-   When the item is not recognized, use the default entry.  */
+/* Identify the item in the translation table.  */
 static struct tui_translate *
 translate (const char *name, struct tui_translate *table)
 {
@@ -269,9 +260,7 @@ translate (const char *name, struct tui_translate *table)
       table++;
     }
 
-  /* Not found, return default entry.  */
-  table++;
-  return table;
+  gdb_assert_not_reached ("");
 }
 
 /* Update the tui internal configuration according to gdb settings.

base-commit: 8a269c262e3d0611c01edd915f230bbd2ad78015
-- 
2.35.3


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/4] [gdb/tui] Introduce translate_acs
  2023-06-23 11:15 [PATCH 1/4] [gdb/tui] Remove default entries in TUI translation tables Tom de Vries
@ 2023-06-23 11:15 ` Tom de Vries
  2023-06-23 20:28   ` Tom Tromey
  2023-06-23 11:15 ` [PATCH 3/4] [gdb/tui] Merge tui border-kind corner translation tables Tom de Vries
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Tom de Vries @ 2023-06-23 11:15 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

In function tui_update_variables we have the somewhat inconvenient:
...
  entry = translate (tui_border_kind, tui_border_kind_translate_lrcorner);
  int val = (entry->value < 0) ? ACS_LRCORNER : entry->value;
...

Add a new function translate_acs, that allows us to do the more straighforward:
...
  int val = translate_acs (tui_border_kind, tui_border_kind_translate_lrcorner,
			   ACS_LRCORNER);
...

By special-casing "acs" in translate_acs, we can now remove the acs entries
from the translation tables.

Tested on x86_64-linux.
---
 gdb/tui/tui-win.c | 59 +++++++++++++++++++++++++++--------------------
 1 file changed, 34 insertions(+), 25 deletions(-)

diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index fe80df468fa..1406e072c43 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -128,49 +128,41 @@ static struct tui_translate tui_border_mode_translate[] = {
   { 0, 0 }
 };
 
-/* Translation tables for border-kind, one for each border
-   character (see wborder, border curses operations).
-   -1 is used to indicate the ACS because ACS characters
-   are determined at run time by curses (depends on terminal).  */
+/* Translation tables for border-kind (acs excluded), one for each border
+   character (see wborder, border curses operations).  */
 static struct tui_translate tui_border_kind_translate_vline[] = {
   { "space",    ' ' },
   { "ascii",    '|' },
-  { "acs",      -1 },
   { 0, 0 }
 };
 
 static struct tui_translate tui_border_kind_translate_hline[] = {
   { "space",    ' ' },
   { "ascii",    '-' },
-  { "acs",      -1 },
   { 0, 0 }
 };
 
 static struct tui_translate tui_border_kind_translate_ulcorner[] = {
   { "space",    ' ' },
   { "ascii",    '+' },
-  { "acs",      -1 },
   { 0, 0 }
 };
 
 static struct tui_translate tui_border_kind_translate_urcorner[] = {
   { "space",    ' ' },
   { "ascii",    '+' },
-  { "acs",      -1 },
   { 0, 0 }
 };
 
 static struct tui_translate tui_border_kind_translate_llcorner[] = {
   { "space",    ' ' },
   { "ascii",    '+' },
-  { "acs",      -1 },
   { 0, 0 }
 };
 
 static struct tui_translate tui_border_kind_translate_lrcorner[] = {
   { "space",    ' ' },
   { "ascii",    '+' },
-  { "acs",      -1 },
   { 0, 0 }
 };
 
@@ -263,6 +255,19 @@ translate (const char *name, struct tui_translate *table)
   gdb_assert_not_reached ("");
 }
 
+/* Translate NAME to a value.  If NAME is "acs", use ACS_CHAR.  Otherwise, use
+   translation table TABLE. */
+static int
+translate_acs (const char *name, struct tui_translate *table, int acs_char)
+{
+  /* The ACS characters are determined at run time by curses terminal
+     management.  */
+  if (strcmp (name, "acs") == 0)
+    return acs_char;
+
+  return translate (name, table)->value;
+}
+
 /* Update the tui internal configuration according to gdb settings.
    Returns 1 if the configuration has changed and the screen should
    be redrawn.  */
@@ -280,27 +285,31 @@ tui_update_variables ()
   need_redraw
     |= assign_return_if_changed<int> (tui_active_border_attrs, entry->value);
 
-  /* If one corner changes, all characters are changed.
-     Only check the first one.  The ACS characters are determined at
-     run time by curses terminal management.  */
-  entry = translate (tui_border_kind, tui_border_kind_translate_lrcorner);
-  int val = (entry->value < 0) ? ACS_LRCORNER : entry->value;
+  /* If one corner changes, all characters are changed.  Only check the first
+     one.  */
+  int val = translate_acs (tui_border_kind, tui_border_kind_translate_lrcorner,
+			   ACS_LRCORNER);
   need_redraw |= assign_return_if_changed<chtype> (tui_border_lrcorner, val);
 
-  entry = translate (tui_border_kind, tui_border_kind_translate_llcorner);
-  tui_border_llcorner = (entry->value < 0) ? ACS_LLCORNER : entry->value;
+  tui_border_llcorner
+    = translate_acs (tui_border_kind, tui_border_kind_translate_llcorner,
+		     ACS_LLCORNER);
 
-  entry = translate (tui_border_kind, tui_border_kind_translate_ulcorner);
-  tui_border_ulcorner = (entry->value < 0) ? ACS_ULCORNER : entry->value;
+  tui_border_ulcorner
+    = translate_acs (tui_border_kind, tui_border_kind_translate_ulcorner,
+		     ACS_ULCORNER);
 
-  entry = translate (tui_border_kind, tui_border_kind_translate_urcorner);
-  tui_border_urcorner = (entry->value < 0) ? ACS_URCORNER : entry->value;
+  tui_border_urcorner =
+    translate_acs (tui_border_kind, tui_border_kind_translate_urcorner,
+		   ACS_URCORNER);
 
-  entry = translate (tui_border_kind, tui_border_kind_translate_hline);
-  tui_border_hline = (entry->value < 0) ? ACS_HLINE : entry->value;
+  tui_border_hline
+    = translate_acs (tui_border_kind, tui_border_kind_translate_hline,
+		     ACS_HLINE);
 
-  entry = translate (tui_border_kind, tui_border_kind_translate_vline);
-  tui_border_vline = (entry->value < 0) ? ACS_VLINE : entry->value;
+  tui_border_vline
+    = translate_acs (tui_border_kind, tui_border_kind_translate_vline,
+		     ACS_VLINE);
 
   return need_redraw;
 }
-- 
2.35.3


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 3/4] [gdb/tui] Merge tui border-kind corner translation tables
  2023-06-23 11:15 [PATCH 1/4] [gdb/tui] Remove default entries in TUI translation tables Tom de Vries
  2023-06-23 11:15 ` [PATCH 2/4] [gdb/tui] Introduce translate_acs Tom de Vries
@ 2023-06-23 11:15 ` Tom de Vries
  2023-06-23 20:30   ` Tom Tromey
  2023-06-23 11:15 ` [PATCH 4/4] [gdb/tui] Make translate return entry->value instead of entry Tom de Vries
  2023-06-23 20:28 ` [PATCH 1/4] [gdb/tui] Remove default entries in TUI translation tables Tom Tromey
  3 siblings, 1 reply; 8+ messages in thread
From: Tom de Vries @ 2023-06-23 11:15 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

The tables:
- tui_border_kind_translate_ulcorner
- tui_border_kind_translate_urcorner
- tui_border_kind_translate_llcorner
- tui_border_kind_translate_lrcorner
are identical.

Merge and rename to tui_border_kind_translate_corner.

Tested on x86_64-linux.
---
 gdb/tui/tui-win.c | 32 +++++++-------------------------
 1 file changed, 7 insertions(+), 25 deletions(-)

diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index 1406e072c43..2cc81778f3a 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -128,8 +128,8 @@ static struct tui_translate tui_border_mode_translate[] = {
   { 0, 0 }
 };
 
-/* Translation tables for border-kind (acs excluded), one for each border
-   character (see wborder, border curses operations).  */
+/* Translation tables for border-kind (acs excluded), one for vline, hline and
+   corners (see wborder, border curses operations).  */
 static struct tui_translate tui_border_kind_translate_vline[] = {
   { "space",    ' ' },
   { "ascii",    '|' },
@@ -142,25 +142,7 @@ static struct tui_translate tui_border_kind_translate_hline[] = {
   { 0, 0 }
 };
 
-static struct tui_translate tui_border_kind_translate_ulcorner[] = {
-  { "space",    ' ' },
-  { "ascii",    '+' },
-  { 0, 0 }
-};
-
-static struct tui_translate tui_border_kind_translate_urcorner[] = {
-  { "space",    ' ' },
-  { "ascii",    '+' },
-  { 0, 0 }
-};
-
-static struct tui_translate tui_border_kind_translate_llcorner[] = {
-  { "space",    ' ' },
-  { "ascii",    '+' },
-  { 0, 0 }
-};
-
-static struct tui_translate tui_border_kind_translate_lrcorner[] = {
+static struct tui_translate tui_border_kind_translate_corner[] = {
   { "space",    ' ' },
   { "ascii",    '+' },
   { 0, 0 }
@@ -287,20 +269,20 @@ tui_update_variables ()
 
   /* If one corner changes, all characters are changed.  Only check the first
      one.  */
-  int val = translate_acs (tui_border_kind, tui_border_kind_translate_lrcorner,
+  int val = translate_acs (tui_border_kind, tui_border_kind_translate_corner,
 			   ACS_LRCORNER);
   need_redraw |= assign_return_if_changed<chtype> (tui_border_lrcorner, val);
 
   tui_border_llcorner
-    = translate_acs (tui_border_kind, tui_border_kind_translate_llcorner,
+    = translate_acs (tui_border_kind, tui_border_kind_translate_corner,
 		     ACS_LLCORNER);
 
   tui_border_ulcorner
-    = translate_acs (tui_border_kind, tui_border_kind_translate_ulcorner,
+    = translate_acs (tui_border_kind, tui_border_kind_translate_corner,
 		     ACS_ULCORNER);
 
   tui_border_urcorner =
-    translate_acs (tui_border_kind, tui_border_kind_translate_urcorner,
+    translate_acs (tui_border_kind, tui_border_kind_translate_corner,
 		   ACS_URCORNER);
 
   tui_border_hline
-- 
2.35.3


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 4/4] [gdb/tui] Make translate return entry->value instead of entry
  2023-06-23 11:15 [PATCH 1/4] [gdb/tui] Remove default entries in TUI translation tables Tom de Vries
  2023-06-23 11:15 ` [PATCH 2/4] [gdb/tui] Introduce translate_acs Tom de Vries
  2023-06-23 11:15 ` [PATCH 3/4] [gdb/tui] Merge tui border-kind corner translation tables Tom de Vries
@ 2023-06-23 11:15 ` Tom de Vries
  2023-06-23 20:30   ` Tom Tromey
  2023-06-23 20:28 ` [PATCH 1/4] [gdb/tui] Remove default entries in TUI translation tables Tom Tromey
  3 siblings, 1 reply; 8+ messages in thread
From: Tom de Vries @ 2023-06-23 11:15 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

The only use of "entry = translate (...)" is entry->value.

Simplify using the function by returning entry->value instead.

Tested on x86_64-linux.
---
 gdb/tui/tui-win.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index 2cc81778f3a..93cf45ed296 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -223,14 +223,14 @@ chtype tui_border_lrcorner;
 int tui_border_attrs;
 int tui_active_border_attrs;
 
-/* Identify the item in the translation table.  */
-static struct tui_translate *
+/* Identify the item in the translation table, and return the corresponding value.  */
+static int
 translate (const char *name, struct tui_translate *table)
 {
   while (table->name)
     {
       if (name && strcmp (table->name, name) == 0)
-	return table;
+	return table->value;
       table++;
     }
 
@@ -247,7 +247,7 @@ translate_acs (const char *name, struct tui_translate *table, int acs_char)
   if (strcmp (name, "acs") == 0)
     return acs_char;
 
-  return translate (name, table)->value;
+  return translate (name, table);
 }
 
 /* Update the tui internal configuration according to gdb settings.
@@ -257,20 +257,18 @@ bool
 tui_update_variables ()
 {
   bool need_redraw = false;
-  struct tui_translate *entry;
+  int val;
 
-  entry = translate (tui_border_mode, tui_border_mode_translate);
-  need_redraw
-    |= assign_return_if_changed<int> (tui_border_attrs, entry->value);
+  val = translate (tui_border_mode, tui_border_mode_translate);
+  need_redraw |= assign_return_if_changed<int> (tui_border_attrs, val);
 
-  entry = translate (tui_active_border_mode, tui_border_mode_translate);
-  need_redraw
-    |= assign_return_if_changed<int> (tui_active_border_attrs, entry->value);
+  val = translate (tui_active_border_mode, tui_border_mode_translate);
+  need_redraw |= assign_return_if_changed<int> (tui_active_border_attrs, val);
 
   /* If one corner changes, all characters are changed.  Only check the first
      one.  */
-  int val = translate_acs (tui_border_kind, tui_border_kind_translate_corner,
-			   ACS_LRCORNER);
+  val = translate_acs (tui_border_kind, tui_border_kind_translate_corner,
+		       ACS_LRCORNER);
   need_redraw |= assign_return_if_changed<chtype> (tui_border_lrcorner, val);
 
   tui_border_llcorner
-- 
2.35.3


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/4] [gdb/tui] Remove default entries in TUI translation tables
  2023-06-23 11:15 [PATCH 1/4] [gdb/tui] Remove default entries in TUI translation tables Tom de Vries
                   ` (2 preceding siblings ...)
  2023-06-23 11:15 ` [PATCH 4/4] [gdb/tui] Make translate return entry->value instead of entry Tom de Vries
@ 2023-06-23 20:28 ` Tom Tromey
  3 siblings, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2023-06-23 20:28 UTC (permalink / raw)
  To: Tom de Vries; +Cc: gdb-patches, Tom Tromey

>>>>> Tom de Vries <tdevries@suse.de> writes:

> The TUI translation tables contain default entries at the end:
> ...
> static struct tui_translate tui_border_kind_translate_hline[] = {
>   { "space",    ' ' },
>   { "ascii",    '-' },
>   { "acs",      -1 },
>   { 0, 0 },
>   { "ascii",    '-' }
> };
> ...

> A simpler way of implementing this would be to to declare the first (or last)
> entry the default, but in fact these default entries are not used.

> Make this explicit by removing the default entries, and asserting in translate
> that an entry will always be found.

Looks good to me.

Tom

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/4] [gdb/tui] Introduce translate_acs
  2023-06-23 11:15 ` [PATCH 2/4] [gdb/tui] Introduce translate_acs Tom de Vries
@ 2023-06-23 20:28   ` Tom Tromey
  0 siblings, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2023-06-23 20:28 UTC (permalink / raw)
  To: Tom de Vries; +Cc: gdb-patches, Tom Tromey

> By special-casing "acs" in translate_acs, we can now remove the acs entries
> from the translation tables.

Looks nice.  Thank you for doing this.

Tom

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/4] [gdb/tui] Merge tui border-kind corner translation tables
  2023-06-23 11:15 ` [PATCH 3/4] [gdb/tui] Merge tui border-kind corner translation tables Tom de Vries
@ 2023-06-23 20:30   ` Tom Tromey
  0 siblings, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2023-06-23 20:30 UTC (permalink / raw)
  To: Tom de Vries; +Cc: gdb-patches, Tom Tromey

>>>>> Tom de Vries <tdevries@suse.de> writes:

> The tables:
> - tui_border_kind_translate_ulcorner
> - tui_border_kind_translate_urcorner
> - tui_border_kind_translate_llcorner
> - tui_border_kind_translate_lrcorner
> are identical.

> Merge and rename to tui_border_kind_translate_corner.

Thanks for doing this.  Looks good.

Tom

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 4/4] [gdb/tui] Make translate return entry->value instead of entry
  2023-06-23 11:15 ` [PATCH 4/4] [gdb/tui] Make translate return entry->value instead of entry Tom de Vries
@ 2023-06-23 20:30   ` Tom Tromey
  0 siblings, 0 replies; 8+ messages in thread
From: Tom Tromey @ 2023-06-23 20:30 UTC (permalink / raw)
  To: Tom de Vries; +Cc: gdb-patches, Tom Tromey

>>>>> Tom de Vries <tdevries@suse.de> writes:

> The only use of "entry = translate (...)" is entry->value.
> Simplify using the function by returning entry->value instead.

Seems like a good cleanup to me.  Thank you.

Tom

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-06-23 20:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-23 11:15 [PATCH 1/4] [gdb/tui] Remove default entries in TUI translation tables Tom de Vries
2023-06-23 11:15 ` [PATCH 2/4] [gdb/tui] Introduce translate_acs Tom de Vries
2023-06-23 20:28   ` Tom Tromey
2023-06-23 11:15 ` [PATCH 3/4] [gdb/tui] Merge tui border-kind corner translation tables Tom de Vries
2023-06-23 20:30   ` Tom Tromey
2023-06-23 11:15 ` [PATCH 4/4] [gdb/tui] Make translate return entry->value instead of entry Tom de Vries
2023-06-23 20:30   ` Tom Tromey
2023-06-23 20:28 ` [PATCH 1/4] [gdb/tui] Remove default entries in TUI translation tables Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).