public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 1/3] [gdb/tui] Make tui_update_variables more readable
Date: Mon,  8 May 2023 16:10:34 +0200	[thread overview]
Message-ID: <20230508141036.22723-2-tdevries@suse.de> (raw)
In-Reply-To: <20230508141036.22723-1-tdevries@suse.de>

Make tui_update_variables more readable by factoring out two new helper
functions, set_border_attrs and set_border_kind_item.

This makes the code also more regular, and consequently we no longer need the
comment:
...
  /* If one corner changes, all characters are changed.
     Only check the first one.  */
...

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

diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index 7eac03f47a1..cf4cb920524 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -274,6 +274,40 @@ translate (const char *name, struct tui_translate *table)
   return table;
 }
 
+/* Helper function for tui_update_variables.  SET *LVAL to
+   translate (KEY, DICT)->value, and set *LVAL_CHANGED to true if *LVAL
+   changed.  */
+
+static void
+set_border_attrs (int *lval, const char *key, struct tui_translate *dict,
+		  bool *lval_changed)
+{
+  struct tui_translate *entry = translate (key, dict);
+
+  if (*lval != (chtype) entry->value)
+    {
+      *lval = entry->value;
+      *lval_changed = true;
+    }
+}
+
+/* Helper function for tui_update_variables.  SET *LVAL to
+   translate (KEY, DICT)->value, and set *LVAL_CHANGED to true if *LVAL
+   changed.  If translate (KEY, DICT)->value is negative, use ACS instead.  */
+
+static void
+set_border_kind_item (chtype *lval, const char *key,
+		      struct tui_translate *dict, int acs, bool *lval_changed)
+{
+  struct tui_translate *entry = translate (key, dict);
+
+  if (*lval != (chtype) entry->value)
+    {
+      *lval = (entry->value < 0) ? acs : entry->value;
+      *lval_changed = true;
+    }
+}
+
 /* Update the tui internal configuration according to gdb settings.
    Returns 1 if the configuration has changed and the screen should
    be redrawn.  */
@@ -281,44 +315,39 @@ bool
 tui_update_variables ()
 {
   bool need_redraw = false;
-  struct tui_translate *entry;
 
-  entry = translate (tui_border_mode, tui_border_mode_translate);
-  if (tui_border_attrs != entry->value)
-    {
-      tui_border_attrs = entry->value;
-      need_redraw = true;
-    }
-  entry = translate (tui_active_border_mode, tui_border_mode_translate);
-  if (tui_active_border_attrs != entry->value)
-    {
-      tui_active_border_attrs = entry->value;
-      need_redraw = true;
-    }
+  set_border_attrs (&tui_border_attrs, tui_border_mode,
+		    tui_border_mode_translate, &need_redraw);
 
-  /* 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);
-  if (tui_border_lrcorner != (chtype) entry->value)
-    {
-      tui_border_lrcorner = (entry->value < 0) ? ACS_LRCORNER : entry->value;
-      need_redraw = true;
-    }
-  entry = translate (tui_border_kind, tui_border_kind_translate_llcorner);
-  tui_border_llcorner = (entry->value < 0) ? ACS_LLCORNER : entry->value;
+  set_border_attrs (&tui_active_border_attrs, tui_active_border_mode,
+		    tui_border_mode_translate, &need_redraw);
+
+  /* The ACS characters are determined at run time by curses terminal
+     management.  */
+
+  set_border_kind_item (&tui_border_lrcorner, tui_border_kind,
+			tui_border_kind_translate_lrcorner, ACS_LRCORNER,
+			&need_redraw);
+
+  set_border_kind_item (&tui_border_llcorner, tui_border_kind,
+			tui_border_kind_translate_llcorner, ACS_LLCORNER,
+			&need_redraw);
 
-  entry = translate (tui_border_kind, tui_border_kind_translate_ulcorner);
-  tui_border_ulcorner = (entry->value < 0) ? ACS_ULCORNER : entry->value;
+  set_border_kind_item (&tui_border_ulcorner, tui_border_kind,
+			tui_border_kind_translate_ulcorner, ACS_ULCORNER,
+			&need_redraw);
 
-  entry = translate (tui_border_kind, tui_border_kind_translate_urcorner);
-  tui_border_urcorner = (entry->value < 0) ? ACS_URCORNER : entry->value;
+  set_border_kind_item (&tui_border_urcorner, tui_border_kind,
+			tui_border_kind_translate_urcorner, ACS_URCORNER,
+			&need_redraw);
 
-  entry = translate (tui_border_kind, tui_border_kind_translate_hline);
-  tui_border_hline = (entry->value < 0) ? ACS_HLINE : entry->value;
+  set_border_kind_item (&tui_border_hline, tui_border_kind,
+			tui_border_kind_translate_hline, ACS_HLINE,
+			&need_redraw);
 
-  entry = translate (tui_border_kind, tui_border_kind_translate_vline);
-  tui_border_vline = (entry->value < 0) ? ACS_VLINE : entry->value;
+  set_border_kind_item (&tui_border_vline, tui_border_kind,
+			tui_border_kind_translate_vline, ACS_VLINE,
+			&need_redraw);
 
   return need_redraw;
 }
-- 
2.35.3


  reply	other threads:[~2023-05-08 14:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-08 14:10 [PATCH 0/3] [gdb/tui] Add tui border-kind active-ascii Tom de Vries
2023-05-08 14:10 ` Tom de Vries [this message]
2023-12-15 19:48   ` [PATCH 1/3] [gdb/tui] Make tui_update_variables more readable Tom Tromey
2023-05-08 14:10 ` [PATCH 2/3] [gdb/tui] Fix buglet in set_border_kind_item Tom de Vries
2023-05-22 14:47   ` [pushed] [gdb/tui] Fix buglet in tui_update_variables Tom de Vries
2023-05-08 14:10 ` [PATCH 3/3] [gdb/tui] Add tui border-kind active-ascii Tom de Vries
2023-12-15 19:50   ` Tom Tromey
2023-12-15 20:04     ` Eli Zaretskii

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=20230508141036.22723-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).