home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 317a.lha / RCS / diff / diff.h < prev    next >
C/C++ Source or Header  |  1989-12-05  |  10KB  |  343 lines

  1. /* Shared definitions for GNU DIFF
  2.    Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU DIFF.
  5.  
  6. GNU DIFF is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GNU DIFF is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU DIFF; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. #include <ctype.h>
  22. #include <stdio.h>
  23. #ifndef AMIGA
  24. #include <sys/types.h>
  25. #include <sys/stat.h>
  26.  
  27. #ifdef USG
  28. #include <time.h>
  29. #ifdef hp9000s800
  30. #include <ndir.h>
  31. #else
  32. #include <dirent.h>
  33. #endif
  34. #include <fcntl.h>
  35. #define direct dirent
  36. #else
  37. #include <sys/time.h>
  38. #include <sys/dir.h>
  39. #include <sys/file.h>
  40. #endif USG
  41. #else
  42. #include "stat.h"
  43. #include "dir.h"
  44. #ifndef RE_NREGS
  45. #include "regex.h"
  46. #endif
  47. #endif AMIGA
  48.  
  49. #ifdef AMIGA
  50. #define bcmp(a,b,l) memcmp((a),(b),(l))
  51. #define bcopy(f,t,l) movmem((f),(t),(l))
  52. #define bzero(a,l) memset((a),0,(l))
  53. #define index    strchr
  54. #define rindex    strrchr
  55. #endif
  56.  
  57. #ifdef USG
  58. /* Define needed BSD functions in terms of sysV library.  */
  59.  
  60. #define bcopy(s,d,n)    memcpy((d),(s),(n))
  61. #define bcmp(s1,s2,n)    memcmp((s1),(s2),(n))
  62. #define bzero(s,n)    memset((s),0,(n))
  63.  
  64. #define dup2(f,t)    (close(t),fcntl((f),F_DUPFD,(t)))
  65.  
  66. #define vfork    fork
  67. #define index    strchr
  68. #define rindex    strrchr
  69. #endif
  70.  
  71. #include <errno.h>
  72. extern int      errno;
  73. extern int      sys_nerr;
  74. extern char    *sys_errlist[];
  75.  
  76. #define    EOS        (0)
  77. #ifdef AMIGA
  78. #undef FALSE
  79. #endif
  80. #define    FALSE        (0)
  81. #define TRUE        1
  82.  
  83. #ifndef AMIGA
  84. #define min(a,b) ((a) <= (b) ? (a) : (b))
  85. #define max(a,b) ((a) >= (b) ? (a) : (b))
  86. #endif
  87.  
  88. #ifndef PR_FILE_NAME
  89. #define PR_FILE_NAME "/bin/pr"
  90. #endif
  91.  
  92. /* Support old-fashioned C compilers.  */
  93. #if defined (__STDC__) || defined (__GNUC__)
  94. #include "limits.h"
  95. #else
  96. #define INT_MAX 2147483647
  97. #define CHAR_BIT 8
  98. #endif
  99.  
  100. /* Support old-fashioned C compilers.  */
  101. #if !defined (__STDC__) && !defined (__GNUC__)
  102. #define const
  103. #endif
  104.  
  105. /* Variables for command line options */
  106.  
  107. #ifndef GDIFF_MAIN
  108. #define EXTERN extern
  109. #else
  110. #define EXTERN
  111. #endif
  112.  
  113. enum output_style {
  114.   /* Default output style.  */
  115.   OUTPUT_NORMAL,
  116.   /* Output the differences with lines of context before and after (-c).  */
  117.   OUTPUT_CONTEXT,
  118.   /* Output the differences as commands suitable for `ed' (-e).  */
  119.   OUTPUT_ED,
  120.   /* Output the diff as a forward ed script (-f).  */
  121.   OUTPUT_FORWARD_ED,
  122.   /* Like -f, but output a count of changed lines in each "command" (-n). */
  123.   OUTPUT_RCS };
  124.  
  125. EXTERN enum output_style output_style;
  126.  
  127. /* Number of lines of context to show in each set of diffs.
  128.    This is zero when context is not to be shown.  */
  129. EXTERN int      context;
  130.  
  131. /* Consider all files as text files (-a).
  132.    Don't interpret codes over 0177 as implying a "binary file".  */
  133. EXTERN int    always_text_flag;
  134.  
  135. /* Ignore changes in horizontal whitespace (-b).  */
  136. EXTERN int      ignore_space_change_flag;
  137.  
  138. /* Ignore all horizontal whitespace (-w).  */
  139. EXTERN int      ignore_all_space_flag;
  140.  
  141. /* Ignore changes that affect only blank lines (-B).  */
  142. EXTERN int      ignore_blank_lines_flag;
  143.  
  144. /* Ignore changes that affect only lines matching this regexp (-I).  */
  145. EXTERN char    *ignore_regexp;
  146.  
  147. /* Result of regex-compilation of `ignore_regexp'.  */
  148. EXTERN struct re_pattern_buffer ignore_regexp_compiled;
  149.  
  150. /* 1 if lines may match even if their lengths are different.
  151.    This depends on various options.  */
  152. EXTERN int      length_varies;
  153.  
  154. /* Ignore differences in case of letters (-i).  */
  155. EXTERN int      ignore_case_flag;
  156.  
  157. /* Regexp to identify function-header lines (-F).  */
  158. EXTERN char    *function_regexp;
  159.  
  160. /* Result of regex-compilation of `function_regexp'.  */
  161. EXTERN struct re_pattern_buffer function_regexp_compiled;
  162.  
  163. /* Report files compared that match (-s).
  164.    Normally nothing is output when that happens.  */
  165. EXTERN int      print_file_same_flag;
  166.  
  167. /* character that ends a line.  Currently this is always `\n'.  */
  168. EXTERN char     line_end_char;
  169.  
  170. /* Output the differences with exactly 8 columns added to each line
  171.    so that any tabs in the text line up properly (-T).  */
  172. EXTERN int    tab_align_flag;
  173.  
  174. /* Expand tabs in the output so the text lines up properly
  175.    despite the characters added to the front of each line (-t).  */
  176. EXTERN int    tab_expand_flag;
  177.  
  178. /* In directory comparison, specify file to start with (-S).
  179.    All file names less than this name are ignored.  */
  180. EXTERN char    *dir_start_file;
  181.  
  182. /* If a file is new (appears in only one dir)
  183.    include its entire contents (-N).
  184.    Then `patch' would create the file with appropriate contents.  */
  185. EXTERN int    entire_new_file_flag;
  186.  
  187. /* Pipe each file's output through pr (-l).  */
  188. EXTERN int    paginate_flag;
  189.  
  190. /* String containing all the command options diff received,
  191.    with spaces between and at the beginning but none at the end.
  192.    If there were no options given, this string is empty.  */
  193. EXTERN char *    switch_string;
  194.  
  195. /* Nonzero means use heuristics for better speed.  */
  196. EXTERN int    heuristic;
  197.  
  198. /* Name of program the user invoked (for error messages).  */
  199. EXTERN char *    program;
  200.  
  201. /* The result of comparison is an "edit script": a chain of `struct change'.
  202.    Each `struct change' represents one place where some lines are deleted
  203.    and some are inserted.
  204.    
  205.    LINE0 and LINE1 are the first affected lines in the two files (origin 0).
  206.    DELETED is the number of lines deleted here from file 0.
  207.    INSERTED is the number of lines inserted here in file 1.
  208.  
  209.    If DELETED is 0 then LINE0 is the number of the line before
  210.    which the insertion was done; vice versa for INSERTED and LINE1.  */
  211.  
  212. struct change
  213. {
  214.   struct change *link;        /* Previous or next edit command  */
  215.   int inserted;            /* # lines of file 1 changed here.  */
  216.   int deleted;            /* # lines of file 0 changed here.  */
  217.   int line0;            /* Line number of 1st deleted line.  */
  218.   int line1;            /* Line number of 1st inserted line.  */
  219.   char ignore;            /* Flag used in context.c */
  220. };
  221.  
  222. /* Structures that describe the input files.  */
  223.  
  224. /* Data on one line of text.  */
  225.  
  226. struct line_def {
  227.     char        *text;
  228.     int         length;
  229.     unsigned    hash;
  230. };
  231.  
  232. /* Data on one input file being compared.  */
  233.  
  234. struct file_data {
  235.     int             desc;    /* File descriptor  */
  236.     char           *name;    /* File name  */
  237.     struct stat     stat;    /* File status from fstat()  */
  238.     int             dir_p;    /* 1 if file is a directory  */
  239.  
  240.     /* Buffer in which text of file is read.  */
  241.     char *        buffer;
  242.     /* Allocated size of buffer.  */
  243.     int            bufsize;
  244.     /* Number of valid characters now in the buffer. */
  245.     int            buffered_chars;
  246.  
  247.     /* Array of data on analyzed lines of this chunk of this file.  */
  248.     struct line_def *linbuf;
  249.  
  250.     /* Allocated size of linbuf array (# of elements).  */
  251.     int            linbufsize;
  252.  
  253.     /* Number of elements of linbuf containing valid data. */
  254.     int            buffered_lines;
  255.  
  256.     /* Pointer to end of prefix of this file to ignore when hashing. */
  257.     char *prefix_end;
  258.  
  259.     /* Count of lines in the prefix. */
  260.     int prefix_lines;
  261.  
  262.     /* Pointer to start of suffix of this file to ignore when hashing. */
  263.     char *suffix_begin;
  264.  
  265.     /* Count of lines in the suffix. */
  266.     int suffix_lines;
  267.  
  268.     /* Vector, indexed by line number, containing an equivalence code for
  269.        each line.  It is this vector that is actually compared with that
  270.        of another file to generate differences. */
  271.     int           *equivs;
  272.  
  273.     /* Vector, like the previous one except that
  274.        the elements for discarded lines have been squeezed out.  */
  275.     int           *undiscarded;
  276.  
  277.     /* Vector mapping virtual line numbers (not counting discarded lines)
  278.        to real ones (counting those lines).  Both are origin-0.  */
  279.     int           *realindexes;
  280.  
  281.     /* Total number of nondiscarded lines. */
  282.     int            nondiscarded_lines;
  283.  
  284.     /* Vector, indexed by real origin-0 line number,
  285.        containing 1 for a line that is an insertion or a deletion.
  286.        The results of comparison are stored here.  */
  287.     char       *changed_flag;
  288.  
  289.     /* 1 if file ends in a line with no final newline. */
  290.     int            missing_newline;
  291.  
  292.     /* 1 more than the maximum equivalence value used for this or its
  293.        sibling file. */
  294.     int equiv_max;
  295.  
  296.     /* Table translating diff's internal line numbers 
  297.        to actual line numbers in the file.
  298.        This is needed only when some lines have been discarded.
  299.        The allocated size is always linbufsize
  300.        and the number of valid elements is buffered_lines.  */
  301.     int           *ltran;
  302. };
  303.  
  304. /* Describe the two files currently being compared.  */
  305.  
  306. EXTERN struct file_data files[2];
  307.  
  308. /* Queue up one-line messages to be printed at the end,
  309.    when -l is specified.  Each message is recorded with a `struct msg'.  */
  310.  
  311. struct msg
  312. {
  313.   struct msg *next;
  314.   char *format;
  315.   char *arg1;
  316.   char *arg2;
  317. };
  318.  
  319. /* Head of the chain of queues messages.  */
  320.  
  321. EXTERN struct msg *msg_chain;
  322.  
  323. /* Tail of the chain of queues messages.  */
  324.  
  325. EXTERN struct msg *msg_chain_end;
  326.  
  327. /* Stdio stream to output diffs to.  */
  328.  
  329. EXTERN FILE *outfile;
  330.  
  331. /* Declare various functions.  */
  332.  
  333. void *xmalloc ();
  334. void *xrealloc ();
  335. void *xcalloc();
  336. char *concat ();
  337. void free ();
  338. char *rindex ();
  339. char *index ();
  340.  
  341. void message ();
  342. void print_message_queue ();
  343.