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