9 static struct reg_flag reg_flags
[] = {
10 { "EXTENDED", REG_EXTENDED
},
11 { "NEWLINE", REG_NEWLINE
},
12 { "ICASE", REG_ICASE
},
13 { "NOTBOL", REG_NOTBOL
},
14 { "NOTEOL", REG_NOTEOL
},
16 { "STARTEND", REG_STARTEND
},
21 static int test_regex_bug(void)
23 char *pat
= "[^={} \t]+";
24 char *str
= "={}\nfred";
28 if (regcomp(&r
, pat
, REG_EXTENDED
| REG_NEWLINE
))
29 die("failed regcomp() for pattern '%s'", pat
);
30 if (regexec(&r
, str
, 1, m
, 0))
31 die("no match of pattern '%s' to string '%s'", pat
, str
);
33 /* http://sourceware.org/bugzilla/show_bug.cgi?id=3957 */
34 if (m
[0].rm_so
== 3) /* matches '\n' when it should not */
35 die("regex bug confirmed: re-build git with NO_REGEX=1");
41 int cmd__regex(int argc
, const char **argv
)
45 int ret
, silent
= 0, flags
= 0;
56 if (!strcmp(*argv
, "--bug")) {
58 return test_regex_bug();
62 if (!strcmp(*argv
, "--silent")) {
77 for (rf
= reg_flags
; rf
->name
; rf
++)
78 if (!strcmp(*argv
, rf
->name
)) {
83 die("do not recognize flag %s", *argv
);
89 ret
= regcomp(&r
, pat
, flags
);
94 regerror(ret
, &r
, errbuf
, sizeof(errbuf
));
95 die("failed regcomp() for pattern '%s' (%s)", pat
, errbuf
);
100 ret
= regexec(&r
, str
, 1, m
, 0);
102 if (silent
|| ret
== REG_NOMATCH
)
105 regerror(ret
, &r
, errbuf
, sizeof(errbuf
));
106 die("failed regexec() for subject '%s' (%s)", str
, errbuf
);
113 usage("\ttest-tool regex --bug\n"
114 "\ttest-tool regex [--silent] <pattern>\n"
115 "\ttest-tool regex [--silent] <pattern> <string> [<options>]");