summaryrefslogtreecommitdiff
path: root/src/ed.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2004-07-21 08:58:38 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2004-07-21 08:58:38 +0000
commit0d349232b335031c4ef8d8d07e2c712cf1f9ba3d (patch)
tree57422bdf52e56633575f05c1169dac093e2f6e13 /src/ed.c
parent61d0b7e9bd56a3999d0697a5fa2e87c4a2d170d2 (diff)
downloaddiffutils-0d349232b335031c4ef8d8d07e2c712cf1f9ba3d.tar.gz
(print_ed_hunk): Optimize the case where an insert's
last line is a single-dot line.
Diffstat (limited to 'src/ed.c')
-rw-r--r--src/ed.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/ed.c b/src/ed.c
index c90ed78..3c60d00 100644
--- a/src/ed.c
+++ b/src/ed.c
@@ -61,27 +61,37 @@ print_ed_hunk (struct change *hunk)
if (changes != OLD)
{
lin i;
+ bool insert_mode = true;
+
for (i = f1; i <= l1; i++)
{
+ if (!insert_mode)
+ {
+ fprintf (outfile, "a\n");
+ insert_mode = true;
+ }
if (files[1].linbuf[i][0] == '.' && files[1].linbuf[i][1] == '\n')
{
/* The file's line is just a dot, and it would exit
insert mode. Precede the dot with another dot, exit
- insert mode, remove the extra dot, and then resume
- insert mode. */
- fprintf (outfile, "..\n.\ns/.//\na\n");
+ insert mode and remove the extra dot. */
+ fprintf (outfile, "..\n.\ns/.//\n");
+ insert_mode = false;
}
else
print_1_line ("", &files[1].linbuf[i]);
}
- fprintf (outfile, ".\n");
+ if (insert_mode)
+ fprintf (outfile, ".\n");
}
}
/* Print change script in the style of ed commands,
but print the changes in the order they appear in the input files,
- which means that the commands are not truly useful with ed. */
+ which means that the commands are not truly useful with ed.
+ Because of the issue with lines containing just a dot, the output
+ is not even parseable. */
void
pr_forward_ed_script (struct change *script)