From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 2/4] [gdb/tui] Introduce translate_acs
Date: Fri, 23 Jun 2023 13:15:34 +0200 [thread overview]
Message-ID: <20230623111536.1623-2-tdevries@suse.de> (raw)
In-Reply-To: <20230623111536.1623-1-tdevries@suse.de>
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
next prev parent reply other threads:[~2023-06-23 11:15 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2023-06-23 20:28 ` [PATCH 2/4] [gdb/tui] Introduce translate_acs 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230623111536.1623-2-tdevries@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).