| Comparing and Merging Files with GNU diff and patch by David MacKenzie, Paul Eggert, and Richard Stallman Paperback (6"x9"), 120 pages ISBN 0954161750 RRP £12.95 ($19.95) "Well packaged... the quality of information is excellent" --- Linux User and Developer Magazine (Issue 36, Feb 2004) Get a printed copy>>> |
2.6.3 Detailed Description of If-then-else Format
For lines common to both files, diff uses the unchanged line
group format. For each hunk of differences in the merged output
format, if the hunk contains only lines from the first file,
diff uses the old line group format; if the hunk contains only
lines from the second file, diff uses the new group format;
otherwise, diff uses the changed group format.
The old, new, and unchanged line formats specify the output format of lines from the first file, lines from the second file, and lines common to both files, respectively.
The option --ifdef=name is equivalent to
the following sequence of options using shell syntax:
--old-group-format='#ifndef name %<#endif /* ! name */ ' \ --new-group-format='#ifdef name %>#endif /* name */ ' \ --unchanged-group-format='%=' \ --changed-group-format='#ifndef name %<#else /* name */ %>#endif /* name */ '
You should carefully check the diff output for proper nesting.
For example, when using the -D name or
--ifdef=name option, you should check that if the
differing lines contain any of the C preprocessor directives
‘#ifdef’, ‘#ifndef’, ‘#else’, ‘#elif’, or
‘#endif’, they are nested properly and match. If they don't, you
must make corrections manually. It is a good idea to carefully check
the resulting code anyway to make sure that it really does what you
want it to; depending on how the input files were produced, the output
might contain duplicate or otherwise incorrect code.
The patch -D name option behaves like
the diff -D name option, except it operates on
a file and a diff to produce a merged file; See section 15.1 Options to patch.
| ISBN 0954161750 | Comparing and Merging Files with GNU diff and patch | See the print edition |