From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 8NouBhADWWRWyQIAWB0awg (envelope-from ) for ; Mon, 08 May 2023 10:11:28 -0400 Received: by simark.ca (Postfix, from userid 112) id 171B31E11D; Mon, 8 May 2023 10:11:28 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=uQS/G/pJ; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id A635D1E114 for ; Mon, 8 May 2023 10:11:27 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5B3883857017 for ; Mon, 8 May 2023 14:11:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5B3883857017 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1683555087; bh=SNDKwZTgtkymZ5Cr3+lTjHtTu7FGMYUuCEmdUzYchlw=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=uQS/G/pJ/Ssi3osIq6biwnnDaGT31ETTkJCriDoUhMFMfB8bF7gGVv+++0Z88fzOS LTmVMLEQPvL4itrtTj8rOqIZvrPhQsf7r9ZukK+aon8as2o6O68HHLQA6vP+xX1BKT kUnpt7/2wwxlej9+GOe/pizLOMTVQQrmwED71ysA= Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 0F1013858C30 for ; Mon, 8 May 2023 14:10:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0F1013858C30 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 454E31FF4A; Mon, 8 May 2023 14:10:39 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id EC3CD1346B; Mon, 8 May 2023 14:10:38 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id kExSNd4CWWSpAwAAMHmgww (envelope-from ); Mon, 08 May 2023 14:10:38 +0000 To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 1/3] [gdb/tui] Make tui_update_variables more readable Date: Mon, 8 May 2023 16:10:34 +0200 Message-Id: <20230508141036.22723-2-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230508141036.22723-1-tdevries@suse.de> References: <20230508141036.22723-1-tdevries@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Tom de Vries via Gdb-patches Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" 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