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