home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / patch212.zip / patches.os2 < prev    next >
Text File  |  1991-02-18  |  41KB  |  1,616 lines

  1. Only in patch2u: config.h
  2. Only in patch2u: isvalid.c
  3. Only in patch2u: patch.cs
  4. Only in patch2u: patch.def
  5. Only in patch2u: patches.os2
  6. diff -cbBw orig/common.h patch2u/common.h
  7. *** orig/common.h    Mon Feb 18 18:55:30 1991
  8. --- patch2u/common.h    Mon Feb 18 19:46:34 1991
  9. ***************
  10. *** 38,43 ****
  11. --- 38,45 ----
  12.   #include <sys/stat.h>
  13.   #include <ctype.h>
  14.   #include <signal.h>
  15. + #include <io.h>
  16. + #include <fcntl.h>
  17.   
  18.   /* constants */
  19.   
  20. ***************
  21. *** 110,119 ****
  22.   EXT char *origext INIT(Nullch);
  23.   EXT char *origprae INIT(Nullch);
  24.   
  25. ! EXT char TMPOUTNAME[] INIT("/tmp/patchoXXXXXX");
  26. ! EXT char TMPINNAME[] INIT("/tmp/patchiXXXXXX");    /* might want /usr/tmp here */
  27. ! EXT char TMPREJNAME[] INIT("/tmp/patchrXXXXXX");
  28. ! EXT char TMPPATNAME[] INIT("/tmp/patchpXXXXXX");
  29.   EXT bool toutkeep INIT(FALSE);
  30.   EXT bool trejkeep INIT(FALSE);
  31.   
  32. --- 112,122 ----
  33.   EXT char *origext INIT(Nullch);
  34.   EXT char *origprae INIT(Nullch);
  35.   
  36. ! EXT char *TMPOUTNAME;
  37. ! EXT char *TMPINNAME;
  38. ! EXT char *TMPREJNAME;
  39. ! EXT char *TMPPATNAME;
  40.   EXT bool toutkeep INIT(FALSE);
  41.   EXT bool trejkeep INIT(FALSE);
  42.   
  43. ***************
  44. *** 134,139 ****
  45. --- 137,143 ----
  46.   #define NORMAL_DIFF 2
  47.   #define ED_DIFF 3
  48.   #define NEW_CONTEXT_DIFF 4
  49. + #define UNI_DIFF 5
  50.   EXT int diff_type INIT(0);
  51.   
  52.   EXT bool do_defines INIT(FALSE);    /* patch using ifdef, ifndef, etc. */
  53. ***************
  54. *** 144,158 ****
  55.   
  56.   EXT char *revision INIT(Nullch);    /* prerequisite revision, if any */
  57.   
  58. ! char *malloc();
  59. ! char *realloc();
  60.   char *strcpy();
  61.   char *strcat();
  62.   long atol();
  63.   long lseek();
  64.   char *mktemp();
  65.   #ifdef CHARSPRINTF
  66.   char *sprintf();
  67.   #else
  68.   int sprintf();
  69.   #endif
  70. --- 148,168 ----
  71.   
  72.   EXT char *revision INIT(Nullch);    /* prerequisite revision, if any */
  73.   
  74. ! void *malloc();
  75. ! void *realloc();
  76.   char *strcpy();
  77.   char *strcat();
  78.   long atol();
  79.   long lseek();
  80.   char *mktemp();
  81. + #ifdef MSDOS
  82. + #undef stderr
  83. + FILE *stderr;
  84. + #endif
  85.   #ifdef CHARSPRINTF
  86.   char *sprintf();
  87.   #else
  88.   int sprintf();
  89.   #endif
  90. + char *getenv();
  91. diff -cbBw orig/inp.c patch2u/inp.c
  92. *** orig/inp.c    Mon Feb 18 18:55:34 1991
  93. --- patch2u/inp.c    Mon Feb 18 19:00:46 1991
  94. ***************
  95. *** 79,84 ****
  96. --- 79,87 ----
  97.       int ifd;
  98.       Reg1 char *s;
  99.       Reg2 LINENUM iline;
  100. + #ifdef MSDOS
  101. +     int i_res;
  102. + #endif
  103.   
  104.       if (ok_to_create_file && stat(filename, &filestat) < 0) {
  105.       if (verbose)
  106. ***************
  107. *** 115,120 ****
  108. --- 118,127 ----
  109.       if ((filemode & S_IFMT) & ~S_IFREG)
  110.       fatal2("%s is not a normal file--can't patch.\n", filename);
  111.       i_size = filestat.st_size;
  112. + #ifdef MSDOS
  113. +     if ( i_size > 65500L )
  114. +       return FALSE;
  115. + #endif
  116.       if (out_of_mem) {
  117.       set_hunkmax();        /* make sure dynamic arrays are allocated */
  118.       out_of_mem = FALSE;
  119. ***************
  120. *** 128,136 ****
  121.   #endif
  122.       if (i_womp == Nullch)
  123.       return FALSE;
  124. !     if ((ifd = open(filename, 0)) < 0)
  125.       fatal2("Can't open file %s\n", filename);
  126.   #ifndef lint
  127.       if (read(ifd, i_womp, (int)i_size) != i_size) {
  128.       Close(ifd);    /* probably means i_size > 15 or 16 bits worth */
  129.       free(i_womp);    /* at this point it doesn't matter if i_womp was */
  130. --- 135,154 ----
  131.   #endif
  132.       if (i_womp == Nullch)
  133.       return FALSE;
  134. !     if ((ifd = open(filename, O_BINARY)) < 0)
  135.       fatal2("Can't open file %s\n", filename);
  136.   #ifndef lint
  137. + #ifdef DUMMY_MSDOS
  138. +     /* this hack is now obsolete in binary mode */
  139. +     if ((i_res = read(ifd, i_womp, (int)i_size)) == -1) {
  140. +     Close(ifd);    /* probably means i_size > 15 or 16 bits worth */
  141. +     free(i_womp);    /* at this point it doesn't matter if i_womp was */
  142. +     return FALSE;    /*   undersized. */
  143. +     }
  144. +     else
  145. +       /* cr/lf-translations would bomb here (i_res is != file size)! */
  146. +       i_size = i_res;
  147. + #else
  148.       if (read(ifd, i_womp, (int)i_size) != i_size) {
  149.       Close(ifd);    /* probably means i_size > 15 or 16 bits worth */
  150.       free(i_womp);    /* at this point it doesn't matter if i_womp was */
  151. ***************
  152. *** 137,142 ****
  153. --- 155,161 ----
  154.       return FALSE;    /*   undersized. */
  155.       }
  156.   #endif
  157. + #endif
  158.       Close(ifd);
  159.       if (i_size && i_womp[i_size-1] != '\n')
  160.       i_womp[i_size++] = '\n';
  161. ***************
  162. *** 206,214 ****
  163.       Reg4 bool found_revision = (revision == Nullch);
  164.   
  165.       using_plan_a = FALSE;
  166. !     if ((ifp = fopen(filename, "r")) == Nullfp)
  167.       fatal2("Can't open file %s\n", filename);
  168. !     if ((tifd = creat(TMPINNAME, 0666)) < 0)
  169.       fatal2("Can't open file %s\n", TMPINNAME);
  170.       while (fgets(buf, sizeof buf, ifp) != Nullch) {
  171.       if (revision != Nullch && !found_revision && rev_in_string(buf))
  172. --- 225,234 ----
  173.       Reg4 bool found_revision = (revision == Nullch);
  174.   
  175.       using_plan_a = FALSE;
  176. !     if ((ifp = fopen(filename, "rb")) == Nullfp)
  177.       fatal2("Can't open file %s\n", filename);
  178. !     if ((tifd = open(TMPINNAME, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY,
  179. !                      S_IWRITE|S_IREAD)) < 0)
  180.       fatal2("Can't open file %s\n", TMPINNAME);
  181.       while (fgets(buf, sizeof buf, ifp) != Nullch) {
  182.       if (revision != Nullch && !found_revision && rev_in_string(buf))
  183. ***************
  184. *** 236,242 ****
  185.           say2("Good.  This file appears to be the %s version.\n",
  186.           revision);
  187.       }
  188. !     Fseek(ifp, 0L, 0);        /* rewind file */
  189.       lines_per_buf = BUFFERSIZE / maxlen;
  190.       tireclen = maxlen;
  191.       tibuf[0] = malloc((MEM)(BUFFERSIZE + 1));
  192. --- 256,262 ----
  193.           say2("Good.  This file appears to be the %s version.\n",
  194.           revision);
  195.       }
  196. !     rewind(ifp);          /* rewind file */
  197.       lines_per_buf = BUFFERSIZE / maxlen;
  198.       tireclen = maxlen;
  199.       tibuf[0] = malloc((MEM)(BUFFERSIZE + 1));
  200. ***************
  201. *** 258,264 ****
  202.       }
  203.       Fclose(ifp);
  204.       Close(tifd);
  205. !     if ((tifd = open(TMPINNAME, 0)) < 0) {
  206.       fatal2("Can't reopen file %s\n", TMPINNAME);
  207.       }
  208.   }
  209. --- 278,285 ----
  210.       }
  211.       Fclose(ifp);
  212.       Close(tifd);
  213. !     if ((tifd = open(TMPINNAME, O_RDONLY|O_BINARY)) < 0) {
  214.       fatal2("Can't reopen file %s\n", TMPINNAME);
  215.       }
  216.   }
  217. ***************
  218. *** 306,312 ****
  219.       if (revision == Nullch)
  220.       return TRUE;
  221.       patlen = strlen(revision);
  222. !     if (strnEQ(string,revision,patlen) && isspace(s[patlen]))
  223.       return TRUE;
  224.       for (s = string; *s; s++) {
  225.       if (isspace(*s) && strnEQ(s+1, revision, patlen) &&
  226. --- 327,333 ----
  227.       if (revision == Nullch)
  228.       return TRUE;
  229.       patlen = strlen(revision);
  230. !     if (strnEQ(string,revision,patlen) && isspace(string[patlen]))
  231.       return TRUE;
  232.       for (s = string; *s; s++) {
  233.       if (isspace(*s) && strnEQ(s+1, revision, patlen) &&
  234. diff -cbBw orig/patch.c patch2u/patch.c
  235. *** orig/patch.c    Mon Feb 18 18:55:38 1991
  236. --- patch2u/patch.c    Mon Feb 18 19:15:32 1991
  237. ***************
  238. *** 1,5 ****
  239.   char rcsid[] =
  240. !     "$Header: patch.c,v 2.0.1.6 88/06/22 20:46:39 lwall Locked $";
  241.   
  242.   /* patch - a program to apply diffs to original files
  243.    *
  244. --- 1,5 ----
  245.   char rcsid[] =
  246. !     "$Header: patch.c,v 2.0.2.0 90/05/01 22:17:50 davison Locked $";
  247.   
  248.   /* patch - a program to apply diffs to original files
  249.    *
  250. ***************
  251. *** 9,14 ****
  252. --- 9,17 ----
  253.    * money off of it, or pretend that you wrote it.
  254.    *
  255.    * $Log:    patch.c,v $
  256. +  * Revision 2.0.2.0  90/05/01  22:17:50  davison
  257. +  * patch12u: unidiff support added
  258. +  *
  259.    * Revision 2.0.1.6  88/06/22  20:46:39  lwall
  260.    * patch12: rindex() wasn't declared
  261.    *
  262. ***************
  263. *** 94,99 ****
  264. --- 97,103 ----
  265.   #include "util.h"
  266.   #include "pch.h"
  267.   #include "inp.h"
  268. + #include "patchlev.h"
  269.   
  270.   /* procedures */
  271.   
  272. ***************
  273. *** 111,116 ****
  274. --- 115,128 ----
  275.   bool similar();
  276.   void re_input();
  277.   void my_exit();
  278. + char *strchr();
  279. + char *strrchr();
  280. + /* Nonzero if -R was specified on command line.  */
  281. + static int reverse_flag_specified = FALSE;
  282. + /* Program name */
  283. + static char *myname;
  284.   
  285.   /* Apply a set of diffs as appropriate. */
  286.   
  287. ***************
  288. *** 126,143 ****
  289. --- 138,194 ----
  290.       int failed = 0;
  291.       int failtotal = 0;
  292.       int i;
  293. +     char *s;
  294.   
  295. + #ifdef MSDOS
  296. +     stderr = fopen("con", "w");
  297. + #endif
  298.       setbuf(stderr, serrbuf);
  299.       for (i = 0; i<MAXFILEC; i++)
  300.       filearg[i] = Nullch;
  301. +     /* Cons up the names of the temporary files.  */
  302. +     {
  303. +       /* Directory for temporary files.  */
  304. +       char *tmpdir;
  305. +       int tmpname_len;
  306. + #ifdef MSDOS
  307. +       tmpdir = getenv ("TMP");
  308. + #else
  309. +       tmpdir = getenv ("TMPDIR");
  310. + #endif
  311. +       if (tmpdir == NULL) {
  312. +     tmpdir = "/tmp";
  313. +       }
  314. +       tmpname_len = strlen (tmpdir) + 20;
  315. +       TMPOUTNAME = (char *) malloc (tmpname_len);
  316. +       strcpy (TMPOUTNAME, tmpdir);
  317. +       strcat (TMPOUTNAME, "/poXXXXXX");
  318.         Mktemp(TMPOUTNAME);
  319. +       TMPINNAME = (char *) malloc (tmpname_len);
  320. +       strcpy (TMPINNAME, tmpdir);
  321. +       strcat (TMPINNAME, "/piXXXXXX");
  322.         Mktemp(TMPINNAME);
  323. +       TMPREJNAME = (char *) malloc (tmpname_len);
  324. +       strcpy (TMPREJNAME, tmpdir);
  325. +       strcat (TMPREJNAME, "/prXXXXXX");
  326.         Mktemp(TMPREJNAME);
  327. +       TMPPATNAME = (char *) malloc (tmpname_len);
  328. +       strcpy (TMPPATNAME, tmpdir);
  329. +       strcat (TMPPATNAME, "/ppXXXXXX");
  330.         Mktemp(TMPPATNAME);
  331. +     }
  332.   
  333.       /* parse switches */
  334.       Argc = argc;
  335.       Argv = argv;
  336. +     myname = argv[0];
  337.       get_some_switches();
  338.    
  339.       /* make sure we clean up /tmp in case of disaster */
  340. ***************
  341. *** 302,308 ****
  342. --- 353,373 ----
  343.               s[13] = '\0';
  344.                   }
  345.   #endif
  346. + #ifdef MSDOS
  347. +                 s = strchr(rejname, 0);
  348. + #endif
  349.           Strcat(rejname, REJEXT);
  350. + #ifdef MSDOS
  351. +                 if ( !IsFileNameValid(rejname) )
  352. +                 {
  353. +                   *s=0;
  354. +                   if ((s=strrchr(rejname,'.'))!=NULL)
  355. +                     *s=0;
  356. +                   strcat(rejname, ".rej");
  357. +                 }
  358. + #endif
  359.           }
  360.           if (skip_rest_of_patch) {
  361.           say4("%d out of %d hunks ignored--saving rejects to %s\n",
  362. ***************
  363. *** 351,357 ****
  364.       revision = Nullch;
  365.       }
  366.   
  367. !     reverse = FALSE;
  368.       skip_rest_of_patch = FALSE;
  369.   
  370.       get_some_switches();
  371. --- 416,422 ----
  372.       revision = Nullch;
  373.       }
  374.   
  375. !     reverse = reverse_flag_specified;
  376.       skip_rest_of_patch = FALSE;
  377.   
  378.       get_some_switches();
  379. ***************
  380. *** 360,365 ****
  381. --- 425,438 ----
  382.       fatal1("You may not change to a different patch file.\n");
  383.   }
  384.   
  385. + static char *
  386. + nextarg()
  387. + {
  388. +     if (!--Argc)
  389. +     fatal2("patch: missing argument after `%s'\n", *Argv);
  390. +     return *++Argv;
  391. + }
  392.   /* Process switches and filenames up to next '+' or end of list. */
  393.   
  394.   void
  395. ***************
  396. *** 379,415 ****
  397.       }
  398.       if (*s != '-' || !s[1]) {
  399.           if (filec == MAXFILEC)
  400. !         fatal1("Too many file arguments.\n");
  401.           filearg[filec++] = savestr(s);
  402.       }
  403.       else {
  404.           switch (*++s) {
  405.           case 'b':
  406. !         origext = savestr(Argv[1]);
  407. !         Argc--,Argv++;
  408.           break;
  409.           case 'B':
  410. !         origprae = savestr(Argv[1]);
  411. !         Argc--,Argv++;
  412.           break;
  413.           case 'c':
  414.           diff_type = CONTEXT_DIFF;
  415.           break;
  416.           case 'd':
  417. !         if (!*++s) {
  418. !             Argc--,Argv++;
  419. !             s = Argv[0];
  420. !         }
  421.           if (chdir(s) < 0)
  422.               fatal2("Can't cd to %s.\n", s);
  423.           break;
  424.           case 'D':
  425.               do_defines = TRUE;
  426. !         if (!*++s) {
  427. !             Argc--,Argv++;
  428. !             s = Argv[0];
  429. !         }
  430. !         if (!isalpha(*s))
  431.               fatal1("Argument to -D not an identifier.\n");
  432.           Sprintf(if_defined, "#ifdef %s\n", s);
  433.           Sprintf(not_defined, "#ifndef %s\n", s);
  434. --- 452,482 ----
  435.       }
  436.       if (*s != '-' || !s[1]) {
  437.           if (filec == MAXFILEC)
  438. !          fatal1("patch: Too many file arguments.\n");
  439.           filearg[filec++] = savestr(s);
  440.       }
  441.       else {
  442.           switch (*++s) {
  443.           case 'b':
  444. !         origext = savestr(nextarg());
  445.           break;
  446.           case 'B':
  447. !         origprae = savestr(nextarg());
  448.           break;
  449.           case 'c':
  450.           diff_type = CONTEXT_DIFF;
  451.           break;
  452.           case 'd':
  453. !         if (!*++s)
  454. !             s = nextarg();
  455.           if (chdir(s) < 0)
  456.               fatal2("Can't cd to %s.\n", s);
  457.           break;
  458.           case 'D':
  459.               do_defines = TRUE;
  460. !         if (!*++s)
  461. !             s = nextarg();
  462. !         if (!isalpha(*s) && '_' != *s)
  463.               fatal1("Argument to -D not an identifier.\n");
  464.           Sprintf(if_defined, "#ifdef %s\n", s);
  465.           Sprintf(not_defined, "#ifndef %s\n", s);
  466. ***************
  467. *** 436,443 ****
  468.           noreverse = TRUE;
  469.           break;
  470.           case 'o':
  471. !         outname = savestr(Argv[1]);
  472. !         Argc--,Argv++;
  473.           break;
  474.           case 'p':
  475.           if (*++s == '=')
  476. --- 503,509 ----
  477.           noreverse = TRUE;
  478.           break;
  479.           case 'o':
  480. !         outname = savestr(nextarg());
  481.           break;
  482.           case 'p':
  483.           if (*++s == '=')
  484. ***************
  485. *** 445,455 ****
  486.           strippath = atoi(s);
  487.           break;
  488.           case 'r':
  489. !         Strcpy(rejname, Argv[1]);
  490. !         Argc--,Argv++;
  491.           break;
  492.           case 'R':
  493.           reverse = TRUE;
  494.           break;
  495.           case 's':
  496.           verbose = FALSE;
  497. --- 511,521 ----
  498.           strippath = atoi(s);
  499.           break;
  500.           case 'r':
  501. !         Strcpy(rejname, nextarg());
  502.           break;
  503.           case 'R':
  504.           reverse = TRUE;
  505. +         reverse_flag_specified = TRUE;
  506.           break;
  507.           case 's':
  508.           verbose = FALSE;
  509. ***************
  510. *** 457,465 ****
  511. --- 523,538 ----
  512.           case 'S':
  513.           skip_rest_of_patch = TRUE;
  514.           break;
  515. +         case 'u':
  516. +         diff_type = UNI_DIFF;
  517. +         break;
  518.           case 'v':
  519.           version();
  520.           break;
  521. +             case 'h':
  522. +                 Usage();
  523. +                 exit(0);
  524. +         break;
  525.   #ifdef DEBUGGING
  526.           case 'x':
  527.           debug = atoi(s+1);
  528. ***************
  529. *** 468,473 ****
  530. --- 541,547 ----
  531.           default:
  532.                   /*fatal2("Unrecognized switch: %s\n", Argv[0]);*/
  533.                   printf("\nUnrecognized switch: %s.\n", Argv[0]);
  534. +                 Usage();
  535.                   exit(1);
  536.                   break;
  537.           }
  538. ***************
  539. *** 475,480 ****
  540. --- 549,582 ----
  541.       }
  542.   }
  543.   
  544. + Usage()
  545. + {
  546. +   printf("\npatch 2.0, patchlevel %d\n", PATCHLEVEL);
  547. +   printf("\nUsage: %s [options] orig patchfile [+ [options] orig]\n\n", myname);
  548. +   printf("  -b   next argument is the extension to be used in place of '.orig'\n");
  549. +   printf("  -c   forces patch to interpret the patch file as a context diff\n");
  550. +   printf("  -d   next argument is a directory, cd to it before doing anything else\n");
  551. +   printf("  -D   next argument is the symbol for '#ifdef...#endif' to mark changes\n");
  552. +   printf("  -e   forces patch to interpret the patch file as an ed script\n");
  553. +   printf("  -f   do not ask any questions\n");
  554. +   printf("  -l   more loosely whitespace matching\n");
  555. +   printf("  -n   forces patch to interpret the patch file as a normal diff\n");
  556. +   printf("  -N   ignore patches that are reversed or already applied, see -R\n");
  557. +   printf("  -o   next argument is the output file name\n");
  558. +   printf("  -r   next argument is the reject file name\n");
  559. +   printf("  -R   patch was created with the old and new files swapped\n");
  560. +   printf("  -s   makes patch do its work silently, unless an error occurs\n");
  561. +   printf("  -S   ignore this patch from the patch file\n");
  562. +   printf("  -u   forces patch to interpret the patch file as a unified context diff\n");
  563. +   printf("  -v   print out revision header and patch level\n\n");
  564. +   printf("  -F<number>    maximum fuzz factor for context diffs (default 2)\n");
  565. +   printf("  -p<number>    sets the pathname strip count\n");
  566. +   printf("  -x<number>    set internal debugging flags\n");
  567. + }
  568.   /* Attempt to find the right place to apply this hunk of patch. */
  569.   
  570.   LINENUM
  571. ***************
  572. *** 532,539 ****
  573.       LINENUM newfirst = pch_newfirst() + last_offset;
  574.       LINENUM oldlast = oldfirst + pch_ptrn_lines() - 1;
  575.       LINENUM newlast = newfirst + pch_repl_lines() - 1;
  576. !     char *stars = (diff_type == NEW_CONTEXT_DIFF ? " ****" : "");
  577. !     char *minuses = (diff_type == NEW_CONTEXT_DIFF ? " ----" : " -----");
  578.   
  579.       fprintf(rejfp, "***************\n");
  580.       for (i=0; i<=pat_end; i++) {
  581. --- 634,641 ----
  582.       LINENUM newfirst = pch_newfirst() + last_offset;
  583.       LINENUM oldlast = oldfirst + pch_ptrn_lines() - 1;
  584.       LINENUM newlast = newfirst + pch_repl_lines() - 1;
  585. !     char *stars = (diff_type >= NEW_CONTEXT_DIFF ? " ****" : "");
  586. !     char *minuses = (diff_type >= NEW_CONTEXT_DIFF ? " ----" : " -----");
  587.   
  588.       fprintf(rejfp, "***************\n");
  589.       for (i=0; i<=pat_end; i++) {
  590. ***************
  591. *** 569,574 ****
  592. --- 671,699 ----
  593.   
  594.   /* We found where to apply it (we hope), so do it. */
  595.   
  596. + #ifdef MSDOS
  597. + static int fputs(const char *buffer, FILE *file)
  598. + {
  599. +   const char *ptr;
  600. +   for ( ptr = buffer; *ptr; ptr++ )
  601. +     if ( *ptr == '\r' )
  602. +     {
  603. +       putc(*ptr, file);
  604. +       if ( *(ptr + 1) == '\n' )
  605. +         putc(*++ptr, file);
  606. +     }
  607. +     else if ( *ptr == '\n' )
  608. +     {
  609. +       putc('\r', file);
  610. +       putc(*ptr, file);
  611. +     }
  612. +     else
  613. +       putc(*ptr, file);
  614. + }
  615. + #endif
  616.   void
  617.   apply_hunk(where)
  618.   LINENUM where;
  619. ***************
  620. *** 605,612 ****
  621.           last_frozen_line++;
  622.           old++;
  623.       }
  624. !     else if (new > pat_end)
  625.           break;
  626.       else if (pch_char(new) == '+') {
  627.           copy_till(where + old - 1);
  628.           if (R_do_defines) {
  629. --- 730,738 ----
  630.           last_frozen_line++;
  631.           old++;
  632.       }
  633. !     else if (new > pat_end) {
  634.           break;
  635. +     }
  636.       else if (pch_char(new) == '+') {
  637.           copy_till(where + old - 1);
  638.           if (R_do_defines) {
  639. ***************
  640. *** 622,629 ****
  641.           fputs(pfetch(new), ofp);
  642.           new++;
  643.       }
  644. !     else {
  645. !         if (pch_char(new) != pch_char(old)) {
  646.           say3("Out-of-sync patch, lines %ld,%ld--mangled text or line numbers, maybe?\n",
  647.           pch_hunk_beg() + old,
  648.           pch_hunk_beg() + new);
  649. --- 748,754 ----
  650.           fputs(pfetch(new), ofp);
  651.           new++;
  652.       }
  653. !     else if (pch_char(new) != pch_char(old)) {
  654.           say3("Out-of-sync patch, lines %ld,%ld--mangled text or line numbers, maybe?\n",
  655.           pch_hunk_beg() + old,
  656.           pch_hunk_beg() + new);
  657. ***************
  658. *** 633,639 ****
  659.   #endif
  660.           my_exit(1);
  661.       }
  662. !         if (pch_char(new) == '!') {
  663.           copy_till(where + old - 1);
  664.           if (R_do_defines) {
  665.              fputs(not_defined, ofp);
  666. --- 758,764 ----
  667.   #endif
  668.           my_exit(1);
  669.       }
  670. !     else if (pch_char(new) == '!') {
  671.           copy_till(where + old - 1);
  672.           if (R_do_defines) {
  673.              fputs(not_defined, ofp);
  674. ***************
  675. *** 654,668 ****
  676.           fputs(pfetch(new), ofp);
  677.           new++;
  678.           }
  679. -         if (R_do_defines) {
  680. -             fputs(end_defined, ofp);
  681. -             def_state = OUTSIDE;
  682. -     }
  683.       }
  684.       else {
  685.           assert(pch_char(new) == ' ');
  686.           old++;
  687.           new++;
  688.           }
  689.       }
  690.       }
  691. --- 779,792 ----
  692.           fputs(pfetch(new), ofp);
  693.           new++;
  694.           }
  695.       }
  696.       else {
  697.           assert(pch_char(new) == ' ');
  698.           old++;
  699.           new++;
  700. +         if (R_do_defines && def_state != OUTSIDE) {
  701. +         fputs(end_defined, ofp);
  702. +         def_state = OUTSIDE;
  703.           }
  704.       }
  705.       }
  706. ***************
  707. *** 694,700 ****
  708.   init_output(name)
  709.   char *name;
  710.   {
  711. !     ofp = fopen(name, "w");
  712.       if (ofp == Nullfp)
  713.       fatal2("patch: can't create %s.\n", name);
  714.   }
  715. --- 818,824 ----
  716.   init_output(name)
  717.   char *name;
  718.   {
  719. !     ofp = fopen(name, "wb");
  720.       if (ofp == Nullfp)
  721.       fatal2("patch: can't create %s.\n", name);
  722.   }
  723. ***************
  724. *** 773,782 ****
  725. --- 897,925 ----
  726.                pch_line_len(pline) ))
  727.           return FALSE;
  728.       }
  729. + #ifdef MSDOS
  730. +     else
  731. +         {
  732. +           char *s1, *s2;
  733. +           int len;
  734. +           s1 = ifetch(iline, (offset >= 0));
  735. +           s2 = pfetch(pline);
  736. +           len = pch_line_len(pline);
  737. +           /* special CR/LF case */
  738. +           if ( s1[len - 1] == '\r' && s1[len] == '\n' && s2[len - 1] == '\n' )
  739. +             len--;
  740. +           if (strnNE(s1, s2, len))
  741. +         return FALSE;
  742. +         }
  743. + #else
  744.       else if (strnNE(ifetch(iline, (offset >= 0)),
  745.              pfetch(pline),
  746.              pch_line_len(pline) ))
  747.           return FALSE;
  748. + #endif
  749.       }
  750.       return TRUE;
  751.   }
  752. ***************
  753. *** 822,827 ****
  754. --- 965,976 ----
  755.       if (!trejkeep) {
  756.       Unlink(TMPREJNAME);
  757.       }
  758. +     if ( pfp != NULL )
  759. +     {
  760. +       Fclose(pfp);
  761.         Unlink(TMPPATNAME);
  762. +     }
  763.       exit(status);
  764.   }
  765. diff -cbBw orig/pch.c patch2u/pch.c
  766. *** orig/pch.c    Mon Feb 18 18:55:42 1991
  767. --- patch2u/pch.c    Mon Feb 18 19:46:32 1991
  768. ***************
  769. *** 1,6 ****
  770. --- 1,9 ----
  771.   /* $Header: pch.c,v 2.0.1.7 88/06/03 15:13:28 lwall Locked $
  772.    *
  773.    * $Log:    pch.c,v $
  774. +  * Revision 2.0.2.0  90/05/01  22:17:51  davison
  775. +  * patch12u: unidiff support added
  776. +  *
  777.    * Revision 2.0.1.7  88/06/03  15:13:28  lwall
  778.    * patch10: Can now find patches in shar scripts.
  779.    * patch10: Hunks that swapped and then swapped back could core dump.
  780. ***************
  781. *** 34,39 ****
  782. --- 37,43 ----
  783.   #include "util.h"
  784.   #include "INTERN.h"
  785.   #include "pch.h"
  786. + #include "version.h"
  787.   
  788.   /* Patch (diff listing) abstract type. */
  789.   
  790. ***************
  791. *** 81,86 ****
  792. --- 85,96 ----
  793.   {
  794.       if (filename == Nullch || !*filename || strEQ(filename, "-"))
  795.       {
  796. +         if ( isatty(fileno(stdin)) )
  797. +         {
  798. +           Usage();
  799. +           exit(1);
  800. +         }
  801.       pfp = fopen(TMPPATNAME, "w");
  802.       if (pfp == Nullfp)
  803.           fatal2("patch: can't create %s.\n", TMPPATNAME);
  804. ***************
  805. *** 163,168 ****
  806. --- 173,179 ----
  807.       if (verbose)
  808.       say3("  %sooks like %s to me...\n",
  809.           (p_base == 0L ? "L" : "The next patch l"),
  810. +         diff_type == UNI_DIFF ? "a unidiff" :
  811.           diff_type == CONTEXT_DIFF ? "a context diff" :
  812.           diff_type == NEW_CONTEXT_DIFF ? "a new-style context diff" :
  813.           diff_type == NORMAL_DIFF ? "a normal diff" :
  814. ***************
  815. *** 266,271 ****
  816. --- 277,284 ----
  817.           oldtmp = savestr(s+4);
  818.       else if (strnEQ(s, "--- ", 4))
  819.           newtmp = savestr(s+4);
  820. +     else if (strnEQ(s, "+++ ", 4))
  821. +         oldtmp = savestr(s+4);    /* pretend it is the old name */
  822.       else if (strnEQ(s, "Index:", 6))
  823.           indtmp = savestr(s+6);
  824.       else if (strnEQ(s, "Prereq:", 7)) {
  825. ***************
  826. *** 287,292 ****
  827. --- 300,314 ----
  828.           retval = ED_DIFF;
  829.           goto scan_exit;
  830.       }
  831. +     if ((!diff_type || diff_type == UNI_DIFF) && strnEQ(s, "@@ -", 4)) {
  832. +         if (!atol(s+3))
  833. +         ok_to_create_file = TRUE;
  834. +         p_indent = indent;
  835. +         p_start = this_line;
  836. +         p_sline = p_input_line;
  837. +         retval = UNI_DIFF;
  838. +         goto scan_exit;
  839. +     }
  840.       stars_this_line = strnEQ(s, "********", 8);
  841.       if ((!diff_type || diff_type == CONTEXT_DIFF) && stars_last_line &&
  842.            strnEQ(s, "*** ", 4)) {
  843. ***************
  844. *** 408,413 ****
  845. --- 430,443 ----
  846.       p_input_line = file_line - 1;
  847.   }
  848.   
  849. + /* Make this a function for better debugging.  */
  850. + static void
  851. + malformed ()
  852. + {
  853. +     fatal3("Malformed patch at line %ld: %s", p_input_line, buf);
  854. +         /* about as informative as "Syntax error" in C */
  855. + }
  856.   /* True if there is more of the current diff listing to process. */
  857.   
  858.   bool
  859. ***************
  860. *** 502,508 ****
  861.           }
  862.           for (s=buf; *s && !isdigit(*s); s++) ;
  863.           if (!*s)
  864. !             goto malformed;
  865.           if (strnEQ(s,"0,0",3))
  866.               strcpy(s,s+2);
  867.           p_first = (LINENUM) atol(s);
  868. --- 532,538 ----
  869.           }
  870.           for (s=buf; *s && !isdigit(*s); s++) ;
  871.           if (!*s)
  872. !             malformed();
  873.           if (strnEQ(s,"0,0",3))
  874.               strcpy(s,s+2);
  875.           p_first = (LINENUM) atol(s);
  876. ***************
  877. *** 510,516 ****
  878.           if (*s == ',') {
  879.               for (; *s && !isdigit(*s); s++) ;
  880.               if (!*s)
  881. !             goto malformed;
  882.               p_ptrn_lines = ((LINENUM)atol(s)) - p_first + 1;
  883.           }
  884.           else if (p_first)
  885. --- 540,546 ----
  886.           if (*s == ',') {
  887.               for (; *s && !isdigit(*s); s++) ;
  888.               if (!*s)
  889. !             malformed();
  890.               p_ptrn_lines = ((LINENUM)atol(s)) - p_first + 1;
  891.           }
  892.           else if (p_first)
  893. ***************
  894. *** 568,580 ****
  895.               p_char[p_end] = '=';
  896.               for (s=buf; *s && !isdigit(*s); s++) ;
  897.               if (!*s)
  898. !             goto malformed;
  899.               p_newfirst = (LINENUM) atol(s);
  900.               while (isdigit(*s)) s++;
  901.               if (*s == ',') {
  902.               for (; *s && !isdigit(*s); s++) ;
  903.               if (!*s)
  904. !                 goto malformed;
  905.               p_repl_lines = ((LINENUM)atol(s)) - p_newfirst + 1;
  906.               }
  907.               else if (p_newfirst)
  908. --- 598,610 ----
  909.               p_char[p_end] = '=';
  910.               for (s=buf; *s && !isdigit(*s); s++) ;
  911.               if (!*s)
  912. !             malformed();
  913.               p_newfirst = (LINENUM) atol(s);
  914.               while (isdigit(*s)) s++;
  915.               if (*s == ',') {
  916.               for (; *s && !isdigit(*s); s++) ;
  917.               if (!*s)
  918. !                 malformed();
  919.               p_repl_lines = ((LINENUM)atol(s)) - p_newfirst + 1;
  920.               }
  921.               else if (p_newfirst)
  922. ***************
  923. *** 654,660 ****
  924.               repl_missing = TRUE;
  925.               goto hunk_done;
  926.           }
  927. !         goto malformed;
  928.           }
  929.           /* set up p_len for strncmp() so we don't have to */
  930.           /* assume null termination */
  931. --- 684,690 ----
  932.               repl_missing = TRUE;
  933.               goto hunk_done;
  934.           }
  935. !         malformed();
  936.           }
  937.           /* set up p_len for strncmp() so we don't have to */
  938.           /* assume null termination */
  939. ***************
  940. *** 721,726 ****
  941. --- 751,900 ----
  942.           assert(filldst==p_end+1 || filldst==repl_beginning);
  943.       }
  944.       }
  945. +     else if (diff_type == UNI_DIFF) {
  946. +     long line_beginning = ftell(pfp);
  947. +                     /* file pos of the current line */
  948. +     Reg4 LINENUM fillsrc;        /* index of old lines */
  949. +     Reg5 LINENUM filldst;        /* index of new lines */
  950. +     char ch;
  951. +     ret = pgets(buf, sizeof buf, pfp);
  952. +     p_input_line++;
  953. +     if (ret == Nullch || strnNE(buf, "@@ -", 4)) {
  954. +         next_intuit_at(line_beginning,p_input_line);
  955. +         return FALSE;
  956. +     }
  957. +     s = buf+4;
  958. +     if (!*s)
  959. +         malformed ();
  960. +     p_first = (LINENUM) atol(s);
  961. +     while (isdigit(*s)) s++;
  962. +     if (*s == ',') {
  963. +         p_ptrn_lines = (LINENUM) atol(++s);
  964. +         while (isdigit(*s)) s++;
  965. +     } else
  966. +         p_ptrn_lines = 1;
  967. +     if (*s == ' ') s++;
  968. +     if (*s != '+' || !*++s)
  969. +         malformed ();
  970. +     p_newfirst = (LINENUM) atol(s);
  971. +     while (isdigit(*s)) s++;
  972. +     if (*s == ',') {
  973. +         p_repl_lines = (LINENUM) atol(++s);
  974. +         while (isdigit(*s)) s++;
  975. +     } else
  976. +         p_repl_lines = 1;
  977. +     if (*s == ' ') s++;
  978. +     if (*s != '@')
  979. +         malformed ();
  980. +     if (!p_first && !p_ptrn_lines)
  981. +         p_first = 1;
  982. +     p_max = p_ptrn_lines + p_repl_lines + 1;
  983. +     while (p_max >= hunkmax)
  984. +         grow_hunkmax();
  985. +     p_max = hunkmax;
  986. +     fillsrc = 1;
  987. +     filldst = fillsrc + p_ptrn_lines;
  988. +     p_end = filldst + p_repl_lines;
  989. +     Sprintf(buf,"*** %ld,%ld ****\n",p_first,p_first + p_ptrn_lines - 1);
  990. +     p_line[0] = savestr(buf);
  991. +     if (out_of_mem) {
  992. +         p_end = -1;
  993. +         return FALSE;
  994. +     }
  995. +     p_char[0] = '*';
  996. +         Sprintf(buf,"--- %ld,%ld ----\n",p_newfirst,p_newfirst+p_repl_lines-1);
  997. +     p_line[filldst] = savestr(buf);
  998. +     if (out_of_mem) {
  999. +         p_end = 0;
  1000. +         return FALSE;
  1001. +     }
  1002. +     p_char[filldst++] = '=';
  1003. +     p_context = 100;
  1004. +     context = 0;
  1005. +     p_hunk_beg = p_input_line + 1;
  1006. +     while (fillsrc <= p_ptrn_lines || filldst <= p_end) {
  1007. +         line_beginning = ftell(pfp);
  1008. +         ret = pgets(buf, sizeof buf, pfp);
  1009. +         p_input_line++;
  1010. +         if (ret == Nullch) {
  1011. +         if (p_max - filldst < 3)
  1012. +             Strcpy(buf, " \n");  /* assume blank lines got chopped */
  1013. +         else {
  1014. +             fatal1("Unexpected end of file in patch.\n");
  1015. +         }
  1016. +         }
  1017. +         if (*buf == '\t' || *buf == '\n') {
  1018. +         ch = ' ';        /* assume the space got eaten */
  1019. +         s = savestr(buf);
  1020. +         }
  1021. +         else {
  1022. +         ch = *buf;
  1023. +         s = savestr(buf+1);
  1024. +         }
  1025. +         if (out_of_mem) {
  1026. +         while (--filldst > p_ptrn_lines)
  1027. +             free(p_line[filldst]);
  1028. +         p_end = fillsrc-1;
  1029. +         return FALSE;
  1030. +         }
  1031. +         switch (ch) {
  1032. +         case '-':
  1033. +         if (fillsrc > p_ptrn_lines) {
  1034. +             free(s);
  1035. +             p_end = filldst-1;
  1036. +             malformed ();
  1037. +         }
  1038. +         p_char[fillsrc] = ch;
  1039. +         p_line[fillsrc] = s;
  1040. +         p_len[fillsrc++] = strlen(s);
  1041. +         break;
  1042. +         case '=':
  1043. +         ch = ' ';
  1044. +         /* FALL THROUGH */
  1045. +         case ' ':
  1046. +         if (fillsrc > p_ptrn_lines) {
  1047. +             free(s);
  1048. +             while (--filldst > p_ptrn_lines)
  1049. +             free(p_line[filldst]);
  1050. +             p_end = fillsrc-1;
  1051. +             malformed ();
  1052. +         }
  1053. +         context++;
  1054. +         p_char[fillsrc] = ch;
  1055. +         p_line[fillsrc] = s;
  1056. +         p_len[fillsrc++] = strlen(s);
  1057. +         s = savestr(s);
  1058. +         if (out_of_mem) {
  1059. +             while (--filldst > p_ptrn_lines)
  1060. +             free(p_line[filldst]);
  1061. +             p_end = fillsrc-1;
  1062. +             return FALSE;
  1063. +         }
  1064. +         /* FALL THROUGH */
  1065. +         case '+':
  1066. +         if (filldst > p_end) {
  1067. +             free(s);
  1068. +             while (--filldst > p_ptrn_lines)
  1069. +             free(p_line[filldst]);
  1070. +             p_end = fillsrc-1;
  1071. +             malformed ();
  1072. +         }
  1073. +         p_char[filldst] = ch;
  1074. +         p_line[filldst] = s;
  1075. +         p_len[filldst++] = strlen(s);
  1076. +         break;
  1077. +         default:
  1078. +         p_end = filldst;
  1079. +         malformed ();
  1080. +         }
  1081. +         if (ch != ' ' && context > 0) {
  1082. +         if (context < p_context)
  1083. +             p_context = context;
  1084. +         context = -1000;
  1085. +         }
  1086. +     }/* while */
  1087. +     }
  1088.       else {                /* normal diff--fake it up */
  1089.       char hunk_type;
  1090.       Reg3 int i;
  1091. ***************
  1092. *** 793,799 ****
  1093.           if (*buf != '-')
  1094.           fatal2("--- expected at line %ld of patch.\n", p_input_line);
  1095.       }
  1096. !         Sprintf(buf, "--- %ld,%ld\n", min, max);
  1097.       p_line[i] = savestr(buf);
  1098.       if (out_of_mem) {
  1099.           p_end = i-1;
  1100. --- 967,973 ----
  1101.           if (*buf != '-')
  1102.           fatal2("--- expected at line %ld of patch.\n", p_input_line);
  1103.       }
  1104. !         Sprintf(buf, "--- %ld,%ld\n", (long) min, (long) max);
  1105.       p_line[i] = savestr(buf);
  1106.       if (out_of_mem) {
  1107.           p_end = i-1;
  1108. ***************
  1109. *** 838,848 ****
  1110.       if (p_end+1 < hunkmax)    /* paranoia reigns supreme... */
  1111.       p_char[p_end+1] = '^';  /* add a stopper for apply_hunk */
  1112.       return TRUE;
  1113. - malformed:
  1114. -     fatal3("Malformed patch at line %ld: %s", p_input_line, buf);
  1115. -         /* about as informative as "Syntax error" in C */
  1116. -     return FALSE;    /* for lint */
  1117.   }
  1118.   
  1119.   /* Input a line from the patch file, worrying about indentation. */
  1120. --- 1012,1017 ----
  1121. ***************
  1122. *** 1073,1082 ****
  1123. --- 1242,1258 ----
  1124.       if (!skip_rest_of_patch) {
  1125.       Unlink(TMPOUTNAME);
  1126.           copy_file(filearg[0], TMPOUTNAME);
  1127. + #ifdef MSDOS
  1128. +     if (verbose)
  1129. +             Sprintf(buf, "ed %s", TMPOUTNAME);
  1130. +     else
  1131. +             Sprintf(buf, "ed - %s", TMPOUTNAME);
  1132. + #else
  1133.       if (verbose)
  1134.           Sprintf(buf, "/bin/ed %s", TMPOUTNAME);
  1135.       else
  1136.               Sprintf(buf, "/bin/ed - %s", TMPOUTNAME);
  1137. + #endif
  1138.       pipefp = popen(buf, "w");
  1139.       }
  1140.       for (;;) {
  1141. diff -cbBw orig/util.c patch2u/util.c
  1142. *** orig/util.c    Mon Feb 18 18:55:48 1991
  1143. --- patch2u/util.c    Mon Feb 18 19:37:12 1991
  1144. ***************
  1145. *** 5,10 ****
  1146. --- 5,13 ----
  1147.   
  1148.   /* Rename a file, copying it if necessary. */
  1149.   
  1150. + char *strchr();
  1151. + char *strrchr();
  1152.   int
  1153.   move_file(from,to)
  1154.   char *from, *to;
  1155. ***************
  1156. *** 21,27 ****
  1157.       if (debug & 4)
  1158.           say2("Moving %s to stdout.\n", from);
  1159.   #endif
  1160. !     fromfd = open(from, 0);
  1161.       if (fromfd < 0)
  1162.           fatal2("patch: internal error, can't reopen %s\n", from);
  1163.       while ((i=read(fromfd, buf, sizeof buf)) > 0)
  1164. --- 24,30 ----
  1165.       if (debug & 4)
  1166.           say2("Moving %s to stdout.\n", from);
  1167.   #endif
  1168. !         fromfd = open(from, O_RDONLY|O_BINARY);
  1169.       if (fromfd < 0)
  1170.           fatal2("patch: internal error, can't reopen %s\n", from);
  1171.       while ((i=read(fromfd, buf, sizeof buf)) > 0)
  1172. ***************
  1173. *** 36,43 ****
  1174. --- 39,61 ----
  1175.           Strcat(bakname, to);
  1176.       } else {
  1177.           Strcpy(bakname, to);
  1178. + #ifdef MSDOS
  1179. +         s = strchr(bakname, 0);
  1180. + #endif
  1181.           Strcat(bakname, origext?origext:ORIGEXT);
  1182. + #ifdef MSDOS
  1183. +         if ( !IsFileNameValid(bakname) )
  1184. +         {
  1185. +           *s=0;
  1186. +           if ((s=strrchr(bakname,'.'))!=NULL)
  1187. +             *s=0;
  1188. +           strcat(bakname, ".org");
  1189. +         }
  1190. + #endif
  1191.       }
  1192.       if (stat(to, &filestat) >= 0) {    /* output file exists */
  1193.       dev_t to_device = filestat.st_dev;
  1194.       ino_t to_inode  = filestat.st_ino;
  1195. ***************
  1196. *** 44,50 ****
  1197. --- 62,72 ----
  1198.       char *simplename = bakname;
  1199.       
  1200.           for (s=bakname; *s; s++) {
  1201. + #ifdef MSDOS
  1202. +             if (*s == '/' || *s == '\\')
  1203. + #else
  1204.               if (*s == '/')
  1205. + #endif
  1206.           simplename = s+1;
  1207.       }
  1208.       /* find a backup name that is not the same file */
  1209. ***************
  1210. *** 63,75 ****
  1211. --- 85,106 ----
  1212.       if (debug & 4)
  1213.           say3("Moving %s to %s.\n", to, bakname);
  1214.   #endif
  1215. + #ifdef MSDOS
  1216. +         if (rename(to, bakname) < 0) {
  1217. + #else
  1218.       if (link(to, bakname) < 0) {
  1219. + #endif
  1220.           say3("patch: can't backup %s, output is in %s\n",
  1221.           to, from);
  1222.           return -1;
  1223.       }
  1224. + #ifndef MSDOS
  1225.       while (unlink(to) >= 0) ;
  1226. + #endif
  1227.       }
  1228.   #ifdef DEBUGGING
  1229.       if (debug & 4)
  1230.       say3("Moving %s to %s.\n", from, to);
  1231. ***************
  1232. *** 74,89 ****
  1233.       if (debug & 4)
  1234.       say3("Moving %s to %s.\n", from, to);
  1235.   #endif
  1236.       if (link(from, to) < 0) {        /* different file system? */
  1237.       Reg4 int tofd;
  1238.       
  1239. !     tofd = creat(to, 0666);
  1240.       if (tofd < 0) {
  1241.           say3("patch: can't create %s, output is in %s.\n",
  1242.             to, from);
  1243.           return -1;
  1244.       }
  1245. !     fromfd = open(from, 0);
  1246.       if (fromfd < 0)
  1247.           fatal2("patch: internal error, can't reopen %s\n", from);
  1248.       while ((i=read(fromfd, buf, sizeof buf)) > 0)
  1249. --- 105,126 ----
  1250.       if (debug & 4)
  1251.       say3("Moving %s to %s.\n", from, to);
  1252.   #endif
  1253. + #ifdef MSDOS
  1254. +     if (rename(from, to) < 0) {           /* different file system? */
  1255. + #else
  1256.       if (link(from, to) < 0) {        /* different file system? */
  1257. + #endif
  1258.       Reg4 int tofd;
  1259.       
  1260. !         tofd = open(to, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY,S_IWRITE|S_IREAD);
  1261.       if (tofd < 0) {
  1262.           say3("patch: can't create %s, output is in %s.\n",
  1263.             to, from);
  1264.           return -1;
  1265.       }
  1266. !         fromfd = open(from, O_RDONLY|O_BINARY);
  1267.       if (fromfd < 0)
  1268.           fatal2("patch: internal error, can't reopen %s\n", from);
  1269.       while ((i=read(fromfd, buf, sizeof buf)) > 0)
  1270. ***************
  1271. *** 91,98 ****
  1272. --- 128,140 ----
  1273.           fatal1("patch: write failed\n");
  1274.       Close(fromfd);
  1275.       Close(tofd);
  1276. + #ifdef MSDOS
  1277. +     Unlink(from);
  1278.       }
  1279. + #else
  1280. +     }
  1281.       Unlink(from);
  1282. + #endif
  1283.       return 0;
  1284.   }
  1285.   
  1286. ***************
  1287. *** 106,115 ****
  1288.       Reg2 int fromfd;
  1289.       Reg1 int i;
  1290.    
  1291. !     tofd = creat(to, 0666);
  1292.       if (tofd < 0)
  1293.       fatal2("patch: can't create %s.\n", to);
  1294. !     fromfd = open(from, 0);
  1295.       if (fromfd < 0)
  1296.       fatal2("patch: internal error, can't reopen %s\n", from);
  1297.       while ((i=read(fromfd, buf, sizeof buf)) > 0)
  1298. --- 148,157 ----
  1299.       Reg2 int fromfd;
  1300.       Reg1 int i;
  1301.    
  1302. !     tofd = open(to, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY,S_IWRITE|S_IREAD);
  1303.       if (tofd < 0)
  1304.       fatal2("patch: can't create %s.\n", to);
  1305. !     fromfd = open(from, O_RDONLY|O_BINARY);
  1306.       if (fromfd < 0)
  1307.       fatal2("patch: internal error, can't reopen %s\n", from);
  1308.       while ((i=read(fromfd, buf, sizeof buf)) > 0)
  1309. ***************
  1310. *** 159,164 ****
  1311. --- 201,232 ----
  1312.   
  1313.   /* Vanilla terminal output (buffered). */
  1314.   
  1315. + #ifdef MSDOS
  1316. + #include <stdarg.h>
  1317. + void say(char *pat,...)
  1318. + {
  1319. +     va_list argptr;
  1320. +     va_start(argptr, pat);
  1321. +     vfprintf(stderr, pat, argptr);
  1322. +     va_end(argptr);
  1323. +     Fflush(stderr);
  1324. + }
  1325. + void fatal(char *pat,...)
  1326. + {
  1327. +     void my_exit();
  1328. +     va_list argptr;
  1329. +     va_start(argptr, pat);
  1330. +     vfprintf(stderr, pat, argptr);
  1331. +     va_end(argptr);
  1332. +     Fflush(stderr);
  1333. +     my_exit(1);
  1334. + }
  1335. + #else
  1336.   void
  1337.   say(pat,arg1,arg2,arg3)
  1338.   char *pat;
  1339. ***************
  1340. *** 180,188 ****
  1341. --- 248,269 ----
  1342.       say(pat, arg1, arg2, arg3);
  1343.       my_exit(1);
  1344.   }
  1345. + #endif
  1346.   
  1347.   /* Get a response from the user, somehow or other. */
  1348.   
  1349. + #ifdef MSDOS
  1350. + void ask(char *pat,...)
  1351. + {
  1352. +     int ttyfd;
  1353. +     int r;
  1354. +     bool tty2 = isatty(2);
  1355. +     va_list argptr;
  1356. +     va_start(argptr, pat);
  1357. +     vsprintf(buf, pat, argptr);
  1358. +     va_end(argptr);
  1359. + #else
  1360.   void
  1361.   ask(pat,arg1,arg2,arg3)
  1362.   char *pat;
  1363. ***************
  1364. *** 193,198 ****
  1365. --- 274,280 ----
  1366.       bool tty2 = isatty(2);
  1367.   
  1368.       Sprintf(buf, pat, arg1, arg2, arg3);
  1369. + #endif
  1370.       Fflush(stderr);
  1371.       write(2, buf, strlen(buf));
  1372.       if (tty2) {                /* might be redirected to a file */
  1373. ***************
  1374. *** 203,209 ****
  1375.       write(1, buf, strlen(buf));
  1376.       r = read(1, buf, sizeof buf);
  1377.       }
  1378. !     else if ((ttyfd = open("/dev/tty", 2)) >= 0 && isatty(ttyfd)) {
  1379.                       /* might be deleted or unwriteable */
  1380.       write(ttyfd, buf, strlen(buf));
  1381.       r = read(ttyfd, buf, sizeof buf);
  1382. --- 285,295 ----
  1383.       write(1, buf, strlen(buf));
  1384.       r = read(1, buf, sizeof buf);
  1385.       }
  1386. ! #ifdef MSDOS
  1387. !     else if ((ttyfd = open("con", O_RDWR)) >= 0 && isatty(ttyfd)) {
  1388. ! #else
  1389. !     else if ((ttyfd = open("/dev/tty", O_RDWR)) >= 0 && isatty(ttyfd)) {
  1390. ! #endif
  1391.                       /* might be deleted or unwriteable */
  1392.       write(ttyfd, buf, strlen(buf));
  1393.       r = read(ttyfd, buf, sizeof buf);
  1394. ***************
  1395. *** 242,247 ****
  1396. --- 328,334 ----
  1397.   #endif
  1398.   
  1399.       if (!reset) {
  1400. + #ifndef MSDOS
  1401.       hupval = signal(SIGHUP, SIG_IGN);
  1402.       if (hupval != SIG_IGN)
  1403.   #ifdef VOIDSIG
  1404. ***************
  1405. *** 249,254 ****
  1406. --- 336,342 ----
  1407.   #else
  1408.           hupval = (int(*)())my_exit;
  1409.   #endif
  1410. + #endif
  1411.       intval = signal(SIGINT, SIG_IGN);
  1412.       if (intval != SIG_IGN)
  1413.   #ifdef VOIDSIG
  1414. ***************
  1415. *** 257,263 ****
  1416. --- 345,353 ----
  1417.           intval = (int(*)())my_exit;
  1418.   #endif
  1419.       }
  1420. + #ifndef MSDOS
  1421.       Signal(SIGHUP, hupval);
  1422. + #endif
  1423.       Signal(SIGINT, intval);
  1424.   #endif
  1425.   }
  1426. ***************
  1427. *** 268,274 ****
  1428. --- 358,366 ----
  1429.   ignore_signals()
  1430.   {
  1431.   #ifndef lint
  1432. + #ifndef MSDOS
  1433.       Signal(SIGHUP, SIG_IGN);
  1434. + #endif
  1435.       Signal(SIGINT, SIG_IGN);
  1436.   #endif
  1437.   }
  1438. ***************
  1439. *** 287,293 ****
  1440. --- 379,389 ----
  1441.       Reg4 int dirvp = 0;
  1442.   
  1443.       while (*filename) {
  1444. + #ifdef MSDOS
  1445. +         if (*filename == '/' || *filename == '\\') {
  1446. + #else
  1447.           if (*filename == '/') {
  1448. + #endif
  1449.           filename++;
  1450.           dirv[dirvp++] = s;
  1451.           *s++ = '\0';
  1452. ***************
  1453. *** 338,348 ****
  1454. --- 434,452 ----
  1455.       if (strnEQ(name, "/dev/null", 9))    /* so files can be created by diffing */
  1456.       return Nullch;            /*   against /dev/null. */
  1457.       for (; *t && !isspace(*t); t++)
  1458. + #ifdef MSDOS
  1459. +         if (*t == '/' || *t == '\\')
  1460. + #else
  1461.           if (*t == '/')
  1462. + #endif
  1463.           if (--strip_leading >= 0)
  1464.           name = t+1;
  1465.       *t = '\0';
  1466. + #ifdef MSDOS
  1467. +     if (name != s && *s != '/' && *s != '\\') {
  1468. + #else
  1469.       if (name != s && *s != '/') {
  1470. + #endif
  1471.       name[-1] = '\0';
  1472.       if (stat(s, &filestat) && filestat.st_mode & S_IFDIR) {
  1473.           name[-1] = '/';
  1474. ***************
  1475. *** 364,366 ****
  1476. --- 468,525 ----
  1477.       }
  1478.       return name;
  1479.   }
  1480. + #ifdef MSDOS
  1481. + /* only one pipe can be open at a time */
  1482. + static char pipename[128], command[128];
  1483. + static int wrpipe;
  1484. + FILE *popen(char *cmd, char *flags)
  1485. + {
  1486. +   wrpipe = (strchr(flags, 'w') != NULL);
  1487. +   if ( wrpipe )
  1488. +   {
  1489. +     strcpy(command, cmd);
  1490. +     strcpy(pipename, "~WXXXXXX");
  1491. +     Mktemp(pipename);
  1492. +     return fopen(pipename, flags);  /* ordinary file */
  1493. +   }
  1494. +   else
  1495. +   {
  1496. +     strcpy(pipename, "~RXXXXXX");
  1497. +     Mktemp(pipename);
  1498. +     strcpy(command, cmd);
  1499. +     strcat(command, ">");
  1500. +     strcat(command, pipename);
  1501. +     system(command);
  1502. +     return fopen(pipename, flags);  /* ordinary file */
  1503. +   }
  1504. + }
  1505. + int pclose(FILE *pipe)
  1506. + {
  1507. +   int rc;
  1508. +   if ( fclose(pipe) == EOF )
  1509. +     return EOF;
  1510. +   if ( wrpipe )
  1511. +   {
  1512. +     strcat(command, "<");
  1513. +     strcat(command, pipename);
  1514. +     rc = system(command);
  1515. +     unlink(pipename);
  1516. +     return rc;
  1517. +   }
  1518. +   else
  1519. +   {
  1520. +     unlink(pipename);
  1521. +     return 0;
  1522. +   }
  1523. + }
  1524. + #endif
  1525. diff -cbBw orig/version.c patch2u/version.c
  1526. *** orig/version.c    Mon Feb 18 18:55:50 1991
  1527. --- patch2u/version.c    Fri Sep 07 21:03:48 1990
  1528. ***************
  1529. *** 10,16 ****
  1530.   #include "common.h"
  1531.   #include "util.h"
  1532.   #include "INTERN.h"
  1533. ! #include "patchlevel.h"
  1534.   #include "version.h"
  1535.   
  1536.   /* Print out the version number and die. */
  1537. --- 10,16 ----
  1538.   #include "common.h"
  1539.   #include "util.h"
  1540.   #include "INTERN.h"
  1541. ! #include "patchlev.h"
  1542.   #include "version.h"
  1543.   
  1544.   /* Print out the version number and die. */
  1545. ***************
  1546. *** 23,28 ****
  1547.   #ifdef lint
  1548.       rcsid[0] = rcsid[0];
  1549.   #else
  1550. !     fatal3("\n%s\nPatch level: %d\n", rcsid, PATCHLEVEL);
  1551.   #endif
  1552.   }
  1553. --- 23,28 ----
  1554.   #ifdef lint
  1555.       rcsid[0] = rcsid[0];
  1556.   #else
  1557. !     fatal3("\n%s\nPatch level: %d, with unidiff support, for DOS and OS/2\n", rcsid, PATCHLEVEL);
  1558.   #endif
  1559.   }
  1560.