2014-09-14 09:40:45 +02:00
|
|
|
#include "git-compat-util.h"
|
2016-06-25 07:22:29 +02:00
|
|
|
#include "gettext.h"
|
|
|
|
|
|
|
|
struct reg_flag {
|
|
|
|
const char *name;
|
|
|
|
int flag;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct reg_flag reg_flags[] = {
|
|
|
|
{ "EXTENDED", REG_EXTENDED },
|
|
|
|
{ "NEWLINE", REG_NEWLINE },
|
|
|
|
{ "ICASE", REG_ICASE },
|
|
|
|
{ "NOTBOL", REG_NOTBOL },
|
|
|
|
#ifdef REG_STARTEND
|
|
|
|
{ "STARTEND", REG_STARTEND },
|
|
|
|
#endif
|
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
2012-09-01 19:46:54 +02:00
|
|
|
|
2016-06-25 07:22:28 +02:00
|
|
|
static int test_regex_bug(void)
|
2012-09-01 19:46:54 +02:00
|
|
|
{
|
|
|
|
char *pat = "[^={} \t]+";
|
|
|
|
char *str = "={}\nfred";
|
|
|
|
regex_t r;
|
|
|
|
regmatch_t m[1];
|
|
|
|
|
|
|
|
if (regcomp(&r, pat, REG_EXTENDED | REG_NEWLINE))
|
|
|
|
die("failed regcomp() for pattern '%s'", pat);
|
|
|
|
if (regexec(&r, str, 1, m, 0))
|
|
|
|
die("no match of pattern '%s' to string '%s'", pat, str);
|
|
|
|
|
|
|
|
/* http://sourceware.org/bugzilla/show_bug.cgi?id=3957 */
|
|
|
|
if (m[0].rm_so == 3) /* matches '\n' when it should not */
|
|
|
|
die("regex bug confirmed: re-build git with NO_REGEX=1");
|
|
|
|
|
2016-06-25 07:22:28 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2016-06-25 07:22:29 +02:00
|
|
|
const char *pat;
|
|
|
|
const char *str;
|
|
|
|
int flags = 0;
|
|
|
|
regex_t r;
|
|
|
|
regmatch_t m[1];
|
|
|
|
|
2016-06-25 07:22:28 +02:00
|
|
|
if (argc == 2 && !strcmp(argv[1], "--bug"))
|
|
|
|
return test_regex_bug();
|
2016-06-25 07:22:29 +02:00
|
|
|
else if (argc < 3)
|
|
|
|
usage("test-regex --bug\n"
|
|
|
|
"test-regex <pattern> <string> [<options>]");
|
|
|
|
|
|
|
|
argv++;
|
|
|
|
pat = *argv++;
|
|
|
|
str = *argv++;
|
|
|
|
while (*argv) {
|
|
|
|
struct reg_flag *rf;
|
|
|
|
for (rf = reg_flags; rf->name; rf++)
|
|
|
|
if (!strcmp(*argv, rf->name)) {
|
|
|
|
flags |= rf->flag;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!rf->name)
|
|
|
|
die("do not recognize %s", *argv);
|
|
|
|
argv++;
|
|
|
|
}
|
|
|
|
git_setup_gettext();
|
|
|
|
|
|
|
|
if (regcomp(&r, pat, flags))
|
|
|
|
die("failed regcomp() for pattern '%s'", pat);
|
|
|
|
if (regexec(&r, str, 1, m, 0))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
2012-09-01 19:46:54 +02:00
|
|
|
}
|