1275072Semaste/* Normal-format output routines for GNU DIFF.
2275072Semaste   Copyright (C) 1988, 1989, 1993, 1998 Free Software Foundation, Inc.
3275072Semaste
4275072SemasteThis file is part of GNU DIFF.
5275072Semaste
6275072SemasteGNU DIFF is free software; you can redistribute it and/or modify
7275072Semasteit under the terms of the GNU General Public License as published by
8275072Semastethe Free Software Foundation; either version 2, or (at your option)
9275072Semasteany later version.
10275072Semaste
11275072SemasteGNU DIFF is distributed in the hope that it will be useful,
12275072Semastebut WITHOUT ANY WARRANTY; without even the implied warranty of
13275072SemasteMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14275072SemasteGNU General Public License for more details.
15275072Semaste
16275072Semaste*/
17275072Semaste
18280031Sdim
19275072Semaste#include "diff.h"
20275072Semaste
21275072Semastestatic void print_normal_hunk PARAMS((struct change *));
22275072Semaste
23275072Semaste/* Print the edit-script SCRIPT as a normal diff.
24275072Semaste   INF points to an array of descriptions of the two files.  */
25275072Semaste
26275072Semastevoid
27275072Semasteprint_normal_script (script)
28275072Semaste     struct change *script;
29275072Semaste{
30275072Semaste  print_script (script, find_change, print_normal_hunk);
31275072Semaste}
32275072Semaste
33275072Semaste/* Print a hunk of a normal diff.
34275072Semaste   This is a contiguous portion of a complete edit script,
35275072Semaste   describing changes in consecutive lines.  */
36275072Semaste
37275072Semastestatic void
38275072Semasteprint_normal_hunk (hunk)
39288943Sdim     struct change *hunk;
40288943Sdim{
41288943Sdim  int first0, last0, first1, last1, deletes, inserts;
42288943Sdim  register int i;
43288943Sdim
44275072Semaste  /* Determine range of line numbers involved in each file.  */
45275072Semaste  analyze_hunk (hunk, &first0, &last0, &first1, &last1, &deletes, &inserts);
46275072Semaste  if (!deletes && !inserts)
47275072Semaste    return;
48275072Semaste
49275072Semaste  begin_output ();
50275072Semaste
51275072Semaste  /* Print out the line number header for this hunk */
52275072Semaste  print_number_range (',', &files[0], first0, last0);
53275072Semaste  printf_output ("%c", change_letter (inserts, deletes));
54275072Semaste  print_number_range (',', &files[1], first1, last1);
55275072Semaste  printf_output ("\n");
56275072Semaste
57275072Semaste  /* Print the lines that the first file has.  */
58288943Sdim  if (deletes)
59288943Sdim    for (i = first0; i <= last0; i++)
60275072Semaste      print_1_line ("<", &files[0].linbuf[i]);
61275072Semaste
62275072Semaste  if (inserts && deletes)
63275072Semaste    printf_output ("---\n");
64275072Semaste
65275072Semaste  /* Print the lines that the second file has.  */
66275072Semaste  if (inserts)
67275072Semaste    for (i = first1; i <= last1; i++)
68275072Semaste      print_1_line (">", &files[1].linbuf[i]);
69275072Semaste}
70275072Semaste