home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / rcs567s.zip / diff16 / patches.pc < prev    next >
Text File  |  1994-06-25  |  67KB  |  2,379 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(__TURBOC__) && !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,201 ----
  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. + #define _MAX_NAME        256
  1307. + #else
  1308. + #ifdef __TURBOC__
  1309. + #include <dir.h>
  1310. + #define _A_NORMAL        0x00
  1311. + #define _A_SUBDIR        0x10
  1312. + #endif
  1313. + #include <dos.h>
  1314. + #define _MAX_NAME        13
  1315. + #endif
  1316. +
  1317. + struct direct {
  1318. +     char d_name[_MAX_NAME];
  1319. + };
  1320. +
  1321. + typedef struct _dir {
  1322. +         int first;
  1323. + #ifdef OS2
  1324. +         FILEFINDBUF find;
  1325. + #else
  1326. + #ifdef __TURBOC__
  1327. +         struct ffblk dta;
  1328. + #else
  1329. +         struct find_t dta;
  1330. + #endif
  1331. + #endif
  1332. +     struct direct current;
  1333. + } DIR;
  1334. +
  1335. + #ifdef OS2
  1336. + static HDIR hdir;
  1337. + static USHORT count;
  1338. + static BOOL lower;
  1339. + #endif
  1340. +
  1341. + #ifdef OS2
  1342. + int IsFileSystemFAT(char *dir)
  1343. + {
  1344. +   USHORT nDrive;
  1345. +   ULONG lMap;
  1346. +   BYTE bData[64], bName[3];
  1347. +   USHORT cbData;
  1348. +
  1349. +   if ( _osmode == DOS_MODE )
  1350. +     return TRUE;
  1351. +   else
  1352. +   {
  1353. +     /* We separate FAT and HPFS file systems here.
  1354. +      * Filenames read from a FAT system are converted to lower case
  1355. +      * while the case of filenames read from a HPFS (and other future
  1356. +      * file systems, like Unix-compatibles) is preserved.
  1357. +      */
  1358. +
  1359. +     if ( isalpha(dir[0]) && (dir[1] == ':') )
  1360. +       nDrive = toupper(dir[0]) - '@';
  1361. +     else
  1362. +       DosQCurDisk(&nDrive, &lMap);
  1363. +
  1364. +     bName[0] = (char) (nDrive + '@');
  1365. +     bName[1] = ':';
  1366. +     bName[2] = 0;
  1367. +
  1368. +     cbData = sizeof(bData);
  1369. +
  1370. +     if ( !DosQFSAttach(bName, 0U, 1U, bData, &cbData, 0L) )
  1371. +       return !strcmp(bData + (*(USHORT *) (bData + 2) + 7), "FAT");
  1372. +     else
  1373. +       return FALSE;
  1374. +
  1375. +     /* End of this ugly code */
  1376. +   }
  1377. + }
  1378. + #endif
  1379. +
  1380. + DIR *
  1381. + opendir(char *name) {
  1382. +     char localname[_MAX_NAME];
  1383. +     DIR *rval = malloc(sizeof(DIR));
  1384. +     strcpy(localname,name);
  1385. +         strcat(localname,"/*.*");
  1386. + #ifdef OS2
  1387. +         lower = IsFileSystemFAT(name);
  1388. +         hdir = count = 1;
  1389. + #endif
  1390. +     if(rval == NULL ||
  1391. + #ifdef OS2
  1392. +            DosFindFirst(localname, &hdir, _A_NORMAL|_A_SUBDIR, &rval->find,
  1393. +                         sizeof(FILEFINDBUF), &count, 0L) != 0)
  1394. + #else
  1395. + #ifdef __TURBOC__
  1396. +           findfirst(localname,&rval->dta,_A_NORMAL|_A_SUBDIR) != 0)
  1397. + #else
  1398. +           _dos_findfirst(localname,_A_NORMAL|_A_SUBDIR,&rval->dta) != 0)
  1399. + #endif
  1400. + #endif
  1401. +                 return NULL;
  1402. +     rval->first = 1;
  1403. +     return rval;
  1404. + }
  1405. +
  1406. + void
  1407. + closedir(DIR *x) {
  1408. +     free(x);
  1409. + }
  1410. +
  1411. + struct direct *
  1412. + readdir(DIR *thisdir) {
  1413. +     /*
  1414. +     ** first time through, we don't need to look for a file
  1415. +     */
  1416. +         if(!thisdir->first) {
  1417. + #ifdef OS2
  1418. +                 if(DosFindNext(hdir, &thisdir->find, sizeof(FILEFINDBUF),
  1419. +                                &count) != 0)
  1420. + #else
  1421. + #ifdef __TURBOC__
  1422. +                 if(findnext(&thisdir->dta) != 0)
  1423. + #else
  1424. +                 if(_dos_findnext(&thisdir->dta) != 0)
  1425. + #endif
  1426. + #endif
  1427. +             return NULL;
  1428. +     } else
  1429. +                 thisdir->first = 0;
  1430. + #ifdef OS2
  1431. +         strcpy(thisdir->current.d_name,thisdir->find.achName);
  1432. + #else
  1433. + #ifdef __BORLANDC__
  1434. +         strcpy(thisdir->current.d_name,thisdir->dta.ff_name);
  1435. + #else
  1436. +         strcpy(thisdir->current.d_name,thisdir->dta.name);
  1437. + #endif
  1438. + #endif
  1439. +     /* thisdir->current.d_name[13] = '\0'; */
  1440. + #ifdef OS2
  1441. +         if ( lower )
  1442. + #endif
  1443. +       strlwr(thisdir->current.d_name);
  1444. +     return &thisdir->current;
  1445. + }
  1446. +
  1447. + #endif /* MSDOS */
  1448. +
  1449.   static struct dirdata
  1450.   dir_sort (dirname, nonex)
  1451.        char *dirname;
  1452. ***************
  1453. *** 135,142 ****
  1454.   int
  1455.   diff_dirs (name1, name2, handle_file, depth, nonex1, nonex2)
  1456.        char *name1, *name2;
  1457.        int (*handle_file) ();
  1458. !      int nonex1, nonex2;
  1459.   {
  1460.     struct dirdata data1, data2;
  1461.     register int i1, i2;
  1462. --- 300,315 ----
  1463.   int
  1464.   diff_dirs (name1, name2, handle_file, depth, nonex1, nonex2)
  1465.        char *name1, *name2;
  1466. + #if !defined(MSDOS)
  1467.        int (*handle_file) ();
  1468. ! #else
  1469. !       /* sorry, rms, I can't live with the assumption that
  1470. !       ** sizeof(char *) == sizeof(int)
  1471. !       */
  1472. !       int (*handle_file)(char *dir0,char *name0,
  1473. !               char *dir1,char *name1,int depth);
  1474. ! #endif
  1475. !      int depth, nonex1, nonex2;
  1476.   {
  1477.     struct dirdata data1, data2;
  1478.     register int i1, i2;
  1479. diff -cbBw orig/getopt.c new/getopt.c
  1480. *** orig/getopt.c    Tue Dec 24 19:13:26 1991
  1481. --- new/getopt.c    Tue Dec 24 19:19:20 1991
  1482. ***************
  1483. *** 1,5 ****
  1484. --- 1,7 ----
  1485.   /* Getopt for GNU.
  1486.      Copyright (C) 1987, 1989, 1990 Free Software Foundation, Inc.
  1487. +    Modified for DOS and OS/2 on 1991/09/14 by Kai Uwe Rommel
  1488. +     <rommel@ars.muc.de>.
  1489.  
  1490.      This program is free software; you can redistribute it and/or modify
  1491.      it under the terms of the GNU General Public License as published by
  1492. ***************
  1493. *** 15,25 ****
  1494.      along with this program; if not, write to the Free Software
  1495.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  1496.   
  1497. ! #ifdef __STDC__
  1498.   #define CONST const
  1499.   #else
  1500.   #define CONST
  1501.   #endif
  1502.  
  1503.   /* This version of `getopt' appears to the caller like standard Unix `getopt'
  1504.      but it behaves differently for the user, since it allows the user
  1505. --- 17,30 ----
  1506.      along with this program; if not, write to the Free Software
  1507.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  1508.   
  1509. ! #if defined(__STDC__) || defined(MSDOS)
  1510.   #define CONST const
  1511.   #else
  1512.   #define CONST
  1513.   #endif
  1514. + #ifdef MSDOS
  1515. + #define STDC_HEADERS
  1516. + #endif
  1517.  
  1518.   /* This version of `getopt' appears to the caller like standard Unix `getopt'
  1519.      but it behaves differently for the user, since it allows the user
  1520. ***************
  1521. *** 44,51 ****
  1522. --- 49,64 ----
  1523.   #ifdef sparc
  1524.   #include <alloca.h>
  1525.   #else
  1526. + #ifdef MSDOS
  1527. + #ifdef __TURBOC__
  1528. + #include <alloc.h>
  1529. + #else
  1530. + #include <malloc.h>
  1531. + #endif
  1532. + #else
  1533.   char *alloca ();
  1534.   #endif
  1535. + #endif
  1536.   #endif /* not __GNUC__ */
  1537.  
  1538.   #if defined(STDC_HEADERS) || defined(__GNU_LIBRARY__)
  1539. ***************
  1540. *** 72,77 ****
  1541. --- 85,92 ----
  1542.   char *malloc ();
  1543.   #endif
  1544.  
  1545. + static void exchange (char **);
  1546. +
  1547.   /* For communication from `getopt' to the caller.
  1548.      When `getopt' finds an option that takes an argument,
  1549.      the argument value is returned here.
  1550. ***************
  1551. *** 376,382 ****
  1552.          p++, option_index++)
  1553.       if (!strncmp (p->name, nextchar, s - nextchar))
  1554.         {
  1555. !         if (s - nextchar == strlen (p->name))
  1556.             {
  1557.           /* Exact match found.  */
  1558.           pfound = p;
  1559. --- 391,397 ----
  1560.          p++, option_index++)
  1561.       if (!strncmp (p->name, nextchar, s - nextchar))
  1562.         {
  1563. !         if (s - nextchar == (int) strlen (p->name))
  1564.             {
  1565.           /* Exact match found.  */
  1566.           pfound = p;
  1567. diff -cbBw orig/getopt.h new/getopt.h
  1568. *** orig/getopt.h    Tue Dec 24 19:13:26 1991
  1569. --- new/getopt.h    Tue Dec 24 19:19:24 1991
  1570. ***************
  1571. *** 1,5 ****
  1572. --- 1,7 ----
  1573.   /* declarations for getopt
  1574.      Copyright (C) 1989, 1990 Free Software Foundation, Inc.
  1575. +    Modified for DOS and OS/2 on 1991/09/14 by Kai Uwe Rommel
  1576. +     <rommel@ars.muc.de>.
  1577.  
  1578.      This program is free software; you can redistribute it and/or modify
  1579.      it under the terms of the GNU General Public License as published by
  1580. ***************
  1581. *** 70,76 ****
  1582.     int val;
  1583.   };
  1584.  
  1585. ! #ifdef __STDC__
  1586.   extern const struct option *_getopt_long_options;
  1587.   #else
  1588.   extern struct option *_getopt_long_options;
  1589. --- 72,78 ----
  1590.     int val;
  1591.   };
  1592.  
  1593. ! #if defined(__STDC__) || defined(MSDOS)
  1594.   extern const struct option *_getopt_long_options;
  1595.   #else
  1596.   extern struct option *_getopt_long_options;
  1597. ***************
  1598. *** 87,93 ****
  1599.  
  1600.   extern int option_index;
  1601.  
  1602. ! #ifdef __STDC__
  1603.   int getopt (int argc, char **argv, const char *shortopts);
  1604.   int getopt_long (int argc, char **argv, const char *shortopts,
  1605.            const struct option *longopts, int *longind);
  1606. --- 89,95 ----
  1607.  
  1608.   extern int option_index;
  1609.  
  1610. ! #if defined(__STDC__) || defined(MSDOS)
  1611.   int getopt (int argc, char **argv, const char *shortopts);
  1612.   int getopt_long (int argc, char **argv, const char *shortopts,
  1613.            const struct option *longopts, int *longind);
  1614. diff -cbBw orig/getopt1.c new/getopt1.c
  1615. *** orig/getopt1.c    Tue Dec 24 19:13:26 1991
  1616. --- new/getopt1.c    Tue Dec 24 19:19:30 1991
  1617. ***************
  1618. *** 1,5 ****
  1619. --- 1,7 ----
  1620.   /* Getopt for GNU.
  1621.      Copyright (C) 1987, 1989 Free Software Foundation, Inc.
  1622. +    Modified for DOS and OS/2 on 1991/09/14 by Kai Uwe Rommel
  1623. +     <rommel@ars.muc.de>.
  1624.  
  1625.      This program is free software; you can redistribute it and/or modify
  1626.      it under the terms of the GNU General Public License as published by
  1627. ***************
  1628. *** 17,23 ****
  1629.   
  1630.   #include "getopt.h"
  1631.  
  1632. ! #ifdef __STDC__
  1633.   #define CONST const
  1634.   #else
  1635.   #define CONST
  1636. --- 19,25 ----
  1637.   
  1638.   #include "getopt.h"
  1639.  
  1640. ! #if defined(__STDC__) || defined(MSDOS)
  1641.   #define CONST const
  1642.   #else
  1643.   #define CONST
  1644. ***************
  1645. *** 38,43 ****
  1646. --- 40,46 ----
  1647.     int val;
  1648.  
  1649.     _getopt_long_options = long_options;
  1650. +   _getopt_long_only = 0;
  1651.     val = getopt (argc, argv, options);
  1652.     if (val == 0 && opt_index != NULL)
  1653.       *opt_index = option_index;
  1654. diff -cbBw orig/io.c new/io.c
  1655. *** orig/io.c    Tue Dec 24 19:13:30 1991
  1656. --- new/io.c    Tue Dec 24 19:45:04 1991
  1657. ***************
  1658. *** 1,5 ****
  1659. --- 1,7 ----
  1660.   /* File I/O for GNU DIFF.
  1661.      Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  1662. +    Modified for DOS and OS/2 on 1991/09/14 by Kai Uwe Rommel
  1663. +     <rommel@ars.muc.de>.
  1664.  
  1665.   This file is part of GNU DIFF.
  1666.  
  1667. ***************
  1668. *** 20,27 ****
  1669. --- 22,33 ----
  1670.   #include "diff.h"
  1671.  
  1672.   /* Rotate a value n bits to the left. */
  1673. + #if !defined(MSDOS)
  1674.   #define UINT_BIT (sizeof (unsigned) * CHAR_BIT)
  1675.   #define ROL(v, n) ((v) << (n) | (v) >> UINT_BIT - (n))
  1676. + #else
  1677. + #define ROL(v,n)  ((v) << (n) | (v) >> (sizeof(v) * CHAR_BIT) - (n))
  1678. + #endif
  1679.  
  1680.   /* Given a hash value and a new character, return a new hash value. */
  1681.   #define HASH(h, c) ((c) + ROL (h, 7))
  1682. ***************
  1683. *** 57,66 ****
  1684. --- 63,79 ----
  1685.       1, 1, 1, 1, 1, 1, 1, 1,
  1686.       1, 1, 1, 1, 1, 1, 1, 1,
  1687.       1, 1, 1, 1, 1, 1, 1, 0,
  1688. + #ifdef MSDOS
  1689. +     1, 1, 1, 1, 1, 1, 1, 1,
  1690. +     1, 1, 1, 1, 1, 1, 1, 1,
  1691. +     1, 1, 1, 1, 1, 1, 1, 1,
  1692. +     1, 1, 1, 1, 1, 1, 1, 1,
  1693. + #else
  1694.       0, 0, 0, 0, 0, 0, 0, 0,
  1695.       0, 0, 0, 0, 0, 0, 0, 0,
  1696.       0, 0, 0, 0, 0, 0, 0, 0,
  1697.       0, 0, 0, 0, 0, 0, 0, 0,
  1698. + #endif
  1699.       1, 1, 1, 1, 1, 1, 1, 1,
  1700.       1, 1, 1, 1, 1, 1, 1, 1,
  1701.       1, 1, 1, 1, 1, 1, 1, 1,
  1702. ***************
  1703. *** 101,106 ****
  1704. --- 114,120 ----
  1705.        beyond those that current->bufsize describes:
  1706.        one for a newline (in case the text does not end with one)
  1707.        and one for a sentinel in find_identical_ends.  */
  1708. + #if !defined(MSDOS)
  1709.     else if ((current->stat.st_mode & S_IFMT) == S_IFREG)
  1710.       {
  1711.         current->bufsize = current->stat.st_size;
  1712. ***************
  1713. *** 136,146 ****
  1714.         if (cc < 0)
  1715.       pfatal_with_name (current->name);
  1716.       }
  1717.  
  1718.     /* Check first part of file to see if it's a binary file.  */
  1719.     if (! always_text_flag
  1720.         && binary_file_p (current->buffer,
  1721. !             min (current->buffered_chars, binary_file_threshold)))
  1722.       return 1;
  1723.  
  1724.     /* If not binary, make sure text ends in a newline,
  1725. --- 150,201 ----
  1726.         if (cc < 0)
  1727.       pfatal_with_name (current->name);
  1728.       }
  1729. + #else /* MSDOS */
  1730. +   else {
  1731. +       int count;
  1732. +       char huge *ptr;
  1733. +       char *buf;
  1734. + #ifdef __TURBOC__
  1735. +       int cnt;
  1736. + #endif
  1737. +
  1738. +       current->bufsize = current->stat.st_size + 1;
  1739. +       if((current->buffer = halloc(current->bufsize + 2,sizeof(char))) == NULL)
  1740. +              fatal("virtual memory exhausted");
  1741. +
  1742. +       current->buffered_chars = 0;
  1743. +       ptr = current->buffer;
  1744. +
  1745. +      /* this kludge is the only way to prevent read() from segment
  1746. +       * wraparounds in real mode in a OS/2 family mode application  :-( :-(
  1747. +       */
  1748. +
  1749. +       if((buf = malloc(16384)) == NULL)
  1750. +              fatal("virtual memory exhausted");
  1751. +
  1752. +       while((count = read(current->desc, buf, 16384)) > 0)
  1753. +       {
  1754. + #ifdef __TURBOC__
  1755. +              for ( cnt = 0; cnt < count; cnt++ )
  1756. +                 ptr[cnt] = buf[cnt];
  1757. + #else
  1758. +              memcpy(ptr, buf, count); /* MS C memcpy is aware of huge pointers */
  1759. + #endif
  1760. +              current->buffered_chars += count;
  1761. +              ptr += count;
  1762. +       }
  1763. +
  1764. +       free(buf);
  1765. +
  1766. +       if (count < 0)
  1767. +     pfatal_with_name (current->name);
  1768. +     }
  1769. + #endif        /* MSDOS */
  1770.  
  1771.     /* Check first part of file to see if it's a binary file.  */
  1772.     if (! always_text_flag
  1773.         && binary_file_p (current->buffer,
  1774. !             (int) min (current->buffered_chars, binary_file_threshold)))
  1775.       return 1;
  1776.  
  1777.     /* If not binary, make sure text ends in a newline,
  1778. ***************
  1779. *** 169,180 ****
  1780.   {
  1781.     unsigned h;
  1782.     int i;
  1783. !   unsigned char *p = (unsigned char *) current->prefix_end, *ip, c;
  1784.  
  1785.     /* Attempt to get a good initial guess as to the number of lines. */
  1786.     current->linbufsize = current->buffered_chars / 50 + 5;
  1787.     current->linbuf
  1788.       = (struct line_def *) xmalloc (current->linbufsize * sizeof (struct line_def));
  1789.  
  1790.     if (function_regexp || output_style == OUTPUT_IFDEF)
  1791.       {
  1792. --- 224,248 ----
  1793.   {
  1794.     unsigned h;
  1795.     int i;
  1796. ! #if !defined(MSDOS)
  1797. !   char *p = current->prefix_end, *ip, c;
  1798. ! #else
  1799. !   char huge *p = (char huge *) current->prefix_end;
  1800. !   char huge *ip, c;
  1801. !   int old;
  1802. ! #endif
  1803.  
  1804.     /* Attempt to get a good initial guess as to the number of lines. */
  1805.     current->linbufsize = current->buffered_chars / 50 + 5;
  1806. + #if !defined(MSDOS)
  1807.     current->linbuf
  1808.       = (struct line_def *) xmalloc (current->linbufsize * sizeof (struct line_def));
  1809. + #else
  1810. +   current->linbuf
  1811. +     = halloc(current->linbufsize, sizeof(struct line_def));
  1812. +   if ( current->linbuf == NULL )
  1813. +     fatal("virtual memory exhausted");
  1814. + #endif
  1815.  
  1816.     if (function_regexp || output_style == OUTPUT_IFDEF)
  1817.       {
  1818. ***************
  1819. *** 183,189 ****
  1820.        but since we don't know how many, it's easiest to find them all.
  1821.        If -D is specified, we need all the lines of the first file.  */
  1822.         current->buffered_lines = 0;
  1823. !       p = (unsigned char *) current->buffer;
  1824.       }
  1825.     else
  1826.       {
  1827. --- 251,257 ----
  1828.        but since we don't know how many, it's easiest to find them all.
  1829.        If -D is specified, we need all the lines of the first file.  */
  1830.         current->buffered_lines = 0;
  1831. !       p = current->buffer;
  1832.       }
  1833.     else
  1834.       {
  1835. ***************
  1836. *** 195,212 ****
  1837.       current->buffered_lines = 0;
  1838.         for (i = 0; i < context + 1; ++i)
  1839.       /* Unless we are at the beginning, */
  1840. !     if ((char *) p != current->buffer)
  1841.         /* Back up at least 1 char until at the start of a line.  */
  1842. !       while ((char *) --p != current->buffer && p[-1] != '\n')
  1843.           ;
  1844.       }
  1845.  
  1846. !   while ((char *) p < current->suffix_begin)
  1847.       {
  1848.         h = 0;
  1849.         ip = p;
  1850.  
  1851. !       if (current->prefix_end <= (char *) p)
  1852.       {
  1853.         /* Hash this line until we find a newline. */
  1854.         if (ignore_case_flag)
  1855. --- 263,280 ----
  1856.       current->buffered_lines = 0;
  1857.         for (i = 0; i < context + 1; ++i)
  1858.       /* Unless we are at the beginning, */
  1859. !     if (p != current->buffer)
  1860.         /* Back up at least 1 char until at the start of a line.  */
  1861. !       while ( --p != current->buffer && p[-1] != '\n')
  1862.           ;
  1863.       }
  1864.  
  1865. !   while (p < current->suffix_begin)
  1866.       {
  1867.         h = 0;
  1868.         ip = p;
  1869.  
  1870. !       if (current->prefix_end <= p)
  1871.       {
  1872.         /* Hash this line until we find a newline. */
  1873.         if (ignore_case_flag)
  1874. ***************
  1875. *** 291,298 ****
  1876. --- 359,368 ----
  1877.         /* Maybe increase the size of the line table. */
  1878.         if (current->buffered_lines >= current->linbufsize)
  1879.       {
  1880. + #ifndef MSDOS
  1881.         while (current->buffered_lines >= current->linbufsize)
  1882.           current->linbufsize *= 2;
  1883. +
  1884.         current->linbuf
  1885.           = (struct line_def *) xrealloc (current->linbuf,
  1886.                           current->linbufsize
  1887. ***************
  1888. *** 297,304 ****
  1889.           = (struct line_def *) xrealloc (current->linbuf,
  1890.                           current->linbufsize
  1891.                           * sizeof (struct line_def));
  1892.       }
  1893. !       current->linbuf[current->buffered_lines].text = (char *) ip;
  1894.         current->linbuf[current->buffered_lines].length = p - ip + 1;
  1895.         current->linbuf[current->buffered_lines].hash = h;
  1896.         ++current->buffered_lines;
  1897. --- 367,387 ----
  1898.           = (struct line_def *) xrealloc (current->linbuf,
  1899.                           current->linbufsize
  1900.                           * sizeof (struct line_def));
  1901. + #else
  1902. +           old = current->linbufsize;
  1903. +
  1904. +       while (current->buffered_lines >= current->linbufsize)
  1905. +         current->linbufsize += 2048;
  1906. +
  1907. +       current->linbuf = hrealloc(current->linbuf,
  1908. +             (long) current->linbufsize * sizeof (struct line_def),
  1909. +             (long) old * sizeof (struct line_def));
  1910. +
  1911. +           if ( current->linbuf == NULL )
  1912. +              fatal("too many lines");
  1913. + #endif
  1914.       }
  1915. !       current->linbuf[current->buffered_lines].text = ip;
  1916.         current->linbuf[current->buffered_lines].length = p - ip + 1;
  1917.         current->linbuf[current->buffered_lines].hash = h;
  1918.         ++current->buffered_lines;
  1919. ***************
  1920. *** 307,313 ****
  1921. --- 390,400 ----
  1922.  
  1923.     i = 0;
  1924.     while ((i < context || output_style == OUTPUT_IFDEF)
  1925. + #ifndef MSDOS
  1926.        && (char *) p < current->buffer + current->buffered_chars)
  1927. + #else
  1928. +      && p < (char huge *) current->buffer + current->buffered_chars)
  1929. + #endif
  1930.       {
  1931.         ip = p;
  1932.         while (*p++ != '\n')
  1933. ***************
  1934. *** 315,322 ****
  1935. --- 402,411 ----
  1936.         /* Maybe increase the size of the line table. */
  1937.         if (current->buffered_lines >= current->linbufsize)
  1938.       {
  1939. + #ifndef MSDOS
  1940.         while (current->buffered_lines >= current->linbufsize)
  1941.           current->linbufsize *= 2;
  1942. +
  1943.         current->linbuf
  1944.           = (struct line_def *) xrealloc (current->linbuf,
  1945.                           current->linbufsize
  1946. ***************
  1947. *** 321,328 ****
  1948.           = (struct line_def *) xrealloc (current->linbuf,
  1949.                           current->linbufsize
  1950.                           * sizeof (struct line_def));
  1951.       }
  1952. !       current->linbuf[current->buffered_lines].text = (char *) ip;
  1953.         current->linbuf[current->buffered_lines].length = p - ip;
  1954.         current->linbuf[current->buffered_lines].hash = 0;
  1955.         ++current->buffered_lines;
  1956. --- 410,430 ----
  1957.           = (struct line_def *) xrealloc (current->linbuf,
  1958.                           current->linbufsize
  1959.                           * sizeof (struct line_def));
  1960. + #else
  1961. +           old = current->linbufsize;
  1962. +
  1963. +       while (current->buffered_lines >= current->linbufsize)
  1964. +         current->linbufsize += 2048;
  1965. +
  1966. +       current->linbuf = hrealloc(current->linbuf,
  1967. +             (long) current->linbufsize * sizeof (struct line_def),
  1968. +             (long) old * sizeof (struct line_def));
  1969. +
  1970. +           if ( current->linbuf == NULL )
  1971. +              fatal("too many lines");
  1972. + #endif
  1973.       }
  1974. !       current->linbuf[current->buffered_lines].text = ip;
  1975.         current->linbuf[current->buffered_lines].length = p - ip;
  1976.         current->linbuf[current->buffered_lines].hash = 0;
  1977.         ++current->buffered_lines;
  1978. ***************
  1979. *** 342,348 ****
  1980. --- 444,454 ----
  1981.   find_identical_ends (filevec)
  1982.        struct file_data filevec[];
  1983.   {
  1984. + #ifndef MSDOS
  1985.     char *p0, *p1, *end0, *beg0;
  1986. + #else
  1987. +   char huge *p0, huge *p1, huge *end0, huge *beg0;
  1988. + #endif
  1989.     int lines;
  1990.  
  1991.     if (filevec[0].buffered_chars == 0 || filevec[1].buffered_chars == 0)
  1992. ***************
  1993. *** 383,397 ****
  1994.     /* Don't count missing newline as part of prefix in RCS mode. */
  1995.     if (ROBUST_OUTPUT_STYLE (output_style)
  1996.         && ((filevec[0].missing_newline
  1997. !        && p0 - filevec[0].buffer > filevec[0].buffered_chars)
  1998.         ||
  1999.         (filevec[1].missing_newline
  2000. !        && p1 - filevec[1].buffer > filevec[1].buffered_chars)))
  2001.       --p0, --p1, --lines;
  2002.  
  2003.     /* If the sentinel was passed, and lengths are equal, the
  2004.        files are identical.  */
  2005. !   if (p0 - filevec[0].buffer > filevec[0].buffered_chars
  2006.         && filevec[0].buffered_chars == filevec[1].buffered_chars)
  2007.       {
  2008.         filevec[0].prefix_end = p0 - 1;
  2009. --- 489,503 ----
  2010.     /* Don't count missing newline as part of prefix in RCS mode. */
  2011.     if (ROBUST_OUTPUT_STYLE (output_style)
  2012.         && ((filevec[0].missing_newline
  2013. !        && (p0 - filevec[0].buffer) > filevec[0].buffered_chars)
  2014.         ||
  2015.         (filevec[1].missing_newline
  2016. !        && (p1 - filevec[1].buffer) > filevec[1].buffered_chars)))
  2017.       --p0, --p1, --lines;
  2018.  
  2019.     /* If the sentinel was passed, and lengths are equal, the
  2020.        files are identical.  */
  2021. !   if ((p0 - filevec[0].buffer) > filevec[0].buffered_chars
  2022.         && filevec[0].buffered_chars == filevec[1].buffered_chars)
  2023.       {
  2024.         filevec[0].prefix_end = p0 - 1;
  2025. ***************
  2026. *** 435,445 ****
  2027.         else
  2028.       /* Figure out where P0 will be when P1 is at the end of the prefix.
  2029.          Thus we only need to test P0.  */
  2030. !     beg0 = (filevec[0].prefix_end
  2031. !         + filevec[0].buffered_chars - filevec[1].buffered_chars);
  2032.  
  2033.         /* Scan back until chars don't match or we reach that point.  */
  2034. !       while (p0 != beg0)
  2035.       {
  2036.         char c = *--p0;
  2037.         if (c != *--p1)
  2038. --- 541,551 ----
  2039.         else
  2040.       /* Figure out where P0 will be when P1 is at the end of the prefix.
  2041.          Thus we only need to test P0.  */
  2042. !     beg0 = filevec[0].prefix_end
  2043. !         + (filevec[0].buffered_chars - filevec[1].buffered_chars);
  2044.  
  2045.         /* Scan back until chars don't match or we reach that point.  */
  2046. !       while (p0 > beg0)
  2047.       {
  2048.         char c = *--p0;
  2049.         if (c != *--p1)
  2050. ***************
  2051. *** 483,488 ****
  2052. --- 589,597 ----
  2053.   {
  2054.     struct equivclass *next;    /* Next item in this bucket. */
  2055.     struct line_def line;    /* A line that fits this class. */
  2056. + #ifdef MSDOS
  2057. +   long dummy; /* to pad struct size to a power of two, 16 */
  2058. + #endif
  2059.   };
  2060.  
  2061.   /* Hash-table: array of buckets, each being a chain of equivalence classes.  */
  2062. ***************
  2063. *** 494,511 ****
  2064.   /* Array in which the equivalence classes are allocated.
  2065.      The bucket-chains go through the elements in this array.
  2066.      The number of an equivalence class is its index in this array.  */
  2067. ! static struct equivclass *equivs;
  2068.  
  2069.   /* Index of first free element in the array `equivs'.  */
  2070. ! static int equivs_index;
  2071.  
  2072.   /* Size allocated to the array `equivs'.  */
  2073. ! static int equivs_alloc;
  2074.  
  2075.   /* Largest primes less than some power of two, for nbuckets.  Values range
  2076.      from useful to preposterous.  If one of these numbers isn't prime
  2077.      after all, don't blame it on me, blame it on primes (6) . . . */
  2078. ! static int primes[] =
  2079.   {
  2080.     509,
  2081.     1021,
  2082. --- 603,620 ----
  2083.   /* Array in which the equivalence classes are allocated.
  2084.      The bucket-chains go through the elements in this array.
  2085.      The number of an equivalence class is its index in this array.  */
  2086. ! static struct equivclass huge *equivs;
  2087.  
  2088.   /* Index of first free element in the array `equivs'.  */
  2089. ! static long equivs_index;
  2090.  
  2091.   /* Size allocated to the array `equivs'.  */
  2092. ! static long equivs_alloc;
  2093.  
  2094.   /* Largest primes less than some power of two, for nbuckets.  Values range
  2095.      from useful to preposterous.  If one of these numbers isn't prime
  2096.      after all, don't blame it on me, blame it on primes (6) . . . */
  2097. ! static long primes[] =
  2098.   {
  2099.     509,
  2100.     1021,
  2101. ***************
  2102. *** 538,544 ****
  2103.        int n;
  2104.   {
  2105.     int bucket;
  2106. !   struct equivclass *b, *p = NULL;
  2107.  
  2108.     /* Equivalence class 0 is permanently allocated to lines that were
  2109.        not hashed because they were parts of identical prefixes or
  2110. --- 647,653 ----
  2111.        int n;
  2112.   {
  2113.     int bucket;
  2114. !   struct equivclass huge *b, huge *p = NULL;
  2115.  
  2116.     /* Equivalence class 0 is permanently allocated to lines that were
  2117.        not hashed because they were parts of identical prefixes or
  2118. ***************
  2119. *** 564,569 ****
  2120. --- 673,681 ----
  2121.  
  2122.     /* Create a new equivalence class in this bucket. */
  2123.  
  2124. +   if (equivs_index >= equivs_alloc)
  2125. +     fatal ("too many differences, hash table overflow");
  2126. +
  2127.     p = &equivs[equivs_index++];
  2128.     p->next = buckets[bucket];
  2129.     buckets[bucket] = p;
  2130. ***************
  2131. *** 601,608 ****
  2132.       }
  2133.  
  2134.     /* This is guaranteed to be enough space.  */
  2135. !   equivs_alloc = filevec[0].buffered_lines + filevec[1].buffered_lines + 1;
  2136.     equivs = (struct equivclass *) xmalloc (equivs_alloc * sizeof (struct equivclass));
  2137.     /* Equivalence class 0 is permanently safe for lines that were not
  2138.        hashed.  Real equivalence classes start at 1. */
  2139.     equivs_index = 1;
  2140. --- 713,726 ----
  2141.       }
  2142.  
  2143.     /* This is guaranteed to be enough space.  */
  2144. !   equivs_alloc = (long) filevec[0].buffered_lines + filevec[1].buffered_lines + 1L;
  2145. ! #ifndef MSDOS
  2146.     equivs = (struct equivclass *) xmalloc (equivs_alloc * sizeof (struct equivclass));
  2147. + #else
  2148. +   equivs = halloc (equivs_alloc, sizeof (struct equivclass));
  2149. +   if ( equivs == NULL )
  2150. +     fatal("virtual memory exhausted");
  2151. + #endif
  2152.     /* Equivalence class 0 is permanently safe for lines that were not
  2153.        hashed.  Real equivalence classes start at 1. */
  2154.     equivs_index = 1;
  2155. ***************
  2156. *** 611,618 ****
  2157. --- 729,752 ----
  2158.     while (primes[primes_index] < equivs_alloc / 3)
  2159.       primes_index++;
  2160.  
  2161. + #ifndef MSDOS
  2162.     buckets = (struct equivclass **) xmalloc (primes[primes_index] * sizeof (struct equivclass *));
  2163.     bzero (buckets, primes[primes_index] * sizeof (struct equivclass *));
  2164. + #else
  2165. +   buckets = halloc (primes[primes_index], sizeof (struct equivclass *));
  2166. + #ifdef __TURBOC__
  2167. +   /* Microsoft C's halloc already zeroes out the allocated memory.
  2168. +      So this bzero call is only needed for Turbo C and Borland C.
  2169. +      But note that the block may be bigger than 64k and that the bzero
  2170. +      (actually memset) will not fill out the whole block. But this
  2171. +      situation is not very likely to occur, because with Turbo C or
  2172. +      Borland C, you can only make a MS-DOS program, who's memory
  2173. +      is too restricted to diff such big files that this situation
  2174. +      may occur.
  2175. +   */
  2176. +   bzero (buckets, primes[primes_index] * sizeof (struct equivclass *));
  2177. + #endif
  2178. + #endif
  2179.     nbuckets = primes[primes_index];
  2180.  
  2181.     for (i = 0; i < 2; ++i)
  2182. ***************
  2183. *** 626,633 ****
  2184. --- 760,772 ----
  2185.  
  2186.     filevec[0].equiv_max = filevec[1].equiv_max = equivs_index;
  2187.  
  2188. + #ifndef MSDOS
  2189.     free (equivs);
  2190.     free (buckets);
  2191. + #else
  2192. +   hfree (equivs);
  2193. +   hfree (buckets);
  2194. + #endif
  2195.  
  2196.     return 0;
  2197.   }
  2198. diff -cbBw orig/limits.h new/limits.h
  2199. *** orig/limits.h    Tue Dec 24 19:13:30 1991
  2200. --- new/limits.h    Tue Dec 24 19:27:48 1991
  2201. ***************
  2202. *** 1,3 ****
  2203. --- 1,9 ----
  2204. + /*
  2205. +    Modified for DOS and OS/2 on 1991/09/14 by Kai Uwe Rommel
  2206. +     <rommel@ars.muc.de>.
  2207. +  */
  2208. +
  2209. +
  2210.   /* Number of bits in a `char'.  */
  2211.   #define CHAR_BIT 8
  2212.  
  2213. ***************
  2214. *** 28,38 ****
  2215. --- 34,52 ----
  2216.   #define USHRT_MAX 65535U
  2217.  
  2218.   /* Minimum and maximum values a `signed int' can hold.  */
  2219. + #ifdef MSDOS
  2220. + #define INT_MIN (-32768)
  2221. + #define INT_MAX 32767
  2222. +
  2223. + /* Maximum value an `unsigned int' can hold.  (Minimum is 0).  */
  2224. + #define UINT_MAX 65535U
  2225. + #else
  2226.   #define INT_MIN (-INT_MAX-1)
  2227.   #define INT_MAX 2147483647
  2228.  
  2229.   /* Maximum value an `unsigned int' can hold.  (Minimum is 0).  */
  2230.   #define UINT_MAX 4294967295U
  2231. + #endif
  2232.  
  2233.   /* Minimum and maximum values a `signed long int' can hold.
  2234.      (Same as `int').  */
  2235. Only in new: pc-files
  2236. Only in orig: regex.c
  2237. Only in orig: regex.h
  2238. diff -cbBw orig/util.c new/util.c
  2239. *** orig/util.c    Tue Dec 24 19:13:34 1991
  2240. --- new/util.c    Tue Dec 24 19:19:38 1991
  2241. ***************
  2242. *** 1,5 ****
  2243. --- 1,7 ----
  2244.   /* Support routines for GNU DIFF.
  2245.      Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  2246. +    Modified for DOS and OS/2 on 1991/09/14 by Kai Uwe Rommel
  2247. +     <rommel@ars.muc.de>.
  2248.  
  2249.   This file is part of GNU DIFF.
  2250.  
  2251. ***************
  2252. *** 51,57 ****
  2253.        char *arg;
  2254.        char *arg1;
  2255.   {
  2256. !   fprintf (stderr, "%s: ", program);
  2257.     fprintf (stderr, format, arg, arg1);
  2258.     fprintf (stderr, "\n");
  2259.   }
  2260. --- 53,59 ----
  2261.        char *arg;
  2262.        char *arg1;
  2263.   {
  2264. !   fprintf (stderr, "\n%s: ", program);
  2265.     fprintf (stderr, format, arg, arg1);
  2266.     fprintf (stderr, "\n");
  2267.   }
  2268. ***************
  2269. *** 129,134 ****
  2270. --- 131,147 ----
  2271.     strcat (name, " ");
  2272.     strcat (name, name1);
  2273.  
  2274. + #if defined(MSDOS)
  2275. +   if (paginate_flag)
  2276. +     {
  2277. +       extern FILE *popen();
  2278. +
  2279. +       /* Fork a `pr' and make OUTFILE a pipe to it.  */
  2280. +       outfile = popen("pr -o -", "w");
  2281. +       fprintf (outfile, "%s\n", name);
  2282. +     }
  2283. +   else
  2284. + #else
  2285.     if (paginate_flag)
  2286.       {
  2287.         int pipes[2];
  2288. ***************
  2289. *** 164,169 ****
  2290. --- 177,183 ----
  2291.       }
  2292.       }
  2293.     else
  2294. + #endif
  2295.       {
  2296.  
  2297.         /* If -l was not specified, output the diff straight to `stdout'.  */
  2298. ***************
  2299. *** 172,178 ****
  2300.  
  2301.         /* If handling multiple files (because scanning a directory),
  2302.        print which files the following output is about.  */
  2303. !       if (depth > 0)
  2304.       printf ("%s\n", name);
  2305.       }
  2306.  
  2307. --- 186,192 ----
  2308.  
  2309.         /* If handling multiple files (because scanning a directory),
  2310.        print which files the following output is about.  */
  2311. !       if (depth > 0 && !output_patch_flag)
  2312.       printf ("%s\n", name);
  2313.       }
  2314.  
  2315. ***************
  2316. *** 187,194 ****
  2317. --- 201,212 ----
  2318.   {
  2319.     if (outfile != stdout)
  2320.       {
  2321. + #if defined(MSDOS)
  2322. +       pclose (outfile);
  2323. + #else
  2324.         fclose (outfile);
  2325.         wait (0);
  2326. + #endif
  2327.       }
  2328.   }
  2329.   
  2330. ***************
  2331. *** 201,207 ****
  2332. --- 219,229 ----
  2333.   line_cmp (s1, s2)
  2334.        struct line_def *s1, *s2;
  2335.   {
  2336. + #ifdef MSDOS
  2337. +   char huge *t1, huge *t2;
  2338. + #else
  2339.     register char *t1, *t2;
  2340. + #endif
  2341.     register char end_char = line_end_char;
  2342.     int savechar;
  2343.  
  2344. ***************
  2345. *** 382,388 ****
  2346. --- 404,414 ----
  2347.        struct line_def *line;
  2348.   {
  2349.     int length = line->length; /* must be nonzero */
  2350. + #ifdef MSDOS
  2351. +   const char huge *text = line->text; /* Help the compiler.  */
  2352. + #else
  2353.     const char *text = line->text; /* Help the compiler.  */
  2354. + #endif
  2355.     FILE *out = outfile; /* Help the compiler some more.  */
  2356.  
  2357.     /* If -T was specified, use a Tab between the line-flag and the text.
  2358. diff -cbBw orig/version.c new/version.c
  2359. *** orig/version.c    Tue Dec 24 19:13:34 1991
  2360. --- new/version.c    Tue Dec 24 19:29:16 1991
  2361. ***************
  2362. *** 1,3 ****
  2363.   /* Version number of GNU diff.  */
  2364.  
  2365. ! char *version_string = "1.15";
  2366. --- 1,11 ----
  2367.   /* Version number of GNU diff.  */
  2368. + /*
  2369. +    Modified for DOS and OS/2 on 1991/09/14 by Kai Uwe Rommel
  2370. +     <rommel@ars.muc.de>.
  2371. + */
  2372.  
  2373. ! char *version_string = "1.15 (16-bit)";
  2374. !
  2375. ! #ifdef __TURBOC__
  2376. ! unsigned _stklen = 0x8000;
  2377. ! #endif
  2378.