rc.conf: Add and document the missing root_rw_mount=YES
[dragonfly.git] / contrib / diffutils / src / normal.c
blobbdb718bed0d79aaf0e3baaec005279097f4641ba
1 /* Normal-format output routines for GNU DIFF.
3 Copyright (C) 1988-1989, 1993, 1995, 1998, 2001, 2006, 2009-2013, 2015-2018
4 Free Software Foundation, Inc.
6 This file is part of GNU DIFF.
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "diff.h"
23 static void print_normal_hunk (struct change *);
25 /* Print the edit-script SCRIPT as a normal diff.
26 INF points to an array of descriptions of the two files. */
28 void
29 print_normal_script (struct change *script)
31 print_script (script, find_change, print_normal_hunk);
34 /* Print a hunk of a normal diff.
35 This is a contiguous portion of a complete edit script,
36 describing changes in consecutive lines. */
38 static void
39 print_normal_hunk (struct change *hunk)
41 lin first0, last0, first1, last1;
42 register lin i;
44 /* Determine range of line numbers involved in each file. */
45 enum changes changes = analyze_hunk (hunk, &first0, &last0, &first1, &last1);
46 if (!changes)
47 return;
49 begin_output ();
51 /* Print out the line number header for this hunk */
52 set_color_context (LINE_NUMBER_CONTEXT);
53 print_number_range (',', &files[0], first0, last0);
54 fputc (change_letter[changes], outfile);
55 print_number_range (',', &files[1], first1, last1);
56 set_color_context (RESET_CONTEXT);
57 fputc ('\n', outfile);
59 /* Print the lines that the first file has. */
60 if (changes & OLD)
62 for (i = first0; i <= last0; i++)
64 set_color_context (DELETE_CONTEXT);
65 print_1_line_nl ("<", &files[0].linbuf[i], true);
66 set_color_context (RESET_CONTEXT);
67 if (files[0].linbuf[i + 1][-1] == '\n')
68 putc ('\n', outfile);
72 if (changes == CHANGED)
73 fputs ("---\n", outfile);
75 /* Print the lines that the second file has. */
76 if (changes & NEW)
78 for (i = first1; i <= last1; i++)
80 set_color_context (ADD_CONTEXT);
81 print_1_line_nl (">", &files[1].linbuf[i], true);
82 set_color_context (RESET_CONTEXT);
83 if (files[1].linbuf[i + 1][-1] == '\n')
84 putc ('\n', outfile);