userdiff.c: use designated initializers for "struct userdiff_driver"
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
Feb 24, 2022 at 10:33 UTC
2dd75f123d959f185404451ce89c5158debde0bd
1 file changed
+22
-14
userdiff.c
+22
-14
@@ -7,12 +7,24 @@ static struct userdiff_driver *drivers;
7
static int ndrivers;
8
static int drivers_alloc;
9
10
-#define PATTERNS(name, pattern, word_regex) \
11
- { name, NULL, -1, { pattern, REG_EXTENDED }, \
12
- word_regex "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+" }
13
-#define IPATTERN(name, pattern, word_regex) \
14
- { name, NULL, -1, { pattern, REG_EXTENDED | REG_ICASE }, \
15
- word_regex "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+" }
10
+#define PATTERNS(lang, rx, wrx) { \
11
+ .name = lang, \
12
+ .binary = -1, \
13
+ .funcname = { \
14
+ .pattern = rx, \
15
+ .cflags = REG_EXTENDED, \
16
+ }, \
17
+ .word_regex = wrx "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+", \
18
+}
19
+#define IPATTERN(lang, rx, wrx) { \
20
+ .name = lang, \
21
+ .binary = -1, \
22
+ .funcname = { \
23
+ .pattern = rx, \
24
+ .cflags = REG_EXTENDED | REG_ICASE, \
25
+ }, \
26
+ .word_regex = wrx "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+", \
27
+}
28
29
/*
30
* Built-in drivers for various languages, sorted by their names
@@ -275,17 +287,13 @@ PATTERNS("tex", "^(\\\\((sub)*section|chapter|part)\\*{0,1}\\{.*)$",
287
#undef IPATTERN
288
289
static struct userdiff_driver driver_true = {
278
- "diff=true",
279
- NULL,
280
- 0,
281
- { NULL, 0 }
290
+ .name = "diff=true",
291
+ .binary = 0,
292
};
293
294
static struct userdiff_driver driver_false = {
285
- "!diff",
286
- NULL,
287
- 1,
288
- { NULL, 0 }
295
+ .name = "!diff",
296
+ .binary = 1,
297
};
298
299
struct find_by_namelen_data {