home *** CD-ROM | disk | FTP | other *** search
/ Mega CD-ROM 1 / megacd_rom_1.zip / megacd_rom_1 / GNUISH / DIFF115.ZIP / PATCHES < prev   
Text File  |  1991-03-16  |  56KB  |  1,911 lines

  1. *** e:\tmp/RCSt1005321    Tue Mar 12 17:19:54 1991
  2. --- analyze.c    Tue Mar 12 17:18:32 1991
  3. ***************
  4. *** 17,22 ****
  5. --- 17,31 ----
  6.   along with GNU DIFF; see the file COPYING.  If not, write to
  7.   the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  8.   
  9. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  10. + This port is also distributed under the terms of the GNU General
  11. + Public License as published by the Free Software Foundation.
  12. + Please note that this file is not identical to the original GNU release,
  13. + you should have received this code as patch to the official release.
  14. + $Header: e:/gnu/diff/RCS/analyze.c 1.15.0.2 91/03/12 17:05:59 tho Exp $  */
  15.   /* The basic algorithm is described in: 
  16.      "An O(ND) Difference Algorithm and its Variations", Eugene Myers,
  17.      Algorithmica Vol. 1 No. 2, 1986, p 251.  */
  18. ***************
  19. *** 34,39 ****
  20. --- 43,58 ----
  21.   void pr_forward_ed_script ();
  22.   void setup_output ();
  23.   
  24. + #ifdef __STDC__
  25. + static  int diag(int, int, int, int, int *);
  26. + static  void compareseq(int, int, int, int);
  27. + static  void shift_boundaries(struct file_data *);
  28. + static  void discard_confusing_lines(struct file_data *);
  29. + static  struct change *add_change(int, int, int, int, struct change *);
  30. + static  struct change *build_reverse_script(struct file_data *);
  31. + static  struct change *build_script(struct file_data *);
  32. + #endif /* __STDC__ */
  33.   extern int no_discards;
  34.   
  35.   static int *xvec, *yvec;    /* Vectors being compared. */
  36. ***************
  37. *** 729,738 ****
  38. --- 748,759 ----
  39.     /* See if the two named files are actually the same physical file.
  40.        If so, we know they are identical without actually reading them.  */
  41.   
  42. + #ifndef MSDOS
  43.     if (output_style != OUTPUT_IFDEF
  44.         && filevec[0].stat.st_ino == filevec[1].stat.st_ino
  45.         && filevec[0].stat.st_dev == filevec[1].stat.st_dev)
  46.       return 0;
  47. + #endif /* MSDOS */
  48.   
  49.     binary = read_files (filevec);
  50.   
  51. ***************
  52. *** 743,751 ****
  53. --- 764,781 ----
  54.   
  55.     if (binary || no_details_flag)
  56.       {
  57. + #ifdef MSDOS
  58. +       /***********************************************************/
  59. +       /* FIXME: this looses when FILEVEC[1].BUFFERED_CHARS > 64k */
  60. +       /***********************************************************/
  61.         int differs = (filevec[0].buffered_chars != filevec[1].buffered_chars
  62.                || bcmp (filevec[0].buffer, filevec[1].buffer,
  63. +                   (size_t) filevec[1].buffered_chars));
  64. + #else /* not MSDOS */
  65. +       int differs = (filevec[0].buffered_chars != filevec[1].buffered_chars
  66. +              || bcmp (filevec[0].buffer, filevec[1].buffer,
  67.                     filevec[1].buffered_chars));
  68. + #endif /* not MSDOS */
  69.         if (differs) 
  70.       message (binary ? "Binary files %s and %s differ\n"
  71.            : "Files %s and %s differ\n",
  72. ***************
  73. *** 753,759 ****
  74. --- 783,794 ----
  75.   
  76.         for (i = 0; i < 2; ++i)
  77.       if (filevec[i].buffer)
  78. + #ifdef MSDOS
  79. +       hfree (filevec[i].buffer);
  80. + #else /* not MSDOS */
  81.         free (filevec[i].buffer);
  82. + #endif /* not MSDOS */
  83.         return differs;
  84.       }
  85.   
  86. ***************
  87. *** 900,906 ****
  88. --- 935,945 ----
  89.     for (i = 0; i < 2; ++i)
  90.       {
  91.         if (filevec[i].buffer != 0)
  92. + #ifdef MSDOS
  93. +     hfree (filevec[i].buffer);
  94. + #else /* not MSDOS */
  95.       free (filevec[i].buffer);
  96. + #endif /* not MSDOS */
  97.         free (filevec[i].linbuf);
  98.       }
  99.   
  100. *** e:\tmp/RCSt1005321    Tue Mar 12 17:19:56 1991
  101. --- context.c    Tue Mar 12 17:18:34 1991
  102. ***************
  103. *** 17,30 ****
  104. --- 17,52 ----
  105.   along with GNU DIFF; see the file COPYING.  If not, write to
  106.   the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  107.   
  108. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  109. + This port is also distributed under the terms of the GNU General
  110. + Public License as published by the Free Software Foundation.
  111. + Please note that this file is not identical to the original GNU release,
  112. + you should have received this code as patch to the official release.
  113. + $Header: e:/gnu/diff/RCS/context.c 1.15.0.2 91/03/12 17:06:06 tho Exp $  */
  114.   #include "diff.h"
  115.   #include "regex.h"
  116.   
  117. + #ifdef __STDC__
  118. + static void print_context_number_range (struct file_data *file, int a, int b);
  119. + static void pr_context_hunk (struct change *hunk);
  120. + static void pr_unidiff_hunk (struct change *hunk);
  121. + static struct change *find_hunk (struct change *start);
  122. + static void mark_ignorable (struct change *script);
  123. + static void find_function (struct file_data *file, int linenum,
  124. +                char **linep, int *lenp);
  125. + static void print_context_label (const char *mark, struct file_data *inf,
  126. +                  const char *label);
  127. + static void print_unidiff_number_range (struct file_data *file, int a, int b);
  128. + #else /* not __STDC__ */
  129.   static void pr_context_hunk ();
  130.   static void pr_unidiff_hunk ();
  131.   static struct change *find_hunk ();
  132.   static void mark_ignorable ();
  133.   static void find_function ();
  134. + #endif /* not __STDC__ */
  135.   
  136.   /* Last place find_function started searching from.  */
  137.   static int find_function_last_search;
  138. ***************
  139. *** 56,61 ****
  140. --- 78,94 ----
  141.        struct file_data *inf;
  142.        int unidiff_flag;
  143.   {
  144. + #ifdef MSDOS
  145. +   /* If we're dealing with empty files or the standard input,
  146. +      the current time seems to be a reasonable approximation ....
  147. +      MSC's ctime() returns NULL for invalid times, this breaks
  148. +      the context diff format! */
  149. +   if (!inf[0].stat.st_mtime)
  150. +     time (&inf[0].stat.st_mtime);
  151. +   if (!inf[1].stat.st_mtime)
  152. +     time (&inf[1].stat.st_mtime);
  153. + #endif /* MSDOS */
  154.     if (unidiff_flag)
  155.       {
  156.         print_context_label ("---", &inf[0], file_label[0]);
  157. ***************
  158. *** 397,403 ****
  159. --- 430,440 ----
  160.         script->link = next;
  161.   
  162.         /* If the change is ignorable, mark it.  */
  163. + #ifdef MSDOS
  164. +       script->ignore = (char) (!deletes && !inserts);
  165. + #else /* not MSDOS */
  166.         script->ignore = (!deletes && !inserts);
  167. + #endif /* not MSDOS */
  168.   
  169.         /* Advance to the following change.  */
  170.         script = next;
  171. *** e:\tmp/RCSt1005321    Tue Mar 12 17:19:58 1991
  172. --- diff.c    Tue Mar 12 17:18:38 1991
  173. ***************
  174. *** 20,30 ****
  175. --- 20,53 ----
  176.   /* GNU DIFF was written by Mike Haertel, David Hayes,
  177.      Richard Stallman and Len Tower.  */
  178.   
  179. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  180. + This port is also distributed under the terms of the GNU General
  181. + Public License as published by the Free Software Foundation.
  182. + Please note that this file is not identical to the original GNU release,
  183. + you should have received this code as patch to the official release.
  184. + $Header: e:/gnu/diff/RCS/diff.c 1.15.0.2 91/03/12 17:06:09 tho Exp $  */
  185.   #define GDIFF_MAIN
  186.   #include "regex.h"
  187.   #include "diff.h"
  188.   #include "getopt.h"
  189.   
  190. + #ifdef __STDC__
  191. + extern  void main (int argc, char **argv);
  192. + static    void usage(void);
  193. + static    char *option_list(char * *, int);
  194. + static    void specify_style(enum output_style);
  195. + static  int compare_files(char *, char *, char *, char *, int);
  196. + extern  int getopt(int, char * *, char *);
  197. + #else
  198. + static    void usage();
  199. + static    char *option_list();
  200. + static    void specify_style();
  201. + static  int compare_files();
  202. + extern  int getopt();
  203. + #endif /* __STDC__ */
  204.   
  205.   /* Nonzero for -r: if comparing two directories,
  206.      compare their common subdirectories recursively.  */
  207. ***************
  208. *** 106,111 ****
  209. --- 129,137 ----
  210.     {0, 0, 0, 0}
  211.   };
  212.   
  213. + #ifdef __STDC__
  214. + void
  215. + #endif /* __STDC__ */
  216.   main (argc, argv)
  217.        int argc;
  218.        char *argv[];
  219. ***************
  220. *** 399,404 ****
  221. --- 425,431 ----
  222.     exit (val);
  223.   }
  224.   
  225. + void
  226.   usage ()
  227.   {
  228.     fprintf (stderr, "\
  229. ***************
  230. *** 417,422 ****
  231. --- 444,450 ----
  232.     exit (2);
  233.   } 
  234.   
  235. + void
  236.   specify_style (style)
  237.        enum output_style style;
  238.   {
  239. ***************
  240. *** 509,514 ****
  241. --- 537,543 ----
  242.     /* See if the two named files are actually the same physical file.
  243.        If so, we know they are identical without actually reading them.  */
  244.   
  245. + #ifndef MSDOS
  246.     if (output_style != OUTPUT_IFDEF
  247.         && inf[0].stat.st_ino == inf[1].stat.st_ino
  248.         && inf[0].stat.st_dev == inf[1].stat.st_dev
  249. ***************
  250. *** 518,523 ****
  251. --- 547,553 ----
  252.         val = 0;
  253.         goto done;
  254.       }
  255. + #endif /* MSDOS */
  256.   
  257.     if (name0 == 0)
  258.       inf[0].dir_p = inf[1].dir_p;
  259. *** e:\tmp/RCSt1005321    Tue Mar 12 17:20:00 1991
  260. --- diff.h    Tue Mar 12 17:19:06 1991
  261. ***************
  262. *** 17,23 ****
  263. --- 17,32 ----
  264.   along with GNU DIFF; see the file COPYING.  If not, write to
  265.   the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  266.   
  267. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  268. + This port is also distributed under the terms of the GNU General
  269. + Public License as published by the Free Software Foundation.
  270.   
  271. + Please note that this file is not identical to the original GNU release,
  272. + you should have received this code as patch to the official release.
  273. + $Header: e:/gnu/diff/RCS/diff.h 1.15.0.2 91/03/12 17:06:56 tho Exp $  */
  274.   #include <ctype.h>
  275.   #include <stdio.h>
  276.   #include <sys/types.h>
  277. ***************
  278. *** 25,30 ****
  279. --- 34,46 ----
  280.   
  281.   #ifdef USG
  282.   #include <time.h>
  283. + #ifdef MSDOS
  284. + #include <stdlib.h>
  285. + #include <malloc.h>
  286. + #include <string.h>
  287. + #include <process.h>
  288. + #include <io.h>
  289. + #endif /* MSDOS */
  290.   #ifdef HAVE_NDIR
  291.   #ifdef NDIR_IN_SYS
  292.   #include <sys/ndir.h>
  293. ***************
  294. *** 47,57 ****
  295.   #ifdef USG
  296.   /* Define needed BSD functions in terms of sysV library.  */
  297.   
  298.   #define bcopy(s,d,n)    memcpy((d),(s),(n))
  299.   #define bcmp(s1,s2,n)    memcmp((s1),(s2),(n))
  300.   #define bzero(s,n)    memset((s),0,(n))
  301.   
  302. ! #ifndef XENIX
  303.   #define dup2(f,t)    (close(t),fcntl((f),F_DUPFD,(t)))
  304.   #endif
  305.   
  306. --- 63,77 ----
  307.   #ifdef USG
  308.   /* Define needed BSD functions in terms of sysV library.  */
  309.   
  310. + #ifdef MSDOS
  311. + #define bcopy(s,d,n)    memmove((d),(s),(n))    /* more save! */
  312. + #else
  313.   #define bcopy(s,d,n)    memcpy((d),(s),(n))
  314. + #endif
  315.   #define bcmp(s1,s2,n)    memcmp((s1),(s2),(n))
  316.   #define bzero(s,n)    memset((s),0,(n))
  317.   
  318. ! #if !defined (XENIX) && !defined (MSDOS)
  319.   #define dup2(f,t)    (close(t),fcntl((f),F_DUPFD,(t)))
  320.   #endif
  321.   
  322. ***************
  323. *** 66,81 ****
  324. --- 86,105 ----
  325.   #endif
  326.   
  327.   #include <errno.h>
  328. + #ifndef MSDOS            /* have it VOLATILE in <stdlib.h> */
  329.   extern int      errno;
  330.   extern int      sys_nerr;
  331.   extern char    *sys_errlist[];
  332. + #endif /* not MSDOS */
  333.   
  334.   #define    EOS        (0)
  335.   #define    FALSE        (0)
  336.   #define TRUE        1
  337.   
  338. + #ifndef MSDOS                /* have it in <stdlib.h> */
  339.   #define min(a,b) ((a) <= (b) ? (a) : (b))
  340.   #define max(a,b) ((a) >= (b) ? (a) : (b))
  341. + #endif
  342.   
  343.   #ifndef PR_FILE_NAME
  344.   #define PR_FILE_NAME "/bin/pr"
  345. ***************
  346. *** 90,96 ****
  347.   #endif
  348.   
  349.   /* Support old-fashioned C compilers.  */
  350. ! #if !defined (__STDC__) && !defined (__GNUC__)
  351.   #define const
  352.   #endif
  353.   
  354. --- 114,120 ----
  355.   #endif
  356.   
  357.   /* Support old-fashioned C compilers.  */
  358. ! #if !defined (__STDC__) && !defined (__GNUC__) || defined (MSDOS)
  359.   #define const
  360.   #endif
  361.   
  362. ***************
  363. *** 97,102 ****
  364. --- 121,134 ----
  365.   #ifndef O_RDONLY
  366.   #define O_RDONLY 0
  367.   #endif
  368. + #ifdef MSDOS
  369. + #if !defined (_MSC_VER) || (_MSC_VER < 600)
  370. + #define _huge huge
  371. + #endif /* MSC 5.1 */
  372. + #else /* not MSDOS */
  373. + #define _huge
  374. + #endif /* not MSDOS */
  375.   
  376.   /* Variables for command line options */
  377.   
  378. ***************
  379. *** 239,245 ****
  380.   /* Data on one line of text.  */
  381.   
  382.   struct line_def {
  383. !     char        *text;
  384.       int         length;
  385.       unsigned    hash;
  386.   };
  387. --- 271,277 ----
  388.   /* Data on one line of text.  */
  389.   
  390.   struct line_def {
  391. !     char _huge  *text;
  392.       int         length;
  393.       unsigned    hash;
  394.   };
  395. ***************
  396. *** 253,263 ****
  397.       int             dir_p;    /* 1 if file is a directory  */
  398.   
  399.       /* Buffer in which text of file is read.  */
  400. !     char *        buffer;
  401.       /* Allocated size of buffer.  */
  402.       int            bufsize;
  403.       /* Number of valid characters now in the buffer. */
  404.       int            buffered_chars;
  405.   
  406.       /* Array of data on analyzed lines of this chunk of this file.  */
  407.       struct line_def *linbuf;
  408. --- 285,302 ----
  409.       int             dir_p;    /* 1 if file is a directory  */
  410.   
  411.       /* Buffer in which text of file is read.  */
  412. !     char _huge *    buffer;     /* Allocated size of buffer.  */
  413. ! #ifdef MSDOS
  414.       /* Allocated size of buffer.  */
  415. +     long        bufsize;
  416. +     /* Number of valid characters now in the buffer. */
  417. +     long        buffered_chars;
  418. + #else /* not MSDOS */
  419. +     /* Allocated size of buffer.  */
  420.       int            bufsize;
  421.       /* Number of valid characters now in the buffer. */
  422.       int            buffered_chars;
  423. + #endif /* not MSDOS */
  424.   
  425.       /* Array of data on analyzed lines of this chunk of this file.  */
  426.       struct line_def *linbuf;
  427. ***************
  428. *** 269,281 ****
  429.       int            buffered_lines;
  430.   
  431.       /* Pointer to end of prefix of this file to ignore when hashing. */
  432. !     char *prefix_end;
  433.   
  434.       /* Count of lines in the prefix. */
  435.       int prefix_lines;
  436.   
  437.       /* Pointer to start of suffix of this file to ignore when hashing. */
  438. !     char *suffix_begin;
  439.   
  440.       /* Count of lines in the suffix. */
  441.       int suffix_lines;
  442. --- 308,320 ----
  443.       int            buffered_lines;
  444.   
  445.       /* Pointer to end of prefix of this file to ignore when hashing. */
  446. !     char _huge *prefix_end;
  447.   
  448.       /* Count of lines in the prefix. */
  449.       int prefix_lines;
  450.   
  451.       /* Pointer to start of suffix of this file to ignore when hashing. */
  452. !     char _huge *suffix_begin;
  453.   
  454.       /* Count of lines in the suffix. */
  455.       int suffix_lines;
  456. ***************
  457. *** 347,370 ****
  458.   
  459.   #ifdef __STDC__
  460.   #define VOID void
  461.   #else
  462.   #define VOID char
  463. ! #endif
  464. ! VOID *xmalloc ();
  465. ! VOID *xrealloc ();
  466.   char *concat ();
  467.   void free ();
  468.   char *rindex ();
  469.   char *index ();
  470.   
  471. - void analyze_hunk ();
  472. - void error ();
  473. - void fatal ();
  474.   void message ();
  475. - void perror_with_name ();
  476. - void pfatal_with_name ();
  477. - void print_1_line ();
  478.   void print_message_queue ();
  479. ! void print_number_range ();
  480.   void print_script ();
  481.   void translate_range ();
  482. --- 386,447 ----
  483.   
  484.   #ifdef __STDC__
  485.   #define VOID void
  486. + extern int diff_2_files(struct file_data *, int);
  487. + extern void print_context_header (struct file_data *inf, int unidiff_flag);
  488. + extern void print_context_script (struct change *script, int unidiff_flag);
  489. + extern int diff_dirs (char *name1, char *name2,
  490. +               int (*handle_file) (char *, char *, char *, char *, int),
  491. +               int depth, int nonex1, int nonex2);
  492. + extern void print_rcs_script (struct change *);
  493. + extern void print_ed_script (struct change *);
  494. + extern void pr_forward_ed_script (struct change *);
  495. + extern void print_ifdef_script (struct change *);
  496. + extern int read_files (struct file_data *);
  497. + extern void print_normal_script (struct change *);
  498. + extern int line_cmp (struct line_def *, struct line_def *);
  499. + extern  void pfatal_with_name (char *);
  500. + extern void *xcalloc (int, int);
  501. + extern void print_1_line (char *, struct line_def *);
  502. + extern void message (char *,...);
  503. + extern void print_message_queue (void);
  504. + extern struct change *find_change (struct change *);
  505. + extern void error (char *,...);
  506. + extern char *concat (char *, char *, char *);
  507. + extern int change_letter (int, int);
  508. + extern void setup_output (char *, char *, int);
  509. + extern void *xmalloc (unsigned int);
  510. + extern struct change *find_reverse_change (struct change *);
  511. + extern void fatal (char *);
  512. + extern void debug_script (struct change *sp);
  513. + extern int translate_line_number (struct file_data *, int);
  514. + extern void finish_output (void);
  515. + extern void perror_with_name (char *);
  516. + extern void *xrealloc (void *, unsigned int);
  517. + extern void fatal_with_name (char *, char *);
  518. + extern void translate_range (struct file_data *, int, int, int *, int *);
  519. + extern void print_number_range (char, struct file_data *, int, int);
  520. + extern void print_script (struct change *,
  521. +               struct change *(*)(struct change *),
  522. +               void (*)(struct change *));
  523. + extern void analyze_hunk (struct change *, int *, int *, int *, int *, int *, int *);
  524. + extern long hread (int fd, void _huge *buffer, long bytes);
  525. + extern void _huge *xhalloc (long);
  526. + extern void _huge *xhrealloc (void _huge *ptr, long new_size, long old_size);
  527.   #else
  528.   #define VOID char
  529. ! char *xmalloc ();
  530. ! char *xrealloc ();
  531.   char *concat ();
  532.   void free ();
  533.   char *rindex ();
  534.   char *index ();
  535.   
  536.   void message ();
  537.   void print_message_queue ();
  538. ! #endif /* __STDC__ */
  539.   void print_script ();
  540.   void translate_range ();
  541. *** e:\tmp/RCSt1005321    Tue Mar 12 17:20:04 1991
  542. --- diff3.c    Tue Mar 12 17:18:46 1991
  543. ***************
  544. *** 15,23 ****
  545.      along with this program; if not, write to the Free Software
  546.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  547.   
  548.   /* Written by Randy Smith */
  549.   
  550.   #ifdef __STDC__
  551.   #define VOID void
  552.   #else
  553. --- 15,31 ----
  554.      along with this program; if not, write to the Free Software
  555.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  556.   
  557.   /* Written by Randy Smith */
  558.   
  559. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  560. + This port is also distributed under the terms of the GNU General
  561. + Public License as published by the Free Software Foundation.
  562. + Please note that this file is not identical to the original GNU release,
  563. + you should have received this code as patch to the official release.
  564. + $Header: e:/gnu/diff/RCS/diff3.c 1.15.0.2 91/03/12 17:06:13 tho Exp $  */
  565.   #ifdef __STDC__
  566.   #define VOID void
  567.   #else
  568. ***************
  569. *** 35,46 ****
  570.   #ifdef USG
  571.   #include <fcntl.h>
  572.   
  573.   /* Define needed BSD functions in terms of sysV library.  */
  574.   
  575.   #define bcmp(s1,s2,n)    memcmp((s1),(s2),(n))
  576.   #define bzero(s,n)    memset((s),0,(n))
  577.   
  578. ! #ifndef XENIX
  579.   #define dup2(f,t)    (close(t),fcntl((f),F_DUPFD,(t)))
  580.   #endif
  581.   
  582. --- 43,64 ----
  583.   #ifdef USG
  584.   #include <fcntl.h>
  585.   
  586. + #ifdef MSDOS
  587. + #include <stdlib.h>
  588. + #include <sys/types.h>
  589. + #include <sys/stat.h>
  590. + #include <io.h>
  591. + #include <process.h>
  592. + #include <string.h>
  593. + static char *tmpfilename (char *template);
  594. + #endif /* MSDOS */
  595.   /* Define needed BSD functions in terms of sysV library.  */
  596.   
  597.   #define bcmp(s1,s2,n)    memcmp((s1),(s2),(n))
  598.   #define bzero(s,n)    memset((s),0,(n))
  599.   
  600. ! #if !defined (XENIX) && !defined (MSDOS)
  601.   #define dup2(f,t)    (close(t),fcntl((f),F_DUPFD,(t)))
  602.   #endif
  603.   
  604. ***************
  605. *** 209,214 ****
  606. --- 227,267 ----
  607.   /*
  608.    * Forward function declarations.
  609.    */
  610. + #ifdef __STDC__
  611. + extern void main (int argc, char **argv);
  612. + static int myread (int, char *, int);
  613. + static struct diff_block *process_diff (char *, char *);
  614. + static void perror_with_exit (char *string);
  615. + static void fatal (char *string);
  616. + static void usage (void);
  617. + static void *xmalloc (size_t n);
  618. + static void *xrealloc (void *ptr, size_t n);
  619. + static char *tmpfilename (char *);
  620. + static char *read_diff (char *filea, char *fileb, char **output_placement);
  621. + static enum diff_type process_diff_control (char **, struct diff_block *);
  622. + static int copy_stringlist (char **, int *, char **, int *, int);
  623. + static struct diff3_block *create_diff3_block (int, int, int, int, int, int);
  624. + static struct diff3_block *make_3way_diff (struct diff_block *,
  625. +                        struct diff_block *);
  626. + static int compare_line_list (char **, int *, char **, int *, int);
  627. + static int output_diff3_edscript (FILE *outputfile, struct diff3_block *diff,
  628. +                   int mapping[3], int rev_mapping[3],
  629. +                   char *file0, char *file1, char *file2);
  630. + static int output_diff3_merge (FILE *commonfile, FILE *outputfile,
  631. +                    struct diff3_block *diff,
  632. +                    int mapping[3], int rev_mapping[3],
  633. +                    char *file0, char *file1, char *file2);
  634. + static void output_diff3 (FILE *outputfile, struct diff3_block *diff,
  635. +               int mapping[3], int rev_mapping[3]);
  636. + static char *scan_diff_line (char *, char * *, int *, char *, char);
  637. + static struct diff3_block *reverse_diff3_blocklist (struct diff3_block *);
  638. + static struct diff3_block *using_to_diff3_block (struct diff_block **, struct diff_block * *, int, int, struct diff3_block *);
  639. + extern int getopt (int, char * *, char *);
  640. + #else
  641.   struct diff_block *process_diff ();
  642.   struct diff3_block *make_3way_diff ();
  643.   void output_diff3 ();
  644. ***************
  645. *** 230,235 ****
  646. --- 283,290 ----
  647.   VOID *xmalloc ();
  648.   VOID *xrealloc ();
  649.   
  650. + #endif /* __STDC__ */
  651.   char diff_program[] = DIFF_PROGRAM;
  652.   
  653.   /*
  654. ***************
  655. *** 236,241 ****
  656. --- 291,299 ----
  657.    * Main program.  Calls diff twice on two pairs of input files,
  658.    * combines the two diffs, and outputs them.
  659.    */
  660. + #ifdef __STDC__
  661. + void
  662. + #endif /* __STDC__ */
  663.   main (argc, argv)
  664.        int argc;
  665.        char **argv;
  666. ***************
  667. *** 960,966 ****
  668. --- 1018,1026 ----
  669.    * Routines to input and parse two way diffs.
  670.    */
  671.   
  672. + #ifndef MSDOS
  673.   extern char **environ;
  674. + #endif /* MSDOS */
  675.   
  676.   #define    DIFF_CHUNK_SIZE    10000
  677.   
  678. ***************
  679. *** 1180,1185 ****
  680. --- 1240,1250 ----
  681.     int pid, w;
  682.     int wstatus;
  683.   
  684. + #ifdef MSDOS
  685. +   int save_stdout;
  686. +   char *pipe_file = tmpfilename ("diXXXXXX");
  687. + #endif /* MSDOS */
  688.     ap = argv;
  689.     *ap++ = diff_program;
  690.     if (always_text)
  691. ***************
  692. *** 1189,1194 ****
  693. --- 1254,1274 ----
  694.     *ap++ = fileb;
  695.     *ap = (char *) 0;
  696.   
  697. + #ifdef MSDOS
  698. +   save_stdout = dup (1);
  699. +   fds[0] = open (pipe_file, O_CREAT|O_RDWR|O_TEXT,S_IREAD|S_IWRITE);
  700. +   dup2 (fds[0], 1);
  701. +   if ((spawnvp (P_WAIT, diff_program, argv)) == -1)
  702. +     perror_with_exit ("can't spawn diff");
  703. +   dup2 (save_stdout, 1);
  704. +   lseek (fds[0], 0L, SEEK_SET);
  705. + #else
  706.     if (pipe (fds) < 0)
  707.       perror_with_exit ("Pipe failed");
  708.   
  709. ***************
  710. *** 1213,1218 ****
  711. --- 1293,1301 ----
  712.       perror_with_exit ("Fork failed");
  713.   
  714.     close (fds[1]);        /* Prevent erroneous lack of EOF */
  715. + #endif /* MSDOS */
  716.     current_chunk_size = DIFF_CHUNK_SIZE;
  717.     diff_result = (char *) xmalloc (current_chunk_size);
  718.     total = 0;
  719. ***************
  720. *** 1230,1235 ****
  721. --- 1313,1321 ----
  722.   
  723.     *output_placement = diff_result;
  724.   
  725. + #ifdef MSDOS
  726. +   unlink (pipe_file);
  727. + #else /* not MSDOS */
  728.     do
  729.       if ((w = wait (&wstatus)) == -1)
  730.         perror_with_exit ("Wait failed");
  731. ***************
  732. *** 1237,1242 ****
  733. --- 1323,1329 ----
  734.   
  735.     if (! (WIFEXITED (wstatus) && WEXITSTATUS (wstatus) < 2))
  736.       fatal ("Subsidiary diff failed");
  737. + #endif /* not MSDOS */
  738.   
  739.     return diff_result + total;
  740.   }
  741. ***************
  742. *** 1332,1338 ****
  743.       case DIFF_3RD:
  744.         oddoneout = rev_mapping[(int) ptr->correspond - (int) DIFF_1ST];
  745.           
  746. !       x[0] = oddoneout + '1';
  747.         x[1] = '\0';
  748.         dontprint = oddoneout==0;
  749.         break;
  750. --- 1419,1425 ----
  751.       case DIFF_3RD:
  752.         oddoneout = rev_mapping[(int) ptr->correspond - (int) DIFF_1ST];
  753.           
  754. !       x[0] = (char) oddoneout + '1';
  755.         x[1] = '\0';
  756.         dontprint = oddoneout==0;
  757.         break;
  758. ***************
  759. *** 1400,1406 ****
  760.    *
  761.    * Returns 1 if overlaps were found.
  762.    */
  763.   int
  764.   output_diff3_edscript (outputfile, diff, mapping, rev_mapping,
  765.                  file0, file1, file2)
  766. --- 1487,1492 ----
  767. ***************
  768. *** 1655,1661 ****
  769. --- 1741,1751 ----
  770.   
  771.   VOID *
  772.   xmalloc (size)
  773. + #ifdef __STDC__
  774. +      size_t size;
  775. + #else /* not __STDC__ */
  776.        int size;
  777. + #endif /* not __STDC__ */
  778.   {
  779.     VOID *result = (VOID *) malloc (size ? size : 1);
  780.     if (!result)
  781. ***************
  782. *** 1666,1672 ****
  783. --- 1756,1766 ----
  784.   VOID *
  785.   xrealloc (ptr, size)
  786.        VOID *ptr;
  787. + #ifdef __STDC__
  788. +      size_t size;
  789. + #else /* not __STDC__ */
  790.        int size;
  791. + #endif /* not __STDC__ */
  792.   {
  793.     VOID *result = (VOID *) realloc (ptr, size ? size : 1);
  794.     if (!result)
  795. ***************
  796. *** 1674,1679 ****
  797. --- 1768,1776 ----
  798.     return result;
  799.   }
  800.   
  801. + #ifdef __STDC__
  802. + void
  803. + #endif /* __STDC__ */
  804.   fatal (string)
  805.        char *string;
  806.   {
  807. ***************
  808. *** 1681,1686 ****
  809. --- 1778,1786 ----
  810.     exit (2);
  811.   }
  812.   
  813. + #ifdef __STDC__
  814. + void
  815. + #endif /* __STDC__ */
  816.   perror_with_exit (string)
  817.        char *string;
  818.   {
  819. ***************
  820. *** 1687,1689 ****
  821. --- 1787,1826 ----
  822.     perror (string);
  823.     exit (2);
  824.   }
  825. + #ifdef MSDOS
  826. + /*
  827. +  * Get name of temporary directory from environment entry TMP or TEMP.
  828. +  * if this fails, use current directory.
  829. +  */
  830. + static char *
  831. + tmpfilename (char *template)
  832. + {
  833. +   register int l;
  834. +   register char *p;
  835. +   register char *tmpfile;
  836. +   int lt = strlen (template);
  837. +   if ((p = getenv ("TMP")) || (p = getenv ("TEMP")))
  838. +     {
  839. +       l = strlen(p);
  840. +       tmpfile = xmalloc (l + lt + 2);
  841. +       strcpy (tmpfile, p);
  842. +       if ((tmpfile[l-1] != '/') && (tmpfile[l-1] != '\\'))
  843. +     {
  844. +       tmpfile[l] = '/';        /* append slash */
  845. +       tmpfile[l+1] = '\0';
  846. +     }
  847. +     }
  848. +   else
  849. +     {
  850. +       tmpfile = xmalloc (lt + 3);    /* use current directory */
  851. +       strcpy (tmpfile, "./");
  852. +     }
  853. +   return mktemp (strcat (tmpfile, template));
  854. + }
  855. + #endif /* MSDOS */
  856. *** e:\tmp/RCSt1005321    Tue Mar 12 17:20:08 1991
  857. --- dir.c    Tue Mar 12 17:18:50 1991
  858. ***************
  859. *** 17,25 ****
  860. --- 17,36 ----
  861.   along with GNU DIFF; see the file COPYING.  If not, write to
  862.   the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  863.   
  864. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  865. + This port is also distributed under the terms of the GNU General
  866. + Public License as published by the Free Software Foundation.
  867. + Please note that this file is not identical to the original GNU release,
  868. + you should have received this code as patch to the official release.
  869. + $Header: e:/gnu/diff/RCS/dir.c 1.15.0.2 91/03/12 17:06:27 tho Exp $  */
  870.   #include "diff.h"
  871.   
  872. + #ifndef __STDC__
  873.   static int compare_names ();
  874. + #endif /* !__STDC__ */
  875.   
  876.   /* Read the directory named DIRNAME and return a sorted vector
  877.      of filenames for its contents.  NONEX nonzero means this directory is
  878. ***************
  879. *** 31,36 ****
  880. --- 42,52 ----
  881.     char **files;            /* Sorted names of files in the dir */
  882.   };
  883.   
  884. + #ifdef __STDC__
  885. + static  struct dirdata dir_sort(char *, int);
  886. + static  int compare_names(char * *, char * *);
  887. + #endif /* __STDC__ */
  888.   static struct dirdata
  889.   dir_sort (dirname, nonex)
  890.        char *dirname;
  891. ***************
  892. *** 132,142 ****
  893. --- 148,166 ----
  894.      Returns the maximum of all the values returned by HANDLE_FILE,
  895.      or 2 if trouble is encountered in opening files.  */
  896.   
  897. + #ifdef MSDOS
  898. + int
  899. + diff_dirs (name1, name2, handle_file, depth, nonex1, nonex2)
  900. +      char *name1, *name2;
  901. +      int (*handle_file) (char *, char *, char *, char *, int);
  902. +      int depth, nonex1, nonex2;
  903. + #else
  904.   int
  905.   diff_dirs (name1, name2, handle_file, depth, nonex1, nonex2)
  906.        char *name1, *name2;
  907.        int (*handle_file) ();
  908.        int nonex1, nonex2;
  909. + #endif
  910.   {
  911.     struct dirdata data1, data2;
  912.     register int i1, i2;
  913. *** e:\tmp/RCSt1005321    Tue Mar 12 17:20:12 1991
  914. --- ed.c    Tue Mar 12 17:18:52 1991
  915. ***************
  916. *** 17,24 ****
  917. --- 17,38 ----
  918.   along with GNU DIFF; see the file COPYING.  If not, write to
  919.   the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  920.   
  921. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  922. + This port is also distributed under the terms of the GNU General
  923. + Public License as published by the Free Software Foundation.
  924. + Please note that this file is not identical to the original GNU release,
  925. + you should have received this code as patch to the official release.
  926. + $Header: e:/gnu/diff/RCS/ed.c 1.15.0.1 91/03/11 22:11:02 tho Exp $  */
  927.   #include "diff.h"
  928.   
  929. + #ifdef __STDC__
  930. + static  void print_ed_hunk(struct change *);
  931. + static  void pr_forward_ed_hunk(struct change *);
  932. + static  void print_rcs_hunk(struct change *);
  933. + #else
  934.   static void print_rcs_hunk ();
  935.   static void print_ed_hunk ();
  936.   static void pr_forward_ed_hunk ();
  937. ***************
  938. *** 25,30 ****
  939. --- 39,45 ----
  940.   void translate_range ();
  941.   struct change *find_change ();
  942.   struct change *find_reverse_change ();
  943. + #endif /* __STDC__ */
  944.   
  945.   /* Print our script as ed commands.  */
  946.   
  947. *** e:\tmp/RCSt1005321    Tue Mar 12 17:20:12 1991
  948. --- ifdef.c    Tue Mar 12 17:18:54 1991
  949. ***************
  950. *** 17,28 ****
  951. --- 17,39 ----
  952.   can know your rights and responsibilities.  It should be in a
  953.   file named COPYING.  Among other things, the copyright notice
  954.   and this notice must be preserved on all copies.  */
  955. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  956. + This port is also distributed under the terms of the GNU General
  957. + Public License as published by the Free Software Foundation.
  958.   
  959. + Please note that this file is not identical to the original GNU release,
  960. + you should have received this code as patch to the official release.
  961.   
  962. + $Header: e:/gnu/diff/RCS/ifdef.c 1.15.0.1 91/03/11 22:12:20 tho Exp $  */
  963.   #include "diff.h"
  964.   
  965. + #ifdef __STDC__
  966. + static  void print_ifdef_hunk(struct change *);
  967. + #else
  968.   static void print_ifdef_hunk ();
  969.   struct change *find_change ();
  970. + #endif /* __STDC__ */
  971.   
  972.   static int next_line;
  973.   
  974. *** e:\tmp/RCSt1005321    Tue Mar 12 17:20:14 1991
  975. --- io.c    Tue Mar 12 17:18:56 1991
  976. ***************
  977. *** 17,24 ****
  978. --- 17,41 ----
  979.   along with GNU DIFF; see the file COPYING.  If not, write to
  980.   the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  981.   
  982. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  983. + This port is also distributed under the terms of the GNU General
  984. + Public License as published by the Free Software Foundation.
  985. + Please note that this file is not identical to the original GNU release,
  986. + you should have received this code as patch to the official release.
  987. + $Header: e:/gnu/diff/RCS/io.c 1.15.0.2 91/03/12 17:06:38 tho Exp $  */
  988.   #include "diff.h"
  989.   
  990. + #ifdef __STDC__
  991. + static  int binary_file_p(char *, int);
  992. + static  int slurp(void);
  993. + static  void find_identical_ends(struct file_data *);
  994. + static  void find_and_hash_each_line(void);
  995. + static  int find_equiv_class(int);
  996. + #endif /* __STDC__ */
  997.   /* Rotate a value n bits to the left. */
  998.   #define UINT_BIT (sizeof (unsigned) * CHAR_BIT)
  999.   #define ROL(v, n) ((v) << (n) | (v) >> UINT_BIT - (n))
  1000. ***************
  1001. *** 104,123 ****
  1002.     else if ((current->stat.st_mode & S_IFMT) == S_IFREG)
  1003.       {
  1004.         current->bufsize = current->stat.st_size;
  1005.         current->buffer = (char *) xmalloc (current->bufsize + 2);
  1006.         current->buffered_chars
  1007.       = read (current->desc, current->buffer, current->bufsize);
  1008.         if (current->buffered_chars < 0)
  1009.       pfatal_with_name (current->name);
  1010.       }
  1011.     else
  1012.       {
  1013.         int cc;
  1014.   
  1015.         current->bufsize = 4096;
  1016.         current->buffer = (char *) xmalloc (current->bufsize + 2);
  1017.         current->buffered_chars = 0;
  1018. !       
  1019.         /* Not a regular file; read it in a little at a time, growing the
  1020.        buffer as necessary. */
  1021.         while ((cc = read (current->desc,
  1022. --- 121,181 ----
  1023.     else if ((current->stat.st_mode & S_IFMT) == S_IFREG)
  1024.       {
  1025.         current->bufsize = current->stat.st_size;
  1026. + #ifdef MSDOS
  1027. +       current->buffer = (char _huge *) xhalloc (current->bufsize + 2L);
  1028. +       current->buffered_chars
  1029. +     = hread (current->desc, current->buffer, current->bufsize);
  1030. + #else /* not MSDOS */
  1031.         current->buffer = (char *) xmalloc (current->bufsize + 2);
  1032.         current->buffered_chars
  1033.       = read (current->desc, current->buffer, current->bufsize);
  1034. + #endif /* not MSDOS */
  1035.         if (current->buffered_chars < 0)
  1036.       pfatal_with_name (current->name);
  1037.       }
  1038.     else
  1039.       {
  1040. + #ifdef MSDOS
  1041. +       long cc;
  1042. +       current->bufsize = 0x2000L;
  1043. +       current->buffer = (char _huge *) xhalloc (current->bufsize + 2L);
  1044. +       current->buffered_chars = 0L;
  1045. +       /* Not a regular file; read it in a little at a time, growing the
  1046. +      buffer as necessary.
  1047. +      MS-DOS: This is really slow size we do not double
  1048. +      the BUFSIZE on each step, we rather increase it linearly.
  1049. +      I think this greatly inproves the changes of managing a 
  1050. +      tight fit.  */
  1051. +       while ((cc = hread (current->desc,
  1052. +                current->buffer + current->buffered_chars,
  1053. +                current->bufsize - current->buffered_chars))
  1054. +           > 0L)
  1055. +     {
  1056. +       current->buffered_chars += cc;
  1057. +       if (current->buffered_chars == current->bufsize)
  1058. +         {
  1059. +           current->buffer
  1060. +         = (char _huge *) xhrealloc (current->buffer,
  1061. +                        current->bufsize + 0x2002L,
  1062. +                        current->bufsize);
  1063. +           current->bufsize = current->bufsize + 0x2000L;
  1064. +         }
  1065. +     }
  1066. +       if (cc < 0L)
  1067. +     pfatal_with_name (current->name);
  1068. + #else /* not MSDOS */
  1069.         int cc;
  1070.   
  1071.         current->bufsize = 4096;
  1072.         current->buffer = (char *) xmalloc (current->bufsize + 2);
  1073.         current->buffered_chars = 0;
  1074.         /* Not a regular file; read it in a little at a time, growing the
  1075.        buffer as necessary. */
  1076.         while ((cc = read (current->desc,
  1077. ***************
  1078. *** 133,146 ****
  1079.                              current->bufsize + 2);
  1080.           }
  1081.       }
  1082.         if (cc < 0)
  1083.       pfatal_with_name (current->name);
  1084.       }
  1085. !   
  1086.     /* Check first part of file to see if it's a binary file.  */
  1087.     if (! always_text_flag
  1088.         && binary_file_p (current->buffer,
  1089.               min (current->buffered_chars, binary_file_threshold)))
  1090.       return 1;
  1091.   
  1092.     /* If not binary, make sure text ends in a newline,
  1093. --- 191,211 ----
  1094.                              current->bufsize + 2);
  1095.           }
  1096.       }
  1097.         if (cc < 0)
  1098.       pfatal_with_name (current->name);
  1099. + #endif /* not MSDOS */
  1100.       }
  1101.     /* Check first part of file to see if it's a binary file.  */
  1102.     if (! always_text_flag
  1103.         && binary_file_p (current->buffer,
  1104. + #ifdef MSDOS
  1105. +        min ((int) current->buffered_chars, binary_file_threshold)))
  1106. + #else
  1107.               min (current->buffered_chars, binary_file_threshold)))
  1108. + #endif
  1109.       return 1;
  1110.   
  1111.     /* If not binary, make sure text ends in a newline,
  1112. ***************
  1113. *** 169,178 ****
  1114.   {
  1115.     unsigned h;
  1116.     int i;
  1117. !   unsigned char *p = (unsigned char *) current->prefix_end, *ip, c;
  1118.   
  1119.     /* Attempt to get a good initial guess as to the number of lines. */
  1120.     current->linbufsize = current->buffered_chars / 50 + 5;
  1121.     current->linbuf
  1122.       = (struct line_def *) xmalloc (current->linbufsize * sizeof (struct line_def));
  1123.   
  1124. --- 234,248 ----
  1125.   {
  1126.     unsigned h;
  1127.     int i;
  1128. !   unsigned char _huge *p = (unsigned char _huge *) current->prefix_end;
  1129. !   unsigned char _huge *ip, c;
  1130.   
  1131.     /* Attempt to get a good initial guess as to the number of lines. */
  1132. + #ifdef MSDOS
  1133. +   current->linbufsize = (int) (current->buffered_chars / 50) + 5;
  1134. + #else
  1135.     current->linbufsize = current->buffered_chars / 50 + 5;
  1136. + #endif
  1137.     current->linbuf
  1138.       = (struct line_def *) xmalloc (current->linbufsize * sizeof (struct line_def));
  1139.   
  1140. ***************
  1141. *** 183,189 ****
  1142.        but since we don't know how many, it's easiest to find them all.
  1143.        If -D is specified, we need all the lines of the first file.  */
  1144.         current->buffered_lines = 0;
  1145. !       p = (unsigned char *) current->buffer;
  1146.       }
  1147.     else
  1148.       {
  1149. --- 253,259 ----
  1150.        but since we don't know how many, it's easiest to find them all.
  1151.        If -D is specified, we need all the lines of the first file.  */
  1152.         current->buffered_lines = 0;
  1153. !       p = (unsigned char _huge *) current->buffer;
  1154.       }
  1155.     else
  1156.       {
  1157. ***************
  1158. *** 195,212 ****
  1159.       current->buffered_lines = 0;
  1160.         for (i = 0; i < context + 1; ++i)
  1161.       /* Unless we are at the beginning, */
  1162. !     if ((char *) p != current->buffer)
  1163.         /* Back up at least 1 char until at the start of a line.  */
  1164. !       while ((char *) --p != current->buffer && p[-1] != '\n')
  1165.           ;
  1166.       }
  1167.   
  1168. !   while ((char *) p < current->suffix_begin)
  1169.       {
  1170.         h = 0;
  1171.         ip = p;
  1172.   
  1173. !       if (current->prefix_end <= (char *) p)
  1174.       {
  1175.         /* Hash this line until we find a newline. */
  1176.         if (ignore_case_flag)
  1177. --- 265,282 ----
  1178.       current->buffered_lines = 0;
  1179.         for (i = 0; i < context + 1; ++i)
  1180.       /* Unless we are at the beginning, */
  1181. !     if ((char _huge *) p != current->buffer)
  1182.         /* Back up at least 1 char until at the start of a line.  */
  1183. !       while ((char _huge *) --p != current->buffer && p[-1] != '\n')
  1184.           ;
  1185.       }
  1186.   
  1187. !   while ((char _huge *) p < current->suffix_begin)
  1188.       {
  1189.         h = 0;
  1190.         ip = p;
  1191.   
  1192. !       if (current->prefix_end <= (char _huge *) p)
  1193.       {
  1194.         /* Hash this line until we find a newline. */
  1195.         if (ignore_case_flag)
  1196. ***************
  1197. *** 292,305 ****
  1198.         if (current->buffered_lines >= current->linbufsize)
  1199.       {
  1200.         while (current->buffered_lines >= current->linbufsize)
  1201.           current->linbufsize *= 2;
  1202.         current->linbuf
  1203.           = (struct line_def *) xrealloc (current->linbuf,
  1204.                           current->linbufsize
  1205.                           * sizeof (struct line_def));
  1206.       }
  1207. !       current->linbuf[current->buffered_lines].text = (char *) ip;
  1208.         current->linbuf[current->buffered_lines].length = p - ip + 1;
  1209.         current->linbuf[current->buffered_lines].hash = h;
  1210.         ++current->buffered_lines;
  1211.         ++p;
  1212. --- 362,388 ----
  1213.         if (current->buffered_lines >= current->linbufsize)
  1214.       {
  1215.         while (current->buffered_lines >= current->linbufsize)
  1216. + #ifdef MSDOS            /* don't be to generous!  */
  1217. +         {
  1218. +           current->linbufsize += 0x0100;
  1219. +           if (current->linbufsize >= 0xffe0 / sizeof (struct line_def))
  1220. +         fatal ("to many lines in input");
  1221. +         }
  1222. + #else /* not MSDOS */
  1223.           current->linbufsize *= 2;
  1224. + #endif /* not MSDOS */
  1225.         current->linbuf
  1226.           = (struct line_def *) xrealloc (current->linbuf,
  1227.                           current->linbufsize
  1228.                           * sizeof (struct line_def));
  1229.       }
  1230. !       current->linbuf[current->buffered_lines].text = (char _huge *) ip;
  1231. ! #ifdef MSDOS            /* Be explicit to the compiler!  */
  1232. !       current->linbuf[current->buffered_lines].length
  1233. !     = (int) ((long) (p - ip) + 1);
  1234. ! #else /* not MSDOS */
  1235.         current->linbuf[current->buffered_lines].length = p - ip + 1;
  1236. + #endif /* not MSDOS */
  1237.         current->linbuf[current->buffered_lines].hash = h;
  1238.         ++current->buffered_lines;
  1239.         ++p;
  1240. ***************
  1241. *** 307,313 ****
  1242.   
  1243.     i = 0;
  1244.     while ((i < context || output_style == OUTPUT_IFDEF)
  1245. !      && (char *) p < current->buffer + current->buffered_chars)
  1246.       {
  1247.         ip = p;
  1248.         while (*p++ != '\n')
  1249. --- 390,396 ----
  1250.   
  1251.     i = 0;
  1252.     while ((i < context || output_style == OUTPUT_IFDEF)
  1253. !      && (char _huge *) p < current->buffer + current->buffered_chars)
  1254.       {
  1255.         ip = p;
  1256.         while (*p++ != '\n')
  1257. ***************
  1258. *** 316,329 ****
  1259.         if (current->buffered_lines >= current->linbufsize)
  1260.       {
  1261.         while (current->buffered_lines >= current->linbufsize)
  1262.           current->linbufsize *= 2;
  1263.         current->linbuf
  1264.           = (struct line_def *) xrealloc (current->linbuf,
  1265.                           current->linbufsize
  1266.                           * sizeof (struct line_def));
  1267.       }
  1268. !       current->linbuf[current->buffered_lines].text = (char *) ip;
  1269.         current->linbuf[current->buffered_lines].length = p - ip;
  1270.         current->linbuf[current->buffered_lines].hash = 0;
  1271.         ++current->buffered_lines;
  1272.         ++i;
  1273. --- 399,425 ----
  1274.         if (current->buffered_lines >= current->linbufsize)
  1275.       {
  1276.         while (current->buffered_lines >= current->linbufsize)
  1277. + #ifdef MSDOS            /* don't be to generous!  */
  1278. +         {
  1279. +           current->linbufsize += 0x0100;
  1280. +           if (current->linbufsize >= 0xffe0 / sizeof (struct line_def))
  1281. +         fatal ("to many lines in input");
  1282. +         }
  1283. + #else /* not MSDOS */
  1284.           current->linbufsize *= 2;
  1285. + #endif /* not MSDOS */
  1286.         current->linbuf
  1287.           = (struct line_def *) xrealloc (current->linbuf,
  1288.                           current->linbufsize
  1289.                           * sizeof (struct line_def));
  1290.       }
  1291. !       current->linbuf[current->buffered_lines].text = (char _huge *) ip;
  1292. ! #ifdef MSDOS        /* Be explicit to the compiler!  */
  1293. !       current->linbuf[current->buffered_lines].length
  1294. !     = (int) ((long) (p - ip));
  1295. ! #else /* not MSDOS */
  1296.         current->linbuf[current->buffered_lines].length = p - ip;
  1297. + #endif /* not MSDOS */
  1298.         current->linbuf[current->buffered_lines].hash = 0;
  1299.         ++current->buffered_lines;
  1300.         ++i;
  1301. ***************
  1302. *** 342,348 ****
  1303.   find_identical_ends (filevec)
  1304.        struct file_data filevec[];
  1305.   {
  1306. !   char *p0, *p1, *end0, *beg0;
  1307.     int lines;
  1308.   
  1309.     if (filevec[0].buffered_chars == 0 || filevec[1].buffered_chars == 0)
  1310. --- 438,444 ----
  1311.   find_identical_ends (filevec)
  1312.        struct file_data filevec[];
  1313.   {
  1314. !   char _huge *p0, _huge *p1, _huge *end0, _huge *beg0;
  1315.     int lines;
  1316.   
  1317.     if (filevec[0].buffered_chars == 0 || filevec[1].buffered_chars == 0)
  1318. ***************
  1319. *** 382,397 ****
  1320. --- 478,507 ----
  1321.   
  1322.     /* Don't count missing newline as part of prefix in RCS mode. */
  1323.     if (ROBUST_OUTPUT_STYLE (output_style)
  1324. + #ifdef MSDOS
  1325. +       && ((filevec[0].missing_newline
  1326. +        && (long) (p0 - filevec[0].buffer)
  1327. +          > (long) filevec[0].buffered_chars)
  1328. +       ||
  1329. +       (filevec[1].missing_newline
  1330. +        && (long) (p1 - filevec[1].buffer)
  1331. +          > (long) filevec[1].buffered_chars)))
  1332. + #else /* not MSDOS */
  1333.         && ((filevec[0].missing_newline
  1334.          && p0 - filevec[0].buffer > filevec[0].buffered_chars)
  1335.         ||
  1336.         (filevec[1].missing_newline
  1337.          && p1 - filevec[1].buffer > filevec[1].buffered_chars)))
  1338. + #endif /* not MSDOS */
  1339.       --p0, --p1, --lines;
  1340.   
  1341.     /* If the sentinel was passed, and lengths are equal, the
  1342.        files are identical.  */
  1343. + #ifdef MSDOS
  1344. +   if ((long) (p0 - filevec[0].buffer) > (long) filevec[0].buffered_chars
  1345. + #else /* not MSDOS */
  1346.     if (p0 - filevec[0].buffer > filevec[0].buffered_chars
  1347. + #endif /* not MSDOS */
  1348.         && filevec[0].buffered_chars == filevec[1].buffered_chars)
  1349.       {
  1350.         filevec[0].prefix_end = p0 - 1;
  1351. ***************
  1352. *** 515,520 ****
  1353. --- 625,631 ----
  1354.     16381,
  1355.     32749,
  1356.     65521,
  1357. + #ifndef MSDOS
  1358.     131071,
  1359.     262139,
  1360.     524287,
  1361. ***************
  1362. *** 525,530 ****
  1363. --- 636,642 ----
  1364.     16777213,
  1365.     33554393,
  1366.     67108859,            /* Preposterously large . . . */
  1367. + #endif /* not MSDOS */
  1368.     -1
  1369.   };
  1370.   
  1371. ***************
  1372. *** 564,569 ****
  1373. --- 676,686 ----
  1374.   
  1375.     /* Create a new equivalence class in this bucket. */
  1376.   
  1377. + #ifdef MSDOS
  1378. +   if (equivs_index >= equivs_alloc)
  1379. +     fatal ("too many differences, hash table overflow");
  1380. + #endif /* MSDOS */
  1381.     p = &equivs[equivs_index++];
  1382.     p->next = buckets[bucket];
  1383.     buckets[bucket] = p;
  1384. ***************
  1385. *** 600,607 ****
  1386. --- 717,735 ----
  1387.         find_and_hash_each_line ();
  1388.       }
  1389.   
  1390. + #ifdef MSDOS
  1391. +   /* This is NOT guaranteed to be enough space, but we will try anyway and
  1392. +      abort iff the hash table really overflows.  The strategy will help
  1393. +      us A LOT iff there are long matching pre- and suffixes (but the
  1394. +      user will have to wait longer for the bad news if we have to
  1395. +      abort ...).  */
  1396. +   equivs_alloc = min ((int) (0xffe0 / sizeof (struct equivclass)),
  1397. +         filevec[0].buffered_lines + filevec[1].buffered_lines + 1);
  1398. + #else /* not MSDOS */
  1399.     /* This is guaranteed to be enough space.  */
  1400.     equivs_alloc = filevec[0].buffered_lines + filevec[1].buffered_lines + 1;
  1401. + #endif /* not MSDOS */
  1402.     equivs = (struct equivclass *) xmalloc (equivs_alloc * sizeof (struct equivclass));
  1403.     /* Equivalence class 0 is permanently safe for lines that were not
  1404.        hashed.  Real equivalence classes start at 1. */
  1405. *** e:\tmp/RCSt1005321    Tue Mar 12 17:20:18 1991
  1406. --- limits.h    Tue Mar 12 17:19:06 1991
  1407. ***************
  1408. *** 1,3 ****
  1409. --- 1,31 ----
  1410. + /* limits.h - implementation dependent limits
  1411. +    Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  1412. + This file is part of GNU DIFF.
  1413. + GNU DIFF is free software; you can redistribute it and/or modify
  1414. + it under the terms of the GNU General Public License as published by
  1415. + the Free Software Foundation; either version 1, or (at your option)
  1416. + any later version.
  1417. + GNU DIFF is distributed in the hope that it will be useful,
  1418. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  1419. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1420. + GNU General Public License for more details.
  1421. + You should have received a copy of the GNU General Public License
  1422. + along with GNU DIFF; see the file COPYING.  If not, write to
  1423. + the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  1424. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  1425. + This port is also distributed under the terms of the GNU General
  1426. + Public License as published by the Free Software Foundation.
  1427. + Please note that this file is not identical to the original GNU release,
  1428. + you should have received this code as patch to the official release.
  1429. + $Header: e:/gnu/diff/RCS/limits.h 1.15.0.1 91/03/12 10:58:28 tho Exp $  */
  1430.   /* Number of bits in a `char'.  */
  1431.   #define CHAR_BIT 8
  1432.   
  1433. ***************
  1434. *** 29,38 ****
  1435. --- 57,75 ----
  1436.   
  1437.   /* Minimum and maximum values a `signed int' can hold.  */
  1438.   #define INT_MIN (-INT_MAX-1)
  1439. + #ifdef MSDOS
  1440. + #define INT_MAX 32767
  1441. + #else
  1442.   #define INT_MAX 2147483647
  1443. + #endif
  1444.   
  1445.   /* Maximum value an `unsigned int' can hold.  (Minimum is 0).  */
  1446. + #ifdef MSDOS
  1447. + #define UINT_MAX 65535U
  1448. + #else
  1449.   #define UINT_MAX 4294967295U
  1450. + #endif
  1451.   
  1452.   /* Minimum and maximum values a `signed long int' can hold.
  1453.      (Same as `int').  */
  1454. *** e:\tmp/RCSt1005321    Tue Mar 12 17:20:18 1991
  1455. --- normal.c    Tue Mar 12 17:18:58 1991
  1456. ***************
  1457. *** 17,28 ****
  1458.   along with GNU DIFF; see the file COPYING.  If not, write to
  1459.   the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  1460.   
  1461.   
  1462.   #include "diff.h"
  1463.   
  1464. ! void print_normal_hunk ();
  1465.   void print_number_range ();
  1466.   struct change *find_change ();
  1467.   
  1468.   /* Print the edit-script SCRIPT as a normal diff.
  1469.      INF points to an array of descriptions of the two files.  */
  1470. --- 17,41 ----
  1471.   along with GNU DIFF; see the file COPYING.  If not, write to
  1472.   the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  1473.   
  1474. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  1475. + This port is also distributed under the terms of the GNU General
  1476. + Public License as published by the Free Software Foundation.
  1477.   
  1478. + Please note that this file is not identical to the original GNU release,
  1479. + you should have received this code as patch to the official release.
  1480. + $Header: e:/gnu/diff/RCS/normal.c 1.15.0.1 91/03/12 10:45:17 tho Exp $  */
  1481.   #include "diff.h"
  1482.   
  1483. ! #ifdef __STDC__
  1484. ! static  void print_normal_hunk(struct change *);
  1485. ! #else
  1486. ! static  void print_normal_hunk ();
  1487.   void print_number_range ();
  1488.   struct change *find_change ();
  1489. + #endif /* __STDC__ */
  1490.   
  1491.   /* Print the edit-script SCRIPT as a normal diff.
  1492.      INF points to an array of descriptions of the two files.  */
  1493. *** e:\tmp/RCSt1005321    Tue Mar 12 17:20:20 1991
  1494. --- util.c    Tue Mar 12 17:19:02 1991
  1495. ***************
  1496. *** 17,24 ****
  1497. --- 17,40 ----
  1498.   along with GNU DIFF; see the file COPYING.  If not, write to
  1499.   the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  1500.   
  1501. + /* MS-DOS port (c) 1990 by Thorsten Ohl, td12@ddagsi3.bitnet
  1502. + This port is also distributed under the terms of the GNU General
  1503. + Public License as published by the Free Software Foundation.
  1504. + Please note that this file is not identical to the original GNU release,
  1505. + you should have received this code as patch to the official release.
  1506. + $Header: e:/gnu/diff/RCS/util.c 1.15.0.2 91/03/12 17:06:46 tho Exp $  */
  1507.   #include "diff.h"
  1508. + #include "regex.h"            /* was missing [tho] */
  1509.   
  1510. + #ifdef MSDOS
  1511. + #include <conio.h>
  1512. + static char *_pipe_file (void);
  1513. + static void cleanup_pipe (void);
  1514. + #endif /* MSDOS */
  1515.   /* Use when a system call returns non-zero status.
  1516.      TEXT should normally be the file name.  */
  1517.   
  1518. ***************
  1519. *** 66,71 ****
  1520. --- 82,97 ----
  1521.     error (message, "");
  1522.     exit (2);
  1523.   }
  1524. + #ifdef MSDOS
  1525. + void
  1526. + fatal_with_name (char *message,char *name)
  1527. + {
  1528. +   print_message_queue ();
  1529. +   error ("%s: %s", name, message);
  1530. +   exit (2);
  1531. + }
  1532. + #endif
  1533.   
  1534.   /* Like printf, except if -l in effect then save the message and print later.
  1535.      This is used for things like "binary files differ" and "Only in ...".  */
  1536. ***************
  1537. *** 131,136 ****
  1538. --- 157,173 ----
  1539.   
  1540.     if (paginate_flag)
  1541.       {
  1542. + #ifdef MSDOS
  1543. +       if ( !(outfile = fopen(_pipe_file (), "w")) )
  1544. +         {
  1545. +       error ("can't pipe to more, using stdout instead.");
  1546. +       outfile = stdout;
  1547. +         }
  1548. + #else
  1549.         int pipes[2];
  1550.         int desc;
  1551.   
  1552. ***************
  1553. *** 162,167 ****
  1554. --- 199,207 ----
  1555.         close (pipes[0]);
  1556.         outfile = fdopen (pipes[1], "w");
  1557.       } 
  1558. + #endif /* MSDOS */
  1559.       }
  1560.     else
  1561.       {
  1562. ***************
  1563. *** 187,194 ****
  1564. --- 227,268 ----
  1565.   {
  1566.     if (outfile != stdout)
  1567.       {
  1568. + #ifdef MSDOS
  1569. + #ifndef PAGER
  1570. + #define PAGER "more"
  1571. + #endif
  1572. + #ifndef PAGER_ARGS
  1573. + #define PAGER_ARGS NULL
  1574. + #endif
  1575. +       int diff_stdin;
  1576. +       int pager_stdin;
  1577. +       fclose (outfile);
  1578. +       diff_stdin = dup (0);
  1579. +       pager_stdin = open (_pipe_file (), O_RDONLY|O_TEXT);
  1580. +       dup2 (pager_stdin, 0);
  1581. +       spawnlp (P_WAIT, PAGER, PAGER, PAGER_ARGS, NULL);
  1582. +       dup2 (diff_stdin, 0);
  1583. +       close (diff_stdin);
  1584. +       close (pager_stdin);
  1585. +       printf ("hit any key to continue...");
  1586. +       while (!kbhit ())
  1587. +     ;
  1588. +       printf ("\n");
  1589. + #else /* not MSDOS */
  1590.         fclose (outfile);
  1591.         wait (0);
  1592. + #endif /* not MSDOS */
  1593.       }
  1594.   }
  1595.   
  1596. ***************
  1597. *** 201,209 ****
  1598.   line_cmp (s1, s2)
  1599.        struct line_def *s1, *s2;
  1600.   {
  1601. !   register char *t1, *t2;
  1602.     register char end_char = line_end_char;
  1603.     int savechar;
  1604.   
  1605.     /* Check first for exact identity.
  1606.        If that is true, return 0 immediately.
  1607. --- 275,287 ----
  1608.   line_cmp (s1, s2)
  1609.        struct line_def *s1, *s2;
  1610.   {
  1611. !   register char _huge *t1, _huge *t2;
  1612.     register char end_char = line_end_char;
  1613. + #ifdef MSDOS
  1614. +   char savechar;
  1615. + #else /* not MSDOS */
  1616.     int savechar;
  1617. + #endif /* not MSDOS */
  1618.   
  1619.     /* Check first for exact identity.
  1620.        If that is true, return 0 immediately.
  1621. ***************
  1622. *** 340,350 ****
  1623. --- 418,435 ----
  1624.      PRINTFUN takes a subscript which belongs together (with a null
  1625.      link at the end) and prints it.  */
  1626.   
  1627. + #ifdef MSDOS
  1628. + void
  1629. + print_script (    struct change *script,
  1630. +         struct change * (*hunkfun) (struct change *),
  1631. +         void (*printfun) (struct change *) )
  1632. + #else
  1633.   void
  1634.   print_script (script, hunkfun, printfun)
  1635.        struct change *script;
  1636.        struct change * (*hunkfun) ();
  1637.        void (*printfun) ();
  1638. + #endif /* MSDOS */
  1639.   {
  1640.     struct change *next = script;
  1641.   
  1642. ***************
  1643. *** 566,571 ****
  1644. --- 651,728 ----
  1645.   
  1646.   /* malloc a block of memory, with fatal error message if we can't do it. */
  1647.   
  1648. + #ifdef MSDOS
  1649. + #include <malloc.h>
  1650. + #include <dos.h>
  1651. + void _huge *
  1652. + xhalloc (long size)
  1653. + {
  1654. +   void _huge *value = (void _huge *) halloc (size, (size_t)1 );
  1655. +   if (!value)
  1656. +     fatal ("virtual memory exhausted");
  1657. +   return value;
  1658. + }
  1659. + /* Here we do a huge "realloc" by allocating a new block and
  1660. +    moving the old block afterwards.  This is *slow*, but should
  1661. +    be reliable.  */
  1662. + void _huge *
  1663. + xhrealloc (void _huge *ptr, long new_size, long old_size)
  1664. + {
  1665. +   void _huge *value = (void _huge *) halloc (new_size, (size_t)1 );
  1666. +   if (!value)
  1667. +     fatal ("virtual memory exhausted");
  1668. +   else
  1669. +     {
  1670. +       char _huge *dest = value;
  1671. +       char _huge *src = ptr;
  1672. +       while (old_size > 0L)
  1673. +     {
  1674. +       unsigned int bytes = (unsigned int) min (0x8000L, old_size);
  1675. +       memcpy (dest, src, bytes);
  1676. +       old_size -= (long) bytes;
  1677. +       dest += (long) bytes;
  1678. +       src += (long) bytes;
  1679. +     }
  1680. +     }
  1681. +   hfree (ptr);
  1682. +   return value;
  1683. + }
  1684. + long        /* doesn't belong here, but is also a 'huge' pointer kludge */
  1685. + hread (int fd, void _huge *buffer, long bytes)
  1686. + {
  1687. +   long bytes_read = 0L;
  1688. +   while (1)
  1689. +     {
  1690. +       int n = read (fd, buffer, (unsigned int) min (0x4000L, bytes));
  1691. +       if (n > 0)
  1692. +     {
  1693. +       bytes_read += (long) n;
  1694. +       bytes -= (long) n;
  1695. +       /* we can't say buffer += n here, because we have to make
  1696. +          sure that the offset of BUFFER doesn't overflow during
  1697. +          the read() system call.  Therefore we add what we read
  1698. +          to the segment of BUFFER.  */
  1699. +       FP_SEG(buffer) += (n >> 4);
  1700. +       FP_OFF(buffer) += (n & 0x0F);
  1701. +     }
  1702. +       else if (n == 0)
  1703. +     return bytes_read;    /* done */
  1704. +       else
  1705. +     pfatal_with_name ("error while reading input");
  1706. +     }
  1707. + }
  1708. + #endif /* MSDOS */
  1709.   VOID *
  1710.   xmalloc (size)
  1711.        unsigned size;
  1712. ***************
  1713. *** 615,620 ****
  1714. --- 772,780 ----
  1715.     return new;
  1716.   }
  1717.   
  1718. + #ifdef MSDOS
  1719. + void
  1720. + #endif /* MSDOS */
  1721.   debug_script (sp)
  1722.        struct change *sp;
  1723.   {
  1724. ***************
  1725. *** 624,626 ****
  1726. --- 784,839 ----
  1727.            sp->line0, sp->line1, sp->deleted, sp->inserted);
  1728.     fflush (stderr);
  1729.   }
  1730. + #ifdef MSDOS
  1731. + static char *pipe_file = NULL;
  1732. + static char *tmpdir = NULL;
  1733. + static int tmpdirlen;
  1734. + /* Return the name of a temporary file.  */
  1735. + char *
  1736. + _pipe_file (void)
  1737. + {
  1738. +   if (!pipe_file)
  1739. +     {
  1740. +       if (!tmpdir)
  1741. +     {
  1742. +       /* Initialize.  */
  1743. +       atexit (cleanup_pipe);
  1744. +       tmpdir = getenv ("TMP");
  1745. +       if (tmpdir)
  1746. +         {
  1747. +           tmpdirlen = strlen (tmpdir);
  1748. +           if (tmpdir[tmpdirlen - 1] == '/'
  1749. +           || tmpdir[tmpdirlen - 1] == '\\')
  1750. +         tmpdir[tmpdirlen - 1] = '\0';
  1751. +         }
  1752. +       else
  1753. +         {
  1754. +           tmpdir = ".";
  1755. +           tmpdirlen = 1;
  1756. +         }
  1757. +     }
  1758. +       pipe_file = (char *) xmalloc (tmpdirlen + 14);
  1759. +       sprintf (pipe_file, "%s/diff%04x", tmpdir, getpid ());
  1760. +     }
  1761. +   return pipe_file;
  1762. + }
  1763. + /* Clean up after we are done. */
  1764. + void
  1765. + cleanup_pipe (void)
  1766. + {
  1767. +   unlink (pipe_file);
  1768. + }
  1769. + #endif /* MSDOS */
  1770. *** e:\tmp/RCSt1005321    Tue Mar 12 17:20:22 1991
  1771. --- version.c    Tue Mar 12 17:19:02 1991
  1772. ***************
  1773. *** 1,3 ****
  1774. --- 1,8 ----
  1775.   /* Version number of GNU diff.  */
  1776.   
  1777. + #ifdef MSDOS
  1778. + char *version_string
  1779. +   =  "1.15 (compiled " __DATE__ " " __TIME__ " for MS-DOS)";
  1780. + #else /* not MSDOS */
  1781.   char *version_string = "1.15";
  1782. + #endif /* not MSDOS */
  1783.