home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / rcs57pc3.zip / diff16 / patches.pc < prev    next >
Text File  |  1996-03-20  |  68KB  |  2,405 lines

  1. diff -cbBw orig/analyze.c new/analyze.c
  2. *** orig/analyze.c    Tue Dec 24 19:13:18 1991
  3. --- new/analyze.c    Tue Dec 24 19:25:12 1991
  4. ***************
  5. *** 1,5 ****
  6. --- 1,7 ----
  7.   /* Analyze file differences for GNU DIFF.
  8.      Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  9. +    Modified for DOS and OS/2 on 1991/09/14 by Kai Uwe Rommel
  10. +     <rommel@ars.muc.de>.
  11.  
  12.   This file is part of GNU DIFF.
  13.  
  14. ***************
  15. *** 32,42 ****
  16. --- 34,49 ----
  17.   void print_normal_script ();
  18.   void print_rcs_script ();
  19.   void pr_forward_ed_script ();
  20. + void print_merged_script ();
  21.   void setup_output ();
  22.  
  23.   extern int no_discards;
  24.  
  25.   static int *xvec, *yvec;    /* Vectors being compared. */
  26. + #ifdef MSDOS
  27. + static int huge *fdiag;
  28. + static int huge *bdiag;
  29. + #else
  30.   static int *fdiag;        /* Vector, indexed by diagonal, containing
  31.                      the X coordinate of the point furthest
  32.                      along the given diagonal in the forward
  33. ***************
  34. *** 45,50 ****
  35. --- 52,58 ----
  36.                      the X coordinate of the point furthest
  37.                      along the given diagonal in the backward
  38.                      search of the edit matrix. */
  39. + #endif
  40.  
  41.   /* Find the midpoint of the shortest edit script for a specified
  42.      portion of the two files.
  43. ***************
  44. *** 75,84 ****
  45. --- 83,99 ----
  46.        int xoff, xlim, yoff, ylim;
  47.        int *cost;
  48.   {
  49. + #ifdef MSDOS
  50. +   int huge *const fd = fdiag;
  51. +   int huge *const bd = bdiag;
  52. +   int huge *const xv = xvec;
  53. +   int huge *const yv = yvec;
  54. + #else
  55.     int *const fd = fdiag;    /* Give the compiler a chance. */
  56.     int *const bd = bdiag;    /* Additional help for the compiler. */
  57.     int *const xv = xvec;        /* Still more help for the compiler. */
  58.     int *const yv = yvec;        /* And more and more . . . */
  59. + #endif
  60.     const int dmin = xoff - ylim;    /* Minimum valid diagonal. */
  61.     const int dmax = xlim - yoff;    /* Maximum valid diagonal. */
  62.     const int fmid = xoff - yoff;    /* Center diagonal of top-down search. */
  63. ***************
  64. *** 719,725 ****
  65.        struct file_data filevec[];
  66.        int depth;
  67.   {
  68. !   int diags;
  69.     int i;
  70.     struct change *e, *p;
  71.     struct change *script;
  72. --- 734,740 ----
  73.        struct file_data filevec[];
  74.        int depth;
  75.   {
  76. !   long diags;
  77.     int i;
  78.     struct change *e, *p;
  79.     struct change *script;
  80. ***************
  81. *** 729,738 ****
  82. --- 744,768 ----
  83.     /* See if the two named files are actually the same physical file.
  84.        If so, we know they are identical without actually reading them.  */
  85.  
  86. + #if !defined(MSDOS)
  87. +       /*
  88. +       ** since MSC always sets the inode and dev fields to zero under DOS
  89. +       ** this test will always think two files are the same.
  90. +       */
  91.     if (output_style != OUTPUT_IFDEF
  92.         && filevec[0].stat.st_ino == filevec[1].stat.st_ino
  93.         && filevec[0].stat.st_dev == filevec[1].stat.st_dev)
  94.       return 0;
  95. + #endif /* MSDOS */
  96. +
  97. +   if (no_details_flag
  98. +       && (filevec[0].stat.st_mode & S_IFMT) == S_IFREG
  99. +       && (filevec[1].stat.st_mode & S_IFMT) == S_IFREG
  100. +       && filevec[0].stat.st_size != filevec[1].stat.st_size)
  101. +     {
  102. +       message ("Files %s and %s differ\n", filevec[0].name, filevec[1].name);
  103. +       return 1;
  104. +     }
  105.  
  106.     binary = read_files (filevec);
  107.  
  108. ***************
  109. *** 743,759 ****
  110.  
  111.     if (binary || no_details_flag)
  112.       {
  113.         int differs = (filevec[0].buffered_chars != filevec[1].buffered_chars
  114.                || bcmp (filevec[0].buffer, filevec[1].buffer,
  115.                     filevec[1].buffered_chars));
  116.         if (differs)
  117. !     message (binary ? "Binary files %s and %s differ\n"
  118. !          : "Files %s and %s differ\n",
  119.            filevec[0].name, filevec[1].name);
  120.  
  121.         for (i = 0; i < 2; ++i)
  122.       if (filevec[i].buffer)
  123.         free (filevec[i].buffer);
  124.         return differs;
  125.       }
  126.  
  127. --- 773,819 ----
  128.  
  129.     if (binary || no_details_flag)
  130.       {
  131. + #if !defined(MSDOS)
  132.         int differs = (filevec[0].buffered_chars != filevec[1].buffered_chars
  133.                || bcmp (filevec[0].buffer, filevec[1].buffer,
  134.                     filevec[1].buffered_chars));
  135. + #else
  136. +       int differs;
  137. +       if(filevec[0].buffered_chars != filevec[1].buffered_chars)
  138. +               differs = 1;
  139. +       else {
  140. +               /*
  141. +               ** we've got to do it in chunks because of our
  142. +               ** poor 16 bit processor
  143. +               */
  144. +               char huge *b0 = filevec[0].buffer;
  145. +               char huge *b1 = filevec[1].buffer;
  146. +               long int count;
  147. +               unsigned int delta;
  148. +               count = filevec[0].buffered_chars;
  149. +               while(count > 0) {
  150. +                       delta = (unsigned)(count > 65000 ? 65000 : count);
  151. +                       if(bcmp(b0,b1,delta) != 0)
  152. +                               break;
  153. +                       count -= delta;
  154. +                       b0 += delta;
  155. +                       b1 += delta;
  156. +               }
  157. +               differs = count != 0;
  158. +       }
  159. + #endif
  160.         if (differs)
  161. !     message (no_details_flag ? "Files %s and %s differ\n"
  162. !          : "Binary files %s and %s differ\n",
  163.            filevec[0].name, filevec[1].name);
  164.  
  165.         for (i = 0; i < 2; ++i)
  166.       if (filevec[i].buffer)
  167. + #ifndef MSDOS
  168.         free (filevec[i].buffer);
  169. + #else
  170. +           hfree (filevec[i].buffer);
  171. + #endif
  172.         return differs;
  173.       }
  174.  
  175. ***************
  176. *** 780,789 ****
  177.  
  178.     xvec = filevec[0].undiscarded;
  179.     yvec = filevec[1].undiscarded;
  180. !   diags = filevec[0].nondiscarded_lines + filevec[1].nondiscarded_lines + 3;
  181.     fdiag = (int *) xmalloc (diags * sizeof (int));
  182. -   fdiag += filevec[1].nondiscarded_lines + 1;
  183.     bdiag = (int *) xmalloc (diags * sizeof (int));
  184.     bdiag += filevec[1].nondiscarded_lines + 1;
  185.  
  186.     files[0] = filevec[0];
  187. --- 840,856 ----
  188.  
  189.     xvec = filevec[0].undiscarded;
  190.     yvec = filevec[1].undiscarded;
  191. !   diags = (long) filevec[0].nondiscarded_lines + filevec[1].nondiscarded_lines + 3;
  192. ! #ifdef MSDOS
  193. !   fdiag = halloc (diags, sizeof (int));
  194. !   bdiag = halloc (diags, sizeof (int));
  195. !   if ( fdiag == NULL || bdiag == NULL )
  196. !     fatal("virtual memory exhausted");
  197. ! #else
  198.     fdiag = (int *) xmalloc (diags * sizeof (int));
  199.     bdiag = (int *) xmalloc (diags * sizeof (int));
  200. + #endif
  201. +   fdiag += filevec[1].nondiscarded_lines + 1;
  202.     bdiag += filevec[1].nondiscarded_lines + 1;
  203.  
  204.     files[0] = filevec[0];
  205. ***************
  206. *** 793,801 ****
  207.             0, filevec[1].nondiscarded_lines);
  208.  
  209.     bdiag -= filevec[1].nondiscarded_lines + 1;
  210. -   free (bdiag);
  211.     fdiag -= filevec[1].nondiscarded_lines + 1;
  212.     free (fdiag);
  213.  
  214.     /* Modify the results slightly to make them prettier
  215.        in cases where that can validly be done.  */
  216. --- 860,873 ----
  217.             0, filevec[1].nondiscarded_lines);
  218.  
  219.     bdiag -= filevec[1].nondiscarded_lines + 1;
  220.     fdiag -= filevec[1].nondiscarded_lines + 1;
  221. + #ifdef MSDOS
  222. +   hfree (bdiag);
  223. +   hfree (fdiag);
  224. + #else
  225. +   free (bdiag);
  226.     free (fdiag);
  227. + #endif
  228.  
  229.     /* Modify the results slightly to make them prettier
  230.        in cases where that can validly be done.  */
  231. ***************
  232. *** 814,828 ****
  233.       {
  234.         setup_output (files[0].name, files[1].name, depth);
  235.  
  236.         switch (output_style)
  237.       {
  238.       case OUTPUT_CONTEXT:
  239. !       print_context_header (files, 0);
  240.         print_context_script (script, 0);
  241.         break;
  242.  
  243.       case OUTPUT_UNIFIED:
  244. !       print_context_header (files, 1);
  245.         print_context_script (script, 1);
  246.         break;
  247.  
  248. --- 886,905 ----
  249.       {
  250.         setup_output (files[0].name, files[1].name, depth);
  251.  
  252. +       if (output_style == OUTPUT_CONTEXT ||
  253. +           output_style == OUTPUT_UNIFIED ||
  254. +           output_patch_flag)
  255. +       print_context_header (files, output_style == OUTPUT_UNIFIED);
  256. +
  257.         switch (output_style)
  258.       {
  259.       case OUTPUT_CONTEXT:
  260. !       /* print_context_header (files, 0); */
  261.         print_context_script (script, 0);
  262.         break;
  263.  
  264.       case OUTPUT_UNIFIED:
  265. !       /* print_context_header (files, 1); */
  266.         print_context_script (script, 1);
  267.         break;
  268.  
  269. ***************
  270. *** 845,850 ****
  271. --- 922,931 ----
  272.       case OUTPUT_IFDEF:
  273.         print_ifdef_script (script);
  274.         break;
  275. +
  276. +     case OUTPUT_MERGED:
  277. +       print_merged_script (script);
  278. +       break;
  279.       }
  280.  
  281.         finish_output ();
  282. ***************
  283. *** 899,907 ****
  284. --- 980,996 ----
  285.  
  286.     for (i = 0; i < 2; ++i)
  287.       {
  288. + #if !defined(MSDOS)
  289.         if (filevec[i].buffer != 0)
  290.       free (filevec[i].buffer);
  291. +
  292.         free (filevec[i].linbuf);
  293. + #else /* MSDOS */
  294. +       if (filevec[i].buffer != 0)
  295. +         hfree (filevec[i].buffer);
  296. +
  297. +       hfree (filevec[i].linbuf);
  298. + #endif
  299.       }
  300.  
  301.     for (e = script; e; e = p)
  302. diff -cbBw orig/context.c new/context.c
  303. *** orig/context.c    Tue Dec 24 19:13:18 1991
  304. --- new/context.c    Tue Dec 24 19:19:06 1991
  305. ***************
  306. *** 1,5 ****
  307. --- 1,7 ----
  308.   /* Context-format output routines for GNU DIFF.
  309.      Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  310. +    Modified for DOS and OS/2 on 1991/09/14 by Kai Uwe Rommel
  311. +     <rommel@ars.muc.de>.
  312.  
  313.   This file is part of GNU DIFF.
  314.  
  315. ***************
  316. *** 43,49 ****
  317.     if (label)
  318.       fprintf (outfile, "%s %s\n", mark, label);
  319.     else if (inf->stat.st_mtime)
  320. !     fprintf (outfile, "%s %s\t%s", mark, inf->name, ctime(&inf->stat.st_mtime));
  321.     else
  322.       /* Don't pretend that standard input is ancient.  */
  323.       fprintf (outfile, "%s %s\n", mark, inf->name);
  324. --- 45,56 ----
  325.     if (label)
  326.       fprintf (outfile, "%s %s\n", mark, label);
  327.     else if (inf->stat.st_mtime)
  328. !   {
  329. !     char *ct = ctime(&inf->stat.st_mtime);
  330. !     /* some ctime()'s return NULL on illegal times
  331. !        which may occur sometimes under DOS ... */
  332. !     fprintf (outfile, "%s %s\t%s", mark, inf->name, ct ? ct : "\n");
  333. !   }
  334.     else
  335.       /* Don't pretend that standard input is ancient.  */
  336.       fprintf (outfile, "%s %s\n", mark, inf->name);
  337. ***************
  338. *** 51,61 ****
  339. --- 58,92 ----
  340.  
  341.   /* Print a header for a context diff, with the file names and dates.  */
  342.  
  343. + #ifdef MSDOS
  344. + void dosname(char *ptr)
  345. + {
  346. +   for ( ; *ptr; ptr++ )
  347. +     if ( *ptr == '\\' )
  348. +       *ptr = '/';
  349. +     /* else
  350. +       *ptr = tolower(*ptr); */
  351. + }
  352. + #endif
  353. +
  354.   void
  355.   print_context_header (inf, unidiff_flag)
  356.        struct file_data *inf;
  357.        int unidiff_flag;
  358.   {
  359. + #ifdef MSDOS
  360. +   dosname(inf[0].name);
  361. +   dosname(inf[1].name);
  362. + #endif
  363. +   if (output_patch_flag)
  364. +     {
  365. +       char *cp = strlen (inf[0].name) <= strlen (inf[1].name)
  366. +         ? inf[0].name : inf[1].name;
  367. +       if (cp[0] == '.' && cp[1] == '/')
  368. +     cp += 2;
  369. +       fprintf (outfile, "Index: %s\n", cp);
  370. +       return;
  371. +     }
  372.     if (unidiff_flag)
  373.       {
  374.         print_context_label ("---", &inf[0], file_label[0]);
  375. ***************
  376. *** 397,403 ****
  377.         script->link = next;
  378.  
  379.         /* If the change is ignorable, mark it.  */
  380. !       script->ignore = (!deletes && !inserts);
  381.  
  382.         /* Advance to the following change.  */
  383.         script = next;
  384. --- 428,434 ----
  385.         script->link = next;
  386.  
  387.         /* If the change is ignorable, mark it.  */
  388. !       script->ignore = (char) (!deletes && !inserts);
  389.  
  390.         /* Advance to the following change.  */
  391.         script = next;
  392. diff -cbBw orig/diff.c new/diff.c
  393. *** orig/diff.c    Tue Dec 24 19:13:20 1991
  394. --- new/diff.c    Tue Dec 24 19:26:04 1991
  395. ***************
  396. *** 1,5 ****
  397. --- 1,7 ----
  398.   /* GNU DIFF main routine.
  399.      Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  400. +    Modified for DOS and OS/2 on 1991/09/14 by Kai Uwe Rommel
  401. +     <rommel@ars.muc.de>.
  402.  
  403.   This file is part of GNU DIFF.
  404.  
  405. ***************
  406. *** 95,100 ****
  407. --- 97,103 ----
  408.     {"print", 0, 0, 'l'},
  409.     {"rcs", 0, 0, 'n'},
  410.     {"show-c-function", 0, 0, 'p'},
  411. +   {"patch", 0, 0, 'P'},
  412.     {"binary", 0, 0, 'q'},
  413.     {"brief", 0, 0, 'q'},
  414.     {"recursive", 0, 0, 'r'},
  415. ***************
  416. *** 139,153 ****
  417.     paginate_flag = FALSE;
  418.     ifdef_string = NULL;
  419.     heuristic = FALSE;
  420.     dir_start_file = NULL;
  421.     msg_chain = NULL;
  422.     msg_chain_end = NULL;
  423.     no_discards = 0;
  424.  
  425.     /* Decode the options.  */
  426.  
  427.     while ((c = getopt_long (argc, argv,
  428. !                "0123456789abBcC:dD:efF:hHiI:lL:nNpqrsS:tTuvw",
  429.                  longopts, &longind)) != EOF)
  430.       {
  431.         if (c == 0)        /* Long option. */
  432. --- 142,158 ----
  433.     paginate_flag = FALSE;
  434.     ifdef_string = NULL;
  435.     heuristic = FALSE;
  436. +   output_patch_flag = 0;
  437.     dir_start_file = NULL;
  438.     msg_chain = NULL;
  439.     msg_chain_end = NULL;
  440.     no_discards = 0;
  441. +   line_width = 0;
  442.  
  443.     /* Decode the options.  */
  444.  
  445.     while ((c = getopt_long (argc, argv,
  446. !                "0123456789abBcC:dD:efF:hHiI:lL:mM:nNpPqrsS:tTuvw",
  447.                  longopts, &longind)) != EOF)
  448.       {
  449.         if (c == 0)        /* Long option. */
  450. ***************
  451. *** 283,288 ****
  452. --- 288,305 ----
  453.           fatal ("too many file label options");
  454.         break;
  455.  
  456. +     case 'm':
  457. +       /* Make output merged in side-by-side display. */
  458. +       specify_style (OUTPUT_MERGED);
  459. +       line_width = 80;
  460. +       break;
  461. +
  462. +     case 'M':
  463. +       /* Make output merged in side-by-side display. */
  464. +       specify_style (OUTPUT_MERGED);
  465. +       line_width = atoi(optarg);
  466. +       break;
  467. +
  468.       case 'n':
  469.         /* Output RCS-style diffs, like `-f' except that each command
  470.            specifies the number of lines affected.  */
  471. ***************
  472. *** 301,306 ****
  473. --- 318,327 ----
  474.         function_regexp = "^[_a-zA-Z]";
  475.         break;
  476.  
  477. +     case 'P':
  478. +       output_patch_flag = 1;
  479. +       break;
  480. +
  481.       case 'q':
  482.         no_details_flag = 1;
  483.         break;
  484. ***************
  485. *** 399,411 ****
  486.     exit (val);
  487.   }
  488.  
  489.   usage ()
  490.   {
  491.     fprintf (stderr, "\
  492. ! Usage: diff [-#] [-abBcdefhHilnNprstTuvw] [-C lines] [-F regexp] [-I regexp]\n\
  493.          [-L label [-L label]] [-S file] [-D symbol] [+ignore-blank-lines]\n\
  494.          [+context[=lines]] [+unified[=lines]] [+ifdef=symbol]\n\
  495. !        [+show-function-line=regexp]\n");
  496.     fprintf (stderr, "\
  497.          [+speed-large-files] [+ignore-matching-lines=regexp] [+new-file]\n\
  498.          [+initial-tab] [+starting-file=file] [+text] [+all-text] [+ascii]\n\
  499. --- 420,497 ----
  500.     exit (val);
  501.   }
  502.  
  503. + #ifdef MSDOS
  504. + extern char *version_string;
  505. +
  506. + usage()
  507. + {
  508. +   printf("\nGNU diff, version %s\n", version_string);
  509. +
  510. +   printf("\nUsage: %s [-options] file1 file2\n\n", program);
  511. +   printf(
  512. +   "  -c      Make context-style output.\n"
  513. +   "  -p      Make context-style output and show name of last C function.\n"
  514. +   "  -C n    Make context-style output and define context size to be n lines.\n"
  515. +   "  -u      Make unified-context-style output.\n"
  516. +   "  -D      Make merged #ifdef output.\n"
  517. +   "  -e      Make output that is a valid `ed' script.\n"
  518. +   "  -f      Make output that looks vaguely like an `ed' script\n"
  519. +   "          but has changes in the order they appear in the file.\n"
  520. +   "  -n      Make RCS-style output, like `-f' except that each command\n"
  521. +   "          specifies the number of lines affected.\n"
  522. +   "  -m      Make side-by-side merged output.\n"
  523. +   "  -M n    Make side-by-side merged output and specify page-width.\n\n"
  524. +   );
  525. +   printf(
  526. +   "  -[0-9]  digits combined into decimal to specify the context-size.\n"
  527. +   "  -a      Treat all files as text files; never treat as binary.\n"
  528. +   "  -b      Ignore changes in amount of whitespace.\n"
  529. +   "  -B      Ignore changes affecting only blank lines.\n"
  530. +   "  -d      Don't discard lines. This makes things slower (sometimes much\n"
  531. +   "          slower) but will find a guaranteed minimal set of changes.\n"
  532. +   );
  533. +   printf(
  534. +   "  -F re   Show, for each set of changes, the previous line that matches the\n"
  535. +   "          specified regexp. Currently affects only context-style output.\n"
  536. +   "  -h      Split the files into chunks of around 1500 lines\n"
  537. +   "          for faster processing. Usually does not change the result.\n"
  538. +   "  -H      Use heuristic.\n"
  539. +   "  -i      Ignore changes in case.\n"
  540. +   "  -I re   Ignore changes affecting only lines that match the specified regexp.\n"
  541. +   "  -l      Pass the output through `pr' to paginate it.\n"
  542. +   "  -L label [-L label]\n"
  543. +   "          Use the specified label in file header lines output by the -c option.\n"
  544. +   );
  545. +   printf(
  546. +   "  -N      When comparing directories, if a file appears only in one\n"
  547. +   "          directory, treat it as present but empty in the other.\n"
  548. +   "  -P      Create patch headers (Index: ...).\n"
  549. +   "  -q      Treat all files as binaries.\n"
  550. +   "  -r      When comparing directories, recursively compare subdir's found.\n"
  551. +   "  -s      Print a message if the files are the same.\n"
  552. +   );
  553. +   printf(
  554. +   "  -S file When comparing directories, start with the specified\n"
  555. +   "          file name. This is used for resuming an aborted comparison.\n"
  556. +   "  -t      Expand tabs to spaces in the output so that it preserves\n"
  557. +   "          the alignment of the input files.\n"
  558. +   "  -T      Use a tab in the output, rather than a space, before the\n"
  559. +   "          text of an input line, so as to keep the proper alignment\n"
  560. +   "          in the input line without changing the characters in it.\n"
  561. +   "  -v      Print version number.\n"
  562. +   "  -w      Ignore horizontal whitespace when comparing lines.\n"
  563. +   );
  564. +
  565. +   exit(2);
  566. + }
  567. + #else
  568.   usage ()
  569.   {
  570.     fprintf (stderr, "\
  571. ! Usage: diff [-#] [-abBcdefhHilnNpPrstTuvw] [-C lines] [-F regexp] [-I regexp]\n\
  572.          [-L label [-L label]] [-S file] [-D symbol] [+ignore-blank-lines]\n\
  573.          [+context[=lines]] [+unified[=lines]] [+ifdef=symbol]\n\
  574. !        [+show-function-line=regexp] [+patch]\n");
  575.     fprintf (stderr, "\
  576.          [+speed-large-files] [+ignore-matching-lines=regexp] [+new-file]\n\
  577.          [+initial-tab] [+starting-file=file] [+text] [+all-text] [+ascii]\n\
  578. ***************
  579. *** 416,421 ****
  580. --- 502,508 ----
  581.          [+file-label=label [+file-label=label]] [+version] path1 path2\n");
  582.     exit (2);
  583.   }
  584. + #endif
  585.  
  586.   specify_style (style)
  587.        enum output_style style;
  588. ***************
  589. *** 455,460 ****
  590. --- 542,548 ----
  591.       {
  592.         char *name = name0 == 0 ? name1 : name0;
  593.         char *dir = name0 == 0 ? dir1 : dir0;
  594. +       if (!output_patch_flag)
  595.         message ("Only in %s: %s\n", dir, name);
  596.         /* Return 1 so that diff_dirs will return 1 ("some files differ").  */
  597.         return 1;
  598. ***************
  599. *** 506,511 ****
  600. --- 594,606 ----
  601.       }
  602.       }
  603.  
  604. + #if !defined(MSDOS)
  605. +       /*
  606. +       ** this stuff is real bad idea under MSDOS, at least for MSC 5.1
  607. +       ** because the st_ino and st_dev fields are not supported by
  608. +       ** MSDOS, and so stat sets them to zero; therefore
  609. +       ** this test always succeeds.
  610. +       */
  611.     /* See if the two named files are actually the same physical file.
  612.        If so, we know they are identical without actually reading them.  */
  613.  
  614. ***************
  615. *** 518,523 ****
  616. --- 613,619 ----
  617.         val = 0;
  618.         goto done;
  619.       }
  620. + #endif        /* MSDOS */
  621.  
  622.     if (name0 == 0)
  623.       inf[0].dir_p = inf[1].dir_p;
  624. ***************
  625. *** 536,545 ****
  626.         inf[i].name = Standard_Input;
  627.       }
  628.         /* Don't bother opening if stat already failed.  */
  629. !       else if (stat_result[i] == 0 && ! inf[i].dir_p)
  630.       {
  631.         char *filename = inf[i].name;
  632. !
  633.         inf[i].desc = open (filename, O_RDONLY, 0);
  634.         if (0 > inf[i].desc)
  635.           {
  636. --- 632,650 ----
  637.         inf[i].name = Standard_Input;
  638.       }
  639.         /* Don't bother opening if stat already failed.  */
  640. !       else if (stat_result[i] == 0)
  641.       {
  642.         char *filename = inf[i].name;
  643. ! #if !defined(MSDOS)
  644. !       inf[i].desc = open (filename, O_RDONLY, 0);
  645. !       if (0 > inf[i].desc)
  646. !         {
  647. !           perror_with_name (filename);
  648. !           errorcount = 1;
  649. !         }
  650. ! #else
  651. !           if(inf[i].dir_p == 0)
  652. !           {
  653.         inf[i].desc = open (filename, O_RDONLY, 0);
  654.         if (0 > inf[i].desc)
  655.           {
  656. ***************
  657. *** 546,554 ****
  658. --- 651,667 ----
  659.             perror_with_name (filename);
  660.             errorcount = 1;
  661.           }
  662. +           } else
  663. +                 inf[i].desc = 0;
  664. + #endif    /* MSDOS */
  665.       }
  666.       }
  667.  
  668. +   if (name0 == 0)
  669. +     inf[0].dir_p = inf[1].dir_p;
  670. +   if (name1 == 0)
  671. +     inf[1].dir_p = inf[0].dir_p;
  672. +
  673.     if (errorcount)
  674.       {
  675.  
  676. ***************
  677. *** 568,573 ****
  678. --- 681,687 ----
  679.       {
  680.         /* But don't compare dir contents one level down
  681.            unless -r was specified.  */
  682. +       if (!output_patch_flag)
  683.         message ("Common subdirectories: %s and %s\n",
  684.              inf[0].name, inf[1].name);
  685.         val = 0;
  686. ***************
  687. *** 637,642 ****
  688. --- 751,757 ----
  689.         else
  690.           {
  691.             char *dir = (inf[0].desc == -1) ? dir1 : dir0;
  692. +           if (!output_patch_flag)
  693.             message ("Only in %s: %s\n", dir, name0);
  694.             val = 1;
  695.           }
  696. diff -cbBw orig/diff.h new/diff.h
  697. *** orig/diff.h    Tue Dec 24 19:13:22 1991
  698. --- new/diff.h    Tue Dec 24 19:19:10 1991
  699. ***************
  700. *** 1,5 ****
  701. --- 1,7 ----
  702.   /* Shared definitions for GNU DIFF
  703.      Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  704. +    Modified for DOS and OS/2 on 1991/09/14 by Kai Uwe Rommel
  705. +     <rommel@ars.muc.de>.
  706.  
  707.   This file is part of GNU DIFF.
  708.  
  709. ***************
  710. *** 20,28 ****
  711. --- 22,36 ----
  712.  
  713.   #include <ctype.h>
  714.   #include <stdio.h>
  715. + #ifdef __TURBOC__
  716. + #include <types.h>
  717. + #else
  718.   #include <sys/types.h>
  719. + #endif
  720.   #include <sys/stat.h>
  721.  
  722. + #include <string.h>
  723. +
  724.   #ifdef USG
  725.   #include <time.h>
  726.   #ifdef HAVE_NDIR
  727. ***************
  728. *** 32,38 ****
  729. --- 40,48 ----
  730.   #include <ndir.h>
  731.   #endif /* not NDIR_IN_SYS */
  732.   #else
  733. + #ifndef MSDOS
  734.   #include <dirent.h>
  735. + #endif
  736.   #endif /* not HAVE_NDIR */
  737.   #include <fcntl.h>
  738.   #ifndef HAVE_DIRECT
  739. ***************
  740. *** 47,59 ****
  741. --- 57,75 ----
  742.   #ifdef USG
  743.   /* Define needed BSD functions in terms of sysV library.  */
  744.  
  745. + #ifdef MSDOS
  746. + #define bcopy(s,d,n)    memmove((d),(s),(n))
  747. + #else
  748.   #define bcopy(s,d,n)    memcpy((d),(s),(n))
  749. + #endif
  750.   #define bcmp(s1,s2,n)    memcmp((s1),(s2),(n))
  751.   #define bzero(s,n)    memset((s),0,(n))
  752.  
  753.   #ifndef XENIX
  754. + #ifndef MSDOS
  755.   #define dup2(f,t)    (close(t),fcntl((f),F_DUPFD,(t)))
  756.   #endif
  757. + #endif
  758.  
  759.   #define vfork    fork
  760.   #define index    strchr
  761. ***************
  762. *** 65,81 ****
  763. --- 81,106 ----
  764.   #define vfork fork
  765.   #endif
  766.   
  767. + #ifdef MSDOS
  768. + #include <process.h>
  769. + #include <stdlib.h>
  770. + #endif /* MSDOS */
  771. +
  772.   #include <errno.h>
  773. + #if !defined(MSDOS)
  774.   extern int      errno;
  775.   extern int      sys_nerr;
  776.   extern char    *sys_errlist[];
  777. + #endif
  778.  
  779.   #define    EOS        (0)
  780.   #define    FALSE        (0)
  781.   #define TRUE        1
  782.  
  783. + #if !defined(min)
  784.   #define min(a,b) ((a) <= (b) ? (a) : (b))
  785.   #define max(a,b) ((a) >= (b) ? (a) : (b))
  786. + #endif /* MSDOS */
  787.  
  788.   #ifndef PR_FILE_NAME
  789.   #define PR_FILE_NAME "/bin/pr"
  790. ***************
  791. *** 83,96 ****
  792.  
  793.   /* Support old-fashioned C compilers.  */
  794.   #if defined (__STDC__) || defined (__GNUC__)
  795.   #include "limits.h"
  796.   #else
  797.   #define INT_MAX 2147483647
  798.   #define CHAR_BIT 8
  799.   #endif
  800.  
  801.   /* Support old-fashioned C compilers.  */
  802. ! #if !defined (__STDC__) && !defined (__GNUC__)
  803.   #define const
  804.   #endif
  805.  
  806. --- 108,144 ----
  807.  
  808.   /* Support old-fashioned C compilers.  */
  809.   #if defined (__STDC__) || defined (__GNUC__)
  810. + #if !defined(MSDOS)
  811.   #include "limits.h"
  812.   #else
  813. + #include <limits.h>
  814. + #endif        /* MSDOS */
  815. + #else
  816.   #define INT_MAX 2147483647
  817.   #define CHAR_BIT 8
  818.   #endif
  819.  
  820. + #if defined(MSDOS)
  821. + #ifdef INT_MAX
  822. + #undef INT_MAX
  823. + #include <limits.h>
  824. + #endif
  825. + #ifdef __TURBOC__
  826. + #include <alloc.h>
  827. + #include <mem.h>
  828. + #define halloc(n, s) farmalloc((long) n * s)
  829. + #define hrealloc(x, s, o) farrealloc(x, s)
  830. + #define hfree(x) farfree(x)
  831. + #else
  832. + #include <malloc.h>
  833. + #include <memory.h>
  834. + #endif
  835. + #include <io.h>
  836. + extern int getopt(int nargc,char **nargv,char *ostr);
  837. + #endif
  838. +
  839.   /* Support old-fashioned C compilers.  */
  840. ! #if !defined (__STDC__) && !defined (__GNUC__) || defined(MSDOS)
  841.   #define const
  842.   #endif
  843.  
  844. ***************
  845. *** 120,126 ****
  846.     /* Like -f, but output a count of changed lines in each "command" (-n). */
  847.     OUTPUT_RCS,
  848.     /* Output merged #ifdef'd file (-D).  */
  849. !   OUTPUT_IFDEF };
  850.  
  851.   /* True for output styles that are robust,
  852.      i.e. can handle a file that ends in a non-newline.  */
  853. --- 168,177 ----
  854.     /* Like -f, but output a count of changed lines in each "command" (-n). */
  855.     OUTPUT_RCS,
  856.     /* Output merged #ifdef'd file (-D).  */
  857. !   OUTPUT_IFDEF,
  858. !   /* Output merged in side-by-side display (-m). */
  859. !   OUTPUT_MERGED
  860. ! };
  861.  
  862.   /* True for output styles that are robust,
  863.      i.e. can handle a file that ends in a non-newline.  */
  864. ***************
  865. *** 199,204 ****
  866. --- 250,258 ----
  867.   /* Pipe each file's output through pr (-l).  */
  868.   EXTERN int    paginate_flag;
  869.  
  870. + /* Line width for the merged display (-m,-M).  */
  871. + EXTERN int    line_width;
  872. +
  873.   /* String to use for #ifdef (-D).  */
  874.   EXTERN char *    ifdef_string;
  875.  
  876. ***************
  877. *** 210,215 ****
  878. --- 264,272 ----
  879.   /* Nonzero means use heuristics for better speed.  */
  880.   EXTERN int    heuristic;
  881.  
  882. + /* Reduce extraneous output when they're outputting a patch. */
  883. + EXTERN int    output_patch_flag;
  884. +
  885.   /* Name of program the user invoked (for error messages).  */
  886.   EXTERN char *    program;
  887.   
  888. ***************
  889. *** 239,245 ****
  890. --- 296,306 ----
  891.   /* Data on one line of text.  */
  892.  
  893.   struct line_def {
  894. + #ifdef MSDOS
  895. +     char huge   *text;
  896. + #else
  897.       char        *text;
  898. + #endif
  899.       int         length;
  900.       unsigned    hash;
  901.   };
  902. ***************
  903. *** 252,257 ****
  904. --- 313,319 ----
  905.       struct stat     stat;    /* File status from fstat()  */
  906.       int             dir_p;    /* 1 if file is a directory  */
  907.  
  908. + #if !defined(MSDOS)
  909.       /* Buffer in which text of file is read.  */
  910.       char *        buffer;
  911.       /* Allocated size of buffer.  */
  912. ***************
  913. *** 279,284 ****
  914. --- 341,375 ----
  915.  
  916.       /* Count of lines in the suffix. */
  917.       int suffix_lines;
  918. + #else /* MSDOS */
  919. +     /* Buffer in which text of file is read.  */
  920. +     char huge *buffer;
  921. +     /* Allocated size of buffer.  */
  922. +     long int        bufsize;
  923. +     /* Number of valid characters now in the buffer. */
  924. +     long int        buffered_chars;
  925. +
  926. +     /* Array of data on analyzed lines of this chunk of this file.  */
  927. +     struct line_def huge *linbuf;
  928. +
  929. +     /* Allocated size of linbuf array (# of elements).  */
  930. +     int            linbufsize;
  931. +
  932. +     /* Number of elements of linbuf containing valid data. */
  933. +     int            buffered_lines;
  934. +
  935. +     /* Pointer to end of prefix of this file to ignore when hashing. */
  936. +     char huge *prefix_end;
  937. +
  938. +     /* Count of lines in the prefix. */
  939. +     int prefix_lines;
  940. +
  941. +     /* Pointer to start of suffix of this file to ignore when hashing. */
  942. +     char huge *suffix_begin;
  943. +
  944. +     /* Count of lines in the suffix. */
  945. +     int suffix_lines;
  946. + #endif        /* MSDOS */
  947.  
  948.       /* Vector, indexed by line number, containing an equivalence code for
  949.          each line.  It is this vector that is actually compared with that
  950. ***************
  951. *** 318,324 ****
  952. --- 409,419 ----
  953.  
  954.   /* Describe the two files currently being compared.  */
  955.  
  956. + #if !defined(GDIFF_MAIN)
  957. + extern struct file_data files[2];
  958. + #else
  959.   struct file_data files[2];
  960. + #endif
  961.   
  962.   /* Queue up one-line messages to be printed at the end,
  963.      when -l is specified.  Each message is recorded with a `struct msg'.  */
  964. ***************
  965. *** 366,370 ****
  966. --- 461,476 ----
  967.   void print_1_line ();
  968.   void print_message_queue ();
  969.   void print_number_range ();
  970. +
  971. + #ifdef MSDOS
  972. + #ifndef __TURBOC__
  973. + void huge *hrealloc(void huge *, long, long);
  974. + #endif
  975. + #endif
  976.   void print_script ();
  977.   void translate_range ();
  978. +
  979. +
  980. + #ifdef PROTO
  981. + #include "proto.h"
  982. + #endif
  983. diff -cbBw orig/diff3.c new/diff3.115
  984. *** orig/diff3.c    Tue Dec 24 19:13:24 1991
  985. --- new/diff3.115    Tue Dec 24 19:26:32 1991
  986. ***************
  987. *** 1,5 ****
  988. --- 1,7 ----
  989.   /* Three-way file comparison program (diff3) for Project GNU
  990.      Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  991. +    Modified for DOS and OS/2 on 1991/09/14 by Kai Uwe Rommel
  992. +     <rommel@ars.muc.de>.
  993.  
  994.      This program is free software; you can redistribute it and/or modify
  995.      it under the terms of the GNU General Public License as published by
  996. ***************
  997. *** 29,37 ****
  998. --- 31,67 ----
  999.    */
  1000.   #include <stdio.h>
  1001.   #include <ctype.h>
  1002. + #ifdef __TURBOC__
  1003. + #include <types.h>
  1004. + #else
  1005.   #include <sys/types.h>
  1006. + #endif
  1007.   #include <sys/stat.h>
  1008.  
  1009. + #include <getopt.h>
  1010. +
  1011. + #ifdef MSDOS
  1012. +
  1013. + #include <stdlib.h>
  1014. +
  1015. + extern FILE *popen(char *, char *);
  1016. + extern int pclose(FILE *);
  1017. +
  1018. + #define WEXITSTATUS(stat_val)  (stat_val & 255)
  1019. + #define WIFEXITED(stat_val)    (((unsigned)stat_val >> 8) == 0)
  1020. + /* pclose() returns status in inverse byte order than wait() does */
  1021. +
  1022. + #define bcopy(s,d,n)    memmove((d),(s),(n))
  1023. + #define bcmp(s1,s2,n)    memcmp((s1),(s2),(n))
  1024. + #define bzero(s,n)    memset((s),0,(n))
  1025. +
  1026. + #define index    strchr
  1027. + #define rindex    strrchr
  1028. +
  1029. + #else  /* MSDOS */
  1030. +
  1031. + extern char **environ;
  1032. +
  1033.   #ifdef USG
  1034.   #include <fcntl.h>
  1035.  
  1036. ***************
  1037. *** 58,63 ****
  1038. --- 88,95 ----
  1039.   #define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
  1040.   #endif
  1041.  
  1042. + #endif /* MSDOS */
  1043. +
  1044.   #ifdef sparc
  1045.   /* vfork clobbers registers on the Sparc, so don't use it.  */
  1046.   #define vfork fork
  1047. ***************
  1048. *** 281,297 ****
  1049.     struct diff3_block *diff;
  1050.     int tag_count = 0;
  1051.     /* Element 0 is for file 0, element 1 is for file 2.  */
  1052. !   char *tag_strings[2];
  1053.     extern char *optarg;
  1054.     char *commonname;
  1055.     struct stat statb;
  1056.   
  1057.     incompat = 0;
  1058. !   tag_strings[0] = tag_strings[1] = 0;
  1059.   
  1060.     argv0 = argv[0];
  1061.     
  1062. !   while ((c = getopt (argc, argv, "aeimx3EXL:")) != EOF)
  1063.       {
  1064.         switch (c)
  1065.       {
  1066. --- 281,297 ----
  1067.     struct diff3_block *diff;
  1068.     int tag_count = 0;
  1069.     /* Element 0 is for file 0, element 1 is for file 2.  */
  1070. !   char *tag_strings[3];
  1071.     extern char *optarg;
  1072.     char *commonname;
  1073.     struct stat statb;
  1074.   
  1075.     incompat = 0;
  1076. !   tag_strings[0] = tag_strings[1] = tag_strings[2] = 0;
  1077.   
  1078.     argv0 = argv[0];
  1079.     
  1080. !   while ((c = getopt (argc, argv, "aeimx3AEXL:")) != EOF)
  1081.       {
  1082.         switch (c)
  1083.       {
  1084. ***************
  1085. *** 315,320 ****
  1086. --- 315,321 ----
  1087.       case 'X':
  1088.         dont_write_simple = 1;
  1089.         /* Falls through */
  1090. +     case 'A':
  1091.       case 'E':
  1092.         flagging = 1;
  1093.         /* Falls through */
  1094. ***************
  1095. *** 323,329 ****
  1096.         break;
  1097.       case 'L':
  1098.         /* Handle one or two -L arguments.  */
  1099. !       if (tag_count < 2)
  1100.           {
  1101.             tag_strings[tag_count++] = optarg;
  1102.             break;
  1103. --- 324,330 ----
  1104.         break;
  1105.       case 'L':
  1106.         /* Handle one or two -L arguments.  */
  1107. !       if (tag_count < 3)
  1108.           {
  1109.             tag_strings[tag_count++] = optarg;
  1110.             break;
  1111. ***************
  1112. *** 345,350 ****
  1113. --- 346,355 ----
  1114.         || tag_count && ! flagging /* -L requires one of -EX.  */
  1115.         || argc - optind != 3)
  1116.       usage ();
  1117. +   /* ignore the second of *three* -L arguments! */
  1118. +   if (tag_strings[2] != 0)
  1119. +     tag_strings[1] = tag_strings[2];
  1120.   
  1121.     if (tag_strings[0] == 0)
  1122.       tag_strings[0] = argv[optind];
  1123. ***************
  1124. *** 390,398 ****
  1125.   void
  1126.   usage ()
  1127.   {
  1128. !   fprintf (stderr, "Usage:\t%s [-exEX3 [-i | -m] [-L label1 -L label3]] file1 file2 file3\n",
  1129.          argv0);
  1130. !   fprintf (stderr, "\tOnly one of [exEX3] allowed\n");
  1131.     exit (2);
  1132.   }
  1133.   
  1134. --- 422,444 ----
  1135.   void
  1136.   usage ()
  1137.   {
  1138. !   extern char *version_string;
  1139. !
  1140. !   printf ("\nGNU diff3, version %s\n", version_string);
  1141. !   printf ("\nUsage:\t%s [-exEX3 [-a] [-i | -m] [-L label1 -L label3]] file1 file2 file3\n",
  1142.          argv0);
  1143. !
  1144. !   printf ("\n  -e   Create ed script."
  1145. !           "\n  -x   ED script, write only overlapping diffs."
  1146. !           "\n  -E   ED script, flag overlapping diffs."
  1147. !           "\n  -X   ED script, write and flag only overlapping diffs."
  1148. !           "\n  -3   ED script, write only non-overlapping diffs."
  1149. !           "\n  -a   Treat all files as text, never as binary."
  1150. !           "\n  -i   Like -e, but append final :wq commands."
  1151. !           "\n  -m   Output a merged file."
  1152. !           "\n  -L label   use the specified label for lines output by the -E and -X options.\n");
  1153. !
  1154. !   printf ("\nOnly one of [exEX3] is allowed.\n");
  1155.     exit (2);
  1156.   }
  1157.   
  1158. ***************
  1159. *** 960,967 ****
  1160.    * Routines to input and parse two way diffs.
  1161.    */
  1162.  
  1163. - extern char **environ;
  1164. -
  1165.   #define    DIFF_CHUNK_SIZE    10000
  1166.  
  1167.   struct diff_block *
  1168. --- 1006,1011 ----
  1169. ***************
  1170. *** 1170,1182 ****
  1171. --- 1214,1233 ----
  1172.        char *filea, *fileb;
  1173.        char **output_placement;
  1174.   {
  1175. + #ifndef MSDOS
  1176.     char *argv[6];
  1177.     char **ap;
  1178. + #endif
  1179.     int fds[2];
  1180.     char *diff_result;
  1181.     int current_chunk_size;
  1182.     int bytes;
  1183.     int total;
  1184. + #ifdef MSDOS
  1185. +   FILE *pipe;
  1186. +   char buffer[256];
  1187. +   int wstatus;
  1188. + #else
  1189.     int pid, w;
  1190.     int wstatus;
  1191.  
  1192. ***************
  1193. *** 1188,1194 ****
  1194. --- 1239,1251 ----
  1195.     *ap++ = filea;
  1196.     *ap++ = fileb;
  1197.     *ap = (char *) 0;
  1198. + #endif
  1199.  
  1200. + #ifdef MSDOS
  1201. +   sprintf(buffer, "%s -a -- %s %s", diff_program, filea, fileb);
  1202. +   pipe = popen(buffer, "r");
  1203. +   fds[0] = fileno(pipe);
  1204. + #else
  1205.     if (pipe (fds) < 0)
  1206.       perror_with_exit ("Pipe failed");
  1207.  
  1208. ***************
  1209. *** 1213,1218 ****
  1210. --- 1270,1276 ----
  1211.       perror_with_exit ("Fork failed");
  1212.  
  1213.     close (fds[1]);        /* Prevent erroneous lack of EOF */
  1214. + #endif
  1215.     current_chunk_size = DIFF_CHUNK_SIZE;
  1216.     diff_result = (char *) xmalloc (current_chunk_size);
  1217.     total = 0;
  1218. ***************
  1219. *** 1222,1228 ****
  1220. --- 1280,1291 ----
  1221.               current_chunk_size - total);
  1222.       total += bytes;
  1223.       if (total == current_chunk_size)
  1224. + #ifdef MSDOS
  1225. +       diff_result = (char *) xrealloc (diff_result,
  1226. +         (current_chunk_size += DIFF_CHUNK_SIZE));
  1227. + #else
  1228.         diff_result = (char *) xrealloc (diff_result, (current_chunk_size *= 2));
  1229. + #endif
  1230.     } while (bytes);
  1231.  
  1232.     if (total != 0 && diff_result[total-1] != '\n')
  1233. ***************
  1234. *** 1230,1239 ****
  1235. --- 1293,1306 ----
  1236.  
  1237.     *output_placement = diff_result;
  1238.  
  1239. + #ifdef MSDOS
  1240. +   wstatus = pclose(pipe);
  1241. + #else
  1242.     do
  1243.       if ((w = wait (&wstatus)) == -1)
  1244.         perror_with_exit ("Wait failed");
  1245.     while (w != pid);
  1246. + #endif
  1247.  
  1248.     if (! (WIFEXITED (wstatus) && WEXITSTATUS (wstatus) < 2))
  1249.       fatal ("Subsidiary diff failed");
  1250. ***************
  1251. *** 1332,1338 ****
  1252.       case DIFF_3RD:
  1253.         oddoneout = rev_mapping[(int) ptr->correspond - (int) DIFF_1ST];
  1254.  
  1255. !       x[0] = oddoneout + '1';
  1256.         x[1] = '\0';
  1257.         dontprint = oddoneout==0;
  1258.         break;
  1259. --- 1399,1405 ----
  1260.       case DIFF_3RD:
  1261.         oddoneout = rev_mapping[(int) ptr->correspond - (int) DIFF_1ST];
  1262.  
  1263. !       x[0] = (char) (oddoneout + '1');
  1264.         x[1] = '\0';
  1265.         dontprint = oddoneout==0;
  1266.         break;
  1267. diff -cbBw orig/dir.c new/dir.c
  1268. *** orig/dir.c    Tue Dec 24 19:13:24 1991
  1269. --- new/dir.c    Tue Dec 24 19:37:14 1991
  1270. ***************
  1271. *** 1,5 ****
  1272. --- 1,7 ----
  1273.   /* Read, sort and compare two directories.  Used for GNU DIFF.
  1274.      Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  1275. +    Modified for DOS and OS/2 on 1991/09/14 by Kai Uwe Rommel
  1276. +     <rommel@ars.muc.de>.
  1277.  
  1278.   This file is part of GNU DIFF.
  1279.  
  1280. ***************
  1281. *** 31,36 ****
  1282. --- 33,203 ----
  1283.     char **files;            /* Sorted names of files in the dir */
  1284.   };
  1285.  
  1286. + #if defined(MSDOS)
  1287. + /*
  1288. + ** due to difference of opinion btw gnu and microsoft about what
  1289. + ** const means, const is defined away in diff.h, which causes warnings
  1290. + ** when compiling the headers.  This ugliness is avoided here.
  1291. + */
  1292. + #ifdef const
  1293. + #undef const
  1294. + #endif
  1295. + #include <string.h>
  1296. + #include <ctype.h>
  1297. + #ifdef OS2
  1298. + #define strcmp stricmp
  1299. +   /* stricmp() this is important for the HPFS because it is
  1300. +   /* case-preserving but NOT case-sensitive */
  1301. + #include <stdlib.h>
  1302. + #define INCL_NOPM
  1303. + #include <os2.h>
  1304. + #define _A_NORMAL        0x00
  1305. + #define _A_SUBDIR        0x10
  1306. + #ifndef _MAX_NAME
  1307. + #define _MAX_NAME        256
  1308. + #endif
  1309. + #else
  1310. + #ifdef __TURBOC__
  1311. + #include <dir.h>
  1312. + #define _A_NORMAL        0x00
  1313. + #define _A_SUBDIR        0x10
  1314. + #endif
  1315. + #include <dos.h>
  1316. + #define _MAX_NAME        13
  1317. + #endif
  1318. +
  1319. + struct direct {
  1320. +     char d_name[_MAX_NAME];
  1321. + };
  1322. +
  1323. + typedef struct _dir {
  1324. +         int first;
  1325. + #ifdef OS2
  1326. +         FILEFINDBUF find;
  1327. + #else
  1328. + #ifdef __TURBOC__
  1329. +         struct ffblk dta;
  1330. + #else
  1331. +         struct find_t dta;
  1332. + #endif
  1333. + #endif
  1334. +     struct direct current;
  1335. + } DIR;
  1336. +
  1337. + #ifdef OS2
  1338. + static HDIR hdir;
  1339. + static USHORT count;
  1340. + static BOOL lower;
  1341. + #endif
  1342. +
  1343. + #ifdef OS2
  1344. + int IsFileSystemFAT(char *dir)
  1345. + {
  1346. +   USHORT nDrive;
  1347. +   ULONG lMap;
  1348. +   BYTE bData[64], bName[3];
  1349. +   USHORT cbData;
  1350. +
  1351. +   if ( _osmode == DOS_MODE )
  1352. +     return TRUE;
  1353. +   else
  1354. +   {
  1355. +     /* We separate FAT and HPFS file systems here.
  1356. +      * Filenames read from a FAT system are converted to lower case
  1357. +      * while the case of filenames read from a HPFS (and other future
  1358. +      * file systems, like Unix-compatibles) is preserved.
  1359. +      */
  1360. +
  1361. +     if ( isalpha(dir[0]) && (dir[1] == ':') )
  1362. +       nDrive = toupper(dir[0]) - '@';
  1363. +     else
  1364. +       DosQCurDisk(&nDrive, &lMap);
  1365. +
  1366. +     bName[0] = (char) (nDrive + '@');
  1367. +     bName[1] = ':';
  1368. +     bName[2] = 0;
  1369. +
  1370. +     cbData = sizeof(bData);
  1371. +
  1372. +     if ( !DosQFSAttach(bName, 0U, 1U, bData, &cbData, 0L) )
  1373. +       return !strcmp(bData + (*(USHORT *) (bData + 2) + 7), "FAT");
  1374. +     else
  1375. +       return FALSE;
  1376. +
  1377. +     /* End of this ugly code */
  1378. +   }
  1379. + }
  1380. + #endif
  1381. +
  1382. + DIR *
  1383. + opendir(char *name) {
  1384. +     char localname[_MAX_NAME];
  1385. +     DIR *rval = malloc(sizeof(DIR));
  1386. +     strcpy(localname,name);
  1387. +         strcat(localname,"/*.*");
  1388. + #ifdef OS2
  1389. +         lower = IsFileSystemFAT(name);
  1390. +         hdir = count = 1;
  1391. + #endif
  1392. +     if(rval == NULL ||
  1393. + #ifdef OS2
  1394. +            DosFindFirst(localname, &hdir, _A_NORMAL|_A_SUBDIR, &rval->find,
  1395. +                         sizeof(FILEFINDBUF), &count, 0L) != 0)
  1396. + #else
  1397. + #ifdef __TURBOC__
  1398. +           findfirst(localname,&rval->dta,_A_NORMAL|_A_SUBDIR) != 0)
  1399. + #else
  1400. +           _dos_findfirst(localname,_A_NORMAL|_A_SUBDIR,&rval->dta) != 0)
  1401. + #endif
  1402. + #endif
  1403. +                 return NULL;
  1404. +     rval->first = 1;
  1405. +     return rval;
  1406. + }
  1407. +
  1408. + void
  1409. + closedir(DIR *x) {
  1410. +     free(x);
  1411. + }
  1412. +
  1413. + struct direct *
  1414. + readdir(DIR *thisdir) {
  1415. +     /*
  1416. +     ** first time through, we don't need to look for a file
  1417. +     */
  1418. +         if(!thisdir->first) {
  1419. + #ifdef OS2
  1420. +                 if(DosFindNext(hdir, &thisdir->find, sizeof(FILEFINDBUF),
  1421. +                                &count) != 0)
  1422. + #else
  1423. + #ifdef __TURBOC__
  1424. +                 if(findnext(&thisdir->dta) != 0)
  1425. + #else
  1426. +                 if(_dos_findnext(&thisdir->dta) != 0)
  1427. + #endif
  1428. + #endif
  1429. +             return NULL;
  1430. +     } else
  1431. +                 thisdir->first = 0;
  1432. + #ifdef OS2
  1433. +         strcpy(thisdir->current.d_name,thisdir->find.achName);
  1434. + #else
  1435. + #ifdef __BORLANDC__
  1436. +         strcpy(thisdir->current.d_name,thisdir->dta.ff_name);
  1437. + #else
  1438. +         strcpy(thisdir->current.d_name,thisdir->dta.name);
  1439. + #endif
  1440. + #endif
  1441. +     /* thisdir->current.d_name[13] = '\0'; */
  1442. + #ifdef OS2
  1443. +         if ( lower )
  1444. + #endif
  1445. +       strlwr(thisdir->current.d_name);
  1446. +     return &thisdir->current;
  1447. + }
  1448. +
  1449. + #endif /* MSDOS */
  1450. +
  1451.   static struct dirdata
  1452.   dir_sort (dirname, nonex)
  1453.        char *dirname;
  1454. ***************
  1455. *** 135,142 ****
  1456.   int
  1457.   diff_dirs (name1, name2, handle_file, depth, nonex1, nonex2)
  1458.        char *name1, *name2;
  1459.        int (*handle_file) ();
  1460. !      int nonex1, nonex2;
  1461.   {
  1462.     struct dirdata data1, data2;
  1463.     register int i1, i2;
  1464. --- 300,315 ----
  1465.   int
  1466.   diff_dirs (name1, name2, handle_file, depth, nonex1, nonex2)
  1467.        char *name1, *name2;
  1468. + #if !defined(MSDOS)
  1469.        int (*handle_file) ();
  1470. ! #else
  1471. !       /* sorry, rms, I can't live with the assumption that
  1472. !       ** sizeof(char *) == sizeof(int)
  1473. !       */
  1474. !       int (*handle_file)(char *dir0,char *name0,
  1475. !               char *dir1,char *name1,int depth);
  1476. ! #endif
  1477. !      int depth, nonex1, nonex2;
  1478.   {
  1479.     struct dirdata data1, data2;
  1480.     register int i1, i2;
  1481. diff -cbBw orig/getopt.c new/getopt.c
  1482. *** orig/getopt.c    Tue Dec 24 19:13:26 1991
  1483. --- new/getopt.c    Tue Dec 24 19:19:20 1991
  1484. ***************
  1485. *** 1,5 ****
  1486. --- 1,7 ----
  1487.   /* Getopt for GNU.
  1488.      Copyright (C) 1987, 1989, 1990 Free Software Foundation, Inc.
  1489. +    Modified for DOS and OS/2 on 1991/09/14 by Kai Uwe Rommel
  1490. +     <rommel@ars.muc.de>.
  1491.  
  1492.      This program is free software; you can redistribute it and/or modify
  1493.      it under the terms of the GNU General Public License as published by
  1494. ***************
  1495. *** 15,25 ****
  1496.      along with this program; if not, write to the Free Software
  1497.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  1498.   
  1499. ! #ifdef __STDC__
  1500.   #define CONST const
  1501.   #else
  1502.   #define CONST
  1503.   #endif
  1504.  
  1505.   /* This version of `getopt' appears to the caller like standard Unix `getopt'
  1506.      but it behaves differently for the user, since it allows the user
  1507. --- 17,30 ----
  1508.      along with this program; if not, write to the Free Software
  1509.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  1510.   
  1511. ! #if defined(__STDC__) || defined(MSDOS)
  1512.   #define CONST const
  1513.   #else
  1514.   #define CONST
  1515.   #endif
  1516. + #ifdef MSDOS
  1517. + #define STDC_HEADERS
  1518. + #endif
  1519.  
  1520.   /* This version of `getopt' appears to the caller like standard Unix `getopt'
  1521.      but it behaves differently for the user, since it allows the user
  1522. ***************
  1523. *** 44,51 ****
  1524. --- 49,64 ----
  1525.   #ifdef sparc
  1526.   #include <alloca.h>
  1527.   #else
  1528. + #ifdef MSDOS
  1529. + #ifdef __TURBOC__
  1530. + #include <alloc.h>
  1531. + #else
  1532. + #include <malloc.h>
  1533. + #endif
  1534. + #else
  1535.   char *alloca ();
  1536.   #endif
  1537. + #endif
  1538.   #endif /* not __GNUC__ */
  1539.  
  1540.   #if defined(STDC_HEADERS) || defined(__GNU_LIBRARY__)
  1541. ***************
  1542. *** 72,77 ****
  1543. --- 85,92 ----
  1544.   char *malloc ();
  1545.   #endif
  1546.  
  1547. + static void exchange (char **);
  1548. +
  1549.   /* For communication from `getopt' to the caller.
  1550.      When `getopt' finds an option that takes an argument,
  1551.      the argument value is returned here.
  1552. ***************
  1553. *** 376,382 ****
  1554.          p++, option_index++)
  1555.       if (!strncmp (p->name, nextchar, s - nextchar))
  1556.         {
  1557. !         if (s - nextchar == strlen (p->name))
  1558.             {
  1559.           /* Exact match found.  */
  1560.           pfound = p;
  1561. --- 391,397 ----
  1562.          p++, option_index++)
  1563.       if (!strncmp (p->name, nextchar, s - nextchar))
  1564.         {
  1565. !         if (s - nextchar == (int) strlen (p->name))
  1566.             {
  1567.           /* Exact match found.  */
  1568.           pfound = p;
  1569. diff -cbBw orig/getopt.h new/getopt.h
  1570. *** orig/getopt.h    Tue Dec 24 19:13:26 1991
  1571. --- new/getopt.h    Tue Dec 24 19:19:24 1991
  1572. ***************
  1573. *** 1,5 ****
  1574. --- 1,7 ----
  1575.   /* declarations for getopt
  1576.      Copyright (C) 1989, 1990 Free Software Foundation, Inc.
  1577. +    Modified for DOS and OS/2 on 1991/09/14 by Kai Uwe Rommel
  1578. +     <rommel@ars.muc.de>.
  1579.  
  1580.      This program is free software; you can redistribute it and/or modify
  1581.      it under the terms of the GNU General Public License as published by
  1582. ***************
  1583. *** 70,76 ****
  1584.     int val;
  1585.   };
  1586.  
  1587. ! #ifdef __STDC__
  1588.   extern const struct option *_getopt_long_options;
  1589.   #else
  1590.   extern struct option *_getopt_long_options;
  1591. --- 72,78 ----
  1592.     int val;
  1593.   };
  1594.  
  1595. ! #if defined(__STDC__) || defined(MSDOS)
  1596.   extern const struct option *_getopt_long_options;
  1597.   #else
  1598.   extern struct option *_getopt_long_options;
  1599. ***************
  1600. *** 87,93 ****
  1601.  
  1602.   extern int option_index;
  1603.  
  1604. ! #ifdef __STDC__
  1605.   int getopt (int argc, char **argv, const char *shortopts);
  1606.   int getopt_long (int argc, char **argv, const char *shortopts,
  1607.            const struct option *longopts, int *longind);
  1608. --- 89,95 ----
  1609.  
  1610.   extern int option_index;
  1611.  
  1612. ! #if defined(__STDC__) || defined(MSDOS)
  1613.   int getopt (int argc, char **argv, const char *shortopts);
  1614.   int getopt_long (int argc, char **argv, const char *shortopts,
  1615.            const struct option *longopts, int *longind);
  1616. diff -cbBw orig/getopt1.c new/getopt1.c
  1617. *** orig/getopt1.c    Tue Dec 24 19:13:26 1991
  1618. --- new/getopt1.c    Tue Dec 24 19:19:30 1991
  1619. ***************
  1620. *** 1,5 ****
  1621. --- 1,7 ----
  1622.   /* Getopt for GNU.
  1623.      Copyright (C) 1987, 1989 Free Software Foundation, Inc.
  1624. +    Modified for DOS and OS/2 on 1991/09/14 by Kai Uwe Rommel
  1625. +     <rommel@ars.muc.de>.
  1626.  
  1627.      This program is free software; you can redistribute it and/or modify
  1628.      it under the terms of the GNU General Public License as published by
  1629. ***************
  1630. *** 17,23 ****
  1631.   
  1632.   #include "getopt.h"
  1633.  
  1634. ! #ifdef __STDC__
  1635.   #define CONST const
  1636.   #else
  1637.   #define CONST
  1638. --- 19,25 ----
  1639.   
  1640.   #include "getopt.h"
  1641.  
  1642. ! #if defined(__STDC__) || defined(MSDOS)
  1643.   #define CONST const
  1644.   #else
  1645.   #define CONST
  1646. ***************
  1647. *** 38,43 ****
  1648. --- 40,46 ----
  1649.     int val;
  1650.  
  1651.     _getopt_long_options = long_options;
  1652. +   _getopt_long_only = 0;
  1653.     val = getopt (argc, argv, options);
  1654.     if (val == 0 && opt_index != NULL)
  1655.       *opt_index = option_index;
  1656. diff -cbBw orig/io.c new/io.c
  1657. *** orig/io.c    Tue Dec 24 19:13:30 1991
  1658. --- new/io.c    Tue Dec 24 19:45:04 1991
  1659. ***************
  1660. *** 1,5 ****
  1661. --- 1,7 ----
  1662.   /* File I/O for GNU DIFF.
  1663.      Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  1664. +    Modified for DOS and OS/2 on 1991/09/14 by Kai Uwe Rommel
  1665. +     <rommel@ars.muc.de>.
  1666.  
  1667.   This file is part of GNU DIFF.
  1668.  
  1669. ***************
  1670. *** 20,27 ****
  1671. --- 22,33 ----
  1672.   #include "diff.h"
  1673.  
  1674.   /* Rotate a value n bits to the left. */
  1675. + #if !defined(MSDOS)
  1676.   #define UINT_BIT (sizeof (unsigned) * CHAR_BIT)
  1677.   #define ROL(v, n) ((v) << (n) | (v) >> UINT_BIT - (n))
  1678. + #else
  1679. + #define ROL(v,n)  ((v) << (n) | (v) >> (sizeof(v) * CHAR_BIT) - (n))
  1680. + #endif
  1681.  
  1682.   /* Given a hash value and a new character, return a new hash value. */
  1683.   #define HASH(h, c) ((c) + ROL (h, 7))
  1684. ***************
  1685. *** 57,66 ****
  1686. --- 63,79 ----
  1687.       1, 1, 1, 1, 1, 1, 1, 1,
  1688.       1, 1, 1, 1, 1, 1, 1, 1,
  1689.       1, 1, 1, 1, 1, 1, 1, 0,
  1690. + #ifdef MSDOS
  1691. +     1, 1, 1, 1, 1, 1, 1, 1,
  1692. +     1, 1, 1, 1, 1, 1, 1, 1,
  1693. +     1, 1, 1, 1, 1, 1, 1, 1,
  1694. +     1, 1, 1, 1, 1, 1, 1, 1,
  1695. + #else
  1696.       0, 0, 0, 0, 0, 0, 0, 0,
  1697.       0, 0, 0, 0, 0, 0, 0, 0,
  1698.       0, 0, 0, 0, 0, 0, 0, 0,
  1699.       0, 0, 0, 0, 0, 0, 0, 0,
  1700. + #endif
  1701.       1, 1, 1, 1, 1, 1, 1, 1,
  1702.       1, 1, 1, 1, 1, 1, 1, 1,
  1703.       1, 1, 1, 1, 1, 1, 1, 1,
  1704. ***************
  1705. *** 101,106 ****
  1706. --- 114,120 ----
  1707.        beyond those that current->bufsize describes:
  1708.        one for a newline (in case the text does not end with one)
  1709.        and one for a sentinel in find_identical_ends.  */
  1710. + #if !defined(MSDOS)
  1711.     else if ((current->stat.st_mode & S_IFMT) == S_IFREG)
  1712.       {
  1713.         current->bufsize = current->stat.st_size;
  1714. ***************
  1715. *** 136,146 ****
  1716.         if (cc < 0)
  1717.       pfatal_with_name (current->name);
  1718.       }
  1719.  
  1720.     /* Check first part of file to see if it's a binary file.  */
  1721.     if (! always_text_flag
  1722.         && binary_file_p (current->buffer,
  1723. !             min (current->buffered_chars, binary_file_threshold)))
  1724.       return 1;
  1725.  
  1726.     /* If not binary, make sure text ends in a newline,
  1727. --- 150,201 ----
  1728.         if (cc < 0)
  1729.       pfatal_with_name (current->name);
  1730.       }
  1731. + #else /* MSDOS */
  1732. +   else {
  1733. +       int count;
  1734. +       char huge *ptr;
  1735. +       char *buf;
  1736. + #ifdef __TURBOC__
  1737. +       int cnt;
  1738. + #endif
  1739. +
  1740. +       current->bufsize = current->stat.st_size + 1;
  1741. +       if((current->buffer = halloc(current->bufsize + 2,sizeof(char))) == NULL)
  1742. +              fatal("virtual memory exhausted");
  1743. +
  1744. +       current->buffered_chars = 0;
  1745. +       ptr = current->buffer;
  1746. +
  1747. +      /* this kludge is the only way to prevent read() from segment
  1748. +       * wraparounds in real mode in a OS/2 family mode application  :-( :-(
  1749. +       */
  1750. +
  1751. +       if((buf = malloc(16384)) == NULL)
  1752. +              fatal("virtual memory exhausted");
  1753. +
  1754. +       while((count = read(current->desc, buf, 16384)) > 0)
  1755. +       {
  1756. + #ifdef __TURBOC__
  1757. +              for ( cnt = 0; cnt < count; cnt++ )
  1758. +                 ptr[cnt] = buf[cnt];
  1759. + #else
  1760. +              memcpy(ptr, buf, count); /* MS C memcpy is aware of huge pointers */
  1761. + #endif
  1762. +              current->buffered_chars += count;
  1763. +              ptr += count;
  1764. +       }
  1765. +
  1766. +       free(buf);
  1767. +
  1768. +       if (count < 0)
  1769. +     pfatal_with_name (current->name);
  1770. +     }
  1771. + #endif        /* MSDOS */
  1772.  
  1773.     /* Check first part of file to see if it's a binary file.  */
  1774.     if (! always_text_flag
  1775.         && binary_file_p (current->buffer,
  1776. !             (int) min (current->buffered_chars, binary_file_threshold)))
  1777.       return 1;
  1778.  
  1779.     /* If not binary, make sure text ends in a newline,
  1780. ***************
  1781. *** 169,180 ****
  1782.   {
  1783.     unsigned h;
  1784.     int i;
  1785. !   unsigned char *p = (unsigned char *) current->prefix_end, *ip, c;
  1786.  
  1787.     /* Attempt to get a good initial guess as to the number of lines. */
  1788.     current->linbufsize = current->buffered_chars / 50 + 5;
  1789.     current->linbuf
  1790.       = (struct line_def *) xmalloc (current->linbufsize * sizeof (struct line_def));
  1791.  
  1792.     if (function_regexp || output_style == OUTPUT_IFDEF)
  1793.       {
  1794. --- 224,248 ----
  1795.   {
  1796.     unsigned h;
  1797.     int i;
  1798. ! #if !defined(MSDOS)
  1799. !   char *p = current->prefix_end, *ip, c;
  1800. ! #else
  1801. !   char huge *p = (char huge *) current->prefix_end;
  1802. !   char huge *ip, c;
  1803. !   int old;
  1804. ! #endif
  1805.  
  1806.     /* Attempt to get a good initial guess as to the number of lines. */
  1807.     current->linbufsize = current->buffered_chars / 50 + 5;
  1808. + #if !defined(MSDOS)
  1809.     current->linbuf
  1810.       = (struct line_def *) xmalloc (current->linbufsize * sizeof (struct line_def));
  1811. + #else
  1812. +   current->linbuf
  1813. +     = halloc(current->linbufsize, sizeof(struct line_def));
  1814. +   if ( current->linbuf == NULL )
  1815. +     fatal("virtual memory exhausted");
  1816. + #endif
  1817.  
  1818.     if (function_regexp || output_style == OUTPUT_IFDEF)
  1819.       {
  1820. ***************
  1821. *** 183,189 ****
  1822.        but since we don't know how many, it's easiest to find them all.
  1823.        If -D is specified, we need all the lines of the first file.  */
  1824.         current->buffered_lines = 0;
  1825. !       p = (unsigned char *) current->buffer;
  1826.       }
  1827.     else
  1828.       {
  1829. --- 251,257 ----
  1830.        but since we don't know how many, it's easiest to find them all.
  1831.        If -D is specified, we need all the lines of the first file.  */
  1832.         current->buffered_lines = 0;
  1833. !       p = current->buffer;
  1834.       }
  1835.     else
  1836.       {
  1837. ***************
  1838. *** 195,212 ****
  1839.       current->buffered_lines = 0;
  1840.         for (i = 0; i < context + 1; ++i)
  1841.       /* Unless we are at the beginning, */
  1842. !     if ((char *) p != current->buffer)
  1843.         /* Back up at least 1 char until at the start of a line.  */
  1844. !       while ((char *) --p != current->buffer && p[-1] != '\n')
  1845.           ;
  1846.       }
  1847.  
  1848. !   while ((char *) p < current->suffix_begin)
  1849.       {
  1850.         h = 0;
  1851.         ip = p;
  1852.  
  1853. !       if (current->prefix_end <= (char *) p)
  1854.       {
  1855.         /* Hash this line until we find a newline. */
  1856.         if (ignore_case_flag)
  1857. --- 263,280 ----
  1858.       current->buffered_lines = 0;
  1859.         for (i = 0; i < context + 1; ++i)
  1860.       /* Unless we are at the beginning, */
  1861. !     if (p != current->buffer)
  1862.         /* Back up at least 1 char until at the start of a line.  */
  1863. !       while ( --p != current->buffer && p[-1] != '\n')
  1864.           ;
  1865.       }
  1866.  
  1867. !   while (p < current->suffix_begin)
  1868.       {
  1869.         h = 0;
  1870.         ip = p;
  1871.  
  1872. !       if (current->prefix_end <= p)
  1873.       {
  1874.         /* Hash this line until we find a newline. */
  1875.         if (ignore_case_flag)
  1876. ***************
  1877. *** 291,298 ****
  1878. --- 359,368 ----
  1879.         /* Maybe increase the size of the line table. */
  1880.         if (current->buffered_lines >= current->linbufsize)
  1881.       {
  1882. + #ifndef MSDOS
  1883.         while (current->buffered_lines >= current->linbufsize)
  1884.           current->linbufsize *= 2;
  1885. +
  1886.         current->linbuf
  1887.           = (struct line_def *) xrealloc (current->linbuf,
  1888.                           current->linbufsize
  1889. ***************
  1890. *** 297,304 ****
  1891.           = (struct line_def *) xrealloc (current->linbuf,
  1892.                           current->linbufsize
  1893.                           * sizeof (struct line_def));
  1894.       }
  1895. !       current->linbuf[current->buffered_lines].text = (char *) ip;
  1896.         current->linbuf[current->buffered_lines].length = p - ip + 1;
  1897.         current->linbuf[current->buffered_lines].hash = h;
  1898.         ++current->buffered_lines;
  1899. --- 367,387 ----
  1900.           = (struct line_def *) xrealloc (current->linbuf,
  1901.                           current->linbufsize
  1902.                           * sizeof (struct line_def));
  1903. + #else
  1904. +           old = current->linbufsize;
  1905. +
  1906. +       while (current->buffered_lines >= current->linbufsize)
  1907. +         current->linbufsize += 2048;
  1908. +
  1909. +       current->linbuf = hrealloc(current->linbuf,
  1910. +             (long) current->linbufsize * sizeof (struct line_def),
  1911. +             (long) old * sizeof (struct line_def));
  1912. +
  1913. +           if ( current->linbuf == NULL )
  1914. +              fatal("too many lines");
  1915. + #endif
  1916.       }
  1917. !       current->linbuf[current->buffered_lines].text = ip;
  1918.         current->linbuf[current->buffered_lines].length = p - ip + 1;
  1919.         current->linbuf[current->buffered_lines].hash = h;
  1920.         ++current->buffered_lines;
  1921. ***************
  1922. *** 307,313 ****
  1923. --- 390,400 ----
  1924.  
  1925.     i = 0;
  1926.     while ((i < context || output_style == OUTPUT_IFDEF)
  1927. + #ifndef MSDOS
  1928.        && (char *) p < current->buffer + current->buffered_chars)
  1929. + #else
  1930. +      && p < (char huge *) current->buffer + current->buffered_chars)
  1931. + #endif
  1932.       {
  1933.         ip = p;
  1934.         while (*p++ != '\n')
  1935. ***************
  1936. *** 315,322 ****
  1937. --- 402,411 ----
  1938.         /* Maybe increase the size of the line table. */
  1939.         if (current->buffered_lines >= current->linbufsize)
  1940.       {
  1941. + #ifndef MSDOS
  1942.         while (current->buffered_lines >= current->linbufsize)
  1943.           current->linbufsize *= 2;
  1944. +
  1945.         current->linbuf
  1946.           = (struct line_def *) xrealloc (current->linbuf,
  1947.                           current->linbufsize
  1948. ***************
  1949. *** 321,328 ****
  1950.           = (struct line_def *) xrealloc (current->linbuf,
  1951.                           current->linbufsize
  1952.                           * sizeof (struct line_def));
  1953.       }
  1954. !       current->linbuf[current->buffered_lines].text = (char *) ip;
  1955.         current->linbuf[current->buffered_lines].length = p - ip;
  1956.         current->linbuf[current->buffered_lines].hash = 0;
  1957.         ++current->buffered_lines;
  1958. --- 410,430 ----
  1959.           = (struct line_def *) xrealloc (current->linbuf,
  1960.                           current->linbufsize
  1961.                           * sizeof (struct line_def));
  1962. + #else
  1963. +           old = current->linbufsize;
  1964. +
  1965. +       while (current->buffered_lines >= current->linbufsize)
  1966. +         current->linbufsize += 2048;
  1967. +
  1968. +       current->linbuf = hrealloc(current->linbuf,
  1969. +             (long) current->linbufsize * sizeof (struct line_def),
  1970. +             (long) old * sizeof (struct line_def));
  1971. +
  1972. +           if ( current->linbuf == NULL )
  1973. +              fatal("too many lines");
  1974. + #endif
  1975.       }
  1976. !       current->linbuf[current->buffered_lines].text = ip;
  1977.         current->linbuf[current->buffered_lines].length = p - ip;
  1978.         current->linbuf[current->buffered_lines].hash = 0;
  1979.         ++current->buffered_lines;
  1980. ***************
  1981. *** 342,348 ****
  1982. --- 444,454 ----
  1983.   find_identical_ends (filevec)
  1984.        struct file_data filevec[];
  1985.   {
  1986. + #ifndef MSDOS
  1987.     char *p0, *p1, *end0, *beg0;
  1988. + #else
  1989. +   char huge *p0, huge *p1, huge *end0, huge *beg0;
  1990. + #endif
  1991.     int lines;
  1992.  
  1993.     if (filevec[0].buffered_chars == 0 || filevec[1].buffered_chars == 0)
  1994. ***************
  1995. *** 383,397 ****
  1996.     /* Don't count missing newline as part of prefix in RCS mode. */
  1997.     if (ROBUST_OUTPUT_STYLE (output_style)
  1998.         && ((filevec[0].missing_newline
  1999. !        && p0 - filevec[0].buffer > filevec[0].buffered_chars)
  2000.         ||
  2001.         (filevec[1].missing_newline
  2002. !        && p1 - filevec[1].buffer > filevec[1].buffered_chars)))
  2003.       --p0, --p1, --lines;
  2004.  
  2005.     /* If the sentinel was passed, and lengths are equal, the
  2006.        files are identical.  */
  2007. !   if (p0 - filevec[0].buffer > filevec[0].buffered_chars
  2008.         && filevec[0].buffered_chars == filevec[1].buffered_chars)
  2009.       {
  2010.         filevec[0].prefix_end = p0 - 1;
  2011. --- 489,503 ----
  2012.     /* Don't count missing newline as part of prefix in RCS mode. */
  2013.     if (ROBUST_OUTPUT_STYLE (output_style)
  2014.         && ((filevec[0].missing_newline
  2015. !        && (p0 - filevec[0].buffer) > filevec[0].buffered_chars)
  2016.         ||
  2017.         (filevec[1].missing_newline
  2018. !        && (p1 - filevec[1].buffer) > filevec[1].buffered_chars)))
  2019.       --p0, --p1, --lines;
  2020.  
  2021.     /* If the sentinel was passed, and lengths are equal, the
  2022.        files are identical.  */
  2023. !   if ((p0 - filevec[0].buffer) > filevec[0].buffered_chars
  2024.         && filevec[0].buffered_chars == filevec[1].buffered_chars)
  2025.       {
  2026.         filevec[0].prefix_end = p0 - 1;
  2027. ***************
  2028. *** 435,445 ****
  2029.         else
  2030.       /* Figure out where P0 will be when P1 is at the end of the prefix.
  2031.          Thus we only need to test P0.  */
  2032. !     beg0 = (filevec[0].prefix_end
  2033. !         + filevec[0].buffered_chars - filevec[1].buffered_chars);
  2034.  
  2035.         /* Scan back until chars don't match or we reach that point.  */
  2036. !       while (p0 != beg0)
  2037.       {
  2038.         char c = *--p0;
  2039.         if (c != *--p1)
  2040. --- 541,551 ----
  2041.         else
  2042.       /* Figure out where P0 will be when P1 is at the end of the prefix.
  2043.          Thus we only need to test P0.  */
  2044. !     beg0 = filevec[0].prefix_end
  2045. !         + (filevec[0].buffered_chars - filevec[1].buffered_chars);
  2046.  
  2047.         /* Scan back until chars don't match or we reach that point.  */
  2048. !       while (p0 > beg0)
  2049.       {
  2050.         char c = *--p0;
  2051.         if (c != *--p1)
  2052. ***************
  2053. *** 483,488 ****
  2054. --- 589,597 ----
  2055.   {
  2056.     struct equivclass *next;    /* Next item in this bucket. */
  2057.     struct line_def line;    /* A line that fits this class. */
  2058. + #ifdef MSDOS
  2059. +   long dummy; /* to pad struct size to a power of two, 16 */
  2060. + #endif
  2061.   };
  2062.  
  2063.   /* Hash-table: array of buckets, each being a chain of equivalence classes.  */
  2064. ***************
  2065. *** 494,511 ****
  2066.   /* Array in which the equivalence classes are allocated.
  2067.      The bucket-chains go through the elements in this array.
  2068.      The number of an equivalence class is its index in this array.  */
  2069. ! static struct equivclass *equivs;
  2070.  
  2071.   /* Index of first free element in the array `equivs'.  */
  2072. ! static int equivs_index;
  2073.  
  2074.   /* Size allocated to the array `equivs'.  */
  2075. ! static int equivs_alloc;
  2076.  
  2077.   /* Largest primes less than some power of two, for nbuckets.  Values range
  2078.      from useful to preposterous.  If one of these numbers isn't prime
  2079.      after all, don't blame it on me, blame it on primes (6) . . . */
  2080. ! static int primes[] =
  2081.   {
  2082.     509,
  2083.     1021,
  2084. --- 603,620 ----
  2085.   /* Array in which the equivalence classes are allocated.
  2086.      The bucket-chains go through the elements in this array.
  2087.      The number of an equivalence class is its index in this array.  */
  2088. ! static struct equivclass huge *equivs;
  2089.  
  2090.   /* Index of first free element in the array `equivs'.  */
  2091. ! static long equivs_index;
  2092.  
  2093.   /* Size allocated to the array `equivs'.  */
  2094. ! static long equivs_alloc;
  2095.  
  2096.   /* Largest primes less than some power of two, for nbuckets.  Values range
  2097.      from useful to preposterous.  If one of these numbers isn't prime
  2098.      after all, don't blame it on me, blame it on primes (6) . . . */
  2099. ! static long primes[] =
  2100.   {
  2101.     509,
  2102.     1021,
  2103. ***************
  2104. *** 538,544 ****
  2105.        int n;
  2106.   {
  2107.     int bucket;
  2108. !   struct equivclass *b, *p = NULL;
  2109.  
  2110.     /* Equivalence class 0 is permanently allocated to lines that were
  2111.        not hashed because they were parts of identical prefixes or
  2112. --- 647,653 ----
  2113.        int n;
  2114.   {
  2115.     int bucket;
  2116. !   struct equivclass huge *b, huge *p = NULL;
  2117.  
  2118.     /* Equivalence class 0 is permanently allocated to lines that were
  2119.        not hashed because they were parts of identical prefixes or
  2120. ***************
  2121. *** 564,569 ****
  2122. --- 673,681 ----
  2123.  
  2124.     /* Create a new equivalence class in this bucket. */
  2125.  
  2126. +   if (equivs_index >= equivs_alloc)
  2127. +     fatal ("too many differences, hash table overflow");
  2128. +
  2129.     p = &equivs[equivs_index++];
  2130.     p->next = buckets[bucket];
  2131.     buckets[bucket] = p;
  2132. ***************
  2133. *** 601,608 ****
  2134.       }
  2135.  
  2136.     /* This is guaranteed to be enough space.  */
  2137. !   equivs_alloc = filevec[0].buffered_lines + filevec[1].buffered_lines + 1;
  2138.     equivs = (struct equivclass *) xmalloc (equivs_alloc * sizeof (struct equivclass));
  2139.     /* Equivalence class 0 is permanently safe for lines that were not
  2140.        hashed.  Real equivalence classes start at 1. */
  2141.     equivs_index = 1;
  2142. --- 713,726 ----
  2143.       }
  2144.  
  2145.     /* This is guaranteed to be enough space.  */
  2146. !   equivs_alloc = (long) filevec[0].buffered_lines + filevec[1].buffered_lines + 1L;
  2147. ! #ifndef MSDOS
  2148.     equivs = (struct equivclass *) xmalloc (equivs_alloc * sizeof (struct equivclass));
  2149. + #else
  2150. +   equivs = halloc (equivs_alloc, sizeof (struct equivclass));
  2151. +   if ( equivs == NULL )
  2152. +     fatal("virtual memory exhausted");
  2153. + #endif
  2154.     /* Equivalence class 0 is permanently safe for lines that were not
  2155.        hashed.  Real equivalence classes start at 1. */
  2156.     equivs_index = 1;
  2157. ***************
  2158. *** 611,618 ****
  2159. --- 729,752 ----
  2160.     while (primes[primes_index] < equivs_alloc / 3)
  2161.       primes_index++;
  2162.  
  2163. + #ifndef MSDOS
  2164.     buckets = (struct equivclass **) xmalloc (primes[primes_index] * sizeof (struct equivclass *));
  2165.     bzero (buckets, primes[primes_index] * sizeof (struct equivclass *));
  2166. + #else
  2167. +   buckets = halloc (primes[primes_index], sizeof (struct equivclass *));
  2168. + #ifdef __TURBOC__
  2169. +   /* Microsoft C's halloc already zeroes out the allocated memory.
  2170. +      So this bzero call is only needed for Turbo C and Borland C.
  2171. +      But note that the block may be bigger than 64k and that the bzero
  2172. +      (actually memset) will not fill out the whole block. But this
  2173. +      situation is not very likely to occur, because with Turbo C or
  2174. +      Borland C, you can only make a MS-DOS program, who's memory
  2175. +      is too restricted to diff such big files that this situation
  2176. +      may occur.
  2177. +   */
  2178. +   bzero (buckets, primes[primes_index] * sizeof (struct equivclass *));
  2179. + #endif
  2180. + #endif
  2181.     nbuckets = primes[primes_index];
  2182.  
  2183.     for (i = 0; i < 2; ++i)
  2184. ***************
  2185. *** 626,633 ****
  2186. --- 760,772 ----
  2187.  
  2188.     filevec[0].equiv_max = filevec[1].equiv_max = equivs_index;
  2189.  
  2190. + #ifndef MSDOS
  2191.     free (equivs);
  2192.     free (buckets);
  2193. + #else
  2194. +   hfree (equivs);
  2195. +   hfree (buckets);
  2196. + #endif
  2197.  
  2198.     return 0;
  2199.   }
  2200. diff -cbBw orig/limits.h new/limits.h
  2201. *** orig/limits.h    Tue Dec 24 19:13:30 1991
  2202. --- new/limits.h    Tue Dec 24 19:27:48 1991
  2203. ***************
  2204. *** 1,3 ****
  2205. --- 1,9 ----
  2206. + /*
  2207. +    Modified for DOS and OS/2 on 1991/09/14 by Kai Uwe Rommel
  2208. +     <rommel@ars.muc.de>.
  2209. +  */
  2210. +
  2211. +
  2212.   /* Number of bits in a `char'.  */
  2213.   #define CHAR_BIT 8
  2214.  
  2215. ***************
  2216. *** 28,38 ****
  2217. --- 34,52 ----
  2218.   #define USHRT_MAX 65535U
  2219.  
  2220.   /* Minimum and maximum values a `signed int' can hold.  */
  2221. + #ifdef MSDOS
  2222. + #define INT_MIN (-32768)
  2223. + #define INT_MAX 32767
  2224. +
  2225. + /* Maximum value an `unsigned int' can hold.  (Minimum is 0).  */
  2226. + #define UINT_MAX 65535U
  2227. + #else
  2228.   #define INT_MIN (-INT_MAX-1)
  2229.   #define INT_MAX 2147483647
  2230.  
  2231.   /* Maximum value an `unsigned int' can hold.  (Minimum is 0).  */
  2232.   #define UINT_MAX 4294967295U
  2233. + #endif
  2234.  
  2235.   /* Minimum and maximum values a `signed long int' can hold.
  2236.      (Same as `int').  */
  2237. diff -cbBw orig/util.c new/util.c
  2238. *** orig/util.c    Tue Dec 24 19:13:34 1991
  2239. --- new/util.c    Tue Dec 24 19:19:38 1991
  2240. ***************
  2241. *** 1,5 ****
  2242. --- 1,7 ----
  2243.   /* Support routines for GNU DIFF.
  2244.      Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  2245. +    Modified for DOS and OS/2 on 1991/09/14 by Kai Uwe Rommel
  2246. +     <rommel@ars.muc.de>.
  2247.  
  2248.   This file is part of GNU DIFF.
  2249.  
  2250. ***************
  2251. *** 19,24 ****
  2252. --- 19,25 ----
  2253.   along with GNU DIFF; see the file COPYING.  If not, write to
  2254.   the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  2255.   
  2256. + #include "regex.h"
  2257.   #include "diff.h"
  2258.   
  2259.   /* Use when a system call returns non-zero status.
  2260. ***************
  2261. *** 51,57 ****
  2262.        char *arg;
  2263.        char *arg1;
  2264.   {
  2265. !   fprintf (stderr, "%s: ", program);
  2266.     fprintf (stderr, format, arg, arg1);
  2267.     fprintf (stderr, "\n");
  2268.   }
  2269. --- 53,59 ----
  2270.        char *arg;
  2271.        char *arg1;
  2272.   {
  2273. !   fprintf (stderr, "\n%s: ", program);
  2274.     fprintf (stderr, format, arg, arg1);
  2275.     fprintf (stderr, "\n");
  2276.   }
  2277. ***************
  2278. *** 65,71 ****
  2279.        char *message;
  2280.   {
  2281.     print_message_queue ();
  2282. !   error (message, "");
  2283.     exit (2);
  2284.   }
  2285.   
  2286. --- 66,72 ----
  2287.        char *message;
  2288.   {
  2289.     print_message_queue ();
  2290. !   error (message, "", "");
  2291.     exit (2);
  2292.   }
  2293.   
  2294. ***************
  2295. *** 129,134 ****
  2296. --- 131,147 ----
  2297.     strcat (name, " ");
  2298.     strcat (name, name1);
  2299.  
  2300. + #if defined(MSDOS)
  2301. +   if (paginate_flag)
  2302. +     {
  2303. +       extern FILE *popen();
  2304. +
  2305. +       /* Fork a `pr' and make OUTFILE a pipe to it.  */
  2306. +       outfile = popen("pr -o -", "w");
  2307. +       fprintf (outfile, "%s\n", name);
  2308. +     }
  2309. +   else
  2310. + #else
  2311.     if (paginate_flag)
  2312.       {
  2313.         int pipes[2];
  2314. ***************
  2315. *** 164,169 ****
  2316. --- 177,183 ----
  2317.       }
  2318.       }
  2319.     else
  2320. + #endif
  2321.       {
  2322.  
  2323.         /* If -l was not specified, output the diff straight to `stdout'.  */
  2324. ***************
  2325. *** 172,178 ****
  2326.  
  2327.         /* If handling multiple files (because scanning a directory),
  2328.        print which files the following output is about.  */
  2329. !       if (depth > 0)
  2330.       printf ("%s\n", name);
  2331.       }
  2332.  
  2333. --- 186,192 ----
  2334.  
  2335.         /* If handling multiple files (because scanning a directory),
  2336.        print which files the following output is about.  */
  2337. !       if (depth > 0 && !output_patch_flag)
  2338.       printf ("%s\n", name);
  2339.       }
  2340.  
  2341. ***************
  2342. *** 187,194 ****
  2343. --- 201,212 ----
  2344.   {
  2345.     if (outfile != stdout)
  2346.       {
  2347. + #if defined(MSDOS)
  2348. +       pclose (outfile);
  2349. + #else
  2350.         fclose (outfile);
  2351.         wait (0);
  2352. + #endif
  2353.       }
  2354.   }
  2355.   
  2356. ***************
  2357. *** 201,207 ****
  2358. --- 219,229 ----
  2359.   line_cmp (s1, s2)
  2360.        struct line_def *s1, *s2;
  2361.   {
  2362. + #ifdef MSDOS
  2363. +   char huge *t1, huge *t2;
  2364. + #else
  2365.     register char *t1, *t2;
  2366. + #endif
  2367.     register char end_char = line_end_char;
  2368.     int savechar;
  2369.  
  2370. ***************
  2371. *** 382,388 ****
  2372. --- 404,414 ----
  2373.        struct line_def *line;
  2374.   {
  2375.     int length = line->length; /* must be nonzero */
  2376. + #ifdef MSDOS
  2377. +   const char huge *text = line->text; /* Help the compiler.  */
  2378. + #else
  2379.     const char *text = line->text; /* Help the compiler.  */
  2380. + #endif
  2381.     FILE *out = outfile; /* Help the compiler some more.  */
  2382.  
  2383.     /* If -T was specified, use a Tab between the line-flag and the text.
  2384. diff -cbBw orig/version.c new/version.c
  2385. *** orig/version.c    Tue Dec 24 19:13:34 1991
  2386. --- new/version.c    Tue Dec 24 19:29:16 1991
  2387. ***************
  2388. *** 1,3 ****
  2389.   /* Version number of GNU diff.  */
  2390.  
  2391. ! char *version_string = "1.15";
  2392. --- 1,11 ----
  2393.   /* Version number of GNU diff.  */
  2394. + /*
  2395. +    Modified for DOS and OS/2 on 1991/09/14 by Kai Uwe Rommel
  2396. +     <rommel@ars.muc.de>.
  2397. + */
  2398.  
  2399. ! char *version_string = "1.15 (16-bit)";
  2400. !
  2401. ! #ifdef __TURBOC__
  2402. ! unsigned _stklen = 0x8000;
  2403. ! #endif
  2404.