summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8997da3)
raw | patch | inline | side by side (parent: 8997da3)
author | Michał Kiedrowicz <michal.kiedrowicz@gmail.com> | |
Mon, 9 May 2011 21:52:04 +0000 (23:52 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 9 May 2011 23:28:53 +0000 (16:28 -0700) |
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>
handling code.
Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
grep.c | patch | blob | history |
index 250462e0c0dd09c1047273dd8f0470bcb2db2ccd..870d10cf6969d8b78bb6a2d2ea5262c1ddef0f62 100644 (file)
--- a/grep.c
+++ b/grep.c
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;
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);
}
}