118fd37a7SXin LI /* Normal-format output routines for GNU DIFF.
218fd37a7SXin LI
318fd37a7SXin LI Copyright (C) 1988, 1989, 1993, 1995, 1998, 2001 Free Software
418fd37a7SXin LI Foundation, Inc.
518fd37a7SXin LI
618fd37a7SXin LI This file is part of GNU DIFF.
718fd37a7SXin LI
818fd37a7SXin LI GNU DIFF is free software; you can redistribute it and/or modify
918fd37a7SXin LI it under the terms of the GNU General Public License as published by
1018fd37a7SXin LI the Free Software Foundation; either version 2, or (at your option)
1118fd37a7SXin LI any later version.
1218fd37a7SXin LI
1318fd37a7SXin LI GNU DIFF is distributed in the hope that it will be useful,
1418fd37a7SXin LI but WITHOUT ANY WARRANTY; without even the implied warranty of
1518fd37a7SXin LI MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1618fd37a7SXin LI GNU General Public License for more details.
1718fd37a7SXin LI
1818fd37a7SXin LI You should have received a copy of the GNU General Public License
1918fd37a7SXin LI along with this program; see the file COPYING.
2018fd37a7SXin LI If not, write to the Free Software Foundation,
2118fd37a7SXin LI 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
2218fd37a7SXin LI
2318fd37a7SXin LI #include "diff.h"
2418fd37a7SXin LI
2518fd37a7SXin LI static void print_normal_hunk (struct change *);
2618fd37a7SXin LI
2718fd37a7SXin LI /* Print the edit-script SCRIPT as a normal diff.
2818fd37a7SXin LI INF points to an array of descriptions of the two files. */
2918fd37a7SXin LI
3018fd37a7SXin LI void
print_normal_script(struct change * script)3118fd37a7SXin LI print_normal_script (struct change *script)
3218fd37a7SXin LI {
3318fd37a7SXin LI print_script (script, find_change, print_normal_hunk);
3418fd37a7SXin LI }
3518fd37a7SXin LI
3618fd37a7SXin LI /* Print a hunk of a normal diff.
3718fd37a7SXin LI This is a contiguous portion of a complete edit script,
3818fd37a7SXin LI describing changes in consecutive lines. */
3918fd37a7SXin LI
4018fd37a7SXin LI static void
print_normal_hunk(struct change * hunk)4118fd37a7SXin LI print_normal_hunk (struct change *hunk)
4218fd37a7SXin LI {
4318fd37a7SXin LI lin first0, last0, first1, last1;
4418fd37a7SXin LI register lin i;
4518fd37a7SXin LI
4618fd37a7SXin LI /* Determine range of line numbers involved in each file. */
4718fd37a7SXin LI enum changes changes = analyze_hunk (hunk, &first0, &last0, &first1, &last1);
4818fd37a7SXin LI if (!changes)
4918fd37a7SXin LI return;
5018fd37a7SXin LI
5118fd37a7SXin LI begin_output ();
5218fd37a7SXin LI
5318fd37a7SXin LI /* Print out the line number header for this hunk */
5418fd37a7SXin LI print_number_range (',', &files[0], first0, last0);
5518fd37a7SXin LI fprintf (outfile, "%c", change_letter[changes]);
5618fd37a7SXin LI print_number_range (',', &files[1], first1, last1);
5718fd37a7SXin LI fprintf (outfile, "\n");
5818fd37a7SXin LI
5918fd37a7SXin LI /* Print the lines that the first file has. */
6018fd37a7SXin LI if (changes & OLD)
6118fd37a7SXin LI for (i = first0; i <= last0; i++)
6218fd37a7SXin LI print_1_line ("<", &files[0].linbuf[i]);
6318fd37a7SXin LI
6418fd37a7SXin LI if (changes == CHANGED)
6518fd37a7SXin LI fprintf (outfile, "---\n");
6618fd37a7SXin LI
6718fd37a7SXin LI /* Print the lines that the second file has. */
6818fd37a7SXin LI if (changes & NEW)
6918fd37a7SXin LI for (i = first1; i <= last1; i++)
7018fd37a7SXin LI print_1_line (">", &files[1].linbuf[i]);
7118fd37a7SXin LI }
72