1170754Sdelphij/* Normal-format output routines for GNU DIFF.
2170754Sdelphij
3170754Sdelphij   Copyright (C) 1988, 1989, 1993, 1995, 1998, 2001 Free Software
4170754Sdelphij   Foundation, Inc.
5170754Sdelphij
6170754Sdelphij   This file is part of GNU DIFF.
7170754Sdelphij
8170754Sdelphij   GNU DIFF is free software; you can redistribute it and/or modify
9170754Sdelphij   it under the terms of the GNU General Public License as published by
10170754Sdelphij   the Free Software Foundation; either version 2, or (at your option)
11170754Sdelphij   any later version.
12170754Sdelphij
13170754Sdelphij   GNU DIFF is distributed in the hope that it will be useful,
14170754Sdelphij   but WITHOUT ANY WARRANTY; without even the implied warranty of
15170754Sdelphij   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16170754Sdelphij   GNU General Public License for more details.
17170754Sdelphij
18170754Sdelphij   You should have received a copy of the GNU General Public License
19170754Sdelphij   along with this program; see the file COPYING.
20170754Sdelphij   If not, write to the Free Software Foundation,
21170754Sdelphij   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
22170754Sdelphij
23170754Sdelphij#include "diff.h"
24170754Sdelphij
25170754Sdelphijstatic void print_normal_hunk (struct change *);
26170754Sdelphij
27170754Sdelphij/* Print the edit-script SCRIPT as a normal diff.
28170754Sdelphij   INF points to an array of descriptions of the two files.  */
29170754Sdelphij
30170754Sdelphijvoid
31170754Sdelphijprint_normal_script (struct change *script)
32170754Sdelphij{
33170754Sdelphij  print_script (script, find_change, print_normal_hunk);
34170754Sdelphij}
35170754Sdelphij
36170754Sdelphij/* Print a hunk of a normal diff.
37170754Sdelphij   This is a contiguous portion of a complete edit script,
38170754Sdelphij   describing changes in consecutive lines.  */
39170754Sdelphij
40170754Sdelphijstatic void
41170754Sdelphijprint_normal_hunk (struct change *hunk)
42170754Sdelphij{
43170754Sdelphij  lin first0, last0, first1, last1;
44170754Sdelphij  register lin i;
45170754Sdelphij
46170754Sdelphij  /* Determine range of line numbers involved in each file.  */
47170754Sdelphij  enum changes changes = analyze_hunk (hunk, &first0, &last0, &first1, &last1);
48170754Sdelphij  if (!changes)
49170754Sdelphij    return;
50170754Sdelphij
51170754Sdelphij  begin_output ();
52170754Sdelphij
53170754Sdelphij  /* Print out the line number header for this hunk */
54170754Sdelphij  print_number_range (',', &files[0], first0, last0);
55170754Sdelphij  fprintf (outfile, "%c", change_letter[changes]);
56170754Sdelphij  print_number_range (',', &files[1], first1, last1);
57170754Sdelphij  fprintf (outfile, "\n");
58170754Sdelphij
59170754Sdelphij  /* Print the lines that the first file has.  */
60170754Sdelphij  if (changes & OLD)
61170754Sdelphij    for (i = first0; i <= last0; i++)
62170754Sdelphij      print_1_line ("<", &files[0].linbuf[i]);
63170754Sdelphij
64170754Sdelphij  if (changes == CHANGED)
65170754Sdelphij    fprintf (outfile, "---\n");
66170754Sdelphij
67170754Sdelphij  /* Print the lines that the second file has.  */
68170754Sdelphij  if (changes & NEW)
69170754Sdelphij    for (i = first1; i <= last1; i++)
70170754Sdelphij      print_1_line (">", &files[1].linbuf[i]);
71170754Sdelphij}
72