home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / utils / hwgrcs / hwgdiff / rcs.rcsfiles / diff.h,v < prev    next >
Encoding:
Text File  |  1993-02-20  |  12.4 KB  |  536 lines

  1. head    1.2;
  2. access;
  3. symbols
  4.     HWGDIFF_Fish:1.2
  5.     HWGDIFF:1.2;
  6. locks; strict;
  7. comment    @ * @;
  8.  
  9.  
  10. 1.2
  11. date    93.01.19.14.32.45;    author heinz;    state Exp;
  12. branches;
  13. next    1.1;
  14.  
  15. 1.1
  16. date    93.01.19.14.04.33;    author heinz;    state Exp;
  17. branches;
  18. next    ;
  19.  
  20.  
  21. desc
  22. @RCS for the first time ...
  23. @
  24.  
  25.  
  26. 1.2
  27. log
  28. @Amiga port
  29. @
  30. text
  31. @/* Shared definitions for GNU DIFF
  32.    Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  33.  
  34. This file is part of GNU DIFF.
  35.  
  36. GNU DIFF is free software; you can redistribute it and/or modify
  37. it under the terms of the GNU General Public License as published by
  38. the Free Software Foundation; either version 1, or (at your option)
  39. any later version.
  40.  
  41. GNU DIFF is distributed in the hope that it will be useful,
  42. but WITHOUT ANY WARRANTY; without even the implied warranty of
  43. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  44. GNU General Public License for more details.
  45.  
  46. You should have received a copy of the GNU General Public License
  47. along with GNU DIFF; see the file COPYING.  If not, write to
  48. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  49.  
  50.  
  51. #include <ctype.h>
  52. #include <stdio.h>
  53. #include <sys/types.h>
  54. #include <sys/stat.h>
  55.  
  56. #ifdef USG
  57. #include <time.h>
  58. #ifdef HAVE_NDIR
  59. #ifdef NDIR_IN_SYS
  60. #include <sys/ndir.h>
  61. #else
  62. #include <ndir.h>
  63. #endif /* not NDIR_IN_SYS */
  64. #else
  65. #include <dirent.h>
  66. #endif /* not HAVE_NDIR */
  67. #include <fcntl.h>
  68. #ifndef HAVE_DIRECT
  69. #define direct dirent
  70. #endif
  71. #else /* not USG */
  72. #ifdef AMIGA
  73. #include <stdlib.h>
  74. #include <string.h>
  75. #include <sys/types.h>
  76. #include <sys/stat.h>
  77. #include <sys/dir.h>
  78. #include <fcntl.h>
  79.  
  80. #undef rindex
  81. #undef index
  82. #define index strchr
  83. #define rindex strrchr
  84.  
  85. #define direct dirent
  86.  
  87. #undef FALSE
  88. #undef min
  89. #undef max
  90.  
  91. /* Just being tricky ... */
  92. #define PR_FILE_NAME     "LP OUTPUT=\"\" HEADERNAME"
  93.  
  94. #else
  95. #include <sys/time.h>
  96. #include <sys/dir.h>
  97. #include <sys/file.h>
  98. #endif
  99. #endif
  100.  
  101. #ifdef USG
  102. /* Define needed BSD functions in terms of sysV library.  */
  103.  
  104. #define bcopy(s,d,n)    memcpy((d),(s),(n))
  105. #define bcmp(s1,s2,n)   memcmp((s1),(s2),(n))
  106. #define bzero(s,n)      memset((s),0,(n))
  107.  
  108. #ifndef XENIX
  109. #define dup2(f,t)       (close(t),fcntl((f),F_DUPFD,(t)))
  110. #endif
  111.  
  112. #define vfork    fork
  113. #define index    strchr
  114. #define rindex    strrchr
  115. #endif
  116.  
  117. #ifdef sparc
  118. /* vfork clobbers registers on the Sparc, so don't use it.  */
  119. #define vfork fork
  120. #endif
  121.  
  122. #include <errno.h>
  123. extern int    errno;
  124. extern int    sys_nerr;
  125. extern char    *sys_errlist[];
  126.  
  127. #define EOS        (0)
  128. #define FALSE        (0)
  129. #define TRUE        1
  130.  
  131. #define min(a,b) ((a) <= (b) ? (a) : (b))
  132. #define max(a,b) ((a) >= (b) ? (a) : (b))
  133.  
  134. #ifndef PR_FILE_NAME
  135. #define PR_FILE_NAME "/bin/pr"
  136. #endif
  137.  
  138. /* Support old-fashioned C compilers.  */
  139. #if defined (__STDC__) || defined (__GNUC__)
  140. #include "limits.h"
  141. #else
  142. #define INT_MAX 2147483647
  143. #define CHAR_BIT 8
  144. #endif
  145.  
  146. /* Support old-fashioned C compilers.  */
  147. #if !defined (__STDC__) && !defined (__GNUC__)
  148. #define const
  149. #endif
  150.  
  151. #ifndef O_RDONLY
  152. #define O_RDONLY 0
  153. #endif
  154.  
  155. /* Variables for command line options */
  156.  
  157. #ifndef GDIFF_MAIN
  158. #define EXTERN extern
  159. #else
  160. #define EXTERN
  161. #endif
  162.  
  163. enum output_style {
  164.   /* Default output style.  */
  165.   OUTPUT_NORMAL,
  166.   /* Output the differences with lines of context before and after (-c).  */
  167.   OUTPUT_CONTEXT,
  168.   /* Output the differences in a unified context diff format (-u). */
  169.   OUTPUT_UNIFIED,
  170.   /* Output the differences as commands suitable for `ed' (-e).  */
  171.   OUTPUT_ED,
  172.   /* Output the diff as a forward ed script (-f).  */
  173.   OUTPUT_FORWARD_ED,
  174.   /* Like -f, but output a count of changed lines in each "command" (-n). */
  175.   OUTPUT_RCS,
  176.   /* Output merged #ifdef'd file (-D).  */
  177.   OUTPUT_IFDEF };
  178.  
  179. /* True for output styles that are robust,
  180.    i.e. can handle a file that ends in a non-newline.  */
  181. #define ROBUST_OUTPUT_STYLE(S) \
  182.  ((S) == OUTPUT_CONTEXT || (S) == OUTPUT_UNIFIED || (S) == OUTPUT_RCS \
  183.   || (S) == OUTPUT_NORMAL)
  184.  
  185. EXTERN enum output_style output_style;
  186.  
  187. /* Number of lines of context to show in each set of diffs.
  188.    This is zero when context is not to be shown.  */
  189. EXTERN int    context;
  190.  
  191. /* Consider all files as text files (-a).
  192.    Don't interpret codes over 0177 as implying a "binary file".  */
  193. EXTERN int    always_text_flag;
  194.  
  195. /* Ignore changes in horizontal whitespace (-b).  */
  196. EXTERN int    ignore_space_change_flag;
  197.  
  198. /* Ignore all horizontal whitespace (-w).  */
  199. EXTERN int    ignore_all_space_flag;
  200.  
  201. /* Ignore changes that affect only blank lines (-B).  */
  202. EXTERN int    ignore_blank_lines_flag;
  203.  
  204. /* Ignore changes that affect only lines matching this regexp (-I).  */
  205. EXTERN char    *ignore_regexp;
  206.  
  207. /* Result of regex-compilation of `ignore_regexp'.  */
  208. EXTERN struct re_pattern_buffer ignore_regexp_compiled;
  209.  
  210. /* 1 if lines may match even if their lengths are different.
  211.    This depends on various options.  */
  212. EXTERN int    length_varies;
  213.  
  214. /* Ignore differences in case of letters (-i).  */
  215. EXTERN int    ignore_case_flag;
  216.  
  217. /* File labels for `-c' output headers (-L).  */
  218. EXTERN char *file_label[2];
  219.  
  220. /* Regexp to identify function-header lines (-F).  */
  221. EXTERN char    *function_regexp;
  222.  
  223. /* Result of regex-compilation of `function_regexp'.  */
  224. EXTERN struct re_pattern_buffer function_regexp_compiled;
  225.  
  226. /* Say only whether files differ, not how (-q).  */
  227. EXTERN int    no_details_flag;
  228.  
  229. /* Report files compared that match (-s).
  230.    Normally nothing is output when that happens.  */
  231. EXTERN int    print_file_same_flag;
  232.  
  233. /* character that ends a line.    Currently this is always `\n'.  */
  234. EXTERN char    line_end_char;
  235.  
  236. /* Output the differences with exactly 8 columns added to each line
  237.    so that any tabs in the text line up properly (-T).  */
  238. EXTERN int    tab_align_flag;
  239.  
  240. /* Expand tabs in the output so the text lines up properly
  241.    despite the characters added to the front of each line (-t).  */
  242. EXTERN int    tab_expand_flag;
  243.  
  244. /* In directory comparison, specify file to start with (-S).
  245.    All file names less than this name are ignored.  */
  246. EXTERN char    *dir_start_file;
  247.  
  248. /* If a file is new (appears in only one dir)
  249.    include its entire contents (-N).
  250.    Then `patch' would create the file with appropriate contents.  */
  251. EXTERN int    entire_new_file_flag;
  252.  
  253. /* Pipe each file's output through pr (-l).  */
  254. EXTERN int    paginate_flag;
  255.  
  256. /* String to use for #ifdef (-D).  */
  257. EXTERN char *    ifdef_string;
  258.  
  259. /* String containing all the command options diff received,
  260.    with spaces between and at the beginning but none at the end.
  261.    If there were no options given, this string is empty.  */
  262. EXTERN char *    switch_string;
  263.  
  264. /* Nonzero means use heuristics for better speed.  */
  265. EXTERN int    heuristic;
  266.  
  267. /* Name of program the user invoked (for error messages).  */
  268. EXTERN char *    program;
  269.  
  270. /* The result of comparison is an "edit script": a chain of `struct change'.
  271.    Each `struct change' represents one place where some lines are deleted
  272.    and some are inserted.
  273.  
  274.    LINE0 and LINE1 are the first affected lines in the two files (origin 0).
  275.    DELETED is the number of lines deleted here from file 0.
  276.    INSERTED is the number of lines inserted here in file 1.
  277.  
  278.    If DELETED is 0 then LINE0 is the number of the line before
  279.    which the insertion was done; vice versa for INSERTED and LINE1.  */
  280.  
  281. struct change
  282. {
  283.   struct change *link;        /* Previous or next edit command  */
  284.   int inserted;         /* # lines of file 1 changed here.  */
  285.   int deleted;            /* # lines of file 0 changed here.  */
  286.   int line0;            /* Line number of 1st deleted line.  */
  287.   int line1;            /* Line number of 1st inserted line.  */
  288.   char ignore;            /* Flag used in context.c */
  289. };
  290.  
  291. /* Structures that describe the input files.  */
  292.  
  293. /* Data on one line of text.  */
  294.  
  295. struct line_def {
  296.     char    *text;
  297.     int     length;
  298.     unsigned    hash;
  299. };
  300.  
  301. /* Data on one input file being compared.  */
  302.  
  303. struct file_data {
  304.     int         desc;    /* File descriptor  */
  305.     char       *name;    /* File name  */
  306.     struct stat     stat;    /* File status from fstat()  */
  307.     int         dir_p;    /* 1 if file is a directory  */
  308.  
  309.     /* Buffer in which text of file is read.  */
  310.     char *        buffer;
  311.     /* Allocated size of buffer.  */
  312.     int         bufsize;
  313.     /* Number of valid characters now in the buffer. */
  314.     int         buffered_chars;
  315.  
  316.     /* Array of data on analyzed lines of this chunk of this file.  */
  317.     struct line_def *linbuf;
  318.  
  319.     /* Allocated size of linbuf array (# of elements).  */
  320.     int         linbufsize;
  321.  
  322.     /* Number of elements of linbuf containing valid data. */
  323.     int         buffered_lines;
  324.  
  325.     /* Pointer to end of prefix of this file to ignore when hashing. */
  326.     char *prefix_end;
  327.  
  328.     /* Count of lines in the prefix. */
  329.     int prefix_lines;
  330.  
  331.     /* Pointer to start of suffix of this file to ignore when hashing. */
  332.     char *suffix_begin;
  333.  
  334.     /* Count of lines in the suffix. */
  335.     int suffix_lines;
  336.  
  337.     /* Vector, indexed by line number, containing an equivalence code for
  338.        each line.  It is this vector that is actually compared with that
  339.        of another file to generate differences. */
  340.     int        *equivs;
  341.  
  342.     /* Vector, like the previous one except that
  343.        the elements for discarded lines have been squeezed out.  */
  344.     int        *undiscarded;
  345.  
  346.     /* Vector mapping virtual line numbers (not counting discarded lines)
  347.        to real ones (counting those lines).  Both are origin-0.  */
  348.     int        *realindexes;
  349.  
  350.     /* Total number of nondiscarded lines. */
  351.     int         nondiscarded_lines;
  352.  
  353.     /* Vector, indexed by real origin-0 line number,
  354.        containing 1 for a line that is an insertion or a deletion.
  355.        The results of comparison are stored here.  */
  356.     char       *changed_flag;
  357.  
  358.     /* 1 if file ends in a line with no final newline. */
  359.     int         missing_newline;
  360.  
  361.     /* 1 more than the maximum equivalence value used for this or its
  362.        sibling file. */
  363.     int equiv_max;
  364.  
  365.     /* Table translating diff's internal line numbers
  366.        to actual line numbers in the file.
  367.        This is needed only when some lines have been discarded.
  368.        The allocated size is always linbufsize
  369.        and the number of valid elements is buffered_lines.  */
  370.     int        *ltran;
  371. };
  372.  
  373. /* Describe the two files currently being compared.  */
  374.  
  375. #ifdef AMIGA
  376. EXTERN struct file_data files[2];
  377. #else
  378. struct file_data files[2];
  379. #endif
  380.  
  381. /* Queue up one-line messages to be printed at the end,
  382.    when -l is specified.  Each message is recorded with a `struct msg'.  */
  383.  
  384. struct msg
  385. {
  386.   struct msg *next;
  387.   char *format;
  388.   char *arg1;
  389.   char *arg2;
  390. };
  391.  
  392. /* Head of the chain of queues messages.  */
  393.  
  394. EXTERN struct msg *msg_chain;
  395.  
  396. /* Tail of the chain of queues messages.  */
  397.  
  398. EXTERN struct msg *msg_chain_end;
  399.  
  400. /* Stdio stream to output diffs to.  */
  401.  
  402. EXTERN FILE *outfile;
  403.  
  404. /* Declare various functions.  */
  405.  
  406. #ifdef __STDC__
  407. #define VOID void
  408. #else
  409. #define VOID char
  410. #endif
  411. VOID *xmalloc ();
  412. VOID *xrealloc ();
  413. char *concat ();
  414. void free ();
  415. char *rindex ();
  416. char *index ();
  417.  
  418. void analyze_hunk ();
  419. void error ();
  420. void fatal ();
  421. void message ();
  422. void perror_with_name ();
  423. void pfatal_with_name ();
  424. void print_1_line ();
  425. void print_message_queue ();
  426. void print_number_range ();
  427. void print_script ();
  428. void translate_range ();
  429. @
  430.  
  431.  
  432. 1.1
  433. log
  434. @Initial revision
  435. @
  436. text
  437. @d42 23
  438. d69 1
  439. d74 3
  440. a76 3
  441. #define bcopy(s,d,n)    memcpy((d),(s),(n))
  442. #define bcmp(s1,s2,n)    memcmp((s1),(s2),(n))
  443. #define bzero(s,n)    memset((s),0,(n))
  444. d79 1
  445. a79 1
  446. #define dup2(f,t)    (close(t),fcntl((f),F_DUPFD,(t)))
  447. d93 2
  448. a94 2
  449. extern int      errno;
  450. extern int      sys_nerr;
  451. d97 2
  452. a98 2
  453. #define    EOS        (0)
  454. #define    FALSE        (0)
  455. d159 1
  456. a159 1
  457. EXTERN int      context;
  458. d166 1
  459. a166 1
  460. EXTERN int      ignore_space_change_flag;
  461. d169 1
  462. a169 1
  463. EXTERN int      ignore_all_space_flag;
  464. d172 1
  465. a172 1
  466. EXTERN int      ignore_blank_lines_flag;
  467. d182 1
  468. a182 1
  469. EXTERN int      length_varies;
  470. d185 1
  471. a185 1
  472. EXTERN int      ignore_case_flag;
  473. d197 1
  474. a197 1
  475. EXTERN int     no_details_flag;
  476. d201 1
  477. a201 1
  478. EXTERN int      print_file_same_flag;
  479. d203 2
  480. a204 2
  481. /* character that ends a line.  Currently this is always `\n'.  */
  482. EXTERN char     line_end_char;
  483. d243 1
  484. a243 1
  485.    
  486. d254 1
  487. a254 1
  488.   int inserted;            /* # lines of file 1 changed here.  */
  489. d266 2
  490. a267 2
  491.     char        *text;
  492.     int         length;
  493. d274 2
  494. a275 2
  495.     int             desc;    /* File descriptor  */
  496.     char           *name;    /* File name  */
  497. d277 1
  498. a277 1
  499.     int             dir_p;    /* 1 if file is a directory  */
  500. d282 1
  501. a282 1
  502.     int            bufsize;
  503. d284 1
  504. a284 1
  505.     int            buffered_chars;
  506. d290 1
  507. a290 1
  508.     int            linbufsize;
  509. d293 1
  510. a293 1
  511.     int            buffered_lines;
  512. d310 1
  513. a310 1
  514.     int           *equivs;
  515. d314 1
  516. a314 1
  517.     int           *undiscarded;
  518. d318 1
  519. a318 1
  520.     int           *realindexes;
  521. d321 1
  522. a321 1
  523.     int            nondiscarded_lines;
  524. d329 1
  525. a329 1
  526.     int            missing_newline;
  527. d335 1
  528. a335 1
  529.     /* Table translating diff's internal line numbers 
  530. d340 1
  531. a340 1
  532.     int           *ltran;
  533. d345 3
  534. d349 1
  535. @
  536.