All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Martin Ågren" <martin.agren@gmail.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH 08/12] userdiff.c: use designated initializers for "struct userdiff_driver"
Date: Thu, 24 Feb 2022 10:33:03 +0100	[thread overview]
Message-ID: <patch-08.12-9becff4bae7-20220224T092805Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-00.12-00000000000-20220224T092805Z-avarab@gmail.com>

Change the "struct userdiff_driver" assignmentns to use designated
initializers, but let's keep the PATTERNS() and IPATTERN() convenience
macros to avoid churn, but have them defined in terms of designated
initializers.

For the "driver_true" and "driver_false" let's have the compiler
implicitly initialize most of the fields, but let's leave a redundant
".binary = 0" for "driver_true" to make it obvious that it's the
opposite of the the ".binary = 1" for "driver_false".

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 userdiff.c | 36 ++++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/userdiff.c b/userdiff.c
index 8578cb0d12e..2d9eb99bf28 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -7,12 +7,24 @@ static struct userdiff_driver *drivers;
 static int ndrivers;
 static int drivers_alloc;
 
-#define PATTERNS(name, pattern, word_regex)			\
-	{ name, NULL, -1, { pattern, REG_EXTENDED },		\
-	  word_regex "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+" }
-#define IPATTERN(name, pattern, word_regex)			\
-	{ name, NULL, -1, { pattern, REG_EXTENDED | REG_ICASE }, \
-	  word_regex "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+" }
+#define PATTERNS(lang, rx, wrx) { \
+	.name = lang, \
+	.binary = -1, \
+	.funcname = { \
+		.pattern = rx, \
+		.cflags = REG_EXTENDED, \
+	}, \
+	.word_regex = wrx "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+", \
+}
+#define IPATTERN(lang, rx, wrx) { \
+	.name = lang, \
+	.binary = -1, \
+	.funcname = { \
+		.pattern = rx, \
+		.cflags = REG_EXTENDED | REG_ICASE, \
+	}, \
+	.word_regex = wrx "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+", \
+}
 
 /*
  * Built-in drivers for various languages, sorted by their names
@@ -275,17 +287,13 @@ PATTERNS("tex", "^(\\\\((sub)*section|chapter|part)\\*{0,1}\\{.*)$",
 #undef IPATTERN
 
 static struct userdiff_driver driver_true = {
-	"diff=true",
-	NULL,
-	0,
-	{ NULL, 0 }
+	.name = "diff=true",
+	.binary = 0,
 };
 
 static struct userdiff_driver driver_false = {
-	"!diff",
-	NULL,
-	1,
-	{ NULL, 0 }
+	.name = "!diff",
+	.binary = 1,
 };
 
 struct find_by_namelen_data {
-- 
2.35.1.1157.g524e2d5a0db


  parent reply	other threads:[~2022-02-24  9:33 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-24  9:32 [PATCH 00/12] c99: use more designated initializers Ævar Arnfjörð Bjarmason
2022-02-24  9:32 ` [PATCH 01/12] imap-send.c: use designated initializers for "struct imap_server_conf" Ævar Arnfjörð Bjarmason
2022-02-24  9:32 ` [PATCH 02/12] refs: use designated initializers for "struct ref_storage_be" Ævar Arnfjörð Bjarmason
2022-02-24  9:32 ` [PATCH 03/12] refs: use designated initializers for "struct ref_iterator_vtable" Ævar Arnfjörð Bjarmason
2022-02-24  9:32 ` [PATCH 04/12] trace2: use designated initializers for "struct tr2_tgt" Ævar Arnfjörð Bjarmason
2022-02-24  9:33 ` [PATCH 05/12] trace2: use designated initializers for "struct tr2_dst" Ævar Arnfjörð Bjarmason
2022-02-24  9:33 ` [PATCH 06/12] object-file: use designated initializers for "struct git_hash_algo" Ævar Arnfjörð Bjarmason
2022-02-24  9:33 ` [PATCH 07/12] archive-*.c: use designated initializers for "struct archiver" Ævar Arnfjörð Bjarmason
2022-02-24  9:33 ` Ævar Arnfjörð Bjarmason [this message]
2022-02-24  9:33 ` [PATCH 09/12] convert.c: use designated initializers for "struct stream_filter*" Ævar Arnfjörð Bjarmason
2022-02-24  9:33 ` [PATCH 10/12] refspec.c: use designated initializers for "struct refspec_item" Ævar Arnfjörð Bjarmason
2022-02-24  9:33 ` [PATCH 11/12] misc *.c: use designated initializers for struct assignments Ævar Arnfjörð Bjarmason
2022-02-24  9:33 ` [PATCH 12/12] misc *.c: use designated initializers for "partial" " Ævar Arnfjörð Bjarmason
2022-02-24 19:22 ` [PATCH 00/12] c99: use more designated initializers Johannes Schindelin
2022-02-24 19:53   ` Junio C Hamano
2022-02-24 22:43     ` Ævar Arnfjörð Bjarmason
2022-02-25  0:03 ` Junio C Hamano

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=patch-08.12-9becff4bae7-20220224T092805Z-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=martin.agren@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.