1*18fd37a7SXin LI /* Normal-format output routines for GNU DIFF.
2*18fd37a7SXin LI
3*18fd37a7SXin LI Copyright (C) 1988, 1989, 1993, 1995, 1998, 2001 Free Software
4*18fd37a7SXin LI Foundation, Inc.
5*18fd37a7SXin LI
6*18fd37a7SXin LI This file is part of GNU DIFF.
7*18fd37a7SXin LI
8*18fd37a7SXin LI GNU DIFF is free software; you can redistribute it and/or modify
9*18fd37a7SXin LI it under the terms of the GNU General Public License as published by
10*18fd37a7SXin LI the Free Software Foundation; either version 2, or (at your option)
11*18fd37a7SXin LI any later version.
12*18fd37a7SXin LI
13*18fd37a7SXin LI GNU DIFF is distributed in the hope that it will be useful,
14*18fd37a7SXin LI but WITHOUT ANY WARRANTY; without even the implied warranty of
15*18fd37a7SXin LI MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16*18fd37a7SXin LI GNU General Public License for more details.
17*18fd37a7SXin LI
18*18fd37a7SXin LI You should have received a copy of the GNU General Public License
19*18fd37a7SXin LI along with this program; see the file COPYING.
20*18fd37a7SXin LI If not, write to the Free Software Foundation,
21*18fd37a7SXin LI 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22*18fd37a7SXin LI
23*18fd37a7SXin LI #include "diff.h"
24*18fd37a7SXin LI
25*18fd37a7SXin LI static void print_normal_hunk (struct change *);
26*18fd37a7SXin LI
27*18fd37a7SXin LI /* Print the edit-script SCRIPT as a normal diff.
28*18fd37a7SXin LI INF points to an array of descriptions of the two files. */
29*18fd37a7SXin LI
30*18fd37a7SXin LI void
print_normal_script(struct change * script)31*18fd37a7SXin LI print_normal_script (struct change *script)
32*18fd37a7SXin LI {
33*18fd37a7SXin LI print_script (script, find_change, print_normal_hunk);
34*18fd37a7SXin LI }
35*18fd37a7SXin LI
36*18fd37a7SXin LI /* Print a hunk of a normal diff.
37*18fd37a7SXin LI This is a contiguous portion of a complete edit script,
38*18fd37a7SXin LI describing changes in consecutive lines. */
39*18fd37a7SXin LI
40*18fd37a7SXin LI static void
print_normal_hunk(struct change * hunk)41*18fd37a7SXin LI print_normal_hunk (struct change *hunk)
42*18fd37a7SXin LI {
43*18fd37a7SXin LI lin first0, last0, first1, last1;
44*18fd37a7SXin LI register lin i;
45*18fd37a7SXin LI
46*18fd37a7SXin LI /* Determine range of line numbers involved in each file. */
47*18fd37a7SXin LI enum changes changes = analyze_hunk (hunk, &first0, &last0, &first1, &last1);
48*18fd37a7SXin LI if (!changes)
49*18fd37a7SXin LI return;
50*18fd37a7SXin LI
51*18fd37a7SXin LI begin_output ();
52*18fd37a7SXin LI
53*18fd37a7SXin LI /* Print out the line number header for this hunk */
54*18fd37a7SXin LI print_number_range (',', &files[0], first0, last0);
55*18fd37a7SXin LI fprintf (outfile, "%c", change_letter[changes]);
56*18fd37a7SXin LI print_number_range (',', &files[1], first1, last1);
57*18fd37a7SXin LI fprintf (outfile, "\n");
58*18fd37a7SXin LI
59*18fd37a7SXin LI /* Print the lines that the first file has. */
60*18fd37a7SXin LI if (changes & OLD)
61*18fd37a7SXin LI for (i = first0; i <= last0; i++)
62*18fd37a7SXin LI print_1_line ("<", &files[0].linbuf[i]);
63*18fd37a7SXin LI
64*18fd37a7SXin LI if (changes == CHANGED)
65*18fd37a7SXin LI fprintf (outfile, "---\n");
66*18fd37a7SXin LI
67*18fd37a7SXin LI /* Print the lines that the second file has. */
68*18fd37a7SXin LI if (changes & NEW)
69*18fd37a7SXin LI for (i = first1; i <= last1; i++)
70*18fd37a7SXin LI print_1_line (">", &files[1].linbuf[i]);
71*18fd37a7SXin LI }
72