On Sun, Feb 21, 2016 at 07:04:27PM +0100, Martin Natano wrote:
> The expected order of lines would be, x, y, z but patch produces y, z, x
> instead. The first line is inserted at the correct position, but then
> the other lines are inserted before the first one. The following diff
> solves that problem by retaining the logic for the first line, but then
> switch to append mode to insert the remaining lines after that one.
Completely agree with the rational, the issue can be triggered with
'i'nsert commands, too. Fixing 'c' (which becomes 'i' eventually)
at that position is the right spot.
As discussed with Martin, this diff does the same, but merges the
very duplicated looking FSM_A/FSM_I code. If nobody objects, I'll use
this one.
And thanks a lot Martin for spotting this.
Tobias
Index: ed.c
===================================================================
RCS file: /cvs/src/usr.bin/patch/ed.c,v
retrieving revision 1.1
diff -u -p -u -p -r1.1 ed.c
--- ed.c 16 Oct 2015 07:33:47 -0000 1.1
+++ ed.c 21 Feb 2016 18:23:10 -0000
@@ -121,23 +121,16 @@ do_ed_script(void)
continue;
}
- if (fsm == FSM_A) {
- nline = create_line(linepos);
- if (cline == NULL)
- LIST_INSERT_HEAD(&head, nline, entries);
- else
- LIST_INSERT_AFTER(cline, nline, entries);
- cline = nline;
- line_count++;
- } else if (fsm == FSM_I) {
- nline = create_line(linepos);
- if (cline == NULL) {
- LIST_INSERT_HEAD(&head, nline, entries);
- cline = nline;
- } else
- LIST_INSERT_BEFORE(cline, nline, entries);
- line_count++;
- }
+ nline = create_line(linepos);
+ if (cline == NULL)
+ LIST_INSERT_HEAD(&head, nline, entries);
+ else if (fsm == FSM_A)
+ LIST_INSERT_AFTER(cline, nline, entries);
+ else
+ LIST_INSERT_BEFORE(cline, nline, entries);
+ cline = nline;
+ line_count++;
+ fsm = FSM_A;
}
next_intuit_at(linepos, p_input_line);