From d1e24f318523607c98dc6fbe5a06a5d9e5c87293 Mon Sep 17 00:00:00 2001 From: natano Date: Tue, 1 Mar 2016 20:57:35 +0000 Subject: Rectify line numbers for s/.// commands in ed-style diffs. When diff encounters a line that consists of a single dot, it emits two dots instead, stops the current command and emits a substitute command to replace the double dot with a single one. Then it restarts the (original) command if necessary and inserts further lines. This is done because a single dot on a line does have special meaning in ed. (It stops text insertion.) Following issues are fixed by this commit. - The line number for the substitute command should be the number of the most recently inserted line. diff instead uses the number of the first inserted line of the current hunk. The first character of that line is removed when applying the diff, while the superfluous dot is not. - The line number of the restarted command is not adjusted for the number of lines already inserted, resulting in the reordering of lines.. - When there is a bare dot in the replacement text of a change command, too many lines are deleted, because a second change command is emitted. An append command should be emitted instead, because the target lines have already been removed by the first change command. tweaks and ok stefan@ --- usr.bin/diff/diffreg.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'usr.bin/diff/diffreg.c') diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c index a6194827ac1..35d61c349cb 100644 --- a/usr.bin/diff/diffreg.c +++ b/usr.bin/diff/diffreg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: diffreg.c,v 1.90 2015/10/26 12:52:27 tedu Exp $ */ +/* $OpenBSD: diffreg.c,v 1.91 2016/03/01 20:57:35 natano Exp $ */ /* * Copyright (C) Caldera International Inc. 2001-2002. @@ -1075,8 +1075,9 @@ proceed: * back and restart where we left off. */ diff_output(".\n"); - diff_output("%ds/.//\n", a); - a += i; + diff_output("%ds/.//\n", a + i - 1); + b = a + i - 1; + a = b + 1; c += i; goto restart; } -- cgit v1.2.3-59-g8ed1b