1 /* Normal-format output routines for GNU DIFF.
2 Copyright (C) 1988, 1989, 1993, 1998 Free Software Foundation, Inc.
3
4 This file is part of GNU DIFF.
5
6 GNU DIFF is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU DIFF is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 */
17
18
19 #include "diff.h"
20
21 static void print_normal_hunk PARAMS((struct change *));
22
23 /* Print the edit-script SCRIPT as a normal diff.
24 INF points to an array of descriptions of the two files. */
25
26 void
print_normal_script(script)27 print_normal_script (script)
28 struct change *script;
29 {
30 print_script (script, find_change, print_normal_hunk);
31 }
32
33 /* Print a hunk of a normal diff.
34 This is a contiguous portion of a complete edit script,
35 describing changes in consecutive lines. */
36
37 static void
print_normal_hunk(hunk)38 print_normal_hunk (hunk)
39 struct change *hunk;
40 {
41 int first0, last0, first1, last1, deletes, inserts;
42 register int i;
43
44 /* Determine range of line numbers involved in each file. */
45 analyze_hunk (hunk, &first0, &last0, &first1, &last1, &deletes, &inserts);
46 if (!deletes && !inserts)
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 printf_output ("%c", change_letter (inserts, deletes));
54 print_number_range (',', &files[1], first1, last1);
55 printf_output ("\n");
56
57 /* Print the lines that the first file has. */
58 if (deletes)
59 for (i = first0; i <= last0; i++)
60 print_1_line ("<", &files[0].linbuf[i]);
61
62 if (inserts && deletes)
63 printf_output ("---\n");
64
65 /* Print the lines that the second file has. */
66 if (inserts)
67 for (i = first1; i <= last1; i++)
68 print_1_line (">", &files[1].linbuf[i]);
69 }
70