diff options
Diffstat (limited to 'usr.bin/m4/gnum4.c')
-rw-r--r-- | usr.bin/m4/gnum4.c | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/usr.bin/m4/gnum4.c b/usr.bin/m4/gnum4.c index b6a64134721..612c21c9617 100644 --- a/usr.bin/m4/gnum4.c +++ b/usr.bin/m4/gnum4.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gnum4.c,v 1.45 2014/05/12 19:11:19 espie Exp $ */ +/* $OpenBSD: gnum4.c,v 1.46 2014/07/10 14:12:31 espie Exp $ */ /* * Copyright (c) 1999 Marc Espie @@ -194,10 +194,12 @@ static void addchars(const char *, size_t); static void addchar(int); static char *twiddle(const char *); static char *getstring(void); -static void exit_regerror(int, regex_t *); -static void do_subst(const char *, regex_t *, const char *, regmatch_t *); -static void do_regexpindex(const char *, regex_t *, regmatch_t *); -static void do_regexp(const char *, regex_t *, const char *, regmatch_t *); +static void exit_regerror(int, regex_t *, const char *); +static void do_subst(const char *, regex_t *, const char *, const char *, + regmatch_t *); +static void do_regexpindex(const char *, regex_t *, const char *, regmatch_t *); +static void do_regexp(const char *, regex_t *, const char *, const char *, + regmatch_t *); static void add_sub(int, const char *, regex_t *, regmatch_t *); static void add_replace(const char *, regex_t *, const char *, regmatch_t *); #define addconstantstring(s) addchars((s), sizeof(s)-1) @@ -241,7 +243,7 @@ getstring() static void -exit_regerror(int er, regex_t *re) +exit_regerror(int er, regex_t *re, const char *source) { size_t errlen; char *errbuf; @@ -250,7 +252,7 @@ exit_regerror(int er, regex_t *re) errbuf = xalloc(errlen, "malloc in regerror: %lu", (unsigned long)errlen); regerror(er, re, errbuf, errlen); - m4errx(1, "regular expression error: %s.", errbuf); + m4errx(1, "regular expression error in %s: %s.", source, errbuf); } static void @@ -304,7 +306,8 @@ add_replace(const char *string, regex_t *re, const char *replace, regmatch_t *pm } static void -do_subst(const char *string, regex_t *re, const char *replace, regmatch_t *pm) +do_subst(const char *string, regex_t *re, const char *source, + const char *replace, regmatch_t *pm) { int error; int flags = 0; @@ -339,12 +342,13 @@ do_subst(const char *string, regex_t *re, const char *replace, regmatch_t *pm) string += pm[0].rm_eo; } if (error != REG_NOMATCH) - exit_regerror(error, re); + exit_regerror(error, re, source); pbstr(string); } static void -do_regexp(const char *string, regex_t *re, const char *replace, regmatch_t *pm) +do_regexp(const char *string, regex_t *re, const char *source, + const char *replace, regmatch_t *pm) { int error; @@ -356,12 +360,13 @@ do_regexp(const char *string, regex_t *re, const char *replace, regmatch_t *pm) case REG_NOMATCH: break; default: - exit_regerror(error, re); + exit_regerror(error, re, source); } } static void -do_regexpindex(const char *string, regex_t *re, regmatch_t *pm) +do_regexpindex(const char *string, regex_t *re, const char *source, + regmatch_t *pm) { int error; @@ -373,7 +378,7 @@ do_regexpindex(const char *string, regex_t *re, regmatch_t *pm) pbnum(-1); break; default: - exit_regerror(error, re); + exit_regerror(error, re, source); } } @@ -457,6 +462,7 @@ dopatsubst(const char *argv[], int argc) regex_t re; regmatch_t *pmatch; int mode = REG_EXTENDED; + const char *source; size_t l = strlen(argv[3]); if (!mimic_gnu || @@ -464,14 +470,14 @@ dopatsubst(const char *argv[], int argc) (l > 0 && argv[3][l-1] == '$')) mode |= REG_NEWLINE; - error = regcomp(&re, mimic_gnu ? twiddle(argv[3]) : argv[3], - mode); + source = mimic_gnu ? twiddle(argv[3]) : argv[3]; + error = regcomp(&re, source, mode); if (error != 0) - exit_regerror(error, &re); + exit_regerror(error, &re, source); pmatch = xreallocarray(NULL, re.re_nsub+1, sizeof(regmatch_t), NULL); - do_subst(argv[2], &re, + do_subst(argv[2], &re, source, argc > 4 && argv[4] != NULL ? argv[4] : "", pmatch); free(pmatch); regfree(&re); @@ -485,6 +491,7 @@ doregexp(const char *argv[], int argc) int error; regex_t re; regmatch_t *pmatch; + const char *source; if (argc <= 3) { warnx("Too few arguments to regexp"); @@ -497,16 +504,16 @@ doregexp(const char *argv[], int argc) else pbstr(argv[4]); } - error = regcomp(&re, mimic_gnu ? twiddle(argv[3]) : argv[3], - REG_EXTENDED|REG_NEWLINE); + source = mimic_gnu ? twiddle(argv[3]) : argv[3]; + error = regcomp(&re, source, REG_EXTENDED|REG_NEWLINE); if (error != 0) - exit_regerror(error, &re); + exit_regerror(error, &re, source); pmatch = xreallocarray(NULL, re.re_nsub+1, sizeof(regmatch_t), NULL); if (argc == 4 || argv[4] == NULL) - do_regexpindex(argv[2], &re, pmatch); + do_regexpindex(argv[2], &re, source, pmatch); else - do_regexp(argv[2], &re, argv[4], pmatch); + do_regexp(argv[2], &re, source, argv[4], pmatch); free(pmatch); regfree(&re); } |