home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_200 / 270_01 / diff.doc < prev    next >
Text File  |  1979-12-31  |  8KB  |  218 lines

  1. File Difference Utilities
  2. Ralph E. Brendler (1988)
  3. ===============================================
  4. DIFF    - a file differencer
  5. DELTA    - a delta script creation utility
  6. APPLY    - a delta script application utility
  7. ===============================================
  8.  
  9. These three utilities can be used for detecting the differences between
  10. similar text files, such as different revisions of the same piece of source
  11. code.
  12.  
  13. These programs were developed to offset the severe lack of development
  14. tools for OS/2 in the early stages of the operating system's availability.
  15. My years of experience with DOS based UNIX utilties like DIFF made it very
  16. uncomfortable to develop without them when I changed operating systems.
  17. For a while, I was using the compatability box (which I soon began referring
  18. to as the Chernyobel box) to run my old DOS utilities, but this soon became
  19. cumbersome.  After much unsuccessful searching I finally determined that the
  20. only way to get quality tools in a timely fashion was to write them myself.
  21.  
  22. My goals in writing these utilities was to provide myself with portable
  23. utilities (so that when I change OS's again I won't be stuck), which could 
  24. be run under both OS/2 and DOS 3.X.   Each of these programs compiles without
  25. any warnings under warning level 3 on the MS C 5.1 compiler, and can be bound
  26. (using the MS BIND utility) to run under either DOS or OS/2.
  27.  
  28. No OS specific calls are made in this program, and it should compile under any
  29. memory model on an ANSI standard compiler which supports function prototypes.
  30.  
  31. ............................................................................
  32. ............................................................................
  33.  
  34.  
  35. DIFF
  36. =============
  37.  
  38. DIFF is a plain-vanilla file difference reporting utility based on the
  39. program of the same name found on UNIX systems.  It will compare two files
  40. (supplied on the command line) and display any lines which are different in
  41. the two files.  DIFF is invoked using the command:
  42.  
  43.         DIFF FILE1 FILE2
  44.  
  45.     where FILE1 and FILE2 are the names of the files to compare.
  46.  
  47. All output is to stdout, and can be redirected using the standard '<'
  48. and '|' piping characters.
  49.  
  50. File differences are displayed in the following manner:
  51.  
  52.     Description of change
  53.     .
  54.     .
  55.     text lines different
  56.     .
  57.     .
  58.     .
  59.  
  60. The description of change is in a style similar to that used by the UNIX
  61. editor 'ed'.  The three basic type of file differences are:
  62.  
  63.     Lines in FILE1 not present in FILE2        (DELETE)
  64.     Lines in FILE2 not present in FILE1        (ADD)
  65.     Lines in FILE1 different from lines in FILE2    (CHANGE)
  66.  
  67. These are represented in the change description as:
  68.  
  69.     L1, L2, c L3, L4    (changed range of lines)
  70.     L1 a L3, L4        (added range of lines)
  71.     L1, L2 d L3        (deleted range of lines)
  72.  
  73.     Where:    L1 and L2 are line numbers in FILE1
  74.         L3 and L4 are line numbers in FILE2
  75.  
  76. The actual lines of text which differ are output after the change description
  77. in the following format:
  78.  
  79.     Any line in FILE1 and not in FILE2 is preceded with a '<'
  80.     Any line in FILE2 and not in FILE1 is preceded with a '>'
  81.  
  82. Thus, given the following two text files:
  83.  
  84.     FILE1.TXT
  85.     ---------
  86.     The quick brown fox jumped over the lazy dog.
  87.     Now is the time for all good men to come to the
  88.         aid of their country.
  89.     All work and no play makes Jack a dull boy.
  90.  
  91.     FILE2.TXT
  92.     ---------
  93.     The quick brown fox jumped over the lazy dog.
  94.     Ars longa, vitae brevis.
  95.     Now is the time for all good men to come to the
  96.         aid of their company.
  97.  
  98. The resulting file difference would be reported as such:
  99.  
  100.     DIFF FILE1.TXT FILE2.TXT
  101.     -------------------------
  102.     1a2
  103.     > Ars longa, vitae brevis.
  104.     3c4
  105.     <     aid of their country.
  106.     < All work and no play makes Jack a dull boy.
  107.     ---
  108.     >     aid of their company.
  109.  
  110.  
  111. ............................................................................
  112. ............................................................................
  113.  
  114. DELTA
  115. =============
  116.  
  117. DELTA is a variation of DIFF which can be used to create 'delta scripts'.
  118. A delta script is a series of commands which can be used to create one
  119. text file from another.  Delta scripts are the basis for most Source Code
  120. Control Systems (SCCS's) used to maintain several related versions of a 
  121. software system.  SCCS's work by saving the most current version of a file, 
  122. and a delta script which will create the previous version.  This can be
  123. carried on through multiple versions by maintaining a delta script to
  124. create each revision from its successor.  Thus any version can be recreated
  125. by applying the proper delta script(s).
  126.  
  127. The average SCCS is much more complex than DELTA, however.  A good SCCS will
  128. maintain all delta scripts in one special file, and be able to recreate any
  129. version with a single command by applying the proper sequence of delta scripts.
  130. DELTA is, however, a sound basis for further work in developing a true SCCS,
  131. and this was my initial reason for writing it.  Eventually (but alas, probably
  132. not very soon), I will finish the work started by DELTA and write a SCCS of
  133. my own.
  134.  
  135. DELTA is invoked using the following command:
  136.  
  137.         DELTA FILE1 FILE2
  138.  
  139.     where FILE1 and FILE2 are the names of the files to compare.
  140.  
  141. All output is to stdout, and can be redirected using the standard '<'
  142. and '|' piping characters.
  143.  
  144.  
  145. This program's output is in a form like the UNIX editor 'ed' would understand.  
  146. There are three actions which can be taken on a file.  These are as follows:
  147.     
  148.     CHANGE: Change a range of lines in a file.
  149.     
  150.         This command lists a range of lines to delete in the
  151.         original file, and text for the new lines to insert in
  152.         their place.  The list of lines is terminated by a line
  153.         consisting of a single period character ('.').
  154.     
  155.         Example:    
  156.         --------------------------------------
  157.         40,42c
  158.         Insert these four lines
  159.         where the lines 40, 41, and 42
  160.         were in the
  161.         orignal file
  162.         .
  163.         --------------------------------------
  164.         
  165.     DELETE:    Delete a range of lines in a file.
  166.     
  167.         This command lists a range of lines to delete in the
  168.         original file.  No new lines are added to the new file.
  169.         
  170.         Example:
  171.         --------------------------------------
  172.         40,42d
  173.         --------------------------------------
  174.         this command would delete lines 40, 41, and 42 from the
  175.         original file.
  176.         
  177.     ADD:    Add new lines to the file.
  178.     
  179.         This command lists a location in the file, and a range of
  180.         lines to add at this location.  As in the change command,
  181.         the list of lines to add is terminated with a line with a
  182.         single period character.
  183.         
  184.         Example:
  185.         --------------------------------------
  186.         40a
  187.         These lines are inserted after
  188.         line 40 in the original file
  189.         .
  190.         --------------------------------------
  191.  
  192.  
  193. ............................................................................
  194. ............................................................................
  195.  
  196. APPLY
  197. =============
  198.  
  199. APPLY is a simple utility to apply a delta script created by DELTA to a 
  200. text file.  In a simplistic sense, this 'un-deltas' a file.
  201.  
  202. APPLY is invoked using the following command:
  203.  
  204.         APPLY FILE DELTA
  205.  
  206.     where    FILE is the name of the file to apply the changes to and
  207.         DELTA is the name of the delta script.
  208.  
  209. For instance, if the file FILE1.DTA were created using the following commands:
  210.  
  211.     DELTA FILE2.TXT FILE1.TXT > FILE1.DTA
  212.     DELETE FILE1.TXT
  213.  
  214. FILE1.TXT could be re-created by applying the delta script to FILE2.TXT as
  215. follows:
  216.  
  217.     APPLY FILE2.TXT FILE1.DTA > FILE1.TXT
  218.