2 * wiggle - apply rejected patches
4 * Copyright (C) 2005 Neil Brown <neilb@cse.unsw.edu.au>
5 * Copyright (C) 2010-2011 Neil Brown <neilb@suse.de>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 * Email: <neilb@suse.de>
27 * vpatch - visual front end for wiggle - aka Browse mode.
29 * "files" display, lists all files with statistics
30 * - can hide various lines including subdirectories
31 * and files without wiggles or conflicts
32 * "merge" display shows various views of merged file with different
33 * parts in different colours.
35 * The window can be split horizontally to show the original and result
36 * beside the diff, and each different branch can be shown alone.
48 static void term_init(int raw
);
50 static int intr_kills
= 0;
52 /* global attributes */
53 unsigned int a_delete
, a_added
, a_common
, a_sep
, a_void
,
54 a_unmatched
, a_extra
, a_already
;
55 unsigned int a_has_conflicts
, a_has_wiggles
, a_no_wiggles
, a_saved
;
57 /******************************************************************
59 * We display help in an insert, leaving 5 columns left and right,
60 * and 2 rows top and bottom, but at most 58x15 plus border
62 * SPC or RTN moves down or to next page
63 * BKSPC goes backwards
64 * 'q' returns to origin screen
65 * '?' show help on help
66 * left and right scroll help view
68 * A help text is an array of lines of text
72 " You are viewing the help page for the help viewer.",
73 "You normally get here by typing '?'",
75 "The following keystrokes work in the help viewer:",
76 " ? display this help message",
77 " q return to previous view",
78 " SPC move forward through help document",
80 " BKSP move backward through help document",
81 " RIGHT scroll help window so text on the right appears",
82 " LEFT scroll help window so text on the left appears",
86 char *help_missing
[] = {
87 "The file that this patch applies to appears",
89 "Please type 'q' to continue",
93 char *help_corrupt
[] = {
94 "This patch appears to be corrupt",
95 "Please type 'q' to continue",
99 /* We can give one or two pages to display in the help window.
100 * The first is specific to the current context. The second
101 * is optional and may provide help in a more broad context.
103 static int help_window(char *page1
[], char *page2
[], int query
)
113 getmaxyx(stdscr
, rows
, cols
);
119 left
= (cols
-58)/2 - 1;
127 top
= (rows
-15)/2 - 1;
131 /* Draw a border around the 'help' area */
132 (void)attrset(A_STANDOUT
);
133 for (c
= left
; c
< left
+cols
; c
++) {
134 mvaddch(top
-1, c
, '-');
135 mvaddch(top
+rows
, c
, '-');
137 for (r
= top
; r
< top
+ rows
; r
++) {
138 mvaddch(r
, left
-1, '|');
139 mvaddch(r
, left
+cols
, '|');
141 mvaddch(top
-1, left
-1, '/');
142 mvaddch(top
-1, left
+cols
, '\\');
143 mvaddch(top
+rows
, left
-1, '\\');
144 mvaddch(top
+rows
, left
+cols
, '/');
146 mvaddstr(top
-1, left
+ cols
/2 - 4, "Question");
147 mvaddstr(top
+rows
, left
+ cols
/2 - 9,
148 "Answer Y, N, or Q.");
150 mvaddstr(top
-1, left
+ cols
/2 - 9,
151 "HELP - 'q' to exit");
152 mvaddstr(top
+rows
, left
+cols
/2 - 17,
153 "Press SPACE for more, '?' for help");
155 (void)attrset(A_NORMAL
);
158 char **lnp
= page
+ line
;
160 /* Draw as much of the page at the current offset
163 for (r
= 0; r
< rows
; r
++) {
171 while (*ln
&& sh
> 0) {
175 for (c
= 0; c
< cols
; c
++) {
181 mvaddch(top
+r
, left
+c
, chr
);
184 move(top
+rows
-1, left
);
205 if (page1
!= help_help
)
206 help_window(help_help
, NULL
, 0);
209 case '\r': /* page-down */
210 for (r
= 0; r
< rows
-2; r
++)
213 if (!page
[line
] && !query
) {
224 case '\b': /* page up */
260 static char *typenames
[] = {
262 [Unmatched
] = "Unmatched",
263 [Unchanged
] = "Unchanged",
264 [Extraneous
] = "Extraneous",
265 [Changed
] = "Changed",
266 [Conflict
] = "Conflict",
267 [AlreadyApplied
] = "AlreadyApplied",
270 /* When we merge the original and the diff together we need
271 * to keep track of where everything came from.
272 * When we display the different views, we need to be able to
273 * select certain portions of the whole document.
274 * These flags are used to identify what is present, and to
275 * request different parts be extracted. They also help
276 * guide choice of colour.
282 #define CHANGES 16 /* A change is visible here,
283 * so 2 streams need to be shown */
284 #define WIGGLED 32 /* a conflict that was successfully resolved */
285 #define CONFLICTED 64 /* a conflict that was not successfully resolved */
287 /* Displaying a Merge.
288 * The first step is to linearise the merge. The merge in inherently
289 * parallel with before/after streams. However much of the whole document
290 * is linear as normally much of the original in unchanged.
291 * All parallelism comes from the patch. This normally produces two
292 * parallel stream, but in the case of a conflict can produce three.
293 * For browsing the merge we only ever show two alternates in-line.
294 * When there are three we use two panes with 1 or 2 alternates in each.
295 * So to linearise the two streams we find lines that are completely
296 * unchanged (same for all 3 streams, or missing in 2nd and 3rd) which bound
297 * a region where there are changes. We include everything between
298 * these twice, in two separate passes. The exact interpretation of the
299 * passes is handled at a higher level but will be one of:
300 * original and result
302 * original and after (for a conflict)
303 * This is all encoded in the 'struct merge'. An array of these describes
304 * the whole document.
306 * At any position in the merge we can be in one of 3 states:
307 * 0: unchanged section
311 * So to walk a merge in display order we need a position in the merge,
312 * a current state, and when in a changed section, we need to know the
313 * bounds of that changed section.
314 * This is all encoded in 'struct mpos'.
316 * Each location may or may not be visible depending on certain
319 * Also, some locations might be 'invalid' in that they don't need to be displayed.
320 * For example when the patch leaves a section of the original unchanged,
321 * we only need to see the original - the before/after sections are treated
322 * as invalid and are not displayed.
323 * The visibility of newlines is crucial and guides the display. One line
324 * of displayed text is all the visible sections between two visible newlines.
326 * Counting lines is a bit tricky. We only worry about line numbers in the
327 * original (stream 0) as these could compare with line numbers mentioned in
329 * We count 2 for every line: 1 for everything before the newline and 1 for the newline.
330 * That way we don't get a full counted line until we see the first char after the
331 * newline, so '+' lines are counted with the previous line.
335 int m
; /* merger index */
336 int s
; /* stream 0,1,2 for a,b,c */
337 int o
; /* offset in that stream */
338 int lineno
; /* Counts newlines in stream 0
339 * set lsb when see newline.
340 * add one when not newline and lsb set
344 struct mp p
, /* the current point (end of a line) */
345 lo
, /* eol for start of the current group */
346 hi
; /* eol for end of the current group */
348 * 0 if on an unchanged (lo/hi not meaningful)
349 * 1 if on the '-' of a diff,
350 * 2 if on the '+' of a diff
355 struct mp pos
; /* where in the document we are (an element) */
356 int offset
; /* which char in that element */
357 int target
; /* display column - or -1 if we are looking for 'pos' */
358 int col
; /* where we found pos or target */
359 int width
; /* Size of char, for moving to the right */
360 int alt
; /* Cursor is in alternate window */
363 /* used for checking location during search */
364 static int same_mp(struct mp a
, struct mp b
)
370 static int same_mpos(struct mpos a
, struct mpos b
)
372 return same_mp(a
.p
, b
.p
) &&
373 (a
.state
== b
.state
|| a
.state
== 0 || b
.state
== 0);
376 /* Check if a particular stream is meaningful in a particular merge
377 * section. e.g. in an Unchanged section, only stream 0, the
378 * original, is meaningful. This is used to avoid walking down
381 static int stream_valid(int s
, enum mergetype type
)
403 * Advance the 'pos' in the current mergepos returning the next
405 * This walks the merges in sequence, and the streams within
408 static struct elmnt
next_melmnt(struct mp
*pos
,
409 struct file fm
, struct file fb
, struct file fa
,
413 while (pos
->m
< 0 || m
[pos
->m
].type
!= End
) {
414 int l
= 0; /* Length remaining in current merge section */
428 /* Offset has reached length, choose new stream or
437 } while (!stream_valid(pos
->s
, m
[pos
->m
].oldtype
));
441 if (pos
->m
== -1 || m
[pos
->m
].type
== End
) {
443 e
.start
= NULL
; e
.hash
= 0; e
.len
= 0;
447 default: /* keep compiler happy */
451 if (ends_line(fm
.list
[m
[pos
->m
].a
+ pos
->o
]))
453 return fm
.list
[m
[pos
->m
].a
+ pos
->o
];
454 case 1: return fb
.list
[m
[pos
->m
].b
+ pos
->o
];
455 case 2: return fa
.list
[m
[pos
->m
].c
+ pos
->o
];
459 /* step current position.p backwards */
460 static struct elmnt
prev_melmnt(struct mp
*pos
,
461 struct file fm
, struct file fb
, struct file fa
,
465 if (m
[pos
->m
].a
+ pos
->o
< fm
.elcnt
&&
466 ends_line(fm
.list
[m
[pos
->m
].a
+ pos
->o
]))
473 while (pos
->m
>= 0 && pos
->o
< 0) {
480 } while (pos
->m
>= 0 &&
481 !stream_valid(pos
->s
, m
[pos
->m
].oldtype
));
485 pos
->o
= m
[pos
->m
].al
-1;
488 pos
->o
= m
[pos
->m
].bl
-1;
491 pos
->o
= m
[pos
->m
].cl
-1;
496 if (pos
->m
< 0 || m
[pos
->m
].type
== End
) {
498 e
.start
= NULL
; e
.hash
= 0; e
.len
= 0;
502 default: /* keep compiler happy */
503 case 0: return fm
.list
[m
[pos
->m
].a
+ pos
->o
];
504 case 1: return fb
.list
[m
[pos
->m
].b
+ pos
->o
];
505 case 2: return fa
.list
[m
[pos
->m
].c
+ pos
->o
];
509 /* 'visible' not only checks if this stream in this merge should be
510 * visible in this mode, but also chooses which colour/highlight to use
513 static int visible(int mode
, struct merge
*m
, struct mpos
*pos
)
516 int stream
= pos
->p
.s
;
523 type
= m
[pos
->p
.m
].type
;
524 /* mode can be any combination of ORIG RESULT BEFORE AFTER */
526 case End
: /* The END is always visible */
528 case Unmatched
: /* Visible in ORIG and RESULT */
529 if (mode
& (ORIG
|RESULT
))
532 case Unchanged
: /* visible everywhere, but only show stream 0 */
533 if (m
[pos
->p
.m
].oldtype
== Conflict
) {
555 if (m
[pos
->p
.m
].oldtype
!= Unchanged
)
556 return a_common
| A_UNDERLINE
;
560 case Extraneous
: /* stream 2 is visible in BEFORE and AFTER */
561 if ((mode
& (BEFORE
|AFTER
))
565 case Changed
: /* stream zero visible ORIG and BEFORE, stream 2 elsewhere */
567 (mode
& (ORIG
|BEFORE
)))
570 (mode
& (RESULT
|AFTER
)))
577 return a_unmatched
| A_REVERSE
;
581 return a_extra
| A_UNDERLINE
;
584 if (mode
& (AFTER
|RESULT
))
585 return a_added
| A_UNDERLINE
;
592 if (mode
& (ORIG
|RESULT
))
597 return a_delete
| A_UNDERLINE
;
601 return a_added
| A_UNDERLINE
;
609 /* checkline creates a summary of the sort of changes that
610 * are in a line, returning an "or" of
615 static int check_line(struct mpos pos
, struct file fm
, struct file fb
,
617 struct merge
*m
, int mode
)
626 if (m
[pos
.p
.m
].type
== Changed
)
628 else if (m
[pos
.p
.m
].type
== Conflict
) {
629 rv
|= CONFLICTED
| CHANGES
;
630 } else if (m
[pos
.p
.m
].type
== AlreadyApplied
) {
632 if (mode
& (BEFORE
|AFTER
))
634 } else if (m
[pos
.p
.m
].type
== Extraneous
) {
635 if (fb
.list
[m
[pos
.p
.m
].b
].start
[0] == '\0')
636 /* hunk headers don't count as wiggles
637 * and nothing before a hunk header
638 * can possibly be part of this 'line' */
642 } else if (m
[pos
.p
.m
].type
== Unmatched
)
645 if (m
[pos
.p
.m
].in_conflict
> 1)
646 rv
|= CONFLICTED
| CHANGES
;
647 if (m
[pos
.p
.m
].in_conflict
== 1 &&
648 (pos
.p
.o
< m
[pos
.p
.m
].lo
||
649 pos
.p
.o
> m
[pos
.p
.m
].hi
))
650 rv
|= CONFLICTED
| CHANGES
;
651 e
= prev_melmnt(&pos
.p
, fm
, fb
, fa
, m
);
652 } while (e
.start
!= NULL
&&
654 || visible(mode
, m
, &pos
) == -1));
656 if (unmatched
&& (rv
& CHANGES
))
661 /* Find the next line in the merge which is visible.
662 * If we hit the end of a conflicted set during pass-1
663 * we rewind for pass-2.
664 * 'mode' tells which bits we want to see, possible one of
665 * the 4 parts (before/after/orig/result) or one of the pairs
666 * before+after or orig+result.
668 static void next_mline(struct mpos
*pos
, struct file fm
, struct file fb
,
670 struct merge
*m
, int mode
)
679 struct elmnt e
= next_melmnt(&pos
->p
, fm
, fb
, fa
, m
);
683 visible(mode
, m
, pos
) >= 0)
686 mode2
= check_line(*pos
, fm
, fb
, fa
, m
, mode
);
688 if ((mode2
& CHANGES
) && pos
->state
== 0) {
689 /* Just entered a diff-set */
692 } else if (!(mode2
& CHANGES
) && pos
->state
) {
693 /* Come to the end of a diff-set */
694 switch (pos
->state
) {
696 /* Need to record the end */
698 /* time for another pass */
703 /* finished final pass */
708 mask
= ORIG
|RESULT
|BEFORE
|AFTER
;
709 switch (pos
->state
) {
711 mask
&= ~(RESULT
|AFTER
);
714 mask
&= ~(ORIG
|BEFORE
);
717 } while (visible(mode
&mask
, m
, pos
) < 0);
721 /* Move to previous line - simply the reverse of next_mline */
722 static void prev_mline(struct mpos
*pos
, struct file fm
, struct file fb
,
724 struct merge
*m
, int mode
)
735 struct elmnt e
= prev_melmnt(&pos
->p
, fm
, fb
, fa
, m
);
739 visible(mode
, m
, pos
) >= 0)
742 mode2
= check_line(*pos
, fm
, fb
, fa
, m
, mode
);
744 if ((mode2
& CHANGES
) && pos
->state
== 0) {
745 /* Just entered a diff-set */
748 } else if (!(mode2
& CHANGES
) && pos
->state
) {
749 /* Come to the end (start) of a diff-set */
750 switch (pos
->state
) {
752 /* finished final pass */
756 /* Need to record the start */
758 /* time for another pass */
764 mask
= ORIG
|RESULT
|BEFORE
|AFTER
;
765 switch (pos
->state
) {
767 mask
&= ~(RESULT
|AFTER
);
770 mask
&= ~(ORIG
|BEFORE
);
773 } while (visible(mode
&mask
, m
, pos
) < 0);
776 /* blank a whole row of display */
777 static void blank(int row
, int start
, int cols
, unsigned int attr
)
785 /* search of a string on one display line. If found, update the
789 static int mcontains(struct mpos pos
,
790 struct file fm
, struct file fb
, struct file fa
,
792 int mode
, char *search
, struct cursor
*curs
,
793 int dir
, int ignore_case
)
795 /* See if any of the files, between start of this line and here,
796 * contain the search string.
797 * However this is modified by dir:
798 * -2: find last match *before* curs
799 * -1: find last match at-or-before curs
800 * 1: find first match at-or-after curs
801 * 2: find first match *after* curs
803 * We only test for equality with curs, so if it is on a different
804 * line it will not be found and everything is before/after.
805 * As we search from end-of-line to start we find the last
807 * For a forward search, we stop when we find curs.
808 * For a backward search, we forget anything found when we find curs.
814 int len
= strlen(search
);
817 e
= prev_melmnt(&pos
.p
, fm
, fb
, fa
, m
);
818 if (e
.start
&& e
.start
[0]) {
821 if (same_mp(pos
.p
, curs
->pos
))
822 curs_i
= curs
->offset
;
825 for (i
= e
.len
-1; i
>= 0; i
--) {
826 if (i
== curs_i
&& dir
== -1)
827 /* next match is the one we want */
829 if (i
== curs_i
&& dir
== 2)
830 /* future matches not accepted */
832 if ((!found
|| dir
> 0) &&
833 (ignore_case
? strncasecmp
: strncmp
)
834 (e
.start
+i
, search
, len
) == 0) {
839 if (i
== curs_i
&& dir
== -2)
840 /* next match is the one we want */
842 if (i
== curs_i
&& dir
== 1)
843 /* future matches not accepted */
847 } while (e
.start
!= NULL
&&
849 || visible(mode
, m
, &pos
) == -1));
858 /* Drawing the display window.
859 * There are 7 different ways we can display the data, each
860 * of which can be configured by a keystroke:
861 * o original - just show the original file with no changes, but still
862 * with highlights of what is changed or unmatched
863 * r result - show just the result of the merge. Conflicts just show
864 * the original, not the before/after options
865 * b before - show the 'before' stream of the patch
866 * a after - show the 'after' stream of the patch
867 * d diff - show just the patch, both before and after
868 * m merge - show the full merge with -+ sections for changes.
869 * If point is in a wiggled or conflicted section the
870 * window is split horizontally and the diff is shown
871 * in the bottom window
872 * | sidebyside - two panes, left and right. Left holds the merge,
873 * right holds the diff. In the case of a conflict,
874 * left holds orig/after, right holds before/after
876 * The horizontal split for 'merge' mode is managed as follows.
877 * - The window is split when we first visit a line that contains
878 * a wiggle or a conflict, and the second pane is removed when
879 * we next visit a line that contains no changes (is fully Unchanged).
880 * - to display the second pane, we find a visible end-of-line in the
881 * (BEFORE|AFTER) mode at-or-before the current end-of-line and
882 * the we centre that line.
883 * - We need to rewind to an unchanged section, and wind forward again
884 * to make sure that 'lo' and 'hi' are set properly.
885 * - every time we move, we redraw the second pane (see how that goes).
888 /* draw_mside draws one text line or, in the case of sidebyside, one side
890 * The 'mode' tells us what to draw via the 'visible()' function.
891 * It is one of ORIG RESULT BEFORE AFTER or ORIG|RESULT or BEFORE|AFTER
892 * It may also have WIGGLED or CONFLICTED ored in to trigger extra highlights.
893 * The desired cursor position is given in 'target' the actual end
894 * cursor position (allowing e.g. for tabs) is returned in *colp.
896 static void draw_mside(int mode
, int row
, int offset
, int start
, int cols
,
897 struct file fm
, struct file fb
, struct file fa
,
905 unsigned int tag_attr
;
909 default: /* keep compiler happy */
910 case 0: /* unchanged line */
914 case 1: /* 'before' text */
917 if ((mode
& ORIG
) && (mode
& CONFLICTED
)) {
919 tag_attr
= a_delete
| A_REVERSE
;
921 mode
&= (ORIG
|BEFORE
);
923 case 2: /* the 'after' part */
926 mode
&= (AFTER
|RESULT
);
930 if (visible(mode
, m
, &pos
) < 0) {
931 /* Not visible, just draw a blank */
932 blank(row
, offset
, cols
, a_void
);
942 (void)attrset(tag_attr
);
943 mvaddch(row
, offset
, tag
);
946 (void)attrset(A_NORMAL
);
948 if (check_line(pos
, fm
, fb
, fa
, m
, mode
))
951 /* find previous visible newline, or start of file */
953 e
= prev_melmnt(&pos
.p
, fm
, fb
, fa
, m
);
954 while (e
.start
!= NULL
&&
956 visible(mode
, m
, &pos
) == -1));
963 e
= next_melmnt(&pos
.p
, fm
, fb
, fa
, m
);
967 if (visible(mode
, m
, &pos
) == -1)
971 c
= (unsigned char *)e
.start
- e
.prefix
;
973 attr
= visible(mode
, m
, &pos
);
974 if ((attr
== a_unmatched
|| attr
== a_extra
) &&
976 /* Only highlight spaces if there is a tab nearby */
977 for (l
= 0; l
< e
.plen
+ e
.prefix
; l
++)
980 for (l
= 0; l
< e
.plen
+ e
.prefix
; l
++) {
985 if (*c
>= ' ' && *c
!= 0x7f) {
987 (void)attrset(attr
|A_REVERSE
);
988 if (col
>= start
&& col
< start
+cols
)
989 mvaddch(row
, col
-start
+offset
, *c
);
991 } else if (*c
== '\t') {
993 (void)attrset(attr
|A_UNDERLINE
);
995 if (col
>= start
&& col
< start
+cols
) {
996 mvaddch(row
, col
-start
+offset
, ' ');
998 } while ((col
&7) != 0);
1000 if (col
>= start
&& col
< start
+cols
)
1001 mvaddch(row
, col
-start
+offset
, '?');
1005 if (curs
->target
>= 0) {
1006 if (curs
->target
< col
) {
1007 /* Found target column */
1011 if (scol
>= start
+ cols
)
1012 /* Didn't appear on screen */
1015 curs
->width
= col
- scol
;
1018 } else if (l
== curs
->offset
&&
1019 same_mp(pos
.p
, curs
->pos
)) {
1021 curs
->target
= scol
;
1023 if (scol
>= start
+ cols
)
1024 /* Didn't appear on screen */
1027 curs
->width
= col
- scol
;
1034 && visible(mode
, m
, &pos
) != -1))
1038 /* We have reached the end of visible line, or end of file */
1041 if (col
>= start
+ cols
)
1044 curs
->width
= -1; /* end of line */
1045 if (curs
->target
>= 0) {
1048 } else if (same_mp(pos
.p
, curs
->pos
))
1053 if (e
.start
&& e
.start
[0] == 0) {
1056 if (pos
.p
.s
== 2 && m
[pos
.p
.m
].type
== Extraneous
) {
1057 int A
, B
, C
, D
, E
, F
;
1058 e1
= fb
.list
[m
[pos
.p
.m
].b
+ pos
.p
.o
];
1059 sscanf(e1
.start
+1, "%d %d %d", &A
, &B
, &C
);
1060 sscanf(e
.start
+1, "%d %d %d", &D
, &E
, &F
);
1061 sprintf(b
, "@@ -%d,%d +%d,%d @@\n", B
, C
, E
, F
);
1062 (void)attrset(a_sep
);
1064 (void)attrset(visible(mode
, m
, &pos
));
1065 sprintf(b
, "<%.17s>", e
.start
+1);
1067 mvaddstr(row
, col
-start
+offset
, b
);
1070 blank(row
, col
-start
+offset
, start
+cols
-col
,
1072 ? (unsigned)visible(mode
, m
, &pos
)
1076 /* Draw either 1 or 2 sides depending on the mode. */
1078 static void draw_mline(int mode
, int row
, int start
, int cols
,
1079 struct file fm
, struct file fb
, struct file fa
,
1082 struct cursor
*curs
)
1085 * Draw the left and right images of this line
1086 * One side might be a_blank depending on the
1087 * visibility of this newline
1091 mode
|= check_line(pos
, fm
, fb
, fa
, m
, mode
);
1093 if ((mode
& (BEFORE
|AFTER
)) &&
1094 (mode
& (ORIG
|RESULT
))) {
1097 rcols
= cols
- lcols
- 1;
1099 (void)attrset(A_STANDOUT
);
1100 mvaddch(row
, lcols
, '|');
1102 draw_mside(mode
&~(BEFORE
|AFTER
), row
, 0, start
, lcols
,
1103 fm
, fb
, fa
, m
, pos
, curs
&& !curs
->alt
? curs
: NULL
);
1105 draw_mside(mode
&~(ORIG
|RESULT
), row
, lcols
+1, start
, rcols
,
1106 fm
, fb
, fa
, m
, pos
, curs
&& curs
->alt
? curs
: NULL
);
1108 draw_mside(mode
, row
, 0, start
, cols
,
1109 fm
, fb
, fa
, m
, pos
, curs
);
1112 static char *merge_help
[] = {
1113 "This view shows the merge of the patch with the",
1114 "original file. It is like a full-context diff showing",
1115 "removed lines with a '-' prefix and added lines with a",
1117 "In cases where a patch chunk could not be successfully",
1118 "applied, the original text is prefixed with a '|', and",
1119 "the text that the patch wanted to add is prefixed with",
1121 "When the cursor is over such a conflict, or over a chunk",
1122 "which required wiggling to apply (i.e. there was unmatched",
1123 "text in the original, or extraneous unchanged text in",
1124 "the patch), the terminal is split and the bottom pane is",
1125 "use to display the part of the patch that applied to",
1126 "this section of the original. This allows you to confirm",
1127 "that a wiggled patch applied correctly, and to see",
1128 "why there was a conflict",
1131 static char *diff_help
[] = {
1132 "This is the 'diff' or 'patch' view. It shows",
1133 "only the patch that is being applied without the",
1134 "original to which it is being applied.",
1135 "Underlined text indicates parts of the patch which",
1136 "resulted in a conflict when applied to the",
1140 static char *orig_help
[] = {
1141 "This is the 'original' view which simply shows",
1142 "the original file before applying the patch.",
1143 "Sections of code that would be changed by the patch",
1144 "are highlighted in red.",
1147 static char *result_help
[] = {
1148 "This is the 'result' view which shows just the",
1149 "result of applying the patch. When a conflict",
1150 "occurred this view does not show the full conflict",
1151 "but only the 'after' part of the patch. To see",
1152 "the full conflict, use the 'merge' or 'sidebyside'",
1156 static char *before_help
[] = {
1157 "This view shows the 'before' section of a patch.",
1158 "It allows the expected match text to be seen uncluttered",
1159 "by text that is meant to replaced it.",
1160 "Red text is text that will be removed by the patch",
1163 static char *after_help
[] = {
1164 "This view shows the 'after' section of a patch.",
1165 "It allows the intended result to be seen uncluttered",
1166 "by text that was meant to be matched and replaced.",
1167 "Green text is text that was added by the patch - it",
1168 "was not present in the 'before' part of the patch",
1171 static char *sidebyside_help
[] = {
1172 "This is the Side By Side view of a patched file.",
1173 "The left side shows the original and the result.",
1174 "The right side shows the patch which was applied",
1175 "and lines up with the original/result as much as",
1178 "Where one side has no line which matches the",
1179 "other side it is displayed as a solid colour in the",
1180 "yellow family (depending on your terminal window).",
1183 static char *merge_window_help
[] = {
1184 " Highlight Colours and Keystroke commands",
1186 "In all different views of a merge, highlight colours",
1187 "are used to show which parts of lines were added,",
1188 "removed, already changed, unchanged or in conflict.",
1189 "Colours and their use are:",
1190 " normal unchanged text",
1191 " red text that was removed or changed",
1192 " green text that was added or the result",
1194 " yellow background used in side-by-side for a line",
1195 " which has no match on the other",
1197 " blue text in the original which did not",
1198 " match anything in the patch",
1199 " cyan text in the patch which did not",
1200 " match anything in the original",
1201 " cyan background already changed text: the result",
1202 " of the patch matches the original",
1203 " underline remove or added text can also be",
1204 " underlined indicating that it",
1205 " was involved in a conflict",
1207 "While viewing a merge various keystroke commands can",
1208 "be used to move around and change the view. Basic",
1209 "movement commands from both 'vi' and 'emacs' are",
1212 " p control-p k UP Move to previous line",
1213 " n control-n j DOWN Move to next line",
1214 " l LEFT Move one char to right",
1215 " h RIGHT Move one char to left",
1216 " / control-s Enter incremental search mode",
1217 " control-r Enter reverse-search mode",
1218 " control-g Search again",
1219 " ? Display help message",
1220 " ESC-< 0-G Go to start of file",
1221 " ESC-> G Go to end of file",
1222 " q Return to list of files or exit",
1223 " control-C Disable auto-save-on-exit",
1224 " control-L recenter current line",
1225 " control-V SPACE page down",
1226 " ESC-v BACKSPC page up",
1227 " N go to next patch chunk",
1228 " P go to previous patch chunk",
1229 " C go to next conflicted chunk",
1230 " C-X-o O move cursor to alternate pane",
1231 " ^ control-A go to start of line",
1232 " $ control-E go to end of line",
1234 " a display 'after' view",
1235 " b display 'before' view",
1236 " o display 'original' view",
1237 " r display 'result' view",
1238 " d display 'diff' or 'patch' view",
1239 " m display 'merge' view",
1240 " | display side-by-side view",
1242 " x toggle ignoring of current Changed",
1243 " or Conflict item",
1244 " X toggle ignored of all Change and",
1245 " Conflict items in current line",
1248 static char *save_query
[] = {
1250 "You have modified the merge.",
1251 "Would you like to save it?",
1252 " Y = save the modified merge",
1253 " N = discard modifications, don't save",
1254 " Q = return to viewing modified merge",
1258 static int merge_window(struct plist
*p
, FILE *f
, int reverse
, int replace
,
1259 int selftest
, int ignore_blanks
)
1261 /* Display the merge window in one of the selectable modes,
1262 * starting with the 'merge' mode.
1264 * Newlines are the key to display.
1265 * 'pos' is always a visible newline (or eof).
1266 * In sidebyside mode it might only be visible on one side,
1267 * in which case the other side will be blank.
1268 * Where the newline is visible, we rewind the previous visible
1269 * newline visible and display the stuff in between
1271 * A 'position' is a struct mpos
1274 struct stream sm
, sb
, sa
, sp
; /* main, before, after, patch */
1275 struct file fm
, fb
, fa
;
1276 struct csl
*csl1
, *csl2
;
1278 int ch
; /* count of chunks */
1279 /* Always refresh the current line.
1280 * If refresh == 1, refresh all lines. If == 2, clear first
1283 int rows
= 0, cols
= 0;
1284 int splitrow
= -1; /* screen row for split - diff appears below */
1285 int lastrow
= 0; /* end of screen, or just above 'splitrow' */
1288 int mode
= ORIG
|RESULT
;
1289 int mmode
= mode
; /* Mode for moving - used when in 'other' pane */
1290 char *modename
= "merge";
1291 char **modehelp
= merge_help
;
1295 int trow
; /* screen-row while searching. If we cannot find,
1296 * we forget this number */
1298 struct mpos pos
; /* current point */
1299 struct mpos tpos
, /* temp point while drawing lines above and below pos */
1300 toppos
, /* pos at top of screen - for page-up */
1301 botpos
; /* pos at bottom of screen - for page-down */
1302 struct mpos vpos
, tvpos
, vispos
;
1304 int meta
= 0, /* mode for multi-key commands- SEARCH or META */
1306 int num
= -1, /* numeric arg being typed. */
1308 int changes
= 0; /* If any edits have been made to the merge */
1309 int answer
; /* answer to 'save changes?' question */
1312 char search
[80]; /* string we are searching for */
1313 unsigned int searchlen
= 0;
1314 int search_notfound
= 0;
1318 * 1 == no because there are upper-case chars
1319 * 2 == yes as there are no upper-case chars
1322 int ignore_case
= 2;
1323 /* We record all the places we find so 'backspace'
1324 * can easily return to the previous one
1326 struct search_anchor
{
1327 struct search_anchor
*next
;
1332 unsigned int searchlen
;
1342 /* three separate files */
1343 sm
= load_file(p
->file
);
1344 sb
= load_file(p
->before
);
1345 sa
= load_file(p
->after
);
1347 /* One merge file */
1348 sp
= load_file(p
->file
);
1350 split_merge(sp
, &sm
, &sa
, &sb
);
1352 split_merge(sp
, &sm
, &sb
, &sa
);
1357 sp
= load_segment(f
, p
->start
, p
->end
);
1360 split_merge(sp
, &sm
, &sa
, &sb
);
1362 split_merge(sp
, &sm
, &sb
, &sa
);
1366 ch
= split_patch(sp
, &sa
, &sb
);
1368 ch
= split_patch(sp
, &sb
, &sa
);
1370 sm
= load_file(p
->file
);
1374 if (!sm
.body
|| !sb
.body
|| !sa
.body
) {
1380 help_window(help_missing
, NULL
, 0);
1382 help_window(help_corrupt
, NULL
, 0);
1386 /* FIXME check for errors in the stream */
1387 fm
= split_stream(sm
, ByWord
| ignore_blanks
);
1388 fb
= split_stream(sb
, ByWord
| ignore_blanks
);
1389 fa
= split_stream(sa
, ByWord
| ignore_blanks
);
1392 csl1
= pdiff(fm
, fb
, ch
);
1394 csl1
= diff(fm
, fb
);
1395 csl2
= diff_patch(fb
, fa
);
1397 ci
= make_merger(fm
, fb
, fa
, csl1
, csl2
, 0, 1, 0);
1398 for (i
= 0; ci
.merger
[i
].type
!= End
; i
++)
1399 ci
.merger
[i
].oldtype
= ci
.merger
[i
].type
;
1401 term_init(!selftest
);
1404 pos
.p
.m
= 0; /* merge node */
1405 pos
.p
.s
= 0; /* stream number */
1406 pos
.p
.o
= -1; /* offset */
1409 next_mline(&pos
, fm
, fb
, fa
, ci
.merger
, mode
);
1410 memset(&curs
, 0, sizeof(curs
));
1416 snprintf(buf
, 100, "File: %s%s Mode: %s\n",
1417 p
->file
, reverse
? " - reversed" : "", modename
);
1418 (void)attrset(A_BOLD
);
1419 mvaddstr(0, 0, buf
);
1421 (void)attrset(A_NORMAL
);
1424 if (row
< 1 || row
>= lastrow
)
1429 if (mode
== (ORIG
|RESULT
)) {
1430 int cmode
= check_line(pos
, fm
, fb
, fa
, ci
.merger
, mode
);
1431 if (cmode
& (WIGGLED
| CONFLICTED
)) {
1433 splitrow
= (rows
+1)/2;
1434 lastrow
= splitrow
- 1;
1437 } else if (!curs
.alt
&& splitrow
>= 0) {
1442 } else if (splitrow
>= 0) {
1449 getmaxyx(stdscr
, rows
, cols
);
1450 rows
--; /* keep last row clear */
1451 if (splitrow
>= 0) {
1452 splitrow
= (rows
+1)/2;
1453 lastrow
= splitrow
- 1;
1461 if (row
> lastrow
+3)
1466 if (getenv("WIGGLE_VTRACE")) {
1471 default: /* keep compiler happy */
1473 e
= fm
.list
[ci
.merger
[vpos
.p
.m
].a
+ vpos
.p
.o
].start
;
1476 e
= fb
.list
[ci
.merger
[vpos
.p
.m
].b
+ vpos
.p
.o
].start
;
1479 e
= fa
.list
[ci
.merger
[vpos
.p
.m
].c
+ vpos
.p
.o
].start
;
1482 for (i
= 0; i
< 6; i
++) {
1484 if (e2
[i
] < 32 || e2
[i
] >= 127)
1487 sprintf(b
, "st=%d str=%d o=%d m=%d mt=%s(%d,%d,%d) ic=%d <%.3s>", vpos
.state
,
1489 vpos
.p
.m
, typenames
[ci
.merger
[vpos
.p
.m
].type
],
1490 ci
.merger
[vpos
.p
.m
].al
,
1491 ci
.merger
[vpos
.p
.m
].bl
,
1492 ci
.merger
[vpos
.p
.m
].cl
,
1493 ci
.merger
[vpos
.p
.m
].in_conflict
,
1496 (void)attrset(A_NORMAL
);
1501 /* Always refresh the line */
1502 while (start
> curs
.target
) {
1508 vispos
= pos
; /* visible position - if cursor is in
1509 * alternate pane, pos might not be visible
1511 if (check_line(vispos
, fm
, fb
, fa
, ci
.merger
, mode
)
1513 if (vispos
.state
== 0)
1519 if (visible(mode
, ci
.merger
, &vispos
) < 0)
1520 prev_mline(&vispos
, fm
, fb
, fa
, ci
.merger
, mode
);
1524 draw_mline(mode
, row
, start
, cols
, fm
, fb
, fa
, ci
.merger
,
1525 vispos
, (splitrow
>= 0 && curs
.alt
) ? NULL
: &curs
);
1526 if (curs
.width
== 0 && start
< curs
.col
) {
1527 /* width == 0 implies it appear after end-of-screen */
1532 if (curs
.col
< start
) {
1544 for (i
= row
-1; i
>= 1 && tpos
.p
.m
>= 0; ) {
1545 prev_mline(&tpos
, fm
, fb
, fa
, ci
.merger
, mode
);
1546 draw_mline(mode
, i
--, start
, cols
,
1547 fm
, fb
, fa
, ci
.merger
,
1558 blank(i
--, 0, cols
, a_void
);
1560 for (i
= row
; i
<= lastrow
&& ci
.merger
[tpos
.p
.m
].type
!= End
; ) {
1561 draw_mline(mode
, i
++, start
, cols
,
1562 fm
, fb
, fa
, ci
.merger
,
1564 next_mline(&tpos
, fm
, fb
, fa
, ci
.merger
, mode
);
1566 botpos
= tpos
; botrow
= i
;
1567 while (i
<= lastrow
)
1568 blank(i
++, 0, cols
, a_void
);
1571 if (splitrow
>= 0) {
1572 struct mpos spos
= pos
;
1573 int smode
= BEFORE
|AFTER
;
1574 int srow
= (rows
+ splitrow
)/2;
1575 if (check_line(spos
, fm
, fb
, fa
, ci
.merger
, smode
)
1577 if (spos
.state
== 0)
1582 if (visible(smode
, ci
.merger
, &spos
) < 0)
1583 prev_mline(&spos
, fm
, fb
, fa
, ci
.merger
, smode
);
1584 /* Now hi/lo might be wrong, so lets fix it. */
1587 /* 'hi' might be wrong so we mustn't depend
1588 * on it while walking back. So set state
1589 * to 1 to avoid ever testing it.
1592 while (spos
.p
.m
>= 0 && spos
.state
!= 0)
1593 prev_mline(&spos
, fm
, fb
, fa
, ci
.merger
, smode
);
1594 while (!same_mpos(spos
, tpos
))
1595 next_mline(&spos
, fm
, fb
, fa
, ci
.merger
, smode
);
1597 (void)attrset(a_sep
);
1598 for (i
= 0; i
< cols
; i
++)
1599 mvaddstr(splitrow
, i
, "-");
1602 for (i
= srow
-1; i
> splitrow
; i
--) {
1603 prev_mline(&tpos
, fm
, fb
, fa
, ci
.merger
, smode
);
1604 draw_mline(smode
, i
, start
, cols
, fm
, fb
, fa
, ci
.merger
,
1607 while (i
> splitrow
)
1608 blank(i
--, 0, cols
, a_void
);
1611 i
< rows
&& ci
.merger
[tpos
.p
.m
].type
!= End
;
1613 draw_mline(smode
, i
, start
, cols
, fm
, fb
, fa
, ci
.merger
,
1615 (i
== srow
&& curs
.alt
) ? &curs
: NULL
);
1616 next_mline(&tpos
, fm
, fb
, fa
, ci
.merger
, smode
);
1619 blank(i
++, 0, cols
, a_void
);
1621 /* Now that curs is accurate, report the type */
1624 (void)attrset(A_BOLD
);
1625 snprintf(lbuf
, 29, "%s%s ln:%d",
1626 ci
.merger
[curs
.pos
.m
].type
!= ci
.merger
[curs
.pos
.m
].oldtype
1628 typenames
[ci
.merger
[curs
.pos
.m
].oldtype
],
1629 (pos
.p
.lineno
-1)/2);
1630 /* Longest type is AlreadyApplied - need to ensure
1631 * we erase all of that.
1633 move(0, cols
- strlen(lbuf
) - 14);
1635 mvaddstr(0, cols
- strlen(lbuf
) - 1, lbuf
);
1637 #define META(c) ((c)|0x1000)
1638 #define SEARCH(c) ((c)|0x2000)
1639 #define CTRLX(c) ((c)|0x4000)
1641 (void)attrset(A_NORMAL
);
1650 snprintf(buf
, 10, "%d ", num
);
1655 if (meta
& CTRLX(0))
1657 if (meta
& SEARCH(0)) {
1659 addstr("Backwards ");
1662 if (search_notfound
)
1663 addstr(" - Not Found.");
1664 search_notfound
= 0;
1667 /* '+1' to skip over the leading +/-/| char */
1668 if (curs
.alt
&& splitrow
> 0)
1669 move((rows
+ splitrow
)/2, curs
.col
- start
+ 1);
1670 else if (curs
.alt
&& ((mode
& (BEFORE
|AFTER
)) &&
1671 (mode
& (ORIG
|RESULT
))))
1672 move(row
, curs
.col
-start
+ (cols
-1)/2+2);
1674 move(row
, curs
.col
-start
+1);
1683 tmeta
= meta
; meta
= 0;
1684 tnum
= num
; num
= -1;
1685 tvpos
= vpos
; vpos
= pos
;
1686 cswitch
= c
| tmeta
;
1687 /* Handle some ranges */
1688 /* case '0' ... '9': */
1689 if (cswitch
>= '0' && cswitch
<= '9')
1691 /* case SEARCH(' ') ... SEARCH('~'): */
1692 if (cswitch
>= SEARCH(' ') && cswitch
<= SEARCH('~'))
1693 cswitch
= SEARCH(' ');
1696 case 27: /* escape */
1706 case META('<'): /* start of file */
1711 prev_mline(&tpos
, fm
, fb
, fa
, ci
.merger
, mmode
);
1712 } while (tpos
.p
.m
>= 0);
1716 case META('>'): /* end of file */
1723 next_mline(&tpos
, fm
, fb
, fa
, ci
.merger
, mmode
);
1724 } while (ci
.merger
[tpos
.p
.m
].type
!= End
);
1728 case '0': /* actually '0'...'9' */
1731 num
= tnum
*10 + (c
-'0');
1735 mesg
= "Autosave disabled";
1737 mesg
= "Use 'q' to quit";
1746 answer
= help_window(save_query
, NULL
, 1);
1751 p
->conflicts
= isolate_conflicts(
1752 fm
, fb
, fa
, csl1
, csl2
, 0,
1753 ci
.merger
, 0, &p
->wiggles
);
1754 p
->chunks
= p
->conflicts
;
1755 save_merge(fm
, fb
, fa
, ci
.merger
,
1756 p
->file
, !p
->is_merge
);
1772 /* incr search forward */
1775 search
[searchlen
] = 0;
1780 /* incr search backwards */
1783 search
[searchlen
] = 0;
1786 case SEARCH('G'-64):
1787 case SEARCH('S'-64):
1788 case SEARCH('R'-64):
1790 if ((c
|tmeta
) == SEARCH('R'-64))
1795 tpos
= pos
; trow
= row
;
1798 case SEARCH('H'-64):
1799 case SEARCH(KEY_BACKSPACE
):
1802 struct search_anchor
*a
;
1808 struct search_anchor
*a
;
1816 search_notfound
= a
->notfound
;
1817 searchlen
= a
->searchlen
;
1818 search
[searchlen
] = 0;
1823 case SEARCH(' '): /* actually ' '...'~' */
1826 if (searchlen
< sizeof(search
)-1)
1827 search
[searchlen
++] = c
& (0x7f);
1828 search
[searchlen
] = 0;
1829 tpos
= pos
; trow
= row
;
1831 search_notfound
= 1;
1832 if (ignore_case
== 1 || ignore_case
== 2) {
1835 for (i
=0; i
< searchlen
; i
++)
1836 if (isupper(search
[i
])) {
1842 if (mcontains(tpos
, fm
, fb
, fa
, ci
.merger
,
1843 mmode
, search
, &curs
, searchdir
,
1844 ignore_case
>= 2)) {
1848 search_notfound
= 0;
1851 if (searchdir
< 0) {
1853 prev_mline(&tpos
, fm
, fb
, fa
, ci
.merger
, mmode
);
1856 next_mline(&tpos
, fm
, fb
, fa
, ci
.merger
, mmode
);
1858 } while (tpos
.p
.m
>= 0 && ci
.merger
[tpos
.p
.m
].type
!= End
);
1859 searchdir
/= abs(searchdir
);
1868 case 'V'-64: /* page down */
1870 if (botrow
<= lastrow
) {
1879 case META('v'): /* page up */
1886 if (getmouse(&mevent
) != OK
)
1888 /* First see if this is on the 'other' pane */
1890 /* merge mode, top and bottom */
1891 if ((curs
.alt
&& mevent
.y
< splitrow
) ||
1892 (!curs
.alt
&& mevent
.y
> splitrow
)) {
1895 } else if (mode
== (ORIG
|RESULT
|BEFORE
|AFTER
)) {
1896 /* side-by-side mode */
1897 if ((curs
.alt
&& mevent
.x
< cols
/2) ||
1898 (!curs
.alt
&& mevent
.x
> cols
/2)) {
1902 /* Now try to find the right line */
1903 if (splitrow
< 0 || !curs
.alt
)
1906 trow
= (rows
+ splitrow
)/2;
1907 while (trow
> mevent
.y
) {
1909 prev_mline(&tpos
, fm
, fb
, fa
, ci
.merger
, mmode
);
1910 if (tpos
.p
.m
>= 0) {
1916 while (trow
< mevent
.y
) {
1918 next_mline(&tpos
, fm
, fb
, fa
, ci
.merger
, mmode
);
1919 if (ci
.merger
[tpos
.p
.m
].type
!= End
) {
1925 if (splitrow
< 0 || !curs
.alt
)
1926 /* it is OK to change the row */
1929 /* Now set the target column */
1930 if (mode
== (ORIG
|RESULT
|BEFORE
|AFTER
) &&
1932 curs
.target
= start
+ mevent
.x
- cols
/ 2 - 1;
1934 curs
.target
= start
+ mevent
.x
- 1;
1942 for (; tnum
> 0 ; tnum
--) {
1944 next_mline(&tpos
, fm
, fb
, fa
, ci
.merger
, mmode
);
1945 if (ci
.merger
[tpos
.p
.m
].type
!= End
) {
1960 next_mline(&tpos
, fm
, fb
, fa
, ci
.merger
, mmode
);
1961 } while (!(pos
.state
== 0
1962 && (check_line(pos
, fm
, fb
, fa
, ci
.merger
, mmode
)
1963 & (CONFLICTED
|WIGGLED
)) == 0)
1964 && ci
.merger
[tpos
.p
.m
].type
!= End
);
1968 next_mline(&tpos
, fm
, fb
, fa
, ci
.merger
, mmode
);
1969 } while (pos
.state
== 0
1970 && (check_line(pos
, fm
, fb
, fa
, ci
.merger
, mmode
)
1971 & (CONFLICTED
|WIGGLED
)) == 0
1972 && ci
.merger
[tpos
.p
.m
].type
!= End
);
1980 next_mline(&tpos
, fm
, fb
, fa
, ci
.merger
, mmode
);
1981 } while (!(check_line(pos
, fm
, fb
, fa
, ci
.merger
, mmode
)
1983 && ci
.merger
[tpos
.p
.m
].type
!= End
);
1987 next_mline(&tpos
, fm
, fb
, fa
, ci
.merger
, mmode
);
1988 } while ((check_line(pos
, fm
, fb
, fa
, ci
.merger
, mmode
)
1990 && ci
.merger
[tpos
.p
.m
].type
!= End
);
1999 prev_mline(&tpos
, fm
, fb
, fa
, ci
.merger
, mmode
);
2000 } while (tpos
.state
== 0
2001 && (check_line(tpos
, fm
, fb
, fa
, ci
.merger
, mmode
)
2002 & (CONFLICTED
|WIGGLED
)) == 0
2007 prev_mline(&tpos
, fm
, fb
, fa
, ci
.merger
, mmode
);
2008 } while (!(tpos
.state
== 0
2009 && (check_line(tpos
, fm
, fb
, fa
, ci
.merger
, mmode
)
2010 & (CONFLICTED
|WIGGLED
)) == 0)
2020 for (; tnum
> 0 ; tnum
--) {
2022 prev_mline(&tpos
, fm
, fb
, fa
, ci
.merger
, mmode
);
2023 if (tpos
.p
.m
>= 0) {
2034 curs
.target
= curs
.col
- 1;
2035 if (curs
.target
< 0) {
2036 /* Try to go to end of previous line */
2038 prev_mline(&tpos
, fm
, fb
, fa
, ci
.merger
, mmode
);
2039 if (tpos
.p
.m
>= 0) {
2051 if (curs
.width
>= 0)
2052 curs
.target
= curs
.col
+ curs
.width
;
2054 /* end of line, go to next */
2056 next_mline(&tpos
, fm
, fb
, fa
, ci
.merger
, mmode
);
2057 if (ci
.merger
[tpos
.p
.m
].type
!= End
) {
2080 curs
.alt
= !curs
.alt
;
2081 if (curs
.alt
&& mode
== (ORIG
|RESULT
))
2082 mmode
= (BEFORE
|AFTER
);
2087 case 'a': /* 'after' view in patch window */
2090 mode
= AFTER
; modename
= "after"; modehelp
= after_help
;
2091 mmode
= mode
; curs
.alt
= 0;
2094 case 'b': /* 'before' view in patch window */
2097 mode
= BEFORE
; modename
= "before"; modehelp
= before_help
;
2098 mmode
= mode
; curs
.alt
= 0;
2101 case 'o': /* 'original' view in the merge window */
2104 mode
= ORIG
; modename
= "original"; modehelp
= orig_help
;
2105 mmode
= mode
; curs
.alt
= 0;
2108 case 'r': /* the 'result' view in the merge window */
2111 mode
= RESULT
; modename
= "result"; modehelp
= result_help
;
2112 mmode
= mode
; curs
.alt
= 0;
2116 if (mode
== (BEFORE
|AFTER
))
2118 mode
= BEFORE
|AFTER
; modename
= "diff"; modehelp
= diff_help
;
2119 mmode
= mode
; curs
.alt
= 0;
2124 mode
= ORIG
|RESULT
; modename
= "merge"; modehelp
= merge_help
;
2125 mmode
= mode
; curs
.alt
= 0;
2130 if (mode
== (ORIG
|RESULT
|BEFORE
|AFTER
))
2132 mode
= ORIG
|RESULT
|BEFORE
|AFTER
; modename
= "sidebyside"; modehelp
= sidebyside_help
;
2133 mmode
= mode
; curs
.alt
= 0;
2137 case 'H': /* scroll window to the right */
2140 curs
.target
= start
+ 1;
2143 case 'L': /* scroll window to the left */
2146 curs
.target
= start
+ 1;
2151 prev_melmnt(&tvpos
.p
, fm
, fb
, fa
, ci
.merger
);
2156 next_melmnt(&tvpos
.p
, fm
, fb
, fa
, ci
.merger
);
2157 if (ci
.merger
[tvpos
.p
.m
].type
!= End
)
2161 case 'x': /* Toggle rejecting of conflict.
2162 * A 'Conflict' or 'Changed' becomes 'Unchanged'
2164 if (ci
.merger
[curs
.pos
.m
].oldtype
!= Conflict
&&
2165 ci
.merger
[curs
.pos
.m
].oldtype
!= Changed
)
2168 if (ci
.merger
[curs
.pos
.m
].type
== Unchanged
)
2169 ci
.merger
[curs
.pos
.m
].type
= ci
.merger
[curs
.pos
.m
].oldtype
;
2172 ci
.merger
[curs
.pos
.m
].type
= Unchanged
;
2173 p
->conflicts
= isolate_conflicts(
2174 fm
, fb
, fa
, csl1
, csl2
, 0,
2175 ci
.merger
, 0, &p
->wiggles
);
2180 case 'X': /* toggle where all Conflicts and Changeds
2181 * in the current line are marked Unchanged.
2182 * If any are not mark, mark them all, else
2188 if ((ci
.merger
[tpos
.p
.m
].oldtype
== Conflict
||
2189 ci
.merger
[tpos
.p
.m
].oldtype
== Changed
)
2190 && ci
.merger
[tpos
.p
.m
].type
!= Unchanged
)
2192 e
= prev_melmnt(&tpos
.p
, fm
, fb
, fa
, ci
.merger
);
2193 } while (!ends_line(e
) ||
2194 visible(mode
& (RESULT
|AFTER
), ci
.merger
, &tpos
) < 0);
2197 if (ci
.merger
[tpos
.p
.m
].oldtype
== Conflict
||
2198 ci
.merger
[tpos
.p
.m
].oldtype
== Changed
) {
2200 ci
.merger
[tpos
.p
.m
].type
= Unchanged
;
2202 ci
.merger
[tpos
.p
.m
].type
=
2203 ci
.merger
[tpos
.p
.m
].oldtype
;
2205 e
= prev_melmnt(&tpos
.p
, fm
, fb
, fa
, ci
.merger
);
2206 } while (!ends_line(e
) ||
2207 visible(mode
& (RESULT
|AFTER
), ci
.merger
, &tpos
) < 0);
2208 p
->conflicts
= isolate_conflicts(
2209 fm
, fb
, fa
, csl1
, csl2
, 0,
2210 ci
.merger
, 0, &p
->wiggles
);
2216 help_window(modehelp
, merge_window_help
, 0);
2225 if (meta
== SEARCH(0)) {
2226 if (anchor
== NULL
||
2227 !same_mpos(anchor
->pos
, pos
) ||
2228 anchor
->searchlen
!= searchlen
||
2229 !same_mp(anchor
->curs
.pos
, curs
.pos
)) {
2230 struct search_anchor
*a
= xmalloc(sizeof(*a
));
2235 a
->searchlen
= searchlen
;
2236 a
->notfound
= search_notfound
;
2242 struct search_anchor
*a
= anchor
;
2248 /* move backward and forward to make sure we
2249 * are on a visible line
2252 prev_mline(&tpos
, fm
, fb
, fa
, ci
.merger
, mmode
);
2256 next_mline(&tpos
, fm
, fb
, fa
, ci
.merger
, mmode
);
2257 if (ci
.merger
[tpos
.p
.m
].type
!= End
)
2263 static int show_merge(char *origname
, FILE *patch
, int reverse
,
2264 int is_merge
, char *before
, char *after
,
2265 int replace
, int selftest
, int ignore_blanks
)
2272 fseek(patch
, 0, SEEK_END
);
2273 p
.end
= ftell(patch
);
2274 fseek(patch
, 0, SEEK_SET
);
2277 p
.is_merge
= is_merge
;
2281 freopen("/dev/null","w",stderr
);
2282 return merge_window(&p
, patch
, reverse
, replace
, selftest
,
2286 static void calc_one(struct plist
*pl
, FILE *f
, int reverse
,
2289 struct stream s1
, s2
;
2290 struct stream s
= load_segment(f
, pl
->start
, pl
->end
);
2294 split_merge(s
, &sf
, &s2
, &s1
);
2296 split_merge(s
, &sf
, &s1
, &s2
);
2299 sf
= load_file(pl
->file
);
2301 pl
->chunks
= split_patch(s
, &s2
, &s1
);
2303 pl
->chunks
= split_patch(s
, &s1
, &s2
);
2305 if (sf
.body
== NULL
|| s1
.body
== NULL
|| s1
.body
== NULL
) {
2306 pl
->wiggles
= pl
->conflicts
= -1;
2308 struct file ff
, fp1
, fp2
;
2309 struct csl
*csl1
, *csl2
;
2311 ff
= split_stream(sf
, ByWord
| ignore_blanks
);
2312 fp1
= split_stream(s1
, ByWord
| ignore_blanks
);
2313 fp2
= split_stream(s2
, ByWord
| ignore_blanks
);
2315 csl1
= pdiff(ff
, fp1
, pl
->chunks
);
2317 csl1
= diff(ff
, fp1
);
2318 csl2
= diff_patch(fp1
, fp2
);
2319 ci
= make_merger(ff
, fp1
, fp2
, csl1
, csl2
, 0, 1, 0);
2320 pl
->wiggles
= ci
.wiggles
;
2321 pl
->conflicts
= ci
.conflicts
;
2337 static int get_prev(int pos
, struct plist
*pl
, int n
, int mode
)
2343 if (pl
[pos
].prev
== -1)
2344 return pl
[pos
].parent
;
2346 while (pl
[pos
].open
&&
2349 if (pl
[pos
].last
>= 0)
2350 /* always see directories */
2354 else if (mode
<= 1 && pl
[pos
].wiggles
> 0)
2356 else if (mode
<= 2 && pl
[pos
].conflicts
> 0)
2358 } while (pos
>= 0 && !found
);
2362 static int get_next(int pos
, struct plist
*pl
, int n
, int mode
,
2363 FILE *f
, int reverse
, int ignore_blanks
)
2375 while (pos
>= 0 && pl
[pos
].next
== -1)
2376 pos
= pl
[pos
].parent
;
2382 if (pl
[pos
].calced
== 0 && pl
[pos
].end
)
2383 calc_one(pl
+pos
, f
, reverse
, ignore_blanks
);
2384 if (pl
[pos
].last
>= 0)
2385 /* always see directories */
2389 else if (mode
<= 1 && pl
[pos
].wiggles
> 0)
2391 else if (mode
<= 2 && pl
[pos
].conflicts
> 0)
2393 } while (pos
>= 0 && !found
);
2397 static void draw_one(int row
, struct plist
*pl
, FILE *f
, int reverse
,
2408 if (pl
->calced
== 0 && pl
->end
)
2409 /* better load the patch and count the chunks */
2410 calc_one(pl
, f
, reverse
, ignore_blanks
);
2414 if (pl
->chunks
> 99)
2417 sprintf(hdr
, "%2d", pl
->chunks
);
2418 if (pl
->wiggles
> 99)
2419 strcpy(hdr
+2, " XX");
2421 sprintf(hdr
+2, " %2d", pl
->wiggles
);
2422 if (pl
->conflicts
> 99)
2423 strcpy(hdr
+5, " XX ");
2425 sprintf(hdr
+5, " %2d ", pl
->conflicts
);
2428 strcpy(hdr
+9, "= ");
2430 strcpy(hdr
+9, "+ ");
2432 strcpy(hdr
+9, "- ");
2436 else if (pl
->is_merge
)
2438 else if (pl
->conflicts
)
2439 attrset(a_has_conflicts
);
2440 else if (pl
->wiggles
)
2441 attrset(a_has_wiggles
);
2443 attrset(a_no_wiggles
);
2445 mvaddstr(row
, 0, hdr
);
2446 mvaddstr(row
, 11, pl
->file
);
2450 static int save_one(FILE *f
, struct plist
*pl
, int reverse
,
2453 struct stream sp
, sa
, sb
, sm
;
2454 struct file fa
, fb
, fm
;
2455 struct csl
*csl1
, *csl2
;
2458 sp
= load_segment(f
, pl
->start
,
2461 chunks
= split_patch(sp
, &sa
, &sb
);
2463 chunks
= split_patch(sp
, &sb
, &sa
);
2464 fb
= split_stream(sb
, ByWord
| ignore_blanks
);
2465 fa
= split_stream(sa
, ByWord
| ignore_blanks
);
2466 sm
= load_file(pl
->file
);
2467 fm
= split_stream(sm
, ByWord
| ignore_blanks
);
2468 csl1
= pdiff(fm
, fb
, chunks
);
2469 csl2
= diff_patch(fb
, fa
);
2470 ci
= make_merger(fm
, fb
, fa
, csl1
, csl2
, 0, 1, 0);
2471 return save_merge(fm
, fb
, fa
, ci
.merger
,
2475 static char *main_help
[] = {
2476 " You are using the \"browse\" mode of wiggle.",
2477 "This page shows a list of files in a patch together with",
2478 "the directories that contain them.",
2479 "A directory is indicated by a '+' if the contents are",
2480 "listed or a '-' if the contents are hidden. A file is",
2481 "indicated by an '='. Typing <space> or <return> will",
2482 "expose or hide a directory, and will visit a file.",
2484 "The three columns of numbers are:",
2485 " Ch The number of patch chunks which applied to",
2487 " Wi The number of chunks that needed to be wiggled",
2489 " Co The number of chunks that created an unresolvable",
2492 "Keystrokes recognised in this page are:",
2493 " ? Display this help",
2494 " SPC On a directory, toggle hiding of contents",
2495 " On file, visit the file",
2498 " control-C Disable auto-save-on-exit",
2499 " n,j,DOWN Go to next line",
2500 " p,k,UP Go to previous line",
2502 " A list All files",
2503 " W only list files with a wiggle or a conflict",
2504 " C only list files with a conflict",
2506 " S Save this file with changes applied. If",
2507 " some but not all files are saved, wiggle will",
2508 " prompt on exit to save the rest.",
2509 " R Revert the current saved file to its original",
2513 static char *saveall_msg
= " %d file%s (of %d) have not been saved.";
2514 static char saveall_buf
[200];
2515 static char *saveall_query
[] = {
2518 " Would you like to save them?",
2519 " Y = yes, save them all",
2520 " N = no, exit without saving anything else",
2521 " Q = Don't quit just yet",
2524 static void main_window(struct plist
*pl
, int *np
, FILE *f
, int reverse
,
2525 int replace
, int ignore_blanks
)
2527 /* The main window lists all files together with summary information:
2528 * number of chunks, number of wiggles, number of conflicts.
2529 * The list is scrollable
2530 * When a entry is 'selected', we switch to the 'file' window
2531 * The list can be condensed by removing files with no conflict
2532 * or no wiggles, or removing subdirectories
2534 * We record which file in the list is 'current', and which
2535 * screen line it is on. We try to keep things stable while
2538 * Counts are printed before the name using at most 2 digits.
2539 * Numbers greater than 99 are XX
2541 * 27 5 1 drivers/md/md.c
2543 * A directory show the sum in all children.
2546 * select: enter, space, mouseclick
2547 * on file, go to file window
2548 * on directory, toggle open
2549 * up: k, p, control-p uparrow
2550 * Move to previous open object
2551 * down: j, n, control-n, downarrow
2552 * Move to next open object
2554 * A W C: select All Wiggles or Conflicts
2559 char mesg_buf
[1024];
2560 int last_mesg_len
= 0;
2561 int pos
= 0; /* position in file */
2562 int row
= 1; /* position on screen */
2563 int rows
= 0; /* size of screen in rows */
2568 int mode
= 0; /* 0=all, 1= only wiggled, 2=only conflicted */
2569 int cnt
; /* count of files that need saving */
2570 int any
; /* count of files that have been save*/
2574 freopen("/dev/null","w",stderr
);
2576 pl
= sort_patches(pl
, np
);
2580 clear(); (void)attrset(0);
2582 mvaddstr(0, 0, "Ch Wi Co Patched Files");
2587 if (row
< 1 || row
>= rows
)
2591 getmaxyx(stdscr
, rows
, cols
);
2593 if (row
>= rows
+ 3)
2598 for (i
= row
; i
> 1; i
--) {
2599 tpos
= get_prev(tpos
, pl
, *np
, mode
);
2605 /* Ok, row and pos could be trustworthy now */
2607 for (i
= row
; i
>= 1; i
--) {
2608 draw_one(i
, &pl
[tpos
], f
, reverse
, ignore_blanks
);
2609 tpos
= get_prev(tpos
, pl
, *np
, mode
);
2612 for (i
= row
+1; i
< rows
; i
++) {
2613 tpos
= get_next(tpos
, pl
, *np
, mode
, f
, reverse
,ignore_blanks
);
2615 draw_one(i
, &pl
[tpos
], f
, reverse
, ignore_blanks
);
2617 draw_one(i
, NULL
, f
, reverse
, ignore_blanks
);
2621 if (last_mesg_len
) {
2622 move(0, cols
- last_mesg_len
);
2627 last_mesg_len
= strlen(mesg
);
2628 move(0, cols
- last_mesg_len
);
2632 /* debugging help: report last keystroke */
2634 sprintf(bb
, "last-key = 0%o", c
);
2636 last_mesg_len
= strlen(bb
);
2637 mvaddstr(0, cols
- last_mesg_len
, bb
);
2647 tpos
= get_next(pos
, pl
, *np
, mode
, f
, reverse
, ignore_blanks
);
2658 tpos
= get_prev(pos
, pl
, *np
, mode
);
2666 if (getmouse(&mevent
) != OK
)
2668 while (row
< mevent
.y
&&
2669 (tpos
= get_next(pos
, pl
, *np
, mode
, f
, reverse
, ignore_blanks
))
2674 while (row
> mevent
.y
&&
2675 (tpos
= get_prev(pos
, pl
, *np
, mode
)) >= 0) {
2679 if (row
!= mevent
.y
)
2680 /* couldn't find the line */
2685 if (pl
[pos
].end
== 0) {
2686 pl
[pos
].open
= !pl
[pos
].open
;
2689 mesg
= "Opened folder";
2691 mesg
= "Closed folder";
2694 if (pl
[pos
].is_merge
)
2695 c
= merge_window(&pl
[pos
], NULL
, reverse
, 0, 0, ignore_blanks
);
2697 c
= merge_window(&pl
[pos
], f
, reverse
, 0, 0, ignore_blanks
);
2700 pl
[pos
].is_merge
= 1;
2701 snprintf(mesg_buf
, cols
,
2708 case 27: /* escape */
2710 mvaddstr(0, cols
-10, "ESC..."); clrtoeol();
2714 move(0, cols
-10); clrtoeol();
2718 mesg
= "Save-on-exit disabled. Use 'q' to quit.";
2720 mesg
= "Use 'q' to quit.";
2727 for (i
= 0; i
< *np
; i
++)
2728 if (pl
[i
].end
&& !pl
[i
].is_merge
)
2740 sprintf(saveall_buf
, saveall_msg
,
2741 cnt
, cnt
== 1 ? "" : "s", cnt
+any
);
2742 ans
= help_window(saveall_query
, NULL
, 1);
2748 for (i
= 0; i
< *np
; i
++) {
2759 printf("%d file%s saved\n", cnt
,
2760 cnt
== 1 ? "" : "s");
2764 mode
= 0; refresh
= 1;
2765 mesg
= "Showing ALL files";
2768 mode
= 1; refresh
= 1;
2769 mesg
= "Showing Wiggled files";
2772 mode
= 2; refresh
= 1;
2773 mesg
= "Showing Conflicted files";
2776 case 'S': /* Save updated file */
2777 if (pl
[pos
].end
== 0) {
2779 mesg
= "Cannot save a folder.";
2780 } else if (pl
[pos
].is_merge
) {
2782 mesg
= "File is already saved.";
2784 if (save_one(f
, &pl
[pos
], reverse
, ignore_blanks
) == 0) {
2785 pl
[pos
].is_merge
= 1;
2786 snprintf(mesg_buf
, cols
,
2789 pl
[pos
].chunks
= pl
[pos
].conflicts
;
2790 pl
[pos
].wiggles
= 0;
2792 snprintf(mesg_buf
, cols
,
2793 "Failed to save file %s.",
2800 case 'R': /* Restore updated file */
2801 if (pl
[pos
].end
== 0)
2802 mesg
= "Cannot restore a folder.";
2803 else if (!pl
[pos
].is_merge
)
2804 mesg
= "File has not been saved, cannot restore.";
2806 /* rename foo.porig to foo, and clear is_merge */
2807 char *file
= pl
[pos
].file
;
2808 char *orignew
= xmalloc(strlen(file
) + 20);
2809 strcpy(orignew
, file
);
2810 strcat(orignew
, ".porig");
2811 if (rename(orignew
, file
) == 0) {
2812 mesg
= "File has been restored.";
2813 pl
[pos
].is_merge
= 0;
2815 calc_one(&pl
[pos
], f
, reverse
, ignore_blanks
);
2817 mesg
= "Could not restore file!";
2822 help_window(main_help
, NULL
, 0);
2833 static void catch(int sig
)
2835 if (sig
== SIGINT
&& !intr_kills
) {
2842 printf("Died on signal %d\n", sig
);
2844 if (sig
!= SIGBUS
&& sig
!= SIGSEGV
)
2847 /* Otherwise return and die */
2851 static void term_init(int doraw
)
2854 static int init_done
= 0;
2860 signal(SIGINT
, catch);
2861 signal(SIGQUIT
, catch);
2862 signal(SIGTERM
, catch);
2863 signal(SIGBUS
, catch);
2864 signal(SIGSEGV
, catch);
2873 use_default_colors();
2874 if (!has_colors()) {
2875 a_delete
= A_UNDERLINE
;
2877 a_common
= A_NORMAL
;
2879 a_already
= A_STANDOUT
;
2880 a_has_conflicts
= A_UNDERLINE
;
2881 a_has_wiggles
= A_BOLD
;
2882 a_no_wiggles
= A_NORMAL
;
2884 init_pair(1, COLOR_RED
, -1);
2885 a_delete
= COLOR_PAIR(1);
2886 init_pair(2, COLOR_GREEN
, -1);
2887 a_added
= COLOR_PAIR(2);
2888 a_common
= A_NORMAL
;
2889 init_pair(3, COLOR_WHITE
, COLOR_GREEN
);
2890 a_sep
= COLOR_PAIR(3); a_sep
= A_STANDOUT
;
2891 init_pair(4, -1, COLOR_YELLOW
);
2892 a_void
= COLOR_PAIR(4);
2893 init_pair(5, COLOR_BLUE
, -1);
2894 a_unmatched
= COLOR_PAIR(5);
2895 init_pair(6, COLOR_CYAN
, -1);
2896 a_extra
= COLOR_PAIR(6);
2898 init_pair(7, COLOR_BLACK
, COLOR_CYAN
);
2899 a_already
= COLOR_PAIR(7);
2901 a_has_conflicts
= a_delete
;
2902 a_has_wiggles
= a_added
;
2903 a_no_wiggles
= a_unmatched
;
2906 nonl(); intrflush(stdscr
, FALSE
); keypad(stdscr
, TRUE
);
2907 mousemask(ALL_MOUSE_EVENTS
, NULL
);
2910 int vpatch(int argc
, char *argv
[], int patch
, int strip
,
2911 int reverse
, int replace
, int selftest
, int ignore_blanks
)
2913 /* NOTE argv[0] is first arg...
2914 * Behaviour depends on number of args:
2915 * 0: A multi-file patch is read from stdin
2916 * 1: if 'patch', parse it as a multi-file patch and allow
2917 * the files to be browsed.
2918 * if filename ends '.rej', then treat it as a patch again
2919 * a file with the same basename
2920 * Else treat the file as a merge (with conflicts) and view it.
2921 * 2: First file is original, second is patch
2922 * 3: Files are: original previous new. The diff between 'previous' and
2923 * 'new' needs to be applied to 'original'.
2925 * If a multi-file patch is being read, 'strip' tells how many
2926 * path components to strip. If it is -1, we guess based on
2928 * If 'reverse' is given, when we invert any patch or diff
2929 * If 'replace' then we save the resulting merge.
2938 fprintf(stderr
, "%s: too many file names given.\n", Cmd
);
2941 case 0: /* stdin is a patch */
2942 if (lseek(fileno(stdin
), 0L, 1) == -1) {
2943 /* cannot seek, so need to copy to a temp file */
2946 fprintf(stderr
, "%s: Cannot create temp file\n", Cmd
);
2949 pl
= parse_patch(stdin
, f
, &num_patches
);
2952 pl
= parse_patch(stdin
, NULL
, &num_patches
);
2953 in
= fdopen(dup(0), "r");
2955 /* use stderr for keyboard input */
2957 if (set_prefix(pl
, num_patches
, strip
) == 0) {
2958 fprintf(stderr
, "%s: aborting\n", Cmd
);
2961 main_window(pl
, &num_patches
, in
, reverse
, replace
, ignore_blanks
);
2962 plist_free(pl
, num_patches
);
2966 case 1: /* a patch, a .rej, or a merge file */
2967 f
= fopen(argv
[0], "r");
2969 fprintf(stderr
, "%s: cannot open %s\n", Cmd
, argv
[0]);
2973 pl
= parse_patch(f
, NULL
, &num_patches
);
2974 if (set_prefix(pl
, num_patches
, strip
) == 0) {
2975 fprintf(stderr
, "%s: aborting\n", Cmd
);
2978 main_window(pl
, &num_patches
, f
, reverse
, replace
,ignore_blanks
);
2979 plist_free(pl
, num_patches
);
2980 } else if (strlen(argv
[0]) > 4 &&
2981 strcmp(argv
[0]+strlen(argv
[0])-4, ".rej") == 0) {
2982 char *origname
= strdup(argv
[0]);
2983 origname
[strlen(origname
) - 4] = '\0';
2984 show_merge(origname
, f
, reverse
, 0, NULL
, NULL
,
2985 replace
, selftest
, ignore_blanks
);
2987 show_merge(argv
[0], f
, reverse
, 1, NULL
, NULL
,
2988 replace
, selftest
, ignore_blanks
);
2991 case 2: /* an orig and a diff/.ref */
2992 f
= fopen(argv
[1], "r");
2994 fprintf(stderr
, "%s: cannot open %s\n", Cmd
, argv
[0]);
2997 show_merge(argv
[0], f
, reverse
, 0, NULL
, NULL
,
2998 replace
, selftest
, ignore_blanks
);
3000 case 3: /* orig, before, after */
3001 show_merge(argv
[0], NULL
, reverse
, 0, argv
[1], argv
[2],
3002 replace
, selftest
, ignore_blanks
);