2 |
- |
1 |
/* Normal-format output routines for GNU DIFF.
|
|
|
2 |
Copyright (C) 1988, 1989, 1993 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 |
You should have received a copy of the GNU General Public License
|
|
|
17 |
along with GNU DIFF; see the file COPYING. If not, write to
|
|
|
18 |
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
#include "diff.h"
|
|
|
22 |
|
|
|
23 |
static void print_normal_hunk PARAMS((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 (script)
|
|
|
30 |
struct change *script;
|
|
|
31 |
{
|
|
|
32 |
print_script (script, find_change, print_normal_hunk);
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
/* Print a hunk of a normal diff.
|
|
|
36 |
This is a contiguous portion of a complete edit script,
|
|
|
37 |
describing changes in consecutive lines. */
|
|
|
38 |
|
|
|
39 |
static void
|
|
|
40 |
print_normal_hunk (hunk)
|
|
|
41 |
struct change *hunk;
|
|
|
42 |
{
|
|
|
43 |
int first0, last0, first1, last1, deletes, inserts;
|
|
|
44 |
register int i;
|
|
|
45 |
|
|
|
46 |
/* Determine range of line numbers involved in each file. */
|
|
|
47 |
analyze_hunk (hunk, &first0, &last0, &first1, &last1, &deletes, &inserts);
|
|
|
48 |
if (!deletes && !inserts)
|
|
|
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 (inserts, deletes));
|
|
|
56 |
print_number_range (',', &files[1], first1, last1);
|
|
|
57 |
fprintf (outfile, "\n");
|
|
|
58 |
|
|
|
59 |
/* Print the lines that the first file has. */
|
|
|
60 |
if (deletes)
|
|
|
61 |
for (i = first0; i <= last0; i++)
|
|
|
62 |
print_1_line ("<", &files[0].linbuf[i]);
|
|
|
63 |
|
|
|
64 |
if (inserts && deletes)
|
|
|
65 |
fprintf (outfile, "---\n");
|
|
|
66 |
|
|
|
67 |
/* Print the lines that the second file has. */
|
|
|
68 |
if (inserts)
|
|
|
69 |
for (i = first1; i <= last1; i++)
|
|
|
70 |
print_1_line (">", &files[1].linbuf[i]);
|
|
|
71 |
}
|