diff options
author | Michał Kiedrowicz <michal.kiedrowicz@gmail.com> | 2011-05-09 23:52:04 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-05-09 16:28:53 -0700 |
commit | a30c148aa7ec6583dbdb38fa6601df3cf4f5a660 (patch) | |
tree | bf6742c9ce65a2240649013a351e3b1ca486ff23 /grep.c | |
parent | 8997da3820a0f55d156f43f3bb71856580df160d (diff) | |
download | git-a30c148aa7ec6583dbdb38fa6601df3cf4f5a660.tar.gz |
grep: Extract compile_regexp_failed() from compile_regexp()
This simplifies compile_regexp() a little and allows re-using error
handling code.
Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'grep.c')
-rw-r--r-- | grep.c | 25 |
1 files changed, 16 insertions, 9 deletions
@@ -59,6 +59,21 @@ struct grep_opt *grep_opt_dup(const struct grep_opt *opt) return ret; } +static NORETURN void compile_regexp_failed(const struct grep_pat *p, + const char *error) +{ + char where[1024]; + + if (p->no) + sprintf(where, "In '%s' at %d, ", p->origin, p->no); + else if (p->origin) + sprintf(where, "%s, ", p->origin); + else + where[0] = 0; + + die("%s'%s': %s", where, p->pattern, error); +} + static void compile_regexp(struct grep_pat *p, struct grep_opt *opt) { int err; @@ -73,17 +88,9 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt) err = regcomp(&p->regexp, p->pattern, opt->regflags); if (err) { char errbuf[1024]; - char where[1024]; - if (p->no) - sprintf(where, "In '%s' at %d, ", - p->origin, p->no); - else if (p->origin) - sprintf(where, "%s, ", p->origin); - else - where[0] = 0; regerror(err, &p->regexp, errbuf, 1024); regfree(&p->regexp); - die("%s'%s': %s", where, p->pattern, errbuf); + compile_regexp_failed(p, errbuf); } } |