Commit | Line | Data |
---|---|---|
3c369cdd WJ |
1 | /* #ifdef-format output routines for GNU DIFF. |
2 | Copyright (C) 1989 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GNU DIFF. | |
5 | ||
6 | GNU DIFF is distributed in the hope that it will be useful, | |
7 | but WITHOUT ANY WARRANTY. No author or distributor | |
8 | accepts responsibility to anyone for the consequences of using it | |
9 | or for whether it serves any particular purpose or works at all, | |
10 | unless he says so in writing. Refer to the GNU DIFF General Public | |
11 | License for full details. | |
12 | ||
13 | Everyone is granted permission to copy, modify and redistribute | |
14 | GNU DIFF, but only under the conditions described in the | |
15 | GNU DIFF General Public License. A copy of this license is | |
16 | supposed to have been given to you along with GNU DIFF so you | |
17 | can know your rights and responsibilities. It should be in a | |
18 | file named COPYING. Among other things, the copyright notice | |
19 | and this notice must be preserved on all copies. */ | |
20 | ||
21 | ||
22 | #include "diff.h" | |
23 | ||
24 | static void print_ifdef_hunk (); | |
25 | struct change *find_change (); | |
26 | ||
27 | static int next_line; | |
28 | ||
29 | /* Print the edit-script SCRIPT as a merged #ifdef file. */ | |
30 | ||
31 | void | |
32 | print_ifdef_script (script) | |
33 | struct change *script; | |
34 | { | |
35 | next_line = 0; | |
36 | print_script (script, find_change, print_ifdef_hunk); | |
37 | while (next_line < files[0].buffered_lines) | |
38 | print_1_line ("", &files[0].linbuf[next_line++]); | |
39 | } | |
40 | ||
41 | /* Print a hunk of an ifdef diff. | |
42 | This is a contiguous portion of a complete edit script, | |
43 | describing changes in consecutive lines. */ | |
44 | ||
45 | static void | |
46 | print_ifdef_hunk (hunk) | |
47 | struct change *hunk; | |
48 | { | |
49 | int first0, last0, first1, last1, deletes, inserts; | |
50 | register int i; | |
51 | ||
52 | /* Determine range of line numbers involved in each file. */ | |
53 | analyze_hunk (hunk, &first0, &last0, &first1, &last1, &deletes, &inserts); | |
54 | if (!deletes && !inserts) | |
55 | return; | |
56 | ||
57 | /* Print out lines up to this change. */ | |
58 | while (next_line < first0) | |
59 | print_1_line ("", &files[0].linbuf[next_line++]); | |
60 | ||
61 | /* Print out stuff deleted from first file. */ | |
62 | if (deletes) | |
63 | { | |
64 | fprintf (outfile, "#ifndef %s\n", ifdef_string); | |
65 | for (i = first0; i <= last0; i++) | |
66 | print_1_line ("", &files[0].linbuf[i]); | |
67 | next_line = i; | |
68 | } | |
69 | ||
70 | /* Print out stuff inserted from second file. */ | |
71 | if (inserts) | |
72 | { | |
73 | if (deletes) | |
74 | fprintf (outfile, "#else /* %s */\n", ifdef_string); | |
75 | else | |
76 | fprintf (outfile, "#ifdef %s\n", ifdef_string); | |
77 | for (i = first1; i <= last1; i++) | |
78 | print_1_line ("", &files[1].linbuf[i]); | |
79 | } | |
80 | ||
81 | if (inserts) | |
82 | fprintf (outfile, "#endif /* %s */\n", ifdef_string); | |
83 | else | |
84 | fprintf (outfile, "#endif /* not %s */\n", ifdef_string); | |
85 | } |