Skip to content

Commit

Permalink
Restore missing REG_NOTBOL.
Browse files Browse the repository at this point in the history
Reported by Victor <vico/tuta+io>.
  • Loading branch information
slewsys committed Feb 5, 2024
1 parent 50d0b40 commit 6bdea60
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 20 deletions.
40 changes: 21 additions & 19 deletions src/sub.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* sub.c: Substitution routines for the ed line editor.
*
* Copyright © 1993-2022 Andrew L. Moore, SlewSys Research
* Copyright © 1993-2024 Andrew L. Moore, SlewSys Research
*
* This file is part of ed.
*/
Expand Down Expand Up @@ -460,6 +460,11 @@ substitute_matching (const regex_t *re, const ed_line_node_t *lp,
int nil_prev;
int nil_next = 1;
int status;
#ifdef REG_STARTEND
int eflag = REG_STARTEND;
#else
int eflag = 0;
#endif

if (!(txt = get_buffer_line (lp, ed)))
return ERR;
Expand All @@ -482,18 +487,14 @@ substitute_matching (const regex_t *re, const ed_line_node_t *lp,
else if (!s_mod)
s_mod = 1;

#ifdef REG_STARTEND
for (*len = 0, eot = txt + lp->len, rm->rm_so = 0, rm->rm_eo = lp->len;
(!changed || (s_f & GSUB))
&& !regexec (re, txt, SE_MAX, rm, REG_STARTEND);
txt += j, rm->rm_so = 0, rm->rm_eo = eot - txt)
#else
#ifndef REG_STARTEND
if (ed->state->is_binary)
NUL_TO_NEWLINE (txt, lp->len);
for (*len = 0, eot = txt + lp->len;
(!changed || (s_f & GSUB)) && !regexec (re, txt, SE_MAX, rm, 0);
txt += j)
#endif /* !REG_STARTEND */
#endif
for (*len = 0, eot = txt + lp->len, rm->rm_so = 0, rm->rm_eo = lp->len;
(!changed || (s_f & GSUB))
&& !regexec (re, txt, SE_MAX, rm, eflag);
txt += j, rm->rm_so = 0, rm->rm_eo = eot - txt, eflag |= REG_NOTBOL)
{
i = rm->rm_so, j = rm->rm_eo;
nil_prev = nil_next, nil_next = !j;
Expand Down Expand Up @@ -583,18 +584,19 @@ count_matches (const regex_t *re, const char *txt, int len,
int matched_prev = 0;
int nul_prev;
int nul_next = 1;

#ifdef REG_STARTEND
for (eot = txt + len, rm->rm_so = 0, rm->rm_eo = len;
!regexec (re, txt, SE_MAX, rm, REG_STARTEND);
txt += off, rm->rm_so = 0, rm->rm_eo = eot - txt)
int eflag = REG_STARTEND;
#else
int eflag = 0;
#endif

#ifndef REG_STARTEND
if (buf->is_binary)
NUL_TO_NEWLINE (txt, len);
for (eot = txt + len;
!regexec (re, txt, SE_MAX, rm, 0);
txt += off)
#endif /* !REG_STARTEND */
#endif
for (eot = txt + len, rm->rm_so = 0, rm->rm_eo = len;
!regexec (re, txt, SE_MAX, rm, eflag);
txt += off, rm->rm_so = 0, rm->rm_eo = eot - txt, eflag |= REG_NOTBOL)
{
off = rm->rm_eo;
nul_prev = nul_next;
Expand Down
2 changes: 1 addition & 1 deletion testsuite/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ED_SCRIPTS_OK = \
a.t addr.t ascii.t bang1.t c1.t c2.t comment.t d.t delim.t \
e1.t e2.t e3.t e4.t e5.t g1.t g2.t g3.t g4.t g5.t i1.t i2.t \
j.t k.t m.t nl1.t nl2.t nl3.t nl4.t q2.t r1.t r2.t r3.t s1.t \
s2.t s3.t s4.t s5.t s6.t t1.t t2.t u.t v.t w.t
s2.t s3.t s4.t s5.t s6.t s7.t t1.t t2.t u.t v.t w.t

# Ed scripts tested for expected standard output.
ED_SCRIPTS_OK_SO = \
Expand Down
5 changes: 5 additions & 0 deletions testsuite/s7.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
line 1
line 2
line 3_5
line 4
line5
5 changes: 5 additions & 0 deletions testsuite/s7.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
_l!xine! 1
_l!xine! 2
_l!xine! 3_5!
_l!xine! 4
_l!xine!5
5 changes: 5 additions & 0 deletions testsuite/s7.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
g/./s/^[[:space:]]*/_/g\
s/^_*/\
/2\
s/_*/x/2\
s/8*/!/3g4

0 comments on commit 6bdea60

Please sign in to comment.