diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2001-09-18 13:42:38 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2001-09-18 13:42:38 +0000 |
commit | 5f14ea7930a7bd0063d48e974bb7ec6bee50109d (patch) | |
tree | 5d62e1f9828278f3562b565473c03565fec0ca7d /usr.bin/m4 | |
parent | 982c37e68b050a3e8217f85d986f1af8f663dd6f (diff) |
Fix regexp substitution.
- `vi rule' needs a pointer, because we must distinguish matches as the
string position changes.
- ^ should match only at beginning of line.
- ^ should match at all beginnings of line.
Diffstat (limited to 'usr.bin/m4')
-rw-r--r-- | usr.bin/m4/gnum4.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/usr.bin/m4/gnum4.c b/usr.bin/m4/gnum4.c index 823892d986e..1deb32f1b68 100644 --- a/usr.bin/m4/gnum4.c +++ b/usr.bin/m4/gnum4.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gnum4.c,v 1.10 2001/09/16 21:08:55 espie Exp $ */ +/* $OpenBSD: gnum4.c,v 1.11 2001/09/18 13:42:37 espie Exp $ */ /* * Copyright (c) 1999 Marc Espie @@ -336,23 +336,26 @@ do_subst(string, re, replace, pm) regmatch_t *pm; { int error; - regoff_t last_match = -1; + int flags = 0; + const char *last_match = NULL; - while ((error = regexec(re, string, re->re_nsub+1, pm, 0)) == 0) { + while ((error = regexec(re, string, re->re_nsub+1, pm, flags)) == 0) { + flags = REG_NOTBOL; /* NULL length matches are special... We use the `vi-mode' * rule: don't allow a NULL-match at the last match * position. */ - if (pm[0].rm_so == pm[0].rm_eo && pm[0].rm_so == last_match) { + if (pm[0].rm_so == pm[0].rm_eo && + string + pm[0].rm_so == last_match) { if (*string == '\0') return; addchar(*string); string++; continue; } - last_match = pm[0].rm_so; - addchars(string, last_match); + last_match = string + pm[0].rm_so; + addchars(string, pm[0].rm_so); add_replace(string, re, replace, pm); string += pm[0].rm_eo; } @@ -444,7 +447,7 @@ dopatsubst(argv, argc) return; } error = regcomp(&re, mimic_gnu ? twiddle(argv[3]) : argv[3], - REG_EXTENDED); + REG_NEWLINE | REG_EXTENDED); if (error != 0) exit_regerror(error, &re); |