mirror of
git://git.suckless.org/sbase
synced 2025-01-02 21:12:15 +00:00
ed: Handle correctly lines in substitutions
The s command can apply a replace pattern with embedded newlines which modifies the line/index assignament. Using a range in the address fail because afther the call to subline() the next line has to be searched based in the index because the replace could insert newlines.
This commit is contained in:
parent
e24228e062
commit
2732217a40
8
TODO
8
TODO
@ -50,14 +50,6 @@ ed
|
|||||||
line
|
line
|
||||||
.
|
.
|
||||||
1g/^$/p
|
1g/^$/p
|
||||||
* cat <<EOF | ed
|
|
||||||
i
|
|
||||||
foobar1
|
|
||||||
foobar2
|
|
||||||
.
|
|
||||||
1,2s/foo/&\
|
|
||||||
&/
|
|
||||||
,n
|
|
||||||
|
|
||||||
* Editing huge files doesn't work well.
|
* Editing huge files doesn't work well.
|
||||||
|
|
||||||
|
18
ed.c
18
ed.c
@ -1226,11 +1226,23 @@ subline(int num, int nth)
|
|||||||
static void
|
static void
|
||||||
subst(int nth)
|
subst(int nth)
|
||||||
{
|
{
|
||||||
int i;
|
int i, line, next;
|
||||||
|
|
||||||
for (i = line1; i <= line2; ++i) {
|
line = line1;
|
||||||
|
for (i = 0; i < line2 - line1 + 1; i++) {
|
||||||
chksignals();
|
chksignals();
|
||||||
subline(i, nth);
|
|
||||||
|
next = getindex(nextln(line));
|
||||||
|
subline(line, nth);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The substitution command can add lines, so
|
||||||
|
* we have to skip lines until we find the
|
||||||
|
* index that we saved before the substitution
|
||||||
|
*/
|
||||||
|
do
|
||||||
|
line = nextln(line);
|
||||||
|
while (getindex(line) != next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user