home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / utility / diffx.zip / HDIFF.ARC / HDIFF.DOC < prev    next >
Text File  |  1990-01-11  |  25KB  |  577 lines

  1.                                   hdiff 1.22
  2.                                    hed 1.01
  3.  
  4.         Purpose
  5.         -------
  6.         Hdiff compares two DOS text files and records the differences
  7.         between them in a third file.  Although hdiff can be used for
  8.         simple "what's changed?" purposes, its real function is to
  9.         assist in maintaining program source code or similar text files
  10.         that change over time.  By maintaining an original base file
  11.         and a series of "difference" files, it's possible to retain all
  12.         versions of a file at a great savings in space over retaining
  13.         the full text of all versions.
  14.  
  15.         The hdiff system includes an auxiliary program, hed, that is
  16.         used to apply the difference files to the original (although
  17.         EDLIN can also be used if the files are small enough).
  18.  
  19.         HDIFF 1.22 is unchanged from the version released in December,
  20.         1987.  HED 1.01 corrects a problem that very occasionally caused
  21.         incorrect reproduction of the original file after applying
  22.         updates.  Boy, did it take us a long time to track this one
  23.         down.
  24.  
  25.         Running hdiff
  26.         -------------
  27.         The general syntax for hdiff is:
  28.  
  29.             hdiff [-ecs] old-file new-file [dif-file]
  30.  
  31.         The simplest use of hdiff is exemplified by:
  32.  
  33.             hdiff oldfile.txt newfile.txt
  34.  
  35.         which displays a simple report of differences between the two
  36.         files: it shows which lines of OLDFILE.TXT do not appear in
  37.         NEWFILE.TXT (deletions), and which lines of NEWFILE.TXT do not
  38.         appear in OLDFILE.TXT (insertions).  The simple change report
  39.         consists of text lines in this format:
  40.  
  41.             nnnn[+/-] text
  42.  
  43.         A '+' format indicates that the line is new (an insertion); the
  44.         '-' indicates that the line is gone (a deletion).  Thus:
  45.  
  46.             0001- This line appears in the old file only
  47.             0001+ This line appears in the new file only
  48.  
  49.         The 'nnnn' represents the line number.  For '+' lines, it's the
  50.         line number in the new file; for '-' lines, it's the line number
  51.         in the old file.
  52.  
  53.         (Note that the first file named on the command line is always
  54.         assumed to be the "old" file, and the second is the "new" file.)
  55.  
  56.         If you want the report to be sent to a text file rather than to
  57.         the screen, simply include the file name as a third parameter:
  58.  
  59.             hdiff oldfile.txt newfile.txt changes.txt
  60.  
  61.         NOTE: the simple report does not show lines that have been
  62.         moved.  The edlin-format report (-e switch) does include moved
  63.         lines.  Use the -e report for maintaining difference files; the
  64.         simple report does not contain enough information.
  65.  
  66.  
  67.         Optional switches
  68.         -----------------
  69.         Here are the switches that can optionally be added to the
  70.         command line.  They must precede the file names:
  71.  
  72.         -c      Case insensitive: hdiff ignores differences in
  73.                 alphabetic case.  Thus, the two lines:
  74.  
  75.                         This is text
  76.                         THIS IS TEXT
  77.  
  78.                 are not reported as changed.
  79.  
  80.         -e      Edlin: produce an edlin-compatible difference file
  81.                 rather than the simple difference report described
  82.                 above.  This switch is also used to created hed-format
  83.                 files.  See succeeding sections for more information.
  84.  
  85.         -s      Space insensitive: hdiff ignores differences in spacing.
  86.                 This, the two lines:
  87.  
  88.                         This is text
  89.                         This  is    text
  90.  
  91.                 are not reported as changed.
  92.  
  93.         The switches may be combined, and they may be in any order:
  94.  
  95.                 -e -c
  96.                 -ec
  97.                 -ce
  98.                 -c -e
  99.  
  100.         are all equivalent.  All switches must, however, precede the
  101.         first filename.
  102.  
  103.         Examples of hdiff use:
  104.  
  105.             hdiff foo.c newfoo.c
  106.  
  107.                 compares file 'foo.c' with file 'newfoo.c' and displays
  108.                 a simple report showing insertions (lines in newfoo that
  109.                 do not appear in foo) and deletions (lines in foo that
  110.                 do not appear in newfoo).  Lines that have been moved
  111.                 but are otherwise unchanged do not appear in this
  112.                 report.
  113.  
  114.             hdiff -ec foo.c newfoo.c foo.114
  115.  
  116.                 compares foo.c with newfoo.c, ignoring case differences,
  117.                 and prepares an edlin/hed script in the file foo.114.
  118.                 This script, if applied to foo as described below, will
  119.                 create a copy of newfoo.
  120.  
  121.  
  122.         Applying difference files: edlin and version control
  123.         ----------------------------------------------------------
  124.         The main purpose of hdiff is to assist you in maintaining
  125.         multiple versions of program source or other text files.  Many
  126.         programmers like to keep archival copies of old source, for any
  127.         of a number of reasons (one reason: sometimes changes don't work
  128.         and it's necessary to go back to a previous version!).  You
  129.         could simply keep an archive or library with the complete text
  130.         of all versions, but this is wasteful of disk space.
  131.  
  132.         A better solution (short of purchasing a true SCCS ["Source Code
  133.         Control System"] for big bucks) is to use hdiff and hed or edlin
  134.         to keep one original source file plus smaller difference files
  135.         that can be used to re-create any version.
  136.  
  137.         To see how this works, assume that you have an old version of
  138.         your program MYPROG.C (in a file called MYPROG.SCC) and a new
  139.         version named MYPROG.C:
  140.  
  141.                 myprog.scc     (version 1.00)
  142.                 myprog.c       (version 1.10)
  143.  
  144.         To create a difference file, use hdiff:
  145.  
  146.             hdiff -e myprog.scc myprog.c myprog.110
  147.  
  148.         After hdiff is finished, you will have a file (MYPROG.110) that
  149.         contains the differences between 1.00 and 1.10.  Because of the
  150.         -e switch, this file is in a special format:  it is actually the
  151.         text of a series of edlin commands that would turn version 1.00
  152.         source into version 1.10 source.  It is an edlin script.  So, if
  153.         you were to execute the commands (remember that MYPROG.SCC is
  154.         version 1.00):
  155.  
  156.             copy myprog.scc myprog.c
  157.             edlin myprog.c < myprog.110
  158.  
  159.         the result (after edlin finished) would be a file called
  160.         MYPROG.C that contains the source for version 1.10.  Thus,
  161.         between the original (1.00) MYPROG.SCC and the difference file
  162.         MYPROG.110 you have all you need to re-create either version of
  163.         the program.  Chances are, however, that MYPROG.110 is much
  164.         smaller than the full source for MYPROG.C, so considerable
  165.         storage is saved.
  166.  
  167.         Note that edlin cannot deal, in this context, with files larger
  168.         than about 48K.  If you try to apply a difference file to a base
  169.         file larger than 48K using edlin, the resultant file will be
  170.         damaged and probably unusable.  For this reason and others, we
  171.         recommend using the supplied program "hed" rather than edlin.
  172.  
  173.  
  174.         Using hed
  175.         ---------
  176.         Hed is a simple program that can be used in place of edlin to
  177.         apply update files.  We prefer it to edlin for this purpose;
  178.         there are several reasons:
  179.  
  180.             1. It's much faster.
  181.             2. It doesn't suffer from Edlin's 48K file size restriction.
  182.             3. It handles file dates in a more useful manner.
  183.             4. It can create a new file with a different name.
  184.             5. It can apply more than one update file at a time.
  185.  
  186.         Hed's full syntax is:
  187.  
  188.             hed [-nv] base diff[+diff...] [new]
  189.  
  190.         where base is the original source file (MYPROG.SCC, in the above
  191.         example), diff is the difference file created by hdiff, and new
  192.         is the optional output file name.
  193.  
  194.         The optional parameters are:
  195.  
  196.             -n  No sort: instructs hed not to sort multiple update
  197.                 files, i.e., to apply them in the stated order.
  198.  
  199.             -v  reVerse: instructs hed to sort multiple updates
  200.                 files is reverse order (more about this shortly).
  201.  
  202.         If both -n and -v are specified, -n takes precedence.
  203.  
  204.         This command creates MYPROG version 1.10 from the 1.00 source
  205.         and the difference file created above:
  206.  
  207.             hed myprog.scc myprog.110 myprog.c
  208.  
  209.         On completion, you'll have the 1.10 source in the file MYPROG.C.
  210.  
  211.         If you do not include a third file name (new), hed will change
  212.         the extension of the base file to BAK and re-use the base file
  213.         name for the output.  In other words,
  214.  
  215.             hed myprog.scc myprog.110
  216.  
  217.         wil leave the original MYPROG.SCC in MYPROG.BAK, and the new
  218.         MYPROG.SCC will be the source for version 1.10.  This is exactly
  219.         what edlin would do.
  220.  
  221.         Note that you can apply several updates at once:
  222.  
  223.             hed myprog.scc myprog.110+myprog.111+myprog.120 myprog.c
  224.  
  225.         More information about this feature is in the section called
  226.         "Hed and Multiple Updates".
  227.  
  228.  
  229.         File dates
  230.         ----------
  231.         If you use hdiff's -e switch and specify an output file, hdiff
  232.         will set the difference file date to the same date as new-file.
  233.         That is, after
  234.  
  235.             hdiff -e myprog.scc myprog.c myprog.110
  236.  
  237.         MYRPOG.110 will have the same date as MYPROG.C.  This is useful
  238.         because hed uses the difference file date for its own output.
  239.         That is, after:
  240.  
  241.             hed myprog.scc myprog.110 myprog.c
  242.  
  243.         MYPROG.C will have the same date as MYPROG.110, which, in turn,
  244.         has the same date as the original copy of MYPROG.C.
  245.  
  246.         In this manner, the hdiff/hed system can retain true file dates
  247.         for all versions.
  248.  
  249.  
  250.         Cdelta and cget
  251.         ---------------
  252.         The two demonstration batches, cdelta and cget, provide a quick
  253.         sample of the kinds of things that can be done with hdiff and
  254.         hed.  The two batches are designed for C programs; to revise
  255.         them for other languages, simply replace all references to ".c"
  256.         with the desired extension (.asm, for example).
  257.  
  258.         The purpose of cdelta is to generate a change script that will
  259.         convert a "base" source file into a specified version of your
  260.         source.  Cget performs the inverse task; it applies a specified
  261.         change file to the base and produces a file containing the
  262.         specified version.  File naming conventions are as follows:
  263.  
  264.                 file.scc:    "base" source; scc = source code control
  265.                 file.###:    A change script to produce version ###
  266.                 file.c:      The current version (cdelta), or the
  267.                              output file (cget)
  268.  
  269.         For example, suppose you are working with a C program called
  270.         FOO.  A base (earliest) version of this file should be in
  271.         FOO.SCC.  You have just finished revision 1.10 of FOO.  To
  272.         create the change file, type
  273.  
  274.                 cdelta foo 110
  275.  
  276.         The batch will create a new file, FOO.110; this file is an
  277.         edlin/hed compatible script that will convert FOO.SCC into
  278.         version 1.10 of FOO.C.
  279.  
  280.         To retrieve a specified version, say 1.05, use
  281.  
  282.                 cget foo 105
  283.  
  284.         The batch will apply the script FOO.105 to FOO.SCC (using hed)
  285.         and produce FOO.C, which will contain the source for version
  286.         1.05.
  287.  
  288.         Note that cget always creates a file with a C extension,
  289.         overwriting any existing file with the same name.  This implies
  290.         that you do NOT keep your current source in FILE.C; you keep the
  291.         current source only by retaining FILE.SCC and the delta files.
  292.  
  293.  
  294.         Sequential version control
  295.         --------------------------
  296.         If you have access to a system that provides more sophisticated
  297.         control over the execution of DOS commands (Personal REXX or
  298.         Extended Batch Language, for example), it's not difficult to
  299.         provide for "sequential" version control for even greater space
  300.         savings.  The demo batch files, cdelta and cget, use only one
  301.         base file; each new version is represented by a difference file
  302.         that is the difference from the original version:
  303.  
  304.                 foo.scc + foo.110 = foo.c (version 1.10)
  305.                 foo.scc + foo.111 = foo.c (version 1.11)
  306.                 foo.scc + foo.120 = foo.c (version 1.20)
  307.  
  308.         This scheme has the virtue of simplicity, but there is a
  309.         disadvantage:  the difference files just keep getting bigger and
  310.         bigger.  Each difference file contains the cumulative
  311.         differences of all preceding versions.  You may eventually find
  312.         that the difference files are larger than the base file.
  313.  
  314.         The sequential method keeps differences between versions, rather
  315.         than differences between the current version and an original
  316.         base.  That is, FOO.110 is the difference between FOO.SCC and
  317.         version 1.10; FOO.111 is the difference between versions 1.10
  318.         and 1.11; FOO.120 is the difference between versions 1.11 and
  319.         1.20.  To obtain version 1.20, we start with the base file and
  320.         apply all difference files sequentially:
  321.  
  322.                 foo.scc + foo.110 = temp.c (foo version 1.10)
  323.                 temp.c + foo.111 = temp2.c (foo version 1.11)
  324.                 temp2.c + foo.120 = foo.c  (foo version 1.20)
  325.  
  326.         This scheme is obviously somewhat more complex, but it allows
  327.         you to save all versions of a file in the least amount of space.
  328.  
  329.         Note that the single command:
  330.  
  331.                 hed foo.scc foo.110+foo.111+foo.120 hed.c
  332.  
  333.         would do the whole job in one step.  See the next section for
  334.         more information on how to apply sequential update files.
  335.  
  336.  
  337.         Hed and Multiple Updates
  338.         ------------------------
  339.         As noted, you can apply more than one update file per hed run by
  340.         using the "+" operator:
  341.  
  342.             hed file.scc file.110+file.111+file.112 file.c
  343.  
  344.         Here are the full rules:
  345.  
  346.             1. You can use wildcard file specifications.  For example,
  347.                if FILE.110, FILE.111, and FILE.112 were the only update
  348.                files in the current directory, you could use:
  349.  
  350.                     hed file.scc file.1* file.c
  351.  
  352.                If you had FILE.110, FILE.121, and FILE.200:
  353.  
  354.                     hed file.scc file.1*+file.2* file.c
  355.  
  356.             2. The file list must be separated by "+" ONLY; spaces are
  357.                not permitted.  Thus,
  358.  
  359.                     hed file.scc file.100 + file.110
  360.  
  361.                 is not legal.  It must be
  362.  
  363.                     hed file.scc file.100+file.110
  364.  
  365.             3. A total of up to 40 update files (including all
  366.                wildcard expansions) may be specified.
  367.  
  368.             4. Hed sorts the files by extension and applies them in
  369.                sorted order, one after the other.  (If you use the -v
  370.                switch, hed will sort in reverse order; if you use -n, no
  371.                sorting will be performed.)  In other words, if you
  372.                enter:
  373.  
  374.                     hed file.scc file.1* file.c
  375.  
  376.                and files FILE.120 and FILE.110 are present in the
  377.                current directory (in that order), hed will:
  378.  
  379.                     a. Sort the update files by extension; 110 will
  380.                        precede 120 even though they are "out of order"
  381.                        in the disk directory.
  382.                     b. Read in FILE.SCC.
  383.                     c. Apply FILE.110 updates, creating an "in-memory"
  384.                        copy of version 110.
  385.                     d. Apply FILE.120 updates, creating an "in-memory"
  386.                        copy of version 120.
  387.                     e. Write out the resultant file as FILE.C
  388.  
  389.         Note that intermediate versions are not written to disk.
  390.  
  391.  
  392.         Reverse sorting
  393.         ---------------
  394.         The purpose of the -v switch is to allow you to implement a
  395.         "reverse" version scheme.  Rather than keeping an original base
  396.         and multiple updates from that base, some people prefer to keep
  397.         the full current source and difference files for earlier
  398.         versions.  For example, if you have FOO versions 1.00, 1.05, and
  399.         1.10 (the current), the "traditional" scheme would be to keep
  400.         the source for 1.00 and update files for 1.05 and 1.10:
  401.  
  402.                 foo.scc + foo.105 -> foo.c (version 1.05)
  403.                 foo.c + foo.110 ->   foo.c (version 1.10)
  404.  
  405.         The "reverse" scheme would be to keep the full source to version
  406.         1.10 and keep a difference file that would create 1.05 and 1.00:
  407.  
  408.                 foo.scc = current (1.10)
  409.                 foo.scc + foo.105 -> foo.c (version 1.05)
  410.                 foo.c + foo.100 ->   foo.c (version 1.00)
  411.  
  412.         Using this scheme, the hed command
  413.  
  414.                 hed foo.scc foo.1* foo.c
  415.  
  416.         (to create version 1.00) wouldn't work, because the update files
  417.         would be sorted in the wrong order:  1.00 would precede and be
  418.         applied before 1.05.  However, the command
  419.  
  420.                 hed -v foo.scc foo.1* foo.c
  421.  
  422.         would sort in reverse order and apply 1.05 before 1.00,
  423.         correctly producing 1.00.
  424.  
  425.         The advantage to the "reverse" scheme is that the most current
  426.         version of the source can be obtained immediately, without the
  427.         need to apply many sequential files.
  428.  
  429.  
  430.         Other uses of hdiff
  431.         -------------------
  432.         In addition to the version control application of hdiff, you can
  433.         find other uses for the system.
  434.  
  435.         The simplest use for hdiff is to compare two files to see if
  436.         they are the same.  This can be used to check for corruption
  437.         during backups, copies, etc., or to determine which of two files
  438.         is newer.  Even this simple use of hdiff can be useful in
  439.         unexpected ways, however.  For example, look at this small batch
  440.         file:
  441.  
  442.                 dir a: > temp
  443.                 find "-" temp > dir.a
  444.                 dir b: > temp
  445.                 find "-" temp > dir.b
  446.                 hdiff dir.b dir.a > temp.bat
  447.                 erase dir.a
  448.                 erase dir.b
  449.                 erase temp
  450.  
  451.         This batch can be used for a simple backup system.  Assume that
  452.         the default directory in drive A contains a series of files that
  453.         you want to backup, and that the default directory in drive B
  454.         contains the same set of files from the last backup.  The batch
  455.         will isolate differences between the two directories and prepare
  456.         a file called TEMP.BAT that contains a list of those files that
  457.         have been changed or added since the last backup.  Many popular
  458.         text editors could very easily convert (or be programmed to
  459.         automatically convert) TEMP.BAT file into a series of copy
  460.         commands that could be used, in batch mode, to perform the
  461.         copying.
  462.  
  463.  
  464.         Restrictions
  465.         ------------
  466.         The following act, in one way or another, as restrictions on
  467.         hdiff:
  468.  
  469.         - File format:  hdiff is intended as a DOS text file differencer
  470.         only.  It is NOT a replacement for the DOS utility COMP or our
  471.         own QCMP.  Don't use it on binary (program or data) files, or on
  472.         most word processor files.
  473.  
  474.         - Available memory:  hdiff works entirely in memory, and it
  475.         needs quite a lot.  The starting memory requirement is about
  476.         220K; then, for each UNIQUE line in either file, hdiff needs
  477.         about 12 bytes plus the length of the line.  Identical lines are
  478.         stored only once, no matter how many times they occur.  Thus,
  479.         the two files:
  480.  
  481.             File 1:
  482.                 Line 1
  483.                 /* Comment */
  484.                 Line 2
  485.  
  486.             File 2:
  487.                 Line 1
  488.                 /* Comment */
  489.                 /* Comment */
  490.                 Line 2
  491.                 Line 3
  492.  
  493.         have four unique lines ("Line 1", "/* Comment */", "Line 2", and
  494.         "Line 3").  These will use about 79 bytes of storage (in
  495.         addition to the 220K starting memory!):
  496.  
  497.             4 lines @ 12 bytes:  48
  498.             Total text length:   31
  499.  
  500.         - Number of lines: neither file can exceed 5000 lines of text.
  501.  
  502.         - Line size: limited to a maximum of 1000 characters per line.
  503.  
  504.  
  505.         Notes on the algorithm
  506.         ----------------------
  507.         Hdiff uses a file comparison algorithm that was developed by
  508.         Paul Heckel and described by Dave Cortesi in Dr.  Dobb's Journal
  509.         #94 (August, 1984).  The algorithm is substantially more
  510.         efficient than traditional file comparison methods; it can
  511.         generate a difference report between two files in little more
  512.         than the time it takes for the program to read them.
  513.  
  514.         Hdiff was derived from Cortesi's demonstration program, with
  515.         substantial modifications that
  516.  
  517.             - accomodate differences between edlin and CP/M's "ed" (for
  518.               which the demo was written)
  519.  
  520.             - allow use of edlin's block move capabilities
  521.  
  522.             - allow for much larger files through the use of all
  523.               available memory.
  524.  
  525.             - allow case and spacing insensitive comparisons.
  526.  
  527.             - allow the user to request the simpler difference report
  528.               rather than the edlin script.
  529.  
  530.  
  531.         Copyright/License/Warranty
  532.         --------------------------
  533.         This document and the program files HDIFF.EXE and HED.EXE ("the
  534.         software") are copyrighted by the author.  The copyright owner
  535.         hereby licenses you to:  use the software; make as many copies
  536.         of the program and documentation as you wish; give such copies
  537.         to anyone; and distribute the software and documentation via
  538.         electronic means.  There is no charge for any of the above.
  539.  
  540.         However, you are specifically prohibited from charging, or
  541.         requesting donations, for any such copies, however made; and
  542.         from distributing the software and/or documentation with
  543.         commercial products without prior permission.  An exception is
  544.         granted to not-for-profit user's groups, which are authorized to
  545.         charge a small fee (not to exceed $7) for materials, handling,
  546.         postage, and general overhead.  NO FOR-PROFIT ORGANIZATION IS
  547.         AUTHORIZED TO CHARGE ANY AMOUNT FOR DISTRIBUTION OF COPIES OF
  548.         THE SOFTWARE OR DOCUMENTATION, OR TO INCLUDE COPIES OF THE
  549.         SOFTWARE OR DOCUMENTATION WITH SALES OF THEIR OWN PRODUCTS.
  550.  
  551.         THIS INCLUDES A SPECIFIC PROHIBITION AGAINST FOR-PROFIT
  552.         ORGANIZATIONS DISTRIBUTING THE SOFTWARE, EITHER ALONE OR WITH
  553.         OTHER SOFTWARE, AND CHARGING A "HANDLING" OR "MATERIALS" FEE OR
  554.         ANY OTHER SUCH FEE FOR THE DISTRIBUTION.  NO FOR-PROFIT
  555.         ORGANIZATION IS AUTHORIZED TO INCLUDE THE SOFTWARE ON ANY MEDIA
  556.         FOR WHICH MONEY IS CHARGED.  PERIOD.
  557.  
  558.         No copy of the software may be distributed or given away without
  559.         this document; and this notice must not be removed.
  560.  
  561.         There is no warranty of any kind, and the copyright owner is not
  562.         liable for damages of any kind.  By using this free software,
  563.         you agree to this.
  564.  
  565.         The software and documentation are:
  566.  
  567.                     Copyright (C) 1985, 1986, 1987, 1990 by
  568.                             The Cove Software Group
  569.                             Christopher J. Dunford
  570.                                  P.O. Box 1072
  571.                            Columbia, Maryland 21044
  572.  
  573.                                 (301) 992-9371
  574.                         CompuServe 76703,2002 [IBMNET]
  575.  
  576.         Software and documentation author: Chris Dunford
  577.