home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 317a.lha / RCS / diff / diff.h.old < prev    next >
Text File  |  1989-12-05  |  9KB  |  317 lines

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