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