home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / d / diff20.zip / diff-2.0 / diff.info-1 < prev    next >
Encoding:
GNU Info File  |  1992-09-15  |  47.6 KB  |  1,238 lines

  1. This is Info file diff.info, produced by Makeinfo-1.47 from the input
  2. file ./diff.texi.
  3.  
  4.    This file documents the the GNU `diff', `diff3', `sdiff', and `cmp'
  5. commands for showing the differences between text files and the `patch'
  6. command for using their output to update files.
  7.  
  8.    Copyright (C) 1992 Free Software Foundation, Inc.
  9.  
  10.    Permission is granted to make and distribute verbatim copies of this
  11. manual provided the copyright notice and this permission notice are
  12. preserved on all copies.
  13.  
  14.    Permission is granted to copy and distribute modified versions of
  15. this manual under the conditions for verbatim copying, provided that
  16. the entire resulting derived work is distributed under the terms of a
  17. permission notice identical to this one.
  18.  
  19.    Permission is granted to copy and distribute translations of this
  20. manual into another language, under the above conditions for modified
  21. versions, except that this permission notice may be stated in a
  22. translation approved by the Foundation.
  23.  
  24. 
  25. File: diff.info,  Node: Top,  Up: (dir)
  26.  
  27.    This file documents the the GNU `diff', `diff3', `sdiff', and `cmp'
  28. commands for showing the differences between text files and the `patch'
  29. command for using their output to update files.
  30.  
  31.    This is Edition 1.0, for `diff' 2.0 and `patch' 2.0.12g8.
  32.  
  33. * Menu:
  34.  
  35. * Overview::        Preliminary information.
  36.  
  37. * Comparison::        What file comparison means.
  38. * Output Formats::    Formats for difference reports.
  39. * Comparing Directories::    Comparing files and directories.
  40. * Adjusting Output::    Making `diff' output prettier.
  41. * diff Performance::    Making `diff' smarter or faster.
  42. * Comparing Three Files:: Formats for three-way difference reports.
  43.  
  44. * diff3 Merging::    Merging from a common ancestor.
  45. * Interactive Merging::    Interactive merging with `sdiff'.
  46. * Merging with patch::    Using `patch' to change old files into new ones.
  47. * Making Patches::    Tips for making patch distributions.
  48.  
  49. * Invoking cmp::    How to run `cmp' and a summary of its options.
  50. * Invoking diff::    How to run `diff' and a summary of its options.
  51. * Invoking diff3::    How to run `diff3' and a summary of its options.
  52. * Invoking patch::    How to run `patch' and a summary of its options.
  53. * Invoking sdiff::    How to run `sdiff' and a summary of its options.
  54.  
  55. * Incomplete Lines::    Lines that lack trailing newlines.
  56. * Projects::        If you think you've found a bug or other shortcoming.
  57.  
  58. * Concept Index::    Index of concepts.
  59.  
  60. 
  61. File: diff.info,  Node: Overview,  Next: Comparison,  Up: Top
  62.  
  63. Overview
  64. ********
  65.  
  66.    Computer users often find occasion to ask how two files differ. 
  67. Perhaps one file is a newer version of the other file.  Or maybe the
  68. two files started out as identical copies but were changed by different
  69. people.
  70.  
  71.    You can use the `diff' command to show differences between two
  72. files, or each corresponding file in two directories.  `diff' outputs
  73. differences between files line by line in any of several formats,
  74. selectable by command line options.  This set of differences is often
  75. called a "diff" or "patch".  For files that are identical, `diff'
  76. normally produces no output; for binary (non-text) files, `diff'
  77. normally reports only that they are different.
  78.  
  79.    You can use the `cmp' command to show the offsets and line numbers
  80. where two files differ.  `cmp' can also show all the characters that
  81. differ between the two files, side by side.  Another way to compare two
  82. files character by character is the Emacs command `M-x
  83. compare-windows'.  *Note Other Window: (emacs)Other Window, for more
  84. information on that command.
  85.  
  86.    You can use the `diff3' command to show differences among three
  87. files.  When two people have made independent changes to a common
  88. original, `diff3' can report the differences between the original and
  89. the two changed versions, and can produce a merged file that contains
  90. both persons' changes together with warnings about overlapping changes.
  91.  
  92.    You can use the `sdiff' command to merge two files interactively.
  93.  
  94.    You can use the set of differences produced by `diff' to distribute
  95. updates to text files (such as program source code) to other people.
  96. This method is especially useful when the differences are small compared
  97. to the complete files.  Given `diff' output, you can use the `patch'
  98. program to update, or "patch", a copy of the file.  If you think of
  99. `diff' as subtracting one file from another to produce their
  100. difference, you can think of `patch' as adding the difference to one
  101. file to reproduce the other.
  102.  
  103.    This manual first concentrates on making diffs, and later shows how
  104. to use diffs to update files.
  105.  
  106.    GNU `diff' was written by Mike Haertel, David Hayes, Richard
  107. Stallman, Len Tower, and Paul Eggert.  Wayne Davison designed and
  108. implemented the unified output format.  The basic algorithm is described
  109. in "An O(ND) Difference Algorithm and its Variations", Eugene Myers,
  110. `Algorithmica' Vol. 1 No. 2, 1986, p.  251.
  111.  
  112.    GNU `diff3' was written by Randy Smith.  GNU `sdiff' was written by
  113. Thomas Lord.  GNU `cmp' was written by Torbjorn Granlund and David
  114. MacKenzie.
  115.  
  116.    `patch' was written mainly by Larry Wall; the GNU enhancements were
  117. written mainly by Wayne Davison and David MacKenzie.  Parts of this
  118. manual are adapted from a manual page written by Larry Wall, with his
  119. permission.
  120.  
  121. 
  122. File: diff.info,  Node: Comparison,  Next: Output Formats,  Prev: Overview,  Up: Top
  123.  
  124. What Comparison Means
  125. *********************
  126.  
  127.    There are several ways to think about the differences between two
  128. files. One way to think of the differences is as a series of lines that
  129. were deleted from, inserted in, or changed in one file to produce the
  130. other file.  `diff' compares two files line by line, finds groups of
  131. lines that differ, and reports each group of differing lines.  It can
  132. report the differing lines in several formats, which have different
  133. purposes.
  134.  
  135.    GNU `diff' can show whether files are different without detailing
  136. the differences.  It also provides ways to suppress certain kinds of
  137. differences that are not important to you.  Most commonly, such
  138. differences are changes in the amount of whitespace between words or
  139. lines.  `diff' also provides ways to suppress differences in alphabetic
  140. case or in lines that match a regular expression that you provide. 
  141. These options can accumulate; for example, you can ignore changes in
  142. both whitespace and alphabetic case.
  143.  
  144.    Another way to think of the differences between two files is as a
  145. sequence of pairs of characters that can be either identical or
  146. different.  `cmp' reports the differences between two files character
  147. by character, instead of line by line.  As a result, it is more useful
  148. than `diff' for comparing binary files.  For text files, `cmp' is
  149. useful mainly when you want to know only whether two files are
  150. identical.  For this purpose, it is better than `diff' because it is
  151. much faster.
  152.  
  153.    To illustrate the effect that considering changes character by
  154. character can have compared with considering them line by line, think
  155. of what happens if a single newline character is added to the beginning
  156. of a file.  If that file is then compared with an otherwise identical
  157. file that lacks the newline at the beginning, `diff' will report that a
  158. blank line has been added to the file, while `cmp' will report that
  159. almost every character of the two files differs.
  160.  
  161.    `diff3' normally compares three input files line by line, finds
  162. groups of lines that differ, and reports each group of differing lines.
  163. Its output is designed to make it easy to inspect two different sets of
  164. changes to the same file.
  165.  
  166. * Menu:
  167.  
  168. * Hunks::        Groups of differing lines.
  169. * Whitespace::        Suppressing differences in whitespace.
  170. * Blank Lines::        Suppressing differences in blank lines.
  171. * Case Folding::    Suppressing differences in alphabetic case.
  172. * Specified Folding::    Suppressing differences that match regular expressions.
  173. * Brief::        Summarizing which files are different.
  174. * Binary::        Comparing binary files or forcing text comparisons.
  175.  
  176. 
  177. File: diff.info,  Node: Hunks,  Next: Whitespace,  Up: Comparison
  178.  
  179. Hunks
  180. =====
  181.  
  182.    When comparing two files, `diff' finds sequences of lines common to
  183. both files, interspersed with groups of differing lines called "hunks".
  184.  Comparing two identical files yields one sequence of common lines and
  185. no hunks, because no lines differ.  Comparing two entirely different
  186. files yields no common lines and one large hunk that contains all lines
  187. of both files.  In general, there are many ways to match up lines
  188. between two given files.  `diff' tries to minimize the total hunk size
  189. by finding large sequences of common lines interspersed with small
  190. hunks of differing lines.
  191.  
  192.    For example, suppose the file `F' contains the three lines `a', `b',
  193. `c', and the file `G' contains the same three lines in reverse order
  194. `c', `b', `a'.  If `diff' finds the line `c' as common, then the command
  195. `diff F G' produces this output:
  196.  
  197.      1,2d0
  198.      < a
  199.      < b
  200.      3a2,3
  201.      > b
  202.      > a
  203.  
  204. But if `diff' notices the common line `b' instead, it produces this
  205. output:
  206.  
  207.      1c1
  208.      < a
  209.      ---
  210.      > c
  211.      3c3
  212.      < c
  213.      ---
  214.      > a
  215.  
  216. It is also possible to find `a' as the common line.  `diff' does not
  217. always find an optimal matching between the files; it takes shortcuts
  218. to run faster.  But its output is usually close to the shortest
  219. possible.  You can adjust this tradeoff with the `--minimal' option
  220. (*note diff Performance::.).
  221.  
  222. 
  223. File: diff.info,  Node: Whitespace,  Next: Blank Lines,  Prev: Hunks,  Up: Comparison
  224.  
  225. Suppressing Differences in Blank and Tab Spacing
  226. ================================================
  227.  
  228.    The `-b' and `--ignore-space-change' options ignore blanks and tabs
  229. at line end, and to consider all other sequences of one or more blank
  230. and tab characters to be equivalent.  With these options, `diff'
  231. considers the following two lines to be equivalent, where `$' denotes
  232. the line end:
  233.  
  234.      Here lyeth  muche rychnesse  in lytell space.   -- John Heywood$
  235.      Here lyeth muche rychnesse in lytell space. -- John Heywood   $
  236.  
  237.    The `-w' and `--ignore-all-space' options are stronger than `-b'. 
  238. They ignore difference even if one file has whitespace where the other
  239. file has none, and they ignore all whitespace characters, not just
  240. blanks and tabs.  (The "whitespace" characters include backspace, tab,
  241. vertical tab, formfeed, carriage return, space, and no-break space.) 
  242. With these options, `diff' considers the following two lines to be
  243. equivalent, where `$' denotes the line end and `^M' denotes a carriage
  244. return:
  245.  
  246.      Here lyeth  muche  rychnesse in lytell space.--  John Heywood$
  247.        He relyeth much erychnes  seinly tells pace.  --John Heywood   ^M$
  248.  
  249. 
  250. File: diff.info,  Node: Blank Lines,  Next: Case Folding,  Prev: Whitespace,  Up: Comparison
  251.  
  252. Suppressing Differences in Blank Lines
  253. ======================================
  254.  
  255.    The `-B' and `--ignore-blank-lines' options ignore insertions or
  256. deletions of blank lines.  These options normally affect only lines
  257. that are completely empty; they do not affect lines that look empty but
  258. contain space or tab characters.  With these options, for example, a
  259. file containing
  260.      1.  A point is that which has no part.
  261.      
  262.      2.  A line is breadthless length.
  263.      -- Euclid, The Elements, I
  264.  
  265. is considered identical to a file containing
  266.      1.  A point is that which has no part.
  267.      2.  A line is breadthless length.
  268.      
  269.      
  270.      -- Euclid, The Elements, I
  271.  
  272. 
  273. File: diff.info,  Node: Case Folding,  Next: Specified Folding,  Prev: Blank Lines,  Up: Comparison
  274.  
  275. Suppressing Case Differences
  276. ============================
  277.  
  278.    GNU `diff' can treat lowercase letters as equivalent to their
  279. uppercase counterparts, so that, for example, it considers `Funky
  280. Stuff', `funky STUFF', and `fUNKy stuFf' to all be the same. To request
  281. this, use the `-i' or `--ignore-case' option.
  282.  
  283. 
  284. File: diff.info,  Node: Specified Folding,  Next: Brief,  Prev: Case Folding,  Up: Comparison
  285.  
  286. Suppressing Lines Matching a Regular Expression
  287. ===============================================
  288.  
  289.    To ignore insertions and deletions of lines that match a regular
  290. expression, use the `-I REGEXP' or `--ignore-matching-lines=REGEXP'
  291. option.  You should escape regular expressions that contain shell
  292. metacharacters to prevent the shell from expanding them.  For example,
  293. `diff -I '^[0-9]'' ignores all changes to lines beginning with a digit.
  294.  
  295.    However, `-I' only ignores the insertion or deletion of lines that
  296. contain the regular expression if every changed line in the hunk--every
  297. insertion and every deletion--matches the regular expression.  In other
  298. words, for each nonignorable change, `diff' prints the complete set of
  299. changes in its vicinity, including the ignorable ones.
  300.  
  301.    You can specify more than one regular expression for lines to ignore
  302. by using more than one `-I' option.  `diff' tries to match each line
  303. against each regular expression, starting with the last one given.
  304.  
  305. 
  306. File: diff.info,  Node: Brief,  Next: Binary,  Prev: Specified Folding,  Up: Comparison
  307.  
  308. Summarizing Which Files Differ
  309. ==============================
  310.  
  311.    When you only want to find out whether files are different, and you
  312. don't care what the differences are, you can use the summary output
  313. format.  In this format, instead of showing the differences between the
  314. files, `diff' simply reports whether files differ.  The `-q' and
  315. `--brief' options select this output format.
  316.  
  317.    This format is especially useful when comparing the contents of two
  318. directories.  It is also much faster than doing the normal line by line
  319. comparisons, because `diff' can stop analyzing the files as soon as it
  320. knows that there are any differences.
  321.  
  322.    You can also get a brief indication of whether two files differ by
  323. using `cmp'.  For files that are identical, `cmp' produces no output. 
  324. When the files differ, by default, `cmp' outputs the byte offset and
  325. line number where the first difference occurs.  You can use the `-s'
  326. option to suppress that information, so that `cmp' produces no output
  327. and reports whether the files differ using only its exit status (*note
  328. Invoking cmp::.).
  329.  
  330.    Unlike `diff', `cmp' cannot compare directories; it can only compare
  331. two files.
  332.  
  333. 
  334. File: diff.info,  Node: Binary,  Prev: Brief,  Up: Comparison
  335.  
  336. Binary Files and Forcing Text Comparisons
  337. =========================================
  338.  
  339.    If `diff' thinks that either of the two files it is comparing is
  340. binary (a non-text file), it normally treats that pair of files much as
  341. if the summary output format had been selected (*note Brief::.), and
  342. reports only that the binary files are different.  This is because line
  343. by line comparisons are usually not meaningful for binary files.
  344.  
  345.    `diff' determines whether a file is text or binary by checking the
  346. first few bytes in the file; the exact number of bytes is system
  347. dependent, but it is typically several hundred.  If every character in
  348. that part of the file is non-null, `diff' considers the file to be
  349. text; otherwise it considers the file to be binary.
  350.  
  351.    Sometimes you might want to force `diff' to consider files to be
  352. text.  For example, you might be comparing text files that contain
  353. unusual characters; `diff' would erroneously decide that those are
  354. non-text files.  Or you might be comparing documents that are in a
  355. format used by a word processing system that uses control characters to
  356. indicate special formatting.  You can force `diff' to consider all
  357. files to be text files, and compare them line by line, by using the
  358. `-a' or `--text' option.  If the files you compare using this option do
  359. not in fact contain text, they will probably contain few newline
  360. characters, and the `diff' output will consist of hunks showing
  361. differences between long lines of whatever characters the files contain.
  362.  
  363.    You can also force `diff' to consider all files to be binary files,
  364. and report only whether they differ (but not how).  Use the `--brief'
  365. option for this.
  366.  
  367.    If you want to compare two files byte by byte, you can use the `cmp'
  368. program with the `-l' option to show the values of each differing byte
  369. in the two files.  With GNU `cmp', you can also use the `-c' option to
  370. show the ASCII representation of those bytes. *Note Invoking cmp::, for
  371. more information.
  372.  
  373.    If `diff3' thinks that any of the files it is comparing is binary (a
  374. non-text file), it normally reports an error, because such comparisons
  375. are usually not useful.  `diff3' uses the same test as `diff' to decide
  376. whether a file is binary.  As with `diff', if the input files contain a
  377. few non-text characters but otherwise are like text files, you can
  378. force `diff3' to consider all files to be text files and compare them
  379. line by line by using the `-a' or `--text' options.
  380.  
  381. 
  382. File: diff.info,  Node: Output Formats,  Next: Comparing Directories,  Prev: Comparison,  Up: Top
  383.  
  384. `diff' Output Formats
  385. *********************
  386.  
  387.    `diff' has several mutually exclusive options for output format. The
  388. following sections describe each format, illustrating how `diff'
  389. reports the differences between two sample input files.
  390.  
  391. * Menu:
  392.  
  393. * Sample diff Input::    Sample `diff' input files for examples.
  394. * Normal::        Showing differences without surrounding text.
  395. * Context::        Showing differences with the surrounding text.
  396. * Side by Side::        Showing differences in two columns.
  397. * Scripts::        Generating scripts for other programs.
  398. * Merging C Files::    Merging C source files with `#ifdef'.
  399.  
  400. 
  401. File: diff.info,  Node: Sample diff Input,  Next: Normal,  Up: Output Formats
  402.  
  403. Two Sample Input Files
  404. ======================
  405.  
  406.    Here are two sample files that we will use in numerous examples to
  407. illustrate the output of `diff' and how various options can change it.
  408.  
  409.    This is the file `lao':
  410.  
  411.      The Way that can be told of is not the eternal Way;
  412.      The name that can be named is not the eternal name.
  413.      The Nameless is the origin of Heaven and Earth;
  414.      The Named is the mother of all things.
  415.      Therefore let there always be non-being,
  416.        so we may see their subtlety,
  417.      And let there always be being,
  418.        so we may see their outcome.
  419.      The two are the same,
  420.      But after they are produced,
  421.        they have different names.
  422.  
  423.    This is the file `tzu':
  424.  
  425.      The Nameless is the origin of Heaven and Earth;
  426.      The named is the mother of all things.
  427.      
  428.      Therefore let there always be non-being,
  429.        so we may see their subtlety,
  430.      And let there always be being,
  431.        so we may see their outcome.
  432.      The two are the same,
  433.      But after they are produced,
  434.        they have different names.
  435.      They both may be called deep and profound.
  436.      Deeper and more profound,
  437.      The door of all subtleties!
  438.  
  439.    In this example, the first hunk contains just the first two lines of
  440. `lao', the second hunk contains the fourth line of `lao' opposing the
  441. second and third lines of `tzu', and the last hunk contains just the
  442. last three lines of `tzu'.
  443.  
  444. 
  445. File: diff.info,  Node: Normal,  Next: Context,  Prev: Sample diff Input,  Up: Output Formats
  446.  
  447. Showing Differences Without Context
  448. ===================================
  449.  
  450.    The "normal" `diff' output format shows each hunk of differences
  451. without any surrounding context.  Sometimes such output is the clearest
  452. way to see how lines have changed, without the clutter of nearby
  453. unchanged lines (although you can get similar results with the context
  454. or unified formats by using 0 lines of context).  However, this format
  455. is no longer widely used for sending out patches; for that purpose, the
  456. context format (*note Context Format::.) and the unified format (*note
  457. Unified Format::.) are superior.  Normal format is the default for
  458. compatibility with older versions of `diff' and the POSIX standard.
  459.  
  460. * Menu:
  461.  
  462. * Detailed Normal::    A detailed description of normal output format.
  463. * Example Normal::    Sample output in the normal format.
  464.  
  465. 
  466. File: diff.info,  Node: Detailed Normal,  Next: Example Normal,  Up: Normal
  467.  
  468. Detailed Description of Normal Format
  469. -------------------------------------
  470.  
  471.    The normal output format consists of one or more hunks of
  472. differences; each hunk shows one area where the files differ.  Normal
  473. format hunks look like this:
  474.  
  475.      CHANGE-COMMAND
  476.      < FROM-FILE-LINE
  477.      < FROM-FILE-LINE...
  478.      ---
  479.      > TO-FILE-LINE
  480.      > TO-FILE-LINE...
  481.  
  482.    There are three types of change commands.  Each consists of a line
  483. number or comma-separated range of lines in the first file, a single
  484. character indicating the kind of change to make, and a line number or
  485. comma-separated range of lines in the second file.  All line numbers are
  486. the original line numbers in each file.  The types of change commands
  487. are:
  488.  
  489. `LaR'
  490.      Add the lines in range R of the second file after line L of the
  491.      first file.  For example, `8a12,15' means append lines 12--15 of
  492.      file 2 after line 8 of file 1; or, if changing file 2 into file 1,
  493.      delete lines 12--15 of file 2.
  494.  
  495. `FcT'
  496.      Replace the lines in range F of the first file with lines in range
  497.      T of the second file.  This is like a combined add and delete, but
  498.      more compact.  For example, `5,7c8,10' means change lines 5--7 of
  499.      file 1 to read as lines 8--10 of file 2; or, if changing file 2
  500.      into file 1, change lines 8--10 of file 2 to read as lines 5--7 of
  501.      file 1.
  502.  
  503. `RdL'
  504.      Delete the lines in range R from the first file; L is where they
  505.      would have appeared in the second file had they not been deleted.
  506.      For example, `5,7d3' means delete lines 5--7 of file 1; or, if
  507.      changing file 2 into file 1, append lines 5--7 of file 1 after
  508.      line 3 of file 2.
  509.  
  510. 
  511. File: diff.info,  Node: Example Normal,  Prev: Detailed Normal,  Up: Normal
  512.  
  513. An Example of Normal Format
  514. ---------------------------
  515.  
  516.    Here is the output of the command `diff lao tzu' (*note Sample diff
  517. Input::., for the complete contents of the two files). Notice that it
  518. shows only the lines that are different between the two files.
  519.  
  520.      1,2d0
  521.      < The Way that can be told of is not the eternal Way;
  522.      < The name that can be named is not the eternal name.
  523.      4c2,3
  524.      < The Named is the mother of all things.
  525.      ---
  526.      > The named is the mother of all things.
  527.      >
  528.      11a11,13
  529.      > They both may be called deep and profound.
  530.      > Deeper and more profound,
  531.      > The door of all subtleties!
  532.  
  533. 
  534. File: diff.info,  Node: Context,  Next: Side by Side,  Prev: Normal,  Up: Output Formats
  535.  
  536. Showing Differences in Their Context
  537. ====================================
  538.  
  539.    Usually, when you are looking at the differences between files, you
  540. will also want to see the parts of the files near the lines that
  541. differ, to help you understand exactly what has changed.  These nearby
  542. parts of the files are called the "context".
  543.  
  544.    GNU `diff' provides two output formats that show context around the
  545. differing lines: "context format" and "unified format".  It can
  546. optionally show in which function or section of the file the differing
  547. lines are found.
  548.  
  549.    If you are distributing new versions of files to other people in the
  550. form of `diff' output, you should use one of the output formats that
  551. show context so that they can apply the diffs even if they have made
  552. small changes of their own to the files.  `patch' can apply the diffs
  553. in this case by searching in the files for the lines of context around
  554. the differing lines; if those lines are actually a few lines away from
  555. where the diff says they are, `patch' can adjust the line numbers
  556. accordingly and still apply the diff correctly. *Note Imperfect::, for
  557. more information on using `patch' to apply imperfect diffs.
  558.  
  559. * Menu:
  560.  
  561. * Context Format::    An output format that shows surrounding lines.
  562. * Unified Format::    A more compact output format that shows context.
  563. * Sections::        Showing which sections of the files differences are in.
  564. * Alternate Names::    Showing alternate file names in context headers.
  565.  
  566. 
  567. File: diff.info,  Node: Context Format,  Next: Unified Format,  Up: Context
  568.  
  569. Context Format
  570. --------------
  571.  
  572.    The context output format shows several lines of context around the
  573. lines that differ.  It is the standard format for distributing updates
  574. to source code.
  575.  
  576.    To select this output format, use the `-C LINES',
  577. `--context[=LINES]', or `-c' option.  The argument LINES that some of
  578. these options take is the number of lines of context to show.  If you
  579. do not specify LINES, it defaults to three.
  580.  
  581. * Menu:
  582.  
  583. * Detailed Context::    A detailed description of the context output format.
  584. * Example Context::    Sample output in context format.
  585. * Less Context::    Another sample with less context.
  586.  
  587. 
  588. File: diff.info,  Node: Detailed Context,  Next: Example Context,  Up: Context Format
  589.  
  590. Detailed Description of Context Format
  591. ......................................
  592.  
  593.    The context output format starts with a two-line header, which looks
  594. like this:
  595.  
  596.      *** FROM-FILE FROM-FILE-MODIFICATION-TIME
  597.      --- TO-FILE TO-FILE-MODIFICATION TIME
  598.  
  599. You can change the header's content with the `-L LABEL' or
  600. `--label=LABEL' option; see *Note Alternate Names::.
  601.  
  602.    Next come one or more hunks of differences; each hunk shows one area
  603. where the files differ.  Context format hunks look like this:
  604.  
  605.      ***************
  606.      *** FROM-FILE-LINE-RANGE ****
  607.        FROM-FILE-LINE
  608.        FROM-FILE-LINE...
  609.      --- TO-FILE-LINE-RANGE ----
  610.        TO-FILE-LINE
  611.        TO-FILE-LINE...
  612.  
  613.    The lines of context around the lines that differ start with two
  614. space characters.  The lines that differ between the two files start
  615. with one of the following indicator characters, followed by a space
  616. character:
  617.  
  618. `!'
  619.      A line that is part of a group of one or more lines that changed
  620.      between the two files.  There is a corresponding group of lines
  621.      marked with `!' in the part of this hunk for the other file.
  622.  
  623. `+'
  624.      An "inserted" line in the second file that corresponds to nothing
  625.      in the first file.
  626.  
  627. `-'
  628.      A "deleted" line in the first file that corresponds to nothing in
  629.      the first file.
  630.  
  631.    If all of the changes in a hunk are insertions, the lines of
  632. FROM-FILE are omitted.  If all of the changes are deletions, the lines
  633. of TO-FILE are omitted.
  634.  
  635. 
  636. File: diff.info,  Node: Example Context,  Next: Less Context,  Prev: Detailed Context,  Up: Context Format
  637.  
  638. An Example of Context Format
  639. ............................
  640.  
  641.    Here is the output of `diff -c lao tzu' (*note Sample diff Input::.,
  642. for the complete contents of the two files).  Notice that up to three
  643. lines that are not different are shown around each line that is
  644. different; they are the context lines.  Also notice that the first two
  645. hunks have run together, because their contents overlap.
  646.  
  647.      *** lao    Sat Jan 26 23:30:39 1991
  648.      --- tzu    Sat Jan 26 23:30:50 1991
  649.      ***************
  650.      *** 1,7 ****
  651.      - The Way that can be told of is not the eternal Way;
  652.      - The name that can be named is not the eternal name.
  653.        The Nameless is the origin of Heaven and Earth;
  654.      ! The Named is the mother of all things.
  655.        Therefore let there always be non-being,
  656.          so we may see their subtlety,
  657.        And let there always be being,
  658.      --- 1,6 ----
  659.        The Nameless is the origin of Heaven and Earth;
  660.      ! The named is the mother of all things.
  661.      !
  662.        Therefore let there always be non-being,
  663.          so we may see their subtlety,
  664.        And let there always be being,
  665.      ***************
  666.      *** 9,11 ****
  667.      --- 8,13 ----
  668.        The two are the same,
  669.        But after they are produced,
  670.          they have different names.
  671.      + They both may be called deep and profound.
  672.      + Deeper and more profound,
  673.      + The door of all subtleties!
  674.  
  675. 
  676. File: diff.info,  Node: Less Context,  Prev: Example Context,  Up: Context Format
  677.  
  678. An Example of Context Format with Less Context
  679. ..............................................
  680.  
  681.    Here is the output of `diff --context=1 lao tzu' (*note Sample diff
  682. Input::., for the complete contents of the two files).  Notice that at
  683. most one context line is reported here.
  684.  
  685.      *** lao    Sat Jan 26 23:30:39 1991
  686.      --- tzu    Sat Jan 26 23:30:50 1991
  687.      ***************
  688.      *** 1,5 ****
  689.      - The Way that can be told of is not the eternal Way;
  690.      - The name that can be named is not the eternal name.
  691.        The Nameless is the origin of Heaven and Earth;
  692.      ! The Named is the mother of all things.
  693.        Therefore let there always be non-being,
  694.      --- 1,4 ----
  695.        The Nameless is the origin of Heaven and Earth;
  696.      ! The named is the mother of all things.
  697.      !
  698.        Therefore let there always be non-being,
  699.      ***************
  700.      *** 11 ****
  701.      --- 10,13 ----
  702.          they have different names.
  703.      + They both may be called deep and profound.
  704.      + Deeper and more profound,
  705.      + The door of all subtleties!
  706.  
  707. 
  708. File: diff.info,  Node: Unified Format,  Next: Sections,  Prev: Context Format,  Up: Context
  709.  
  710. Unified Format
  711. --------------
  712.  
  713.    The unified output format is a variation on the context format that
  714. is more compact because it omits redundant context lines.  To select
  715. this output format, use the `-u' or `--unified[=LINES]' option.  The
  716. argument LINES is the number of lines of context to show.  When it is
  717. not given, it defaults to three.
  718.  
  719.    At present, only GNU `diff' can produce this format and only GNU
  720. `patch' can automatically apply diffs in this format.
  721.  
  722. * Menu:
  723.  
  724. * Detailed Unified::    A detailed description of unified format.
  725. * Example Unified::    Sample output in unified format.
  726.  
  727. 
  728. File: diff.info,  Node: Detailed Unified,  Next: Example Unified,  Up: Unified Format
  729.  
  730. Detailed Description of Unified Format
  731. ......................................
  732.  
  733.    The unified output format starts with a two-line header, which looks
  734. like this:
  735.  
  736.      --- FROM-FILE FROM-FILE-MODIFICATION-TIME
  737.      +++ TO-FILE TO-FILE-MODIFICATION-TIME
  738.  
  739. You can change the header's content with the `-L LABEL' or
  740. `--label=LABEL' option; see *Note Alternate Names::.
  741.  
  742.    Next come one or more hunks of differences; each hunk shows one area
  743. where the files differ.  Unified format hunks look like this:
  744.  
  745.      @@ FROM-FILE-RANGE TO-FILE-RANGE @@
  746.       LINE-FROM-EITHER-FILE
  747.       LINE-FROM-EITHER-FILE...
  748.  
  749.    The lines common to both files begin with a space character.  The
  750. lines that actually differ between the two files have one of the
  751. following indicator characters in the left column:
  752.  
  753. `+'
  754.      A line was added here to the first file.
  755.  
  756. `-'
  757.      A line was removed here from the first file.
  758.  
  759. 
  760. File: diff.info,  Node: Example Unified,  Prev: Detailed Unified,  Up: Unified Format
  761.  
  762. An Example of Unified Format
  763. ............................
  764.  
  765.    Here is the output of the command `diff -u lao tzu' (*note Sample
  766. diff Input::., for the complete contents of the two files):
  767.  
  768.      --- lao    Sat Jan 26 23:30:39 1991
  769.      +++ tzu    Sat Jan 26 23:30:50 1991
  770.      @@ -1,7 +1,6 @@
  771.      -The Way that can be told of is not the eternal Way;
  772.      -The name that can be named is not the eternal name.
  773.       The Nameless is the origin of Heaven and Earth;
  774.      -The Named is the mother of all things.
  775.      +The named is the mother of all things.
  776.      +
  777.       Therefore let there always be non-being,
  778.         so we may see their subtlety,
  779.       And let there always be being,
  780.      @@ -9,3 +8,6 @@
  781.       The two are the same,
  782.       But after they are produced,
  783.         they have different names.
  784.      +They both may be called deep and profound.
  785.      +Deeper and more profound,
  786.      +The door of all subtleties!
  787.  
  788. 
  789. File: diff.info,  Node: Sections,  Next: Alternate Names,  Prev: Unified Format,  Up: Context
  790.  
  791. Showing Which Sections Differences Are in
  792. -----------------------------------------
  793.  
  794.    Sometimes you might want to know which part of the files each change
  795. falls in.  If the files are source code, this could mean which function
  796. was changed.  If the files are documents, it could mean which chapter or
  797. appendix was changed.  GNU `diff' can show this by displaying the
  798. nearest section heading line that precedes the differing lines.  Which
  799. lines are "section headings" is determined by a regular expression.
  800.  
  801. * Menu:
  802.  
  803. * Specified Headings::    Showing headings that match regular expressions.
  804. * C Function Headings::    Showing headings of C functions.
  805.  
  806. 
  807. File: diff.info,  Node: Specified Headings,  Next: C Function Headings,  Up: Sections
  808.  
  809. Showing Lines That Match Regular Expressions
  810. ............................................
  811.  
  812.    To show in which sections differences occur for files that are not
  813. source code for C or similar languages, use the `-F REGEXP' or
  814. `--show-function-line=REGEXP' option.  `diff' considers lines that
  815. match the argument REGEXP to be the beginning of a section of the file.
  816.  Here are suggested regular expressions for some common languages:
  817.  
  818. `^[A-Za-z_]'
  819.      C, C++, Prolog
  820.  
  821. `^('
  822.      Lisp
  823.  
  824. `^@\(chapter\|appendix\|unnumbered\|chapheading\)'
  825.      Texinfo
  826.  
  827.    This option does not automatically select an output format; in order
  828. to use it, you must select the context format (*note Context Format::.)
  829. or unified format (*note Unified Format::.).  In other output formats it
  830. has no effect.
  831.  
  832.    The `-F' and `--show-function-line' options find the nearest
  833. unchanged line that precedes each hunk of differences and matches the
  834. given regular expression.  Then they add that line to the end of the
  835. line of asterisks in the context format, or to the `@@' line in unified
  836. format.  If no matching line exists, they leave the output for that
  837. hunk unchanged.  If that line is more than 40 characters long, they
  838. output only the first 40 characters.  You can specify more than one
  839. regular expression for such lines; `diff' tries to match each line
  840. against each regular expression, starting with the last one given.  This
  841. means that you can use `-p' and `-F' together, if you wish.
  842.  
  843. 
  844. File: diff.info,  Node: C Function Headings,  Prev: Specified Headings,  Up: Sections
  845.  
  846. Showing C Function Headings
  847. ...........................
  848.  
  849.    To show in which functions differences occur for C and similar
  850. languages, you can use the `-p' or `--show-c-function' option. This
  851. option automatically selects the context output format (*note Context
  852. Format::.), with the default number of lines of context. You can
  853. override that number with `-C LINES' later in the command line.
  854.  
  855.    The `-p' and `--show-c-function' options are equivalent to `-c
  856. -F'^[_a-zA-Z$]'' (*note Specified Headings::.).  GNU `diff' provides
  857. them for the sake of convenience.
  858.  
  859. 
  860. File: diff.info,  Node: Alternate Names,  Prev: Sections,  Up: Context
  861.  
  862. Showing Alternate File Names
  863. ----------------------------
  864.  
  865.    If you are comparing two files that have meaningless or uninformative
  866. names, you might want `diff' to show alternate names in the header of
  867. the context and unified output formats.  To do this, use the `-L LABEL'
  868. or `--label=LABEL' option.  The first time you give this option, its
  869. argument replaces the name and date of the first file in the header;
  870. the second time, its argument replaces the name and date of the second
  871. file.  If you give this option more than twice, `diff' reports an
  872. error.  The `-L' option does not affect the file names in the `pr'
  873. header when the `-l' or `--paginate' option is used (*note
  874. Pagination::.).
  875.  
  876.    Here are the first two lines of the output from `diff -C2 -Loriginal
  877. -Lmodified lao tzu':
  878.  
  879.      *** original
  880.      --- modified
  881.  
  882. 
  883. File: diff.info,  Node: Side by Side,  Next: Scripts,  Prev: Context,  Up: Output Formats
  884.  
  885. Showing Differences Side by Side
  886. ================================
  887.  
  888.    `diff' can produce a side by side difference listing of two files.
  889. The files are listed in two columns with a gutter between them.  The
  890. gutter contains one of the following markers:
  891.  
  892. white space
  893.      The corresponding lines are in common.  That is, either the lines
  894.      are identical, or the difference is ignored because of one of the
  895.      `--ignore' options (*note Whitespace::.).
  896.  
  897. `|'
  898.      The corresponding lines differ.
  899.  
  900. `<'
  901.      The files differ and only the first file contains the line.
  902.  
  903. `>'
  904.      The files differ and only the second file contains the line.
  905.  
  906. `('
  907.      Only the first file contains the line, but the difference is
  908.      ignored.
  909.  
  910. `)'
  911.      Only the second file contains the line, but the difference is
  912.      ignored.
  913.  
  914.    Side by side format is sometimes easiest to read, but it has
  915. limitations. It generates much wider output than usual, and truncates
  916. lines that are too long to fit.  Also, it relies on lining up output
  917. more heavily than usual, so its output will look particularly bad if
  918. you use varying width fonts, nonstandard tab stops, or nonprinting
  919. characters. The side by side format cannot represent an incomplete
  920. line, so if an input file ends in an incomplete line, `diff' reports an
  921. error and then pretends that a newline was appended.
  922.  
  923.    You can use the `sdiff' command to interactively merge side by side
  924. differences.  *Note Interactive Merging::, for more information on
  925. merging files.
  926.  
  927. * Menu:
  928.  
  929. * Side by Side Format::        Controlling side by side output format.
  930. * Example Side by Side::    Sample side by side output.
  931.  
  932. 
  933. File: diff.info,  Node: Side by Side Format,  Next: Example Side by Side,  Up: Side by Side
  934.  
  935. Controlling Side by Side Format
  936. ===============================
  937.  
  938.    The `-y' or `--side-by-side' option selects side by side format. 
  939. Because side by side output lines contain two input lines, they are
  940. wider than usual.  They are normally 130 columns, which can fit onto a
  941. traditional printer line.  You can set the length of output lines with
  942. the `-W COLUMNS' or `--width=COLUMNS' option.  The output line is split
  943. into two halves of equal length, separated by a small gutter to mark
  944. differences; the right half is aligned to a tab stop so that tabs line
  945. up.  Input lines that are too long to fit in half of an output line are
  946. truncated for output.
  947.  
  948.    The `--left-column' option prints only the left column of two common
  949. lines.  The `--suppress-common-lines' option suppresses common lines
  950. entirely.
  951.  
  952. 
  953. File: diff.info,  Node: Example Side by Side,  Prev: Side by Side Format,  Up: Side by Side
  954.  
  955. An Example of Side by Side Format
  956. ---------------------------------
  957.  
  958.    Here is the output of the command `diff -y -W 72 lao tzu' (*note
  959. Sample diff Input::., for the complete contents of the two files).
  960.  
  961.      The Way that can be told of is n   <
  962.      The name that can be named is no   <
  963.      The Nameless is the origin of He        The Nameless is the origin of He
  964.      The Named is the mother of all t   |    The named is the mother of all t
  965.                                         >
  966.      Therefore let there always be no        Therefore let there always be no
  967.        so we may see their subtlety,           so we may see their subtlety,
  968.      And let there always be being,          And let there always be being,
  969.        so we may see their outcome.            so we may see their outcome.
  970.      The two are the same,                   The two are the same,
  971.      But after they are produced,            But after they are produced,
  972.        they have different names.              they have different names.
  973.                                         >    They both may be called deep and
  974.                                         >    Deeper and more profound,
  975.                                         >    The door of all subtleties!
  976.  
  977. 
  978. File: diff.info,  Node: Scripts,  Next: Merging C Files,  Prev: Side by Side,  Up: Output Formats
  979.  
  980. Making Edit Scripts
  981. ===================
  982.  
  983.    Several output modes produce command scripts for editing the from
  984. file to produce the to file.
  985.  
  986. * Menu:
  987.  
  988. * ed Scripts::        Using `diff' to produce commands for `ed'.
  989. * Forward ed::        Making forward `ed' scripts.
  990. * RCS::            A special `diff' output format used by RCS.
  991.  
  992. 
  993. File: diff.info,  Node: ed Scripts,  Next: Forward ed,  Up: Scripts
  994.  
  995. `ed' Scripts
  996. ------------
  997.  
  998.    `diff' can produce commands that direct the `ed' text editor to
  999. change the first file into the second file.  Long ago, this was the
  1000. only output mode that was suitable for editing one file into another
  1001. automatically; today, with `patch', it is almost obsolete.  Use the
  1002. `-e' or `--ed' option to select this output format.
  1003.  
  1004.    Like the normal format (*note Normal::.), this output format does not
  1005. show any context; unlike the normal format, it does not include the
  1006. information necessary to apply the diff in reverse (to produce the first
  1007. file if all you have is the second file and the diff).
  1008.  
  1009.    If the file `d' contains the output of `diff -e old new', then the
  1010. command `(cat d && echo w) | ed - old' edits `old' to make it a copy of
  1011. `new'.  More generally, if `d1', `d2', ..., `dN' contain the outputs of
  1012. `diff -e old new1', `diff -e new1 new2', ..., `diff -e newN-1 newN',
  1013. respectively, then the command `(cat d1 d2 ... dN && echo w) | ed -
  1014. old' edits `old' to make it a copy of `newN'.
  1015.  
  1016. * Menu:
  1017.  
  1018. * Detailed ed::        A detailed description of `ed' format.
  1019. * Example ed::        A sample `ed' script.
  1020.  
  1021. 
  1022. File: diff.info,  Node: Detailed ed,  Next: Example ed,  Up: ed Scripts
  1023.  
  1024. Detailed Description of `ed' Format
  1025. ...................................
  1026.  
  1027.    The `ed' output format consists of one or more hunks of differences.
  1028.  The changes closest to the ends of the files come first so that
  1029. commands that change the number of lines do not affect how `ed'
  1030. interprets line numbers in succeeding commands.  `ed' format hunks look
  1031. like this:
  1032.  
  1033.      CHANGE-COMMAND
  1034.      TO-FILE-LINE
  1035.      TO-FILE-LINE...
  1036.      .
  1037.  
  1038.    Because `ed' uses a single period on a line to indicate the end of
  1039. input, GNU `diff' protects lines of changes that contain a single
  1040. period on a line by writing two periods instead, then writing a
  1041. subsequent `ed' command to change the two periods into one.  The `ed'
  1042. format cannot represent an incomplete line, so if the second file ends
  1043. in a changed incomplete line, `diff' reports an error and then pretends
  1044. that a newline was appended.
  1045.  
  1046.    There are three types of change commands.  Each consists of a line
  1047. number or comma-separated range of lines in the first file and a single
  1048. character indicating the kind of change to make.  All line numbers are
  1049. the original line numbers in the file.  The types of change commands
  1050. are:
  1051.  
  1052. `La'
  1053.      Add text from the second file after line L in the first file.  For
  1054.      example, `8a' means to add the following lines after line 8 of file
  1055.      1.
  1056.  
  1057. `Rc'
  1058.      Replace the lines in range R in the first file with the following
  1059.      lines.  Like a combined add and delete, but more compact.  For
  1060.      example, `5,7c' means change lines 5--7 of file 1 to read as the
  1061.      text file 2.
  1062.  
  1063. `Rd'
  1064.      Delete the lines in range R from the first file.  For example,
  1065.      `5,7d' means delete lines 5--7 of file 1.
  1066.  
  1067. 
  1068. File: diff.info,  Node: Example ed,  Prev: Detailed ed,  Up: ed Scripts
  1069.  
  1070. Example `ed' Script
  1071. ...................
  1072.  
  1073.    Here is the output of `diff -e lao tzu' (*note Sample diff Input::.,
  1074. for the complete contents of the two files):
  1075.  
  1076.      11a
  1077.      They both may be called deep and profound.
  1078.      Deeper and more profound,
  1079.      The door of all subtleties!
  1080.      .
  1081.      4c
  1082.      The named is the mother of all things.
  1083.      
  1084.      .
  1085.      1,2d
  1086.  
  1087. 
  1088. File: diff.info,  Node: Forward ed,  Next: RCS,  Prev: ed Scripts,  Up: Scripts
  1089.  
  1090. Forward `ed' Scripts
  1091. --------------------
  1092.  
  1093.    `diff' can produce output that is like an `ed' script, but with
  1094. hunks in forward (front to back) order.  The format of the commands is
  1095. also changed slightly: command characters precede the lines they modify,
  1096. spaces separate line numbers in ranges, and no attempt is made to
  1097. disambiguate hunk lines consisting of a single period.  Like `ed'
  1098. format, forward `ed' format cannot represent incomplete lines.
  1099.  
  1100.    Forward `ed' format is not very useful, because neither `ed' nor
  1101. `patch' can apply diffs in this format.  It exists mainly for
  1102. compatibility with older versions of `diff'.  Use the `-f' or
  1103. `--forward-ed' option to select it.
  1104.  
  1105. 
  1106. File: diff.info,  Node: RCS,  Prev: Forward ed,  Up: Scripts
  1107.  
  1108. RCS Scripts
  1109. -----------
  1110.  
  1111.    The RCS output format is designed specifically for use by the
  1112. Revision Control System, which is a set of free programs used for
  1113. organizing different versions and systems of files.  Use the `-n' or
  1114. `--rcs' option to select this output format.  It is like the forward
  1115. `ed' format (*note Forward ed::.), but it can represent arbitrary
  1116. changes to the contents of a file because it avoids the forward `ed'
  1117. format's problems with lines consisting of a single period and with
  1118. incomplete lines.  Instead of ending text sections with a line
  1119. consisting of a single period, each command specifies the number of
  1120. lines it affects; a combination of the `a' and `d' commands are used
  1121. instead of `c'.  Also, if the second file ends in a changed incomplete
  1122. line, then the output also ends in an incomplete line.
  1123.  
  1124.    Here is the output of `diff -n lao tzu' (*note Sample diff Input::.,
  1125. for the complete contents of the two files):
  1126.  
  1127.      d1 2
  1128.      d4 1
  1129.      a4 2
  1130.      The named is the mother of all things.
  1131.      
  1132.      a11 3
  1133.      They both may be called deep and profound.
  1134.      Deeper and more profound,
  1135.      The door of all subtleties!
  1136.  
  1137. 
  1138. File: diff.info,  Node: Merging C Files,  Prev: Scripts,  Up: Output Formats
  1139.  
  1140. Merging C Source Files with `#ifdef'
  1141. ====================================
  1142.  
  1143.    You can use `diff' to merge two files of C source code.  The output
  1144. of `diff' in this format contains all the lines of both files. Lines
  1145. common to both files are output just once; the differing parts are
  1146. separated by the C preprocessor directives `#ifdef NAME' or `#ifndef
  1147. NAME', `#else', and `#endif'.  When compiling the output, you select
  1148. which version to use by either defining or leaving undefined the macro
  1149. NAME.
  1150.  
  1151.    To merge two files, use `diff' with the `-D NAME' or `--ifdef=NAME'
  1152. option.  The argument NAME is the C preprocessor symbol to use in the
  1153. `#ifdef' and `#ifndef' directives.
  1154.  
  1155.    For example, if you change an instance of `wait (&s)' to `waitpid
  1156. (-1, &s, 0)' and then merge the old and new files with the
  1157. `--ifdef=HAVE_WAITPID' option, then the affected part of your code
  1158. might look like this:
  1159.  
  1160.          do {
  1161.      #ifndef HAVE_WAITPID
  1162.              if ((w = wait (&s)) < 0  &&  errno != EINTR)
  1163.      #else /* HAVE_WAITPID */
  1164.              if ((w = waitpid (-1, &s, 0)) < 0  &&  errno != EINTR)
  1165.      #endif /* HAVE_WAITPID */
  1166.                  return w;
  1167.          } while (w != child);
  1168.  
  1169. * Menu:
  1170.  
  1171. * Detailed Merged::    A detailed description of merged format.
  1172. * Example Merged::    Sample merged format output.
  1173.  
  1174. 
  1175. File: diff.info,  Node: Detailed Merged,  Next: Example Merged,  Up: Merging C Files
  1176.  
  1177. Detailed Description of Merged Format
  1178. -------------------------------------
  1179.  
  1180.    For each hunk of differences in the `#ifdef' output format, if the
  1181. hunk contains lines from the first file, they are preceded by a line
  1182. consisting of `#ifndef NAME', where NAME is the argument to the `-D' or
  1183. `--ifdef' option; if the hunk contains lines from the second file, they
  1184. come next, preceded by a `#else' line.  Otherwise the hunk contains
  1185. lines from the second file but not from the first; the lines from the
  1186. second file are preceded by a line consisting of `#ifdef NAME' instead.
  1187.  Last comes a `#endif' line.
  1188.  
  1189.    If an input file ends in an incomplete line, `diff' silently
  1190. pretends that a newline was appended.
  1191.  
  1192.    You should carefully check the `diff' output to make sure that if
  1193. the differing lines contain any of the C preprocessor directives
  1194. `#ifdef', `#ifndef', `#else', `#elif', or `#endif', they are nested
  1195. properly and match.  If they don't, you must make corrections manually.
  1196.  It is a good idea to carefully check the resulting code anyway to make
  1197. sure that it really does what you want it to; depending on how the
  1198. input files were produced, the output might contain duplicate or
  1199. otherwise incorrect code.
  1200.  
  1201.    The `patch' `-D NAME' option behaves just like the `diff' `-D NAME'
  1202. option, except it operates on a file and a diff to produce a merged
  1203. file; *Note patch Options::.
  1204.  
  1205. 
  1206. File: diff.info,  Node: Example Merged,  Prev: Detailed Merged,  Up: Merging C Files
  1207.  
  1208. An Example of Merged Format
  1209. ---------------------------
  1210.  
  1211.    Here is the output of `diff -DTWO lao tzu' (*note Sample diff
  1212. Input::., for the complete contents of the two files):
  1213.  
  1214.      #ifndef TWO
  1215.      The Way that can be told of is not the eternal Way;
  1216.      The name that can be named is not the eternal name.
  1217.      #endif /* not TWO */
  1218.      The Nameless is the origin of Heaven and Earth;
  1219.      #ifndef TWO
  1220.      The Named is the mother of all things.
  1221.      #else /* TWO */
  1222.      The named is the mother of all things.
  1223.      
  1224.      #endif /* TWO */
  1225.      Therefore let there always be non-being,
  1226.        so we may see their subtlety,
  1227.      And let there always be being,
  1228.        so we may see their outcome.
  1229.      The two are the same,
  1230.      But after they are produced,
  1231.        they have different names.
  1232.      #ifdef TWO
  1233.      They both may be called deep and profound.
  1234.      Deeper and more profound,
  1235.      The door of all subtleties!
  1236.      #endif /* TWO */
  1237.  
  1238.