home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 June: Reference Library / Dev.CD Jun 00 RL Disk 1.toast / pc / technical documentation / develop / develop issue 28 / develop issue 28 code / merge tools / diff.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-25  |  8.7 KB  |  214 lines

  1. /* Shared definitions for Eclectus integration utilities
  2.      Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  3.  
  4. This file is part of the Eclectus integration utilities.
  5.  
  6. Eclectus integration utilities are free software; you can redistribute
  7. it and/or modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 1, or
  9. (at your option) any later version.
  10.  
  11. Eclectus integration utilities is distributed in the hope that it
  12. will be useful, but WITHOUT ANY WARRANTY; without even the implied
  13. warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. See the GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with the Eclectus integration utilities; see the file COPYING.
  18. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
  19. MA 02139, USA.    */
  20.  
  21. #ifndef _DIFF
  22.     #define _DIFF
  23.  
  24.     #ifndef DF_COMPILER_MSC    /* MSC uses these modifiers to control argument passing */
  25.         #define __fastcall /* pass arguments in registers */
  26.         #define __cdecl /* C calling conventions; necessary for var args */
  27.     #endif
  28.  
  29.     #ifdef DF_DEBUG
  30.         #include "DebugMalloc.h"
  31.     #endif
  32.  
  33.     #include <limits.h>
  34.     #include <stdio.h>
  35.  
  36.     #define bcopy(s,d,n)        (void) memcpy((d),(s),(n))
  37.     #define bcmp(s1,s2,n)     (void) memcmp((s1),(s2),(n))
  38.     #define bzero(s,n)            (void) memset((s),0,(n))
  39.  
  40.     #define TRUE        1
  41.     #define FALSE     0
  42.  
  43.     #define DIFFERENCE_SCRIPT_START_STRING "# Created by Eclectus Difference integration utility\n"
  44.     #define VERSION_STRING "1.10"
  45.  
  46.     #define COLLISION_PREFIX "!"
  47.     #define LENGTH_OF_COLLISION_PREFIX 1
  48.     #define HEX_LINE_LENGTH 0X30
  49.  
  50.     #ifdef DF_MACHINE_MACINTOSH
  51.         #define DIRECTORY_CHAR ':'
  52.         #define MAXPATHLEN 255
  53.     #elif defined (DF_MACHINE_NEXT)
  54.         #define DIRECTORY_CHAR '/'
  55.     #elif defined (DF_MACHINE_WINDOWS)
  56.         #define DIRECTORY_CHAR '\\'
  57.     #else
  58.         #error Define DIRECTORY_CHAR for your machine
  59.     #endif
  60.  
  61.     /* Program error messages messages */
  62.     enum {
  63.         BAD_SCRIPT_FORMAT,
  64.         BAD_SCRIPT_FOR_SOURCE,
  65.         CANT_CREATE_DIRECTORY,
  66.         CANT_CREATE_FILE,
  67.         CANT_OPEN_FILE,
  68.         HASH_DOESNT_MATCH,
  69.         MEMORY_ERROR,
  70.         MIXED_FILE_TYPES_DONT_MERGE,
  71.         NOT_ASCII,
  72.         PATH_TOO_LONG,
  73.         THREE_OR_MORE_MERGE_FILES,
  74.         THREE_UN_DIFFERENCE_FILES,
  75.         TWO_FILES_ONLY,
  76.         UNEXPECTED_IO_ERROR,
  77.         UNEXPECTED_OPTION,
  78.         MAX_ERROR_KIND = UNEXPECTED_OPTION};
  79.  
  80.     /* Types returned by file type */
  81.     enum {
  82.         BAD_FILE_TYPE,
  83.         BINARY_TYPE,
  84.         DIRECTORY_TYPE,
  85.         TEXT_TYPE,
  86.         MAX_FILE_TYPE_KIND = TEXT_TYPE};
  87.  
  88.     /* Attribute bits for CopyFileAttributes */
  89.     #define    LOCK_MASK        1
  90.     #define    DATE_MASK        2
  91.     #define    RESOURCE_MASK    4
  92.                 
  93.     /* Rotate a value n bits to the left. */
  94.     #define UINT_BIT (sizeof (unsigned) * CHAR_BIT)
  95.     #define ROL(v, n) ((v) << (n) | (v) >> (UINT_BIT - (n)))
  96.  
  97.     /* Given a hash value and a new character, return a new hash value. */
  98.     #define HASH(h, c) ((c) + ROL (h, 7))
  99.  
  100.     /* The result of comparison is an "edit script": a chain of `struct change'.
  101.          Each `struct change' represents one place where some lines are deleted
  102.          and some are inserted.
  103.     
  104.          LINE0 and LINE1 are the first affected lines in the two files (origin 0).
  105.          DELETED is the number of lines deleted here from file 0.
  106.          INSERTED is the number of lines inserted here in file 1.
  107.  
  108.          If DELETED is 0 then LINE0 is the number of the line before
  109.          which the insertion was done; vice versa for INSERTED and LINE1.  */
  110.  
  111.     struct change
  112.     {
  113.         struct change *link;    /* Previous or next edit command    */
  114.         int inserted;                 /* # lines of file 1 changed here.    */
  115.         int deleted;                    /* # lines of file 0 changed here.    */
  116.         int line0;                        /* Line number of 1st deleted line.  */
  117.         int line1;                        /* Line number of 1st inserted line.    */
  118.     };
  119.  
  120.     /* Structures that describe the input files.    */
  121.  
  122.     /* Data on one line of text.    */
  123.  
  124.     struct line_def {
  125.         char                 *text;
  126.         int                     length;
  127.         unsigned            hash;
  128.         /*    The MPW 3.2 C compiler has a bug indexing arrays longer than 32K that have an element size of 12    */
  129.         #ifdef DF_COMPILER_MPW
  130.             int                    unused;
  131.         #endif
  132.     };
  133.  
  134.     /* Data on one input file being compared.  */
  135.  
  136.     struct file_data {
  137.         char                         *buffer;                         /* Buffer in which text of file is read.    */
  138.         unsigned int             buffered_chars;         /* Number of valid characters now in the buffer. */
  139.         unsigned int             buffered_lines;         /* Number of elements of linbuf containing valid data. */
  140.         unsigned int             bufsize;                        /* Allocated size of buffer.    */
  141.         char                         *changed_flag;             /* Vector, indexed by real origin-0 line number, containing 1 for
  142.                                                                                      * a line that is an insertion or a deletion.  The results of
  143.                                                                                      * comparison are stored here.    */
  144.         FILE                         *desc;                             /* File descriptor    */
  145.         int                             dir_p;                            /* 1 if file is a directory  */
  146.         int                             equiv_max;                    /* 1 more than the maximum equivalence value used for this or its
  147.                                                                                      * sibling file. */
  148.         int                          *equivs;                            /* free when done Vector, indexed by line number, containing an
  149.                                                                                      * equivalence code for each line.    It is this vector that is actually
  150.                                                                                      * compared with that of another file to generate differences. */
  151.         struct change      *highLimitPtr;             /* a temporary variable used by Merge */
  152.         struct line_def     *linbuf;                         /* Array of data on analyzed lines of this chunk of this file.    */
  153.         unsigned int             linbufsize;                 /* Allocated size of linbuf array (# of elements).    */
  154.         struct change      *lowLimitPtr;                /* a temporary variable used by Merge */
  155.         int                             missing_newline;        /* 1 if file ends in a line with no final newline. */
  156.         const char             *namePtr;                        /* File name    */
  157.         struct file_data *nextFilePtr;                /* Pointer to next file in a list of files */
  158.         int                             nondiscarded_lines;    /* Total number of nondiscarded lines. */
  159.         char                         *prefix_end;                 /* Pointer to end of prefix of this file to ignore when hashing. */
  160.         unsigned int             prefix_lines;             /* Count of lines in the prefix. */
  161.         int                          *realindexes;                /* Vector mapping virtual line numbers (not counting discarded lines)
  162.                                                                                      * to real ones (counting those lines).  Both are origin-0.  */
  163.         struct change      *scriptPtr;                    /* a pointer to a list of differences between this file and another */
  164.         char                         *suffix_begin;             /* Pointer to start of suffix of this file to ignore when hashing. */
  165.         int                             suffix_lines;             /* Count of lines in the suffix. */
  166.         int                          *undiscarded;                /* Vector, like the previous one except that the elements for
  167.                                                                                      * discarded lines have been squeezed out. */
  168.         int                                version;                        /* version indicated order of file in Merge command string */
  169.     };
  170.  
  171.     /*
  172.      * fileNameListType is a variable length structure with numberOfItems in the names
  173.      * array.  Each item in the array consists of 0 or more characters followed by a null
  174.      * character (i.e. a sequence of null terminated strings stored back to back).  The
  175.      * list is terminated with a extra null (i.e. a null string).  Unfortunately ANSI C
  176.      * requires a single element in this array making the syntax of variable length types
  177.      * extremely awkward.
  178.      */
  179.  
  180.     typedef struct fileNameListType {
  181.         unsigned int                numberOfItems;
  182.         char                                names[1];
  183.     } fileNameListType,     *fileNameListPType;
  184.  
  185.     /* Declare globals */
  186.  
  187.     extern const char          *ECMessagessArray [MAX_ERROR_KIND + 1];
  188.  
  189.     /* Declare functions.  */
  190.     extern void                                AppendCharToPathName (char *destinationCharPtr, const char theChar);
  191.     extern void                             AppendStringToPathName (char *destinationCharPtr, const char *suffixCharPtr);
  192.     extern void                             diff_2_files (register struct file_data *file0Ptr,
  193.                                                                                     register struct file_data *file1Ptr);
  194.     extern void                                CopyFileAttributes (const char *sourceNamePtr,
  195.                                                                                                 const char *destNamePtr,
  196.                                                                                                 const int attributes);
  197.     extern FILE                             *CreateTypedFile (const char *pathCharPtr, int binary);
  198.     extern void                             Error (int errorKind);
  199.     extern void                             ErrorWithStringArgument (int errorKind, const char *argumentStringPtr);
  200.     extern int                                FileType (const char *pathCharPtr);
  201.     extern void                             freeFile (register struct file_data *filePtr);
  202.     extern int                                IgnoreFile (const char *nameSuffixPtr);
  203.     extern int                                line_cmp (struct line_def *s1, struct line_def *s2);
  204.     extern int                                MakeDirectory (const char *pathCharPtr);
  205.     extern void                             print_rcs_script (struct file_data *file0Ptr, struct file_data *file1Ptr);
  206.     extern fileNameListPType    ReadDirectory (const char *pathCharPtr);
  207.     extern void                             read_files (register struct file_data *file0Ptr, register struct file_data *file1Ptr);
  208.     extern void                             slurp (struct file_data *filePtr);
  209.     extern void                          *xmalloc (size_t size);
  210.     extern void                          *xrealloc (void *old, size_t size);
  211.     extern void                             RemoveNameSuffix (char *namePtr);
  212.  
  213. #endif
  214.