home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / rcs / sources / diff115.dif < prev    next >
Text File  |  1991-12-24  |  66KB  |  2,302 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@informatik.tu-muenchen.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@informatik.tu-muenchen.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@informatik.tu-muenchen.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@informatik.tu-muenchen.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.c
  984. *** orig/diff3.c    Tue Dec 24 19:13:24 1991
  985. --- new/diff3.c    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@informatik.tu-muenchen.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. *** 390,398 ****
  1049.   void
  1050.   usage ()
  1051.   {
  1052. !   fprintf (stderr, "Usage:\t%s [-exEX3 [-i | -m] [-L label1 -L label3]] file1 file2 file3\n",
  1053.          argv0);
  1054. !   fprintf (stderr, "\tOnly one of [exEX3] allowed\n");
  1055.     exit (2);
  1056.   }
  1057.   
  1058. --- 422,444 ----
  1059.   void
  1060.   usage ()
  1061.   {
  1062. !   extern char *version_string;
  1063. !
  1064. !   printf ("\nGNU diff3, version %s\n", version_string);
  1065. !   printf ("\nUsage:\t%s [-exEX3 [-a] [-i | -m] [-L label1 -L label3]] file1 file2 file3\n",
  1066.          argv0);
  1067. !
  1068. !   printf ("\n  -e   Create ed script."
  1069. !           "\n  -x   ED script, write only overlapping diffs."
  1070. !           "\n  -E   ED script, flag overlapping diffs."
  1071. !           "\n  -X   ED script, write and flag only overlapping diffs."
  1072. !           "\n  -3   ED script, write only non-overlapping diffs."
  1073. !           "\n  -a   Treat all files as text, never as binary."
  1074. !           "\n  -i   Like -e, but append final :wq commands."
  1075. !           "\n  -m   Output a merged file."
  1076. !           "\n  -L label   use the specified label for lines output by the -E and -X options.\n");
  1077. !
  1078. !   printf ("\nOnly one of [exEX3] is allowed.\n");
  1079.     exit (2);
  1080.   }
  1081.   
  1082. ***************
  1083. *** 960,967 ****
  1084.    * Routines to input and parse two way diffs.
  1085.    */
  1086.  
  1087. - extern char **environ;
  1088. -
  1089.   #define    DIFF_CHUNK_SIZE    10000
  1090.  
  1091.   struct diff_block *
  1092. --- 1006,1011 ----
  1093. ***************
  1094. *** 1170,1182 ****
  1095. --- 1214,1233 ----
  1096.        char *filea, *fileb;
  1097.        char **output_placement;
  1098.   {
  1099. + #ifndef MSDOS
  1100.     char *argv[6];
  1101.     char **ap;
  1102. + #endif
  1103.     int fds[2];
  1104.     char *diff_result;
  1105.     int current_chunk_size;
  1106.     int bytes;
  1107.     int total;
  1108. + #ifdef MSDOS
  1109. +   FILE *pipe;
  1110. +   char buffer[256];
  1111. +   int wstatus;
  1112. + #else
  1113.     int pid, w;
  1114.     int wstatus;
  1115.  
  1116. ***************
  1117. *** 1188,1194 ****
  1118. --- 1239,1251 ----
  1119.     *ap++ = filea;
  1120.     *ap++ = fileb;
  1121.     *ap = (char *) 0;
  1122. + #endif
  1123.  
  1124. + #ifdef MSDOS
  1125. +   sprintf(buffer, "%s -a -- %s %s", diff_program, filea, fileb);
  1126. +   pipe = popen(buffer, "r");
  1127. +   fds[0] = fileno(pipe);
  1128. + #else
  1129.     if (pipe (fds) < 0)
  1130.       perror_with_exit ("Pipe failed");
  1131.  
  1132. ***************
  1133. *** 1213,1218 ****
  1134. --- 1270,1276 ----
  1135.       perror_with_exit ("Fork failed");
  1136.  
  1137.     close (fds[1]);        /* Prevent erroneous lack of EOF */
  1138. + #endif
  1139.     current_chunk_size = DIFF_CHUNK_SIZE;
  1140.     diff_result = (char *) xmalloc (current_chunk_size);
  1141.     total = 0;
  1142. ***************
  1143. *** 1222,1228 ****
  1144. --- 1280,1291 ----
  1145.               current_chunk_size - total);
  1146.       total += bytes;
  1147.       if (total == current_chunk_size)
  1148. + #ifdef MSDOS
  1149. +       diff_result = (char *) xrealloc (diff_result,
  1150. +         (current_chunk_size += DIFF_CHUNK_SIZE));
  1151. + #else
  1152.         diff_result = (char *) xrealloc (diff_result, (current_chunk_size *= 2));
  1153. + #endif
  1154.     } while (bytes);
  1155.  
  1156.     if (total != 0 && diff_result[total-1] != '\n')
  1157. ***************
  1158. *** 1230,1239 ****
  1159. --- 1293,1306 ----
  1160.  
  1161.     *output_placement = diff_result;
  1162.  
  1163. + #ifdef MSDOS
  1164. +   wstatus = pclose(pipe);
  1165. + #else
  1166.     do
  1167.       if ((w = wait (&wstatus)) == -1)
  1168.         perror_with_exit ("Wait failed");
  1169.     while (w != pid);
  1170. + #endif
  1171.  
  1172.     if (! (WIFEXITED (wstatus) && WEXITSTATUS (wstatus) < 2))
  1173.       fatal ("Subsidiary diff failed");
  1174. ***************
  1175. *** 1332,1338 ****
  1176.       case DIFF_3RD:
  1177.         oddoneout = rev_mapping[(int) ptr->correspond - (int) DIFF_1ST];
  1178.  
  1179. !       x[0] = oddoneout + '1';
  1180.         x[1] = '\0';
  1181.         dontprint = oddoneout==0;
  1182.         break;
  1183. --- 1399,1405 ----
  1184.       case DIFF_3RD:
  1185.         oddoneout = rev_mapping[(int) ptr->correspond - (int) DIFF_1ST];
  1186.  
  1187. !       x[0] = (char) (oddoneout + '1');
  1188.         x[1] = '\0';
  1189.         dontprint = oddoneout==0;
  1190.         break;
  1191. diff -cbBw orig/dir.c new/dir.c
  1192. *** orig/dir.c    Tue Dec 24 19:13:24 1991
  1193. --- new/dir.c    Tue Dec 24 19:37:14 1991
  1194. ***************
  1195. *** 1,5 ****
  1196. --- 1,7 ----
  1197.   /* Read, sort and compare two directories.  Used for GNU DIFF.
  1198.      Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  1199. +    Modified for DOS and OS/2 on 1991/09/14 by Kai Uwe Rommel
  1200. +     <rommel@informatik.tu-muenchen.de>.
  1201.  
  1202.   This file is part of GNU DIFF.
  1203.  
  1204. ***************
  1205. *** 31,36 ****
  1206. --- 33,201 ----
  1207.     char **files;            /* Sorted names of files in the dir */
  1208.   };
  1209.  
  1210. + #if defined(MSDOS)
  1211. + /*
  1212. + ** due to difference of opinion btw gnu and microsoft about what
  1213. + ** const means, const is defined away in diff.h, which causes warnings
  1214. + ** when compiling the headers.  This ugliness is avoided here.
  1215. + */
  1216. + #ifdef const
  1217. + #undef const
  1218. + #endif
  1219. + #include <string.h>
  1220. + #include <ctype.h>
  1221. + #ifdef OS2
  1222. + #define strcmp stricmp
  1223. +   /* stricmp() this is important for the HPFS because it is
  1224. +   /* case-preserving but NOT case-sensitive */
  1225. + #include <stdlib.h>
  1226. + #define INCL_NOPM
  1227. + #include <os2.h>
  1228. + #define _A_NORMAL        0x00
  1229. + #define _A_SUBDIR        0x10
  1230. + #define _MAX_NAME        256
  1231. + #else
  1232. + #ifdef __TURBOC__
  1233. + #include <dir.h>
  1234. + #define _A_NORMAL        0x00
  1235. + #define _A_SUBDIR        0x10
  1236. + #endif
  1237. + #include <dos.h>
  1238. + #define _MAX_NAME        13
  1239. + #endif
  1240. +
  1241. + struct direct {
  1242. +     char d_name[_MAX_NAME];
  1243. + };
  1244. +
  1245. + typedef struct _dir {
  1246. +         int first;
  1247. + #ifdef OS2
  1248. +         FILEFINDBUF find;
  1249. + #else
  1250. + #ifdef __TURBOC__
  1251. +         struct ffblk dta;
  1252. + #else
  1253. +         struct find_t dta;
  1254. + #endif
  1255. + #endif
  1256. +     struct direct current;
  1257. + } DIR;
  1258. +
  1259. + #ifdef OS2
  1260. + static HDIR hdir;
  1261. + static USHORT count;
  1262. + static BOOL lower;
  1263. + #endif
  1264. +
  1265. + #ifdef OS2
  1266. + int IsFileSystemFAT(char *dir)
  1267. + {
  1268. +   USHORT nDrive;
  1269. +   ULONG lMap;
  1270. +   BYTE bData[64], bName[3];
  1271. +   USHORT cbData;
  1272. +
  1273. +   if ( _osmode == DOS_MODE )
  1274. +     return TRUE;
  1275. +   else
  1276. +   {
  1277. +     /* We separate FAT and HPFS file systems here.
  1278. +      * Filenames read from a FAT system are converted to lower case
  1279. +      * while the case of filenames read from a HPFS (and other future
  1280. +      * file systems, like Unix-compatibles) is preserved.
  1281. +      */
  1282. +
  1283. +     if ( isalpha(dir[0]) && (dir[1] == ':') )
  1284. +       nDrive = toupper(dir[0]) - '@';
  1285. +     else
  1286. +       DosQCurDisk(&nDrive, &lMap);
  1287. +
  1288. +     bName[0] = (char) (nDrive + '@');
  1289. +     bName[1] = ':';
  1290. +     bName[2] = 0;
  1291. +
  1292. +     cbData = sizeof(bData);
  1293. +
  1294. +     if ( !DosQFSAttach(bName, 0U, 1U, bData, &cbData, 0L) )
  1295. +       return !strcmp(bData + (*(USHORT *) (bData + 2) + 7), "FAT");
  1296. +     else
  1297. +       return FALSE;
  1298. +
  1299. +     /* End of this ugly code */
  1300. +   }
  1301. + }
  1302. + #endif
  1303. +
  1304. + DIR *
  1305. + opendir(char *name) {
  1306. +     char localname[_MAX_NAME];
  1307. +     DIR *rval = malloc(sizeof(DIR));
  1308. +     strcpy(localname,name);
  1309. +         strcat(localname,"/*.*");
  1310. + #ifdef OS2
  1311. +         lower = IsFileSystemFAT(name);
  1312. +         hdir = count = 1;
  1313. + #endif
  1314. +     if(rval == NULL ||
  1315. + #ifdef OS2
  1316. +            DosFindFirst(localname, &hdir, _A_NORMAL|_A_SUBDIR, &rval->find,
  1317. +                         sizeof(FILEFINDBUF), &count, 0L) != 0)
  1318. + #else
  1319. + #ifdef __TURBOC__
  1320. +           findfirst(localname,&rval->dta,_A_NORMAL|_A_SUBDIR) != 0)
  1321. + #else
  1322. +           _dos_findfirst(localname,_A_NORMAL|_A_SUBDIR,&rval->dta) != 0)
  1323. + #endif
  1324. + #endif
  1325. +                 return NULL;
  1326. +     rval->first = 1;
  1327. +     return rval;
  1328. + }
  1329. +
  1330. + void
  1331. + closedir(DIR *x) {
  1332. +     free(x);
  1333. + }
  1334. +
  1335. + struct direct *
  1336. + readdir(DIR *thisdir) {
  1337. +     /*
  1338. +     ** first time through, we don't need to look for a file
  1339. +     */
  1340. +         if(!thisdir->first) {
  1341. + #ifdef OS2
  1342. +                 if(DosFindNext(hdir, &thisdir->find, sizeof(FILEFINDBUF),
  1343. +                                &count) != 0)
  1344. + #else
  1345. + #ifdef __TURBOC__
  1346. +                 if(findnext(&thisdir->dta) != 0)
  1347. + #else
  1348. +                 if(_dos_findnext(&thisdir->dta) != 0)
  1349. + #endif
  1350. + #endif
  1351. +             return NULL;
  1352. +     } else
  1353. +                 thisdir->first = 0;
  1354. + #ifdef OS2
  1355. +         strcpy(thisdir->current.d_name,thisdir->find.achName);
  1356. + #else
  1357. + #ifdef __BORLANDC__
  1358. +         strcpy(thisdir->current.d_name,thisdir->dta.ff_name);
  1359. + #else
  1360. +         strcpy(thisdir->current.d_name,thisdir->dta.name);
  1361. + #endif
  1362. + #endif
  1363. +     /* thisdir->current.d_name[13] = '\0'; */
  1364. + #ifdef OS2
  1365. +         if ( lower )
  1366. + #endif
  1367. +       strlwr(thisdir->current.d_name);
  1368. +     return &thisdir->current;
  1369. + }
  1370. +
  1371. + #endif /* MSDOS */
  1372. +
  1373.   static struct dirdata
  1374.   dir_sort (dirname, nonex)
  1375.        char *dirname;
  1376. ***************
  1377. *** 135,142 ****
  1378.   int
  1379.   diff_dirs (name1, name2, handle_file, depth, nonex1, nonex2)
  1380.        char *name1, *name2;
  1381.        int (*handle_file) ();
  1382. !      int nonex1, nonex2;
  1383.   {
  1384.     struct dirdata data1, data2;
  1385.     register int i1, i2;
  1386. --- 300,315 ----
  1387.   int
  1388.   diff_dirs (name1, name2, handle_file, depth, nonex1, nonex2)
  1389.        char *name1, *name2;
  1390. + #if !defined(MSDOS)
  1391.        int (*handle_file) ();
  1392. ! #else
  1393. !       /* sorry, rms, I can't live with the assumption that
  1394. !       ** sizeof(char *) == sizeof(int)
  1395. !       */
  1396. !       int (*handle_file)(char *dir0,char *name0,
  1397. !               char *dir1,char *name1,int depth);
  1398. ! #endif
  1399. !      int depth, nonex1, nonex2;
  1400.   {
  1401.     struct dirdata data1, data2;
  1402.     register int i1, i2;
  1403. diff -cbBw orig/getopt.c new/getopt.c
  1404. *** orig/getopt.c    Tue Dec 24 19:13:26 1991
  1405. --- new/getopt.c    Tue Dec 24 19:19:20 1991
  1406. ***************
  1407. *** 1,5 ****
  1408. --- 1,7 ----
  1409.   /* Getopt for GNU.
  1410.      Copyright (C) 1987, 1989, 1990 Free Software Foundation, Inc.
  1411. +    Modified for DOS and OS/2 on 1991/09/14 by Kai Uwe Rommel
  1412. +     <rommel@informatik.tu-muenchen.de>.
  1413.  
  1414.      This program is free software; you can redistribute it and/or modify
  1415.      it under the terms of the GNU General Public License as published by
  1416. ***************
  1417. *** 15,25 ****
  1418.      along with this program; if not, write to the Free Software
  1419.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  1420.   
  1421. ! #ifdef __STDC__
  1422.   #define CONST const
  1423.   #else
  1424.   #define CONST
  1425.   #endif
  1426.  
  1427.   /* This version of `getopt' appears to the caller like standard Unix `getopt'
  1428.      but it behaves differently for the user, since it allows the user
  1429. --- 17,30 ----
  1430.      along with this program; if not, write to the Free Software
  1431.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  1432.   
  1433. ! #if defined(__STDC__) || defined(MSDOS)
  1434.   #define CONST const
  1435.   #else
  1436.   #define CONST
  1437.   #endif
  1438. + #ifdef MSDOS
  1439. + #define STDC_HEADERS
  1440. + #endif
  1441.  
  1442.   /* This version of `getopt' appears to the caller like standard Unix `getopt'
  1443.      but it behaves differently for the user, since it allows the user
  1444. ***************
  1445. *** 44,51 ****
  1446. --- 49,64 ----
  1447.   #ifdef sparc
  1448.   #include <alloca.h>
  1449.   #else
  1450. + #ifdef MSDOS
  1451. + #ifdef __TURBOC__
  1452. + #include <alloc.h>
  1453. + #else
  1454. + #include <malloc.h>
  1455. + #endif
  1456. + #else
  1457.   char *alloca ();
  1458.   #endif
  1459. + #endif
  1460.   #endif /* not __GNUC__ */
  1461.  
  1462.   #if defined(STDC_HEADERS) || defined(__GNU_LIBRARY__)
  1463. ***************
  1464. *** 72,77 ****
  1465. --- 85,92 ----
  1466.   char *malloc ();
  1467.   #endif
  1468.  
  1469. + static void exchange (char **);
  1470. +
  1471.   /* For communication from `getopt' to the caller.
  1472.      When `getopt' finds an option that takes an argument,
  1473.      the argument value is returned here.
  1474. ***************
  1475. *** 376,382 ****
  1476.          p++, option_index++)
  1477.       if (!strncmp (p->name, nextchar, s - nextchar))
  1478.         {
  1479. !         if (s - nextchar == strlen (p->name))
  1480.             {
  1481.           /* Exact match found.  */
  1482.           pfound = p;
  1483. --- 391,397 ----
  1484.          p++, option_index++)
  1485.       if (!strncmp (p->name, nextchar, s - nextchar))
  1486.         {
  1487. !         if (s - nextchar == (int) strlen (p->name))
  1488.             {
  1489.           /* Exact match found.  */
  1490.           pfound = p;
  1491. diff -cbBw orig/getopt.h new/getopt.h
  1492. *** orig/getopt.h    Tue Dec 24 19:13:26 1991
  1493. --- new/getopt.h    Tue Dec 24 19:19:24 1991
  1494. ***************
  1495. *** 1,5 ****
  1496. --- 1,7 ----
  1497.   /* declarations for getopt
  1498.      Copyright (C) 1989, 1990 Free Software Foundation, Inc.
  1499. +    Modified for DOS and OS/2 on 1991/09/14 by Kai Uwe Rommel
  1500. +     <rommel@informatik.tu-muenchen.de>.
  1501.  
  1502.      This program is free software; you can redistribute it and/or modify
  1503.      it under the terms of the GNU General Public License as published by
  1504. ***************
  1505. *** 70,76 ****
  1506.     int val;
  1507.   };
  1508.  
  1509. ! #ifdef __STDC__
  1510.   extern const struct option *_getopt_long_options;
  1511.   #else
  1512.   extern struct option *_getopt_long_options;
  1513. --- 72,78 ----
  1514.     int val;
  1515.   };
  1516.  
  1517. ! #if defined(__STDC__) || defined(MSDOS)
  1518.   extern const struct option *_getopt_long_options;
  1519.   #else
  1520.   extern struct option *_getopt_long_options;
  1521. ***************
  1522. *** 87,93 ****
  1523.  
  1524.   extern int option_index;
  1525.  
  1526. ! #ifdef __STDC__
  1527.   int getopt (int argc, char **argv, const char *shortopts);
  1528.   int getopt_long (int argc, char **argv, const char *shortopts,
  1529.            const struct option *longopts, int *longind);
  1530. --- 89,95 ----
  1531.  
  1532.   extern int option_index;
  1533.  
  1534. ! #if defined(__STDC__) || defined(MSDOS)
  1535.   int getopt (int argc, char **argv, const char *shortopts);
  1536.   int getopt_long (int argc, char **argv, const char *shortopts,
  1537.            const struct option *longopts, int *longind);
  1538. diff -cbBw orig/getopt1.c new/getopt1.c
  1539. *** orig/getopt1.c    Tue Dec 24 19:13:26 1991
  1540. --- new/getopt1.c    Tue Dec 24 19:19:30 1991
  1541. ***************
  1542. *** 1,5 ****
  1543. --- 1,7 ----
  1544.   /* Getopt for GNU.
  1545.      Copyright (C) 1987, 1989 Free Software Foundation, Inc.
  1546. +    Modified for DOS and OS/2 on 1991/09/14 by Kai Uwe Rommel
  1547. +     <rommel@informatik.tu-muenchen.de>.
  1548.  
  1549.      This program is free software; you can redistribute it and/or modify
  1550.      it under the terms of the GNU General Public License as published by
  1551. ***************
  1552. *** 17,23 ****
  1553.   
  1554.   #include "getopt.h"
  1555.  
  1556. ! #ifdef __STDC__
  1557.   #define CONST const
  1558.   #else
  1559.   #define CONST
  1560. --- 19,25 ----
  1561.   
  1562.   #include "getopt.h"
  1563.  
  1564. ! #if defined(__STDC__) || defined(MSDOS)
  1565.   #define CONST const
  1566.   #else
  1567.   #define CONST
  1568. ***************
  1569. *** 38,43 ****
  1570. --- 40,46 ----
  1571.     int val;
  1572.  
  1573.     _getopt_long_options = long_options;
  1574. +   _getopt_long_only = 0;
  1575.     val = getopt (argc, argv, options);
  1576.     if (val == 0 && opt_index != NULL)
  1577.       *opt_index = option_index;
  1578. diff -cbBw orig/io.c new/io.c
  1579. *** orig/io.c    Tue Dec 24 19:13:30 1991
  1580. --- new/io.c    Tue Dec 24 19:45:04 1991
  1581. ***************
  1582. *** 1,5 ****
  1583. --- 1,7 ----
  1584.   /* File I/O for GNU DIFF.
  1585.      Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  1586. +    Modified for DOS and OS/2 on 1991/09/14 by Kai Uwe Rommel
  1587. +     <rommel@informatik.tu-muenchen.de>.
  1588.  
  1589.   This file is part of GNU DIFF.
  1590.  
  1591. ***************
  1592. *** 20,27 ****
  1593. --- 22,33 ----
  1594.   #include "diff.h"
  1595.  
  1596.   /* Rotate a value n bits to the left. */
  1597. + #if !defined(MSDOS)
  1598.   #define UINT_BIT (sizeof (unsigned) * CHAR_BIT)
  1599.   #define ROL(v, n) ((v) << (n) | (v) >> UINT_BIT - (n))
  1600. + #else
  1601. + #define ROL(v,n)  ((v) << (n) | (v) >> (sizeof(v) * CHAR_BIT) - (n))
  1602. + #endif
  1603.  
  1604.   /* Given a hash value and a new character, return a new hash value. */
  1605.   #define HASH(h, c) ((c) + ROL (h, 7))
  1606. ***************
  1607. *** 57,66 ****
  1608. --- 63,79 ----
  1609.       1, 1, 1, 1, 1, 1, 1, 1,
  1610.       1, 1, 1, 1, 1, 1, 1, 1,
  1611.       1, 1, 1, 1, 1, 1, 1, 0,
  1612. + #ifdef MSDOS
  1613. +     1, 1, 1, 1, 1, 1, 1, 1,
  1614. +     1, 1, 1, 1, 1, 1, 1, 1,
  1615. +     1, 1, 1, 1, 1, 1, 1, 1,
  1616. +     1, 1, 1, 1, 1, 1, 1, 1,
  1617. + #else
  1618.       0, 0, 0, 0, 0, 0, 0, 0,
  1619.       0, 0, 0, 0, 0, 0, 0, 0,
  1620.       0, 0, 0, 0, 0, 0, 0, 0,
  1621.       0, 0, 0, 0, 0, 0, 0, 0,
  1622. + #endif
  1623.       1, 1, 1, 1, 1, 1, 1, 1,
  1624.       1, 1, 1, 1, 1, 1, 1, 1,
  1625.       1, 1, 1, 1, 1, 1, 1, 1,
  1626. ***************
  1627. *** 101,106 ****
  1628. --- 114,120 ----
  1629.        beyond those that current->bufsize describes:
  1630.        one for a newline (in case the text does not end with one)
  1631.        and one for a sentinel in find_identical_ends.  */
  1632. + #if !defined(MSDOS)
  1633.     else if ((current->stat.st_mode & S_IFMT) == S_IFREG)
  1634.       {
  1635.         current->bufsize = current->stat.st_size;
  1636. ***************
  1637. *** 136,146 ****
  1638.         if (cc < 0)
  1639.       pfatal_with_name (current->name);
  1640.       }
  1641.  
  1642.     /* Check first part of file to see if it's a binary file.  */
  1643.     if (! always_text_flag
  1644.         && binary_file_p (current->buffer,
  1645. !             min (current->buffered_chars, binary_file_threshold)))
  1646.       return 1;
  1647.  
  1648.     /* If not binary, make sure text ends in a newline,
  1649. --- 150,201 ----
  1650.         if (cc < 0)
  1651.       pfatal_with_name (current->name);
  1652.       }
  1653. + #else /* MSDOS */
  1654. +   else {
  1655. +       int count;
  1656. +       char huge *ptr;
  1657. +       char *buf;
  1658. + #ifdef __TURBOC__
  1659. +       int cnt;
  1660. + #endif
  1661. +
  1662. +       current->bufsize = current->stat.st_size + 1;
  1663. +       if((current->buffer = halloc(current->bufsize + 2,sizeof(char))) == NULL)
  1664. +              fatal("virtual memory exhausted");
  1665. +
  1666. +       current->buffered_chars = 0;
  1667. +       ptr = current->buffer;
  1668. +
  1669. +      /* this kludge is the only way to prevent read() from segment
  1670. +       * wraparounds in real mode in a OS/2 family mode application  :-( :-(
  1671. +       */
  1672. +
  1673. +       if((buf = malloc(16384)) == NULL)
  1674. +              fatal("virtual memory exhausted");
  1675. +
  1676. +       while((count = read(current->desc, buf, 16384)) > 0)
  1677. +       {
  1678. + #ifdef __TURBOC__
  1679. +              for ( cnt = 0; cnt < count; cnt++ )
  1680. +                 ptr[cnt] = buf[cnt];
  1681. + #else
  1682. +              memcpy(ptr, buf, count); /* MS C memcpy is aware of huge pointers */
  1683. + #endif
  1684. +              current->buffered_chars += count;
  1685. +              ptr += count;
  1686. +       }
  1687. +
  1688. +       free(buf);
  1689. +
  1690. +       if (count < 0)
  1691. +     pfatal_with_name (current->name);
  1692. +     }
  1693. + #endif        /* MSDOS */
  1694.  
  1695.     /* Check first part of file to see if it's a binary file.  */
  1696.     if (! always_text_flag
  1697.         && binary_file_p (current->buffer,
  1698. !             (int) min (current->buffered_chars, binary_file_threshold)))
  1699.       return 1;
  1700.  
  1701.     /* If not binary, make sure text ends in a newline,
  1702. ***************
  1703. *** 169,180 ****
  1704.   {
  1705.     unsigned h;
  1706.     int i;
  1707. !   unsigned char *p = (unsigned char *) current->prefix_end, *ip, c;
  1708.  
  1709.     /* Attempt to get a good initial guess as to the number of lines. */
  1710.     current->linbufsize = current->buffered_chars / 50 + 5;
  1711.     current->linbuf
  1712.       = (struct line_def *) xmalloc (current->linbufsize * sizeof (struct line_def));
  1713.  
  1714.     if (function_regexp || output_style == OUTPUT_IFDEF)
  1715.       {
  1716. --- 224,248 ----
  1717.   {
  1718.     unsigned h;
  1719.     int i;
  1720. ! #if !defined(MSDOS)
  1721. !   char *p = current->prefix_end, *ip, c;
  1722. ! #else
  1723. !   char huge *p = (char huge *) current->prefix_end;
  1724. !   char huge *ip, c;
  1725. !   int old;
  1726. ! #endif
  1727.  
  1728.     /* Attempt to get a good initial guess as to the number of lines. */
  1729.     current->linbufsize = current->buffered_chars / 50 + 5;
  1730. + #if !defined(MSDOS)
  1731.     current->linbuf
  1732.       = (struct line_def *) xmalloc (current->linbufsize * sizeof (struct line_def));
  1733. + #else
  1734. +   current->linbuf
  1735. +     = halloc(current->linbufsize, sizeof(struct line_def));
  1736. +   if ( current->linbuf == NULL )
  1737. +     fatal("virtual memory exhausted");
  1738. + #endif
  1739.  
  1740.     if (function_regexp || output_style == OUTPUT_IFDEF)
  1741.       {
  1742. ***************
  1743. *** 183,189 ****
  1744.        but since we don't know how many, it's easiest to find them all.
  1745.        If -D is specified, we need all the lines of the first file.  */
  1746.         current->buffered_lines = 0;
  1747. !       p = (unsigned char *) current->buffer;
  1748.       }
  1749.     else
  1750.       {
  1751. --- 251,257 ----
  1752.        but since we don't know how many, it's easiest to find them all.
  1753.        If -D is specified, we need all the lines of the first file.  */
  1754.         current->buffered_lines = 0;
  1755. !       p = current->buffer;
  1756.       }
  1757.     else
  1758.       {
  1759. ***************
  1760. *** 195,212 ****
  1761.       current->buffered_lines = 0;
  1762.         for (i = 0; i < context + 1; ++i)
  1763.       /* Unless we are at the beginning, */
  1764. !     if ((char *) p != current->buffer)
  1765.         /* Back up at least 1 char until at the start of a line.  */
  1766. !       while ((char *) --p != current->buffer && p[-1] != '\n')
  1767.           ;
  1768.       }
  1769.  
  1770. !   while ((char *) p < current->suffix_begin)
  1771.       {
  1772.         h = 0;
  1773.         ip = p;
  1774.  
  1775. !       if (current->prefix_end <= (char *) p)
  1776.       {
  1777.         /* Hash this line until we find a newline. */
  1778.         if (ignore_case_flag)
  1779. --- 263,280 ----
  1780.       current->buffered_lines = 0;
  1781.         for (i = 0; i < context + 1; ++i)
  1782.       /* Unless we are at the beginning, */
  1783. !     if (p != current->buffer)
  1784.         /* Back up at least 1 char until at the start of a line.  */
  1785. !       while ( --p != current->buffer && p[-1] != '\n')
  1786.           ;
  1787.       }
  1788.  
  1789. !   while (p < current->suffix_begin)
  1790.       {
  1791.         h = 0;
  1792.         ip = p;
  1793.  
  1794. !       if (current->prefix_end <= p)
  1795.       {
  1796.         /* Hash this line until we find a newline. */
  1797.         if (ignore_case_flag)
  1798. ***************
  1799. *** 291,298 ****
  1800. --- 359,368 ----
  1801.         /* Maybe increase the size of the line table. */
  1802.         if (current->buffered_lines >= current->linbufsize)
  1803.       {
  1804. + #ifndef MSDOS
  1805.         while (current->buffered_lines >= current->linbufsize)
  1806.           current->linbufsize *= 2;
  1807. +
  1808.         current->linbuf
  1809.           = (struct line_def *) xrealloc (current->linbuf,
  1810.                           current->linbufsize
  1811. ***************
  1812. *** 297,304 ****
  1813.           = (struct line_def *) xrealloc (current->linbuf,
  1814.                           current->linbufsize
  1815.                           * sizeof (struct line_def));
  1816.       }
  1817. !       current->linbuf[current->buffered_lines].text = (char *) ip;
  1818.         current->linbuf[current->buffered_lines].length = p - ip + 1;
  1819.         current->linbuf[current->buffered_lines].hash = h;
  1820.         ++current->buffered_lines;
  1821. --- 367,387 ----
  1822.           = (struct line_def *) xrealloc (current->linbuf,
  1823.                           current->linbufsize
  1824.                           * sizeof (struct line_def));
  1825. + #else
  1826. +           old = current->linbufsize;
  1827. +
  1828. +       while (current->buffered_lines >= current->linbufsize)
  1829. +         current->linbufsize += 2048;
  1830. +
  1831. +       current->linbuf = hrealloc(current->linbuf,
  1832. +             (long) current->linbufsize * sizeof (struct line_def),
  1833. +             (long) old * sizeof (struct line_def));
  1834. +
  1835. +           if ( current->linbuf == NULL )
  1836. +              fatal("too many lines");
  1837. + #endif
  1838.       }
  1839. !       current->linbuf[current->buffered_lines].text = ip;
  1840.         current->linbuf[current->buffered_lines].length = p - ip + 1;
  1841.         current->linbuf[current->buffered_lines].hash = h;
  1842.         ++current->buffered_lines;
  1843. ***************
  1844. *** 307,313 ****
  1845. --- 390,400 ----
  1846.  
  1847.     i = 0;
  1848.     while ((i < context || output_style == OUTPUT_IFDEF)
  1849. + #ifndef MSDOS
  1850.        && (char *) p < current->buffer + current->buffered_chars)
  1851. + #else
  1852. +      && p < (char huge *) current->buffer + current->buffered_chars)
  1853. + #endif
  1854.       {
  1855.         ip = p;
  1856.         while (*p++ != '\n')
  1857. ***************
  1858. *** 315,322 ****
  1859. --- 402,411 ----
  1860.         /* Maybe increase the size of the line table. */
  1861.         if (current->buffered_lines >= current->linbufsize)
  1862.       {
  1863. + #ifndef MSDOS
  1864.         while (current->buffered_lines >= current->linbufsize)
  1865.           current->linbufsize *= 2;
  1866. +
  1867.         current->linbuf
  1868.           = (struct line_def *) xrealloc (current->linbuf,
  1869.                           current->linbufsize
  1870. ***************
  1871. *** 321,328 ****
  1872.           = (struct line_def *) xrealloc (current->linbuf,
  1873.                           current->linbufsize
  1874.                           * sizeof (struct line_def));
  1875.       }
  1876. !       current->linbuf[current->buffered_lines].text = (char *) ip;
  1877.         current->linbuf[current->buffered_lines].length = p - ip;
  1878.         current->linbuf[current->buffered_lines].hash = 0;
  1879.         ++current->buffered_lines;
  1880. --- 410,430 ----
  1881.           = (struct line_def *) xrealloc (current->linbuf,
  1882.                           current->linbufsize
  1883.                           * sizeof (struct line_def));
  1884. + #else
  1885. +           old = current->linbufsize;
  1886. +
  1887. +       while (current->buffered_lines >= current->linbufsize)
  1888. +         current->linbufsize += 2048;
  1889. +
  1890. +       current->linbuf = hrealloc(current->linbuf,
  1891. +             (long) current->linbufsize * sizeof (struct line_def),
  1892. +             (long) old * sizeof (struct line_def));
  1893. +
  1894. +           if ( current->linbuf == NULL )
  1895. +              fatal("too many lines");
  1896. + #endif
  1897.       }
  1898. !       current->linbuf[current->buffered_lines].text = ip;
  1899.         current->linbuf[current->buffered_lines].length = p - ip;
  1900.         current->linbuf[current->buffered_lines].hash = 0;
  1901.         ++current->buffered_lines;
  1902. ***************
  1903. *** 342,348 ****
  1904. --- 444,454 ----
  1905.   find_identical_ends (filevec)
  1906.        struct file_data filevec[];
  1907.   {
  1908. + #ifndef MSDOS
  1909.     char *p0, *p1, *end0, *beg0;
  1910. + #else
  1911. +   char huge *p0, huge *p1, huge *end0, huge *beg0;
  1912. + #endif
  1913.     int lines;
  1914.  
  1915.     if (filevec[0].buffered_chars == 0 || filevec[1].buffered_chars == 0)
  1916. ***************
  1917. *** 383,397 ****
  1918.     /* Don't count missing newline as part of prefix in RCS mode. */
  1919.     if (ROBUST_OUTPUT_STYLE (output_style)
  1920.         && ((filevec[0].missing_newline
  1921. !        && p0 - filevec[0].buffer > filevec[0].buffered_chars)
  1922.         ||
  1923.         (filevec[1].missing_newline
  1924. !        && p1 - filevec[1].buffer > filevec[1].buffered_chars)))
  1925.       --p0, --p1, --lines;
  1926.  
  1927.     /* If the sentinel was passed, and lengths are equal, the
  1928.        files are identical.  */
  1929. !   if (p0 - filevec[0].buffer > filevec[0].buffered_chars
  1930.         && filevec[0].buffered_chars == filevec[1].buffered_chars)
  1931.       {
  1932.         filevec[0].prefix_end = p0 - 1;
  1933. --- 489,503 ----
  1934.     /* Don't count missing newline as part of prefix in RCS mode. */
  1935.     if (ROBUST_OUTPUT_STYLE (output_style)
  1936.         && ((filevec[0].missing_newline
  1937. !        && (p0 - filevec[0].buffer) > filevec[0].buffered_chars)
  1938.         ||
  1939.         (filevec[1].missing_newline
  1940. !        && (p1 - filevec[1].buffer) > filevec[1].buffered_chars)))
  1941.       --p0, --p1, --lines;
  1942.  
  1943.     /* If the sentinel was passed, and lengths are equal, the
  1944.        files are identical.  */
  1945. !   if ((p0 - filevec[0].buffer) > filevec[0].buffered_chars
  1946.         && filevec[0].buffered_chars == filevec[1].buffered_chars)
  1947.       {
  1948.         filevec[0].prefix_end = p0 - 1;
  1949. ***************
  1950. *** 435,445 ****
  1951.         else
  1952.       /* Figure out where P0 will be when P1 is at the end of the prefix.
  1953.          Thus we only need to test P0.  */
  1954. !     beg0 = (filevec[0].prefix_end
  1955. !         + filevec[0].buffered_chars - filevec[1].buffered_chars);
  1956.  
  1957.         /* Scan back until chars don't match or we reach that point.  */
  1958. !       while (p0 != beg0)
  1959.       {
  1960.         char c = *--p0;
  1961.         if (c != *--p1)
  1962. --- 541,551 ----
  1963.         else
  1964.       /* Figure out where P0 will be when P1 is at the end of the prefix.
  1965.          Thus we only need to test P0.  */
  1966. !     beg0 = filevec[0].prefix_end
  1967. !         + (filevec[0].buffered_chars - filevec[1].buffered_chars);
  1968.  
  1969.         /* Scan back until chars don't match or we reach that point.  */
  1970. !       while (p0 > beg0)
  1971.       {
  1972.         char c = *--p0;
  1973.         if (c != *--p1)
  1974. ***************
  1975. *** 483,488 ****
  1976. --- 589,597 ----
  1977.   {
  1978.     struct equivclass *next;    /* Next item in this bucket. */
  1979.     struct line_def line;    /* A line that fits this class. */
  1980. + #ifdef MSDOS
  1981. +   long dummy; /* to pad struct size to a power of two, 16 */
  1982. + #endif
  1983.   };
  1984.  
  1985.   /* Hash-table: array of buckets, each being a chain of equivalence classes.  */
  1986. ***************
  1987. *** 494,511 ****
  1988.   /* Array in which the equivalence classes are allocated.
  1989.      The bucket-chains go through the elements in this array.
  1990.      The number of an equivalence class is its index in this array.  */
  1991. ! static struct equivclass *equivs;
  1992.  
  1993.   /* Index of first free element in the array `equivs'.  */
  1994. ! static int equivs_index;
  1995.  
  1996.   /* Size allocated to the array `equivs'.  */
  1997. ! static int equivs_alloc;
  1998.  
  1999.   /* Largest primes less than some power of two, for nbuckets.  Values range
  2000.      from useful to preposterous.  If one of these numbers isn't prime
  2001.      after all, don't blame it on me, blame it on primes (6) . . . */
  2002. ! static int primes[] =
  2003.   {
  2004.     509,
  2005.     1021,
  2006. --- 603,620 ----
  2007.   /* Array in which the equivalence classes are allocated.
  2008.      The bucket-chains go through the elements in this array.
  2009.      The number of an equivalence class is its index in this array.  */
  2010. ! static struct equivclass huge *equivs;
  2011.  
  2012.   /* Index of first free element in the array `equivs'.  */
  2013. ! static long equivs_index;
  2014.  
  2015.   /* Size allocated to the array `equivs'.  */
  2016. ! static long equivs_alloc;
  2017.  
  2018.   /* Largest primes less than some power of two, for nbuckets.  Values range
  2019.      from useful to preposterous.  If one of these numbers isn't prime
  2020.      after all, don't blame it on me, blame it on primes (6) . . . */
  2021. ! static long primes[] =
  2022.   {
  2023.     509,
  2024.     1021,
  2025. ***************
  2026. *** 538,544 ****
  2027.        int n;
  2028.   {
  2029.     int bucket;
  2030. !   struct equivclass *b, *p = NULL;
  2031.  
  2032.     /* Equivalence class 0 is permanently allocated to lines that were
  2033.        not hashed because they were parts of identical prefixes or
  2034. --- 647,653 ----
  2035.        int n;
  2036.   {
  2037.     int bucket;
  2038. !   struct equivclass huge *b, huge *p = NULL;
  2039.  
  2040.     /* Equivalence class 0 is permanently allocated to lines that were
  2041.        not hashed because they were parts of identical prefixes or
  2042. ***************
  2043. *** 564,569 ****
  2044. --- 673,681 ----
  2045.  
  2046.     /* Create a new equivalence class in this bucket. */
  2047.  
  2048. +   if (equivs_index >= equivs_alloc)
  2049. +     fatal ("too many differences, hash table overflow");
  2050. +
  2051.     p = &equivs[equivs_index++];
  2052.     p->next = buckets[bucket];
  2053.     buckets[bucket] = p;
  2054. ***************
  2055. *** 601,608 ****
  2056.       }
  2057.  
  2058.     /* This is guaranteed to be enough space.  */
  2059. !   equivs_alloc = filevec[0].buffered_lines + filevec[1].buffered_lines + 1;
  2060.     equivs = (struct equivclass *) xmalloc (equivs_alloc * sizeof (struct equivclass));
  2061.     /* Equivalence class 0 is permanently safe for lines that were not
  2062.        hashed.  Real equivalence classes start at 1. */
  2063.     equivs_index = 1;
  2064. --- 713,726 ----
  2065.       }
  2066.  
  2067.     /* This is guaranteed to be enough space.  */
  2068. !   equivs_alloc = (long) filevec[0].buffered_lines + filevec[1].buffered_lines + 1L;
  2069. ! #ifndef MSDOS
  2070.     equivs = (struct equivclass *) xmalloc (equivs_alloc * sizeof (struct equivclass));
  2071. + #else
  2072. +   equivs = halloc (equivs_alloc, sizeof (struct equivclass));
  2073. +   if ( equivs == NULL )
  2074. +     fatal("virtual memory exhausted");
  2075. + #endif
  2076.     /* Equivalence class 0 is permanently safe for lines that were not
  2077.        hashed.  Real equivalence classes start at 1. */
  2078.     equivs_index = 1;
  2079. ***************
  2080. *** 611,618 ****
  2081. --- 729,752 ----
  2082.     while (primes[primes_index] < equivs_alloc / 3)
  2083.       primes_index++;
  2084.  
  2085. + #ifndef MSDOS
  2086.     buckets = (struct equivclass **) xmalloc (primes[primes_index] * sizeof (struct equivclass *));
  2087.     bzero (buckets, primes[primes_index] * sizeof (struct equivclass *));
  2088. + #else
  2089. +   buckets = halloc (primes[primes_index], sizeof (struct equivclass *));
  2090. + #ifdef __TURBOC__
  2091. +   /* Microsoft C's halloc already zeroes out the allocated memory.
  2092. +      So this bzero call is only needed for Turbo C and Borland C.
  2093. +      But note that the block may be bigger than 64k and that the bzero
  2094. +      (actually memset) will not fill out the whole block. But this
  2095. +      situation is not very likely to occur, because with Turbo C or
  2096. +      Borland C, you can only make a MS-DOS program, who's memory
  2097. +      is too restricted to diff such big files that this situation
  2098. +      may occur.
  2099. +   */
  2100. +   bzero (buckets, primes[primes_index] * sizeof (struct equivclass *));
  2101. + #endif
  2102. + #endif
  2103.     nbuckets = primes[primes_index];
  2104.  
  2105.     for (i = 0; i < 2; ++i)
  2106. ***************
  2107. *** 626,633 ****
  2108. --- 760,772 ----
  2109.  
  2110.     filevec[0].equiv_max = filevec[1].equiv_max = equivs_index;
  2111.  
  2112. + #ifndef MSDOS
  2113.     free (equivs);
  2114.     free (buckets);
  2115. + #else
  2116. +   hfree (equivs);
  2117. +   hfree (buckets);
  2118. + #endif
  2119.  
  2120.     return 0;
  2121.   }
  2122. diff -cbBw orig/limits.h new/limits.h
  2123. *** orig/limits.h    Tue Dec 24 19:13:30 1991
  2124. --- new/limits.h    Tue Dec 24 19:27:48 1991
  2125. ***************
  2126. *** 1,3 ****
  2127. --- 1,9 ----
  2128. + /*
  2129. +    Modified for DOS and OS/2 on 1991/09/14 by Kai Uwe Rommel
  2130. +     <rommel@informatik.tu-muenchen.de>.
  2131. +  */
  2132. +
  2133. +
  2134.   /* Number of bits in a `char'.  */
  2135.   #define CHAR_BIT 8
  2136.  
  2137. ***************
  2138. *** 28,38 ****
  2139. --- 34,52 ----
  2140.   #define USHRT_MAX 65535U
  2141.  
  2142.   /* Minimum and maximum values a `signed int' can hold.  */
  2143. + #ifdef MSDOS
  2144. + #define INT_MIN (-32768)
  2145. + #define INT_MAX 32767
  2146. +
  2147. + /* Maximum value an `unsigned int' can hold.  (Minimum is 0).  */
  2148. + #define UINT_MAX 65535U
  2149. + #else
  2150.   #define INT_MIN (-INT_MAX-1)
  2151.   #define INT_MAX 2147483647
  2152.  
  2153.   /* Maximum value an `unsigned int' can hold.  (Minimum is 0).  */
  2154.   #define UINT_MAX 4294967295U
  2155. + #endif
  2156.  
  2157.   /* Minimum and maximum values a `signed long int' can hold.
  2158.      (Same as `int').  */
  2159. Only in new: pc-files
  2160. Only in orig: regex.c
  2161. Only in orig: regex.h
  2162. diff -cbBw orig/util.c new/util.c
  2163. *** orig/util.c    Tue Dec 24 19:13:34 1991
  2164. --- new/util.c    Tue Dec 24 19:19:38 1991
  2165. ***************
  2166. *** 1,5 ****
  2167. --- 1,7 ----
  2168.   /* Support routines for GNU DIFF.
  2169.      Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  2170. +    Modified for DOS and OS/2 on 1991/09/14 by Kai Uwe Rommel
  2171. +     <rommel@informatik.tu-muenchen.de>.
  2172.  
  2173.   This file is part of GNU DIFF.
  2174.  
  2175. ***************
  2176. *** 51,57 ****
  2177.        char *arg;
  2178.        char *arg1;
  2179.   {
  2180. !   fprintf (stderr, "%s: ", program);
  2181.     fprintf (stderr, format, arg, arg1);
  2182.     fprintf (stderr, "\n");
  2183.   }
  2184. --- 53,59 ----
  2185.        char *arg;
  2186.        char *arg1;
  2187.   {
  2188. !   fprintf (stderr, "\n%s: ", program);
  2189.     fprintf (stderr, format, arg, arg1);
  2190.     fprintf (stderr, "\n");
  2191.   }
  2192. ***************
  2193. *** 129,134 ****
  2194. --- 131,147 ----
  2195.     strcat (name, " ");
  2196.     strcat (name, name1);
  2197.  
  2198. + #if defined(MSDOS)
  2199. +   if (paginate_flag)
  2200. +     {
  2201. +       extern FILE *popen();
  2202. +
  2203. +       /* Fork a `pr' and make OUTFILE a pipe to it.  */
  2204. +       outfile = popen("pr -o -", "w");
  2205. +       fprintf (outfile, "%s\n", name);
  2206. +     }
  2207. +   else
  2208. + #else
  2209.     if (paginate_flag)
  2210.       {
  2211.         int pipes[2];
  2212. ***************
  2213. *** 164,169 ****
  2214. --- 177,183 ----
  2215.       }
  2216.       }
  2217.     else
  2218. + #endif
  2219.       {
  2220.  
  2221.         /* If -l was not specified, output the diff straight to `stdout'.  */
  2222. ***************
  2223. *** 172,178 ****
  2224.  
  2225.         /* If handling multiple files (because scanning a directory),
  2226.        print which files the following output is about.  */
  2227. !       if (depth > 0)
  2228.       printf ("%s\n", name);
  2229.       }
  2230.  
  2231. --- 186,192 ----
  2232.  
  2233.         /* If handling multiple files (because scanning a directory),
  2234.        print which files the following output is about.  */
  2235. !       if (depth > 0 && !output_patch_flag)
  2236.       printf ("%s\n", name);
  2237.       }
  2238.  
  2239. ***************
  2240. *** 187,194 ****
  2241. --- 201,212 ----
  2242.   {
  2243.     if (outfile != stdout)
  2244.       {
  2245. + #if defined(MSDOS)
  2246. +       pclose (outfile);
  2247. + #else
  2248.         fclose (outfile);
  2249.         wait (0);
  2250. + #endif
  2251.       }
  2252.   }
  2253.   
  2254. ***************
  2255. *** 201,207 ****
  2256. --- 219,229 ----
  2257.   line_cmp (s1, s2)
  2258.        struct line_def *s1, *s2;
  2259.   {
  2260. + #ifdef MSDOS
  2261. +   char huge *t1, huge *t2;
  2262. + #else
  2263.     register char *t1, *t2;
  2264. + #endif
  2265.     register char end_char = line_end_char;
  2266.     int savechar;
  2267.  
  2268. ***************
  2269. *** 382,388 ****
  2270. --- 404,414 ----
  2271.        struct line_def *line;
  2272.   {
  2273.     int length = line->length; /* must be nonzero */
  2274. + #ifdef MSDOS
  2275. +   const char huge *text = line->text; /* Help the compiler.  */
  2276. + #else
  2277.     const char *text = line->text; /* Help the compiler.  */
  2278. + #endif
  2279.     FILE *out = outfile; /* Help the compiler some more.  */
  2280.  
  2281.     /* If -T was specified, use a Tab between the line-flag and the text.
  2282. diff -cbBw orig/version.c new/version.c
  2283. *** orig/version.c    Tue Dec 24 19:13:34 1991
  2284. --- new/version.c    Tue Dec 24 19:29:16 1991
  2285. ***************
  2286. *** 1,3 ****
  2287.   /* Version number of GNU diff.  */
  2288.  
  2289. ! char *version_string = "1.15";
  2290. --- 1,11 ----
  2291.   /* Version number of GNU diff.  */
  2292. + /*
  2293. +    Modified for DOS and OS/2 on 1991/09/14 by Kai Uwe Rommel
  2294. +     <rommel@informatik.tu-muenchen.de>.
  2295. + */
  2296.  
  2297. ! char *version_string = "1.15-ms";
  2298. !
  2299. ! #ifdef __TURBOC__
  2300. ! unsigned _stklen = 0x8000;
  2301. ! #endif
  2302.