Upgrade diffutils from 2.8.7 to 3.0 on the vendor branch
[dragonfly.git] / contrib / diffutils / src / normal.c
1 /* Normal-format output routines for GNU DIFF.
2
3    Copyright (C) 1988-1989, 1993, 1995, 1998, 2001, 2006, 2009-2010 Free
4    Software Foundation, Inc.
5
6    This file is part of GNU DIFF.
7
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 3 of the License, or
11    (at your option) any later version.
12
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.
17
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
20
21 #include "diff.h"
22
23 static void print_normal_hunk (struct change *);
24
25 /* Print the edit-script SCRIPT as a normal diff.
26    INF points to an array of descriptions of the two files.  */
27
28 void
29 print_normal_script (struct change *script)
30 {
31   print_script (script, find_change, print_normal_hunk);
32 }
33
34 /* Print a hunk of a normal diff.
35    This is a contiguous portion of a complete edit script,
36    describing changes in consecutive lines.  */
37
38 static void
39 print_normal_hunk (struct change *hunk)
40 {
41   lin first0, last0, first1, last1;
42   register lin i;
43
44   /* Determine range of line numbers involved in each file.  */
45   enum changes changes = analyze_hunk (hunk, &first0, &last0, &first1, &last1);
46   if (!changes)
47     return;
48
49   begin_output ();
50
51   /* Print out the line number header for this hunk */
52   print_number_range (',', &files[0], first0, last0);
53   fputc (change_letter[changes], outfile);
54   print_number_range (',', &files[1], first1, last1);
55   fputc ('\n', outfile);
56
57   /* Print the lines that the first file has.  */
58   if (changes & OLD)
59     for (i = first0; i <= last0; i++)
60       print_1_line ("<", &files[0].linbuf[i]);
61
62   if (changes == CHANGED)
63     fputs ("---\n", outfile);
64
65   /* Print the lines that the second file has.  */
66   if (changes & NEW)
67     for (i = first1; i <= last1; i++)
68       print_1_line (">", &files[1].linbuf[i]);
69 }