xref: /freebsd/contrib/diff/src/normal.c (revision 5956d97f4b3204318ceb6aa9c77bd0bc6ea87a41)
1 /* Normal-format output routines for GNU DIFF.
2 
3    Copyright (C) 1988, 1989, 1993, 1995, 1998, 2001 Free Software
4    Foundation, Inc.
5 
6    This file is part of GNU DIFF.
7 
8    GNU DIFF 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, or (at your option)
11    any later version.
12 
13    GNU DIFF 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; see the file COPYING.
20    If not, write to the Free Software Foundation,
21    59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
22 
23 #include "diff.h"
24 
25 static void print_normal_hunk (struct change *);
26 
27 /* Print the edit-script SCRIPT as a normal diff.
28    INF points to an array of descriptions of the two files.  */
29 
30 void
31 print_normal_script (struct change *script)
32 {
33   print_script (script, find_change, print_normal_hunk);
34 }
35 
36 /* Print a hunk of a normal diff.
37    This is a contiguous portion of a complete edit script,
38    describing changes in consecutive lines.  */
39 
40 static void
41 print_normal_hunk (struct change *hunk)
42 {
43   lin first0, last0, first1, last1;
44   register lin i;
45 
46   /* Determine range of line numbers involved in each file.  */
47   enum changes changes = analyze_hunk (hunk, &first0, &last0, &first1, &last1);
48   if (!changes)
49     return;
50 
51   begin_output ();
52 
53   /* Print out the line number header for this hunk */
54   print_number_range (',', &files[0], first0, last0);
55   fprintf (outfile, "%c", change_letter[changes]);
56   print_number_range (',', &files[1], first1, last1);
57   fprintf (outfile, "\n");
58 
59   /* Print the lines that the first file has.  */
60   if (changes & OLD)
61     for (i = first0; i <= last0; i++)
62       print_1_line ("<", &files[0].linbuf[i]);
63 
64   if (changes == CHANGED)
65     fprintf (outfile, "---\n");
66 
67   /* Print the lines that the second file has.  */
68   if (changes & NEW)
69     for (i = first1; i <= last1; i++)
70       print_1_line (">", &files[1].linbuf[i]);
71 }
72