Skip to content

Commit 2dd75f1

Browse files
avargitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4fbedd4 commit 2dd75f1

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

userdiff.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,24 @@ static struct userdiff_driver *drivers;
77
static int ndrivers;
88
static int drivers_alloc;
99

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+
}
1628

1729
/*
1830
* Built-in drivers for various languages, sorted by their names
@@ -275,17 +287,13 @@ PATTERNS("tex", "^(\\\\((sub)*section|chapter|part)\\*{0,1}\\{.*)$",
275287
#undef IPATTERN
276288

277289
static struct userdiff_driver driver_true = {
278-
"diff=true",
279-
NULL,
280-
0,
281-
{ NULL, 0 }
290+
.name = "diff=true",
291+
.binary = 0,
282292
};
283293

284294
static struct userdiff_driver driver_false = {
285-
"!diff",
286-
NULL,
287-
1,
288-
{ NULL, 0 }
295+
.name = "!diff",
296+
.binary = 1,
289297
};
290298

291299
struct find_by_namelen_data {

0 commit comments

Comments
 (0)