home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / os2 / rcs / rcs56src / source / patch / pc-files / patches.os2 < prev   
Encoding:
Text File  |  1991-12-24  |  22.5 KB  |  917 lines

  1. Only in new: patch.cs
  2. Only in new: patch.def
  3. Only in new: patches.os2
  4. Only in new: isvalid.c
  5. diff -cbBw orig/common.h new/common.h
  6. *** orig/common.h    Tue Dec 24 18:13:12 1991
  7. --- new/common.h    Tue Dec 24 18:17:02 1991
  8. ***************
  9. *** 39,44 ****
  10. --- 39,46 ----
  11.   #include <sys/stat.h>
  12.   #include <ctype.h>
  13.   #include <signal.h>
  14. + #include <io.h>
  15. + #include <fcntl.h>
  16.   
  17.   /* constants */
  18.   
  19. ***************
  20. *** 146,153 ****
  21.   
  22.   EXT char *revision INIT(Nullch);    /* prerequisite revision, if any */
  23.   
  24. ! char *malloc();
  25. ! char *realloc();
  26.   char *strcpy();
  27.   char *strcat();
  28.   long atol();
  29. --- 148,155 ----
  30.   
  31.   EXT char *revision INIT(Nullch);    /* prerequisite revision, if any */
  32.   
  33. ! void *malloc();
  34. ! void *realloc();
  35.   char *strcpy();
  36.   char *strcat();
  37.   long atol();
  38. diff -cbBw orig/inp.c new/inp.c
  39. *** orig/inp.c    Tue Dec 24 18:10:30 1991
  40. --- new/inp.c    Tue Dec 24 18:25:40 1991
  41. ***************
  42. *** 115,120 ****
  43. --- 115,124 ----
  44.       if ((filemode & S_IFMT) & ~S_IFREG)
  45.       fatal2("%s is not a normal file--can't patch.\n", filename);
  46.       i_size = filestat.st_size;
  47. + #ifdef OS2
  48. +     if ( i_size > 65500L )
  49. +       return FALSE;
  50. + #endif
  51.       if (out_of_mem) {
  52.       set_hunkmax();        /* make sure dynamic arrays are allocated */
  53.       out_of_mem = FALSE;
  54. ***************
  55. *** 128,134 ****
  56.   #endif
  57.       if (i_womp == Nullch)
  58.       return FALSE;
  59. !     if ((ifd = open(filename, 0)) < 0)
  60.       fatal2("Can't open file %s\n", filename);
  61.   #ifndef lint
  62.       if (read(ifd, i_womp, (int)i_size) != i_size) {
  63. --- 132,138 ----
  64.   #endif
  65.       if (i_womp == Nullch)
  66.       return FALSE;
  67. !     if ((ifd = open(filename, O_BINARY)) < 0)
  68.       fatal2("Can't open file %s\n", filename);
  69.   #ifndef lint
  70.       if (read(ifd, i_womp, (int)i_size) != i_size) {
  71. ***************
  72. *** 206,214 ****
  73.       Reg4 bool found_revision = (revision == Nullch);
  74.   
  75.       using_plan_a = FALSE;
  76. !     if ((ifp = fopen(filename, "r")) == Nullfp)
  77.       fatal2("Can't open file %s\n", filename);
  78. !     if ((tifd = creat(TMPINNAME, 0666)) < 0)
  79.       fatal2("Can't open file %s\n", TMPINNAME);
  80.       while (fgets(buf, sizeof buf, ifp) != Nullch) {
  81.       if (revision != Nullch && !found_revision && rev_in_string(buf))
  82. --- 210,219 ----
  83.       Reg4 bool found_revision = (revision == Nullch);
  84.   
  85.       using_plan_a = FALSE;
  86. !     if ((ifp = fopen(filename, "rb")) == Nullfp)
  87.       fatal2("Can't open file %s\n", filename);
  88. !     if ((tifd = open(TMPINNAME, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY,
  89. !                      S_IWRITE|S_IREAD)) < 0)
  90.       fatal2("Can't open file %s\n", TMPINNAME);
  91.       while (fgets(buf, sizeof buf, ifp) != Nullch) {
  92.       if (revision != Nullch && !found_revision && rev_in_string(buf))
  93. ***************
  94. *** 236,242 ****
  95.           say2("Good.  This file appears to be the %s version.\n",
  96.           revision);
  97.       }
  98. !     Fseek(ifp, 0L, 0);        /* rewind file */
  99.       lines_per_buf = BUFFERSIZE / maxlen;
  100.       tireclen = maxlen;
  101.       tibuf[0] = malloc((MEM)(BUFFERSIZE + 1));
  102. --- 241,247 ----
  103.           say2("Good.  This file appears to be the %s version.\n",
  104.           revision);
  105.       }
  106. !     rewind(ifp);          /* rewind file */
  107.       lines_per_buf = BUFFERSIZE / maxlen;
  108.       tireclen = maxlen;
  109.       tibuf[0] = malloc((MEM)(BUFFERSIZE + 1));
  110. ***************
  111. *** 258,264 ****
  112.       }
  113.       Fclose(ifp);
  114.       Close(tifd);
  115. !     if ((tifd = open(TMPINNAME, 0)) < 0) {
  116.       fatal2("Can't reopen file %s\n", TMPINNAME);
  117.       }
  118.   }
  119. --- 263,270 ----
  120.       }
  121.       Fclose(ifp);
  122.       Close(tifd);
  123. !     if ((tifd = open(TMPINNAME, O_RDONLY|O_BINARY)) < 0) {
  124.       fatal2("Can't reopen file %s\n", TMPINNAME);
  125.       }
  126.   }
  127. diff -cbBw orig/patch.c new/patch.c
  128. *** orig/patch.c    Tue Dec 24 18:10:32 1991
  129. --- new/patch.c    Tue Dec 24 18:25:40 1991
  130. ***************
  131. *** 97,102 ****
  132. --- 97,103 ----
  133.   #include "util.h"
  134.   #include "pch.h"
  135.   #include "inp.h"
  136. + #include "patchlevel.h"
  137.   
  138.   /* procedures */
  139.   
  140. ***************
  141. *** 114,120 ****
  142. --- 115,126 ----
  143.   bool similar();
  144.   void re_input();
  145.   void my_exit();
  146. + char *strchr();
  147. + char *strrchr();
  148.   
  149. + /* Program name */
  150. + static char *myname;
  151.   /* Nonzero if -R was specified on command line.  */
  152.   static int reverse_flag_specified = FALSE;
  153.   
  154. ***************
  155. *** 132,137 ****
  156. --- 138,144 ----
  157.       int failed = 0;
  158.       int failtotal = 0;
  159.       int i;
  160. +     char *s;
  161.   
  162.       setbuf(stderr, serrbuf);
  163.       for (i = 0; i<MAXFILEC; i++)
  164. ***************
  165. *** 143,172 ****
  166.         char *tmpdir;
  167.         int tmpname_len;
  168.   
  169.         tmpdir = getenv ("TMPDIR");
  170.         if (tmpdir == NULL) {
  171.       tmpdir = "/tmp";
  172.         }
  173.         tmpname_len = strlen (tmpdir) + 20;
  174.   
  175.         TMPOUTNAME = (char *) malloc (tmpname_len);
  176.         strcpy (TMPOUTNAME, tmpdir);
  177. !       strcat (TMPOUTNAME, "/patchoXXXXXX");
  178.         Mktemp(TMPOUTNAME);
  179.   
  180.         TMPINNAME = (char *) malloc (tmpname_len);
  181.         strcpy (TMPINNAME, tmpdir);
  182. !       strcat (TMPINNAME, "/patchiXXXXXX");
  183.         Mktemp(TMPINNAME);
  184.   
  185.         TMPREJNAME = (char *) malloc (tmpname_len);
  186.         strcpy (TMPREJNAME, tmpdir);
  187. !       strcat (TMPREJNAME, "/patchrXXXXXX");
  188.         Mktemp(TMPREJNAME);
  189.   
  190.         TMPPATNAME = (char *) malloc (tmpname_len);
  191.         strcpy (TMPPATNAME, tmpdir);
  192. !       strcat (TMPPATNAME, "/patchpXXXXXX");
  193.         Mktemp(TMPPATNAME);
  194.       }
  195.   
  196. --- 150,185 ----
  197.         char *tmpdir;
  198.         int tmpname_len;
  199.   
  200. + #ifdef OS2
  201. +       tmpdir = getenv ("TMP");
  202. +       if (tmpdir == NULL) {
  203. +     tmpdir = "";
  204. + #else
  205.         tmpdir = getenv ("TMPDIR");
  206.         if (tmpdir == NULL) {
  207.       tmpdir = "/tmp";
  208. + #endif
  209.         }
  210.         tmpname_len = strlen (tmpdir) + 20;
  211.   
  212.         TMPOUTNAME = (char *) malloc (tmpname_len);
  213.         strcpy (TMPOUTNAME, tmpdir);
  214. !       strcat (TMPOUTNAME, "/poXXXXXX");
  215.         Mktemp(TMPOUTNAME);
  216.   
  217.         TMPINNAME = (char *) malloc (tmpname_len);
  218.         strcpy (TMPINNAME, tmpdir);
  219. !       strcat (TMPINNAME, "/piXXXXXX");
  220.         Mktemp(TMPINNAME);
  221.   
  222.         TMPREJNAME = (char *) malloc (tmpname_len);
  223.         strcpy (TMPREJNAME, tmpdir);
  224. !       strcat (TMPREJNAME, "/prXXXXXX");
  225.         Mktemp(TMPREJNAME);
  226.   
  227.         TMPPATNAME = (char *) malloc (tmpname_len);
  228.         strcpy (TMPPATNAME, tmpdir);
  229. !       strcat (TMPPATNAME, "/ppXXXXXX");
  230.         Mktemp(TMPPATNAME);
  231.       }
  232.   
  233. ***************
  234. *** 173,178 ****
  235. --- 186,192 ----
  236.       /* parse switches */
  237.       Argc = argc;
  238.       Argv = argv;
  239. +     myname = argv[0];
  240.       get_some_switches();
  241.   
  242.       /* make sure we clean up /tmp in case of disaster */
  243. ***************
  244. *** 337,343 ****
  245. --- 351,371 ----
  246.               s[13] = '\0';
  247.           }
  248.   #endif
  249. + #ifdef OS2
  250. +                 s = strchr(rejname, 0);
  251. + #endif
  252.           Strcat(rejname, REJEXT);
  253. + #ifdef OS2
  254. +                 if ( !IsFileNameValid(rejname) )
  255. +                 {
  256. +                   *s=0;
  257. +                   if ((s=strrchr(rejname,'.'))!=NULL)
  258. +                     *s=0;
  259. +                   strcat(rejname, ".rej");
  260. +                 }
  261. + #endif
  262.           }
  263.           if (skip_rest_of_patch) {
  264.           say4("%d out of %d hunks ignored--saving rejects to %s\n",
  265. ***************
  266. *** 499,504 ****
  267. --- 527,536 ----
  268.           case 'v':
  269.           version();
  270.           break;
  271. +             case 'h':
  272. +                 Usage();
  273. +                 exit(0);
  274. +         break;
  275.   #ifdef DEBUGGING
  276.           case 'x':
  277.           debug = atoi(s+1);
  278. ***************
  279. *** 506,516 ****
  280. --- 538,552 ----
  281.   #endif
  282.           default:
  283.           fprintf(stderr, "patch: unrecognized option `%s'\n", Argv[0]);
  284. + #ifdef OS2
  285. +                 Usage();
  286. + #else
  287.           fprintf(stderr, "\
  288.   Usage: patch [-ceflnNRsSuv] [-b backup-ext] [-B backup-prefix] [-d directory]\n\
  289.          [-D symbol] [-Fmax-fuzz] [-o out-file] [-p[strip-count]]\n\
  290.          [-r rej-name] [origfile] [patchfile] [[+] [options] [origfile]...]\n\
  291.   ");
  292. + #endif
  293.           my_exit(1);
  294.           }
  295.       }
  296. ***************
  297. *** 517,522 ****
  298. --- 553,586 ----
  299.       }
  300.   }
  301.   
  302. + Usage()
  303. + {
  304. +   printf("\npatch 2.0, patchlevel %s\n", PATCHLEVEL);
  305. +   printf("\nUsage: %s [options] orig patchfile [+ [options] orig]\n\n", myname);
  306. +   printf("  -b   next argument is the extension to be used in place of '.orig'\n");
  307. +   printf("  -c   forces patch to interpret the patch file as a context diff\n");
  308. +   printf("  -d   next argument is a directory, cd to it before doing anything else\n");
  309. +   printf("  -D   next argument is the symbol for '#ifdef...#endif' to mark changes\n");
  310. +   printf("  -e   forces patch to interpret the patch file as an ed script\n");
  311. +   printf("  -f   do not ask any questions\n");
  312. +   printf("  -l   more loosely whitespace matching\n");
  313. +   printf("  -n   forces patch to interpret the patch file as a normal diff\n");
  314. +   printf("  -N   ignore patches that are reversed or already applied, see -R\n");
  315. +   printf("  -o   next argument is the output file name\n");
  316. +   printf("  -r   next argument is the reject file name\n");
  317. +   printf("  -R   patch was created with the old and new files swapped\n");
  318. +   printf("  -s   makes patch do its work silently, unless an error occurs\n");
  319. +   printf("  -S   ignore this patch from the patch file\n");
  320. +   printf("  -u   forces patch to interpret the patch file as a unified context diff\n");
  321. +   printf("  -v   print out revision header and patch level\n\n");
  322. +   printf("  -F<number>    maximum fuzz factor for context diffs (default 2)\n");
  323. +   printf("  -p<number>    sets the pathname strip count\n");
  324. +   printf("  -x<number>    set internal debugging flags\n");
  325. + }
  326.   /* Attempt to find the right place to apply this hunk of patch. */
  327.   
  328.   LINENUM
  329. ***************
  330. *** 611,616 ****
  331. --- 675,703 ----
  332.   
  333.   /* We found where to apply it (we hope), so do it. */
  334.   
  335. + #ifdef OS2
  336. + static int fputs(const char *buffer, FILE *file)
  337. + {
  338. +   const char *ptr;
  339. +   for ( ptr = buffer; *ptr; ptr++ )
  340. +     if ( *ptr == '\r' )
  341. +     {
  342. +       putc(*ptr, file);
  343. +       if ( *(ptr + 1) == '\n' )
  344. +         putc(*++ptr, file);
  345. +     }
  346. +     else if ( *ptr == '\n' )
  347. +     {
  348. +       putc('\r', file);
  349. +       putc(*ptr, file);
  350. +     }
  351. +     else
  352. +       putc(*ptr, file);
  353. + }
  354. + #endif
  355.   void
  356.   apply_hunk(where)
  357.   LINENUM where;
  358. ***************
  359. *** 735,741 ****
  360.   init_output(name)
  361.   char *name;
  362.   {
  363. !     ofp = fopen(name, "w");
  364.       if (ofp == Nullfp)
  365.       fatal2("patch: can't create %s.\n", name);
  366.   }
  367. --- 822,828 ----
  368.   init_output(name)
  369.   char *name;
  370.   {
  371. !     ofp = fopen(name, "wb");
  372.       if (ofp == Nullfp)
  373.       fatal2("patch: can't create %s.\n", name);
  374.   }
  375. ***************
  376. *** 814,823 ****
  377. --- 901,929 ----
  378.                pch_line_len(pline) ))
  379.           return FALSE;
  380.       }
  381. + #ifdef OS2
  382. +     else
  383. +         {
  384. +           char *s1, *s2;
  385. +           int len;
  386. +           s1 = ifetch(iline, (offset >= 0));
  387. +           s2 = pfetch(pline);
  388. +           len = pch_line_len(pline);
  389. +           /* special CR/LF case */
  390. +           if ( s1[len - 1] == '\r' && s1[len] == '\n' && s2[len - 1] == '\n' )
  391. +             len--;
  392. +           if (strnNE(s1, s2, len))
  393. +         return FALSE;
  394. +         }
  395. + #else
  396.       else if (strnNE(ifetch(iline, (offset >= 0)),
  397.              pfetch(pline),
  398.              pch_line_len(pline) ))
  399.           return FALSE;
  400. + #endif
  401.       }
  402.       return TRUE;
  403.   }
  404. ***************
  405. *** 863,868 ****
  406. --- 969,978 ----
  407.       if (!trejkeep) {
  408.       Unlink(TMPREJNAME);
  409.       }
  410. +     if ( pfp != NULL )
  411. +     {
  412. +       Fclose(pfp);
  413.         Unlink(TMPPATNAME);
  414. +     }
  415.       exit(status);
  416.   }
  417. diff -cbBw orig/pch.c new/pch.c
  418. *** orig/pch.c    Tue Dec 24 18:11:18 1991
  419. --- new/pch.c    Tue Dec 24 18:25:40 1991
  420. ***************
  421. *** 37,43 ****
  422. --- 37,50 ----
  423.   #include "util.h"
  424.   #include "INTERN.h"
  425.   #include "pch.h"
  426. + #include "version.h"
  427.   
  428. + #ifdef OS2
  429. + #define EDPATH "ed"
  430. + #else
  431. + #define EDPATH "/bin/ed"
  432. + #endif
  433.   /* Patch (diff listing) abstract type. */
  434.   
  435.   static long p_filesize;            /* size of the patch file */
  436. ***************
  437. *** 83,88 ****
  438. --- 90,101 ----
  439.   char *filename;
  440.   {
  441.       if (filename == Nullch || !*filename || strEQ(filename, "-")) {
  442. +         if ( isatty(fileno(stdin)) )
  443. +         {
  444. +           Usage();
  445. +           exit(1);
  446. +         }
  447.       pfp = fopen(TMPPATNAME, "w");
  448.       if (pfp == Nullfp)
  449.           fatal2("patch: can't create %s.\n", TMPPATNAME);
  450. ***************
  451. *** 978,984 ****
  452.           if (*buf != '-')
  453.           fatal2("--- expected at line %ld of patch.\n", p_input_line);
  454.       }
  455. !     Sprintf(buf, "--- %ld,%ld\n", min, max);
  456.       p_line[i] = savestr(buf);
  457.       if (out_of_mem) {
  458.           p_end = i-1;
  459. --- 991,997 ----
  460.           if (*buf != '-')
  461.           fatal2("--- expected at line %ld of patch.\n", p_input_line);
  462.       }
  463. !     Sprintf(buf, "--- %ld,%ld\n", (long) min, (long) max);
  464.       p_line[i] = savestr(buf);
  465.       if (out_of_mem) {
  466.           p_end = i-1;
  467. ***************
  468. *** 1254,1262 ****
  469.       Unlink(TMPOUTNAME);
  470.       copy_file(filearg[0], TMPOUTNAME);
  471.       if (verbose)
  472. !         Sprintf(buf, "/bin/ed %s", TMPOUTNAME);
  473.       else
  474. !         Sprintf(buf, "/bin/ed - %s", TMPOUTNAME);
  475.       pipefp = popen(buf, "w");
  476.       }
  477.       for (;;) {
  478. --- 1267,1275 ----
  479.       Unlink(TMPOUTNAME);
  480.       copy_file(filearg[0], TMPOUTNAME);
  481.       if (verbose)
  482. !         Sprintf(buf, "%s %s", EDPATH, TMPOUTNAME);
  483.       else
  484. !         Sprintf(buf, "%s - %s", EDPATH, TMPOUTNAME);
  485.       pipefp = popen(buf, "w");
  486.       }
  487.       for (;;) {
  488. diff -cbBw orig/util.c new/util.c
  489. *** orig/util.c    Tue Dec 24 18:10:38 1991
  490. --- new/util.c    Tue Dec 24 18:25:40 1991
  491. ***************
  492. *** 5,10 ****
  493. --- 5,13 ----
  494.   
  495.   /* Rename a file, copying it if necessary. */
  496.   
  497. + char *strchr();
  498. + char *strrchr();
  499.   int
  500.   move_file(from,to)
  501.   char *from, *to;
  502. ***************
  503. *** 21,27 ****
  504.       if (debug & 4)
  505.           say2("Moving %s to stdout.\n", from);
  506.   #endif
  507. !     fromfd = open(from, 0);
  508.       if (fromfd < 0)
  509.           fatal2("patch: internal error, can't reopen %s\n", from);
  510.       while ((i=read(fromfd, buf, sizeof buf)) > 0)
  511. --- 24,30 ----
  512.       if (debug & 4)
  513.           say2("Moving %s to stdout.\n", from);
  514.   #endif
  515. !         fromfd = open(from, O_RDONLY|O_BINARY);
  516.       if (fromfd < 0)
  517.           fatal2("patch: internal error, can't reopen %s\n", from);
  518.       while ((i=read(fromfd, buf, sizeof buf)) > 0)
  519. ***************
  520. *** 36,43 ****
  521. --- 39,61 ----
  522.           Strcat(bakname, to);
  523.       } else {
  524.              Strcpy(bakname, to);
  525. + #ifdef OS2
  526. +         s = strchr(bakname, 0);
  527. + #endif
  528.           Strcat(bakname, origext?origext:ORIGEXT);
  529. + #ifdef OS2
  530. +         if ( !IsFileNameValid(bakname) )
  531. +         {
  532. +           *s=0;
  533. +           if ((s=strrchr(bakname,'.'))!=NULL)
  534. +             *s=0;
  535. +           strcat(bakname, ".org");
  536. +         }
  537. + #endif
  538.       }
  539.       if (stat(to, &filestat) >= 0) {    /* output file exists */
  540.       dev_t to_device = filestat.st_dev;
  541.       ino_t to_inode  = filestat.st_ino;
  542. ***************
  543. *** 44,50 ****
  544. --- 62,72 ----
  545.       char *simplename = bakname;
  546.   
  547.       for (s=bakname; *s; s++) {
  548. + #ifdef OS2
  549. +             if (*s == '/' || *s == '\\')
  550. + #else
  551.           if (*s == '/')
  552. + #endif
  553.           simplename = s+1;
  554.       }
  555.       /* find a backup name that is not the same file */
  556. ***************
  557. *** 61,73 ****
  558. --- 83,104 ----
  559.       if (debug & 4)
  560.           say3("Moving %s to %s.\n", to, bakname);
  561.   #endif
  562. + #ifdef OS2
  563. +         if (rename(to, bakname) < 0) {
  564. + #else
  565.       if (link(to, bakname) < 0) {
  566. + #endif
  567.           say3("patch: can't backup %s, output is in %s\n",
  568.           to, from);
  569.           return -1;
  570.       }
  571. + #ifndef OS2
  572.       while (unlink(to) >= 0) ;
  573. + #endif
  574.       }
  575.   #ifdef DEBUGGING
  576.       if (debug & 4)
  577.       say3("Moving %s to %s.\n", from, to);
  578. ***************
  579. *** 72,87 ****
  580.       if (debug & 4)
  581.       say3("Moving %s to %s.\n", from, to);
  582.   #endif
  583.       if (link(from, to) < 0) {        /* different file system? */
  584.       Reg4 int tofd;
  585.   
  586. !     tofd = creat(to, 0666);
  587.       if (tofd < 0) {
  588.           say3("patch: can't create %s, output is in %s.\n",
  589.             to, from);
  590.           return -1;
  591.       }
  592. !     fromfd = open(from, 0);
  593.       if (fromfd < 0)
  594.           fatal2("patch: internal error, can't reopen %s\n", from);
  595.       while ((i=read(fromfd, buf, sizeof buf)) > 0)
  596. --- 103,124 ----
  597.       if (debug & 4)
  598.       say3("Moving %s to %s.\n", from, to);
  599.   #endif
  600. + #ifdef OS2
  601. +     if (rename(from, to) < 0) {           /* different file system? */
  602. + #else
  603.       if (link(from, to) < 0) {        /* different file system? */
  604. + #endif
  605.       Reg4 int tofd;
  606.   
  607. !         tofd = open(to, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY,S_IWRITE|S_IREAD);
  608.       if (tofd < 0) {
  609.           say3("patch: can't create %s, output is in %s.\n",
  610.             to, from);
  611.           return -1;
  612.       }
  613. !         fromfd = open(from, O_RDONLY|O_BINARY);
  614.       if (fromfd < 0)
  615.           fatal2("patch: internal error, can't reopen %s\n", from);
  616.       while ((i=read(fromfd, buf, sizeof buf)) > 0)
  617. ***************
  618. *** 89,96 ****
  619. --- 126,138 ----
  620.           fatal1("patch: write failed\n");
  621.       Close(fromfd);
  622.       Close(tofd);
  623. + #ifdef OS2
  624. +     Unlink(from);
  625.       }
  626. + #else
  627. +     }
  628.       Unlink(from);
  629. + #endif
  630.       return 0;
  631.   }
  632.   
  633. ***************
  634. *** 104,113 ****
  635.       Reg2 int fromfd;
  636.       Reg1 int i;
  637.   
  638. !     tofd = creat(to, 0666);
  639.       if (tofd < 0)
  640.       fatal2("patch: can't create %s.\n", to);
  641. !     fromfd = open(from, 0);
  642.       if (fromfd < 0)
  643.       fatal2("patch: internal error, can't reopen %s\n", from);
  644.       while ((i=read(fromfd, buf, sizeof buf)) > 0)
  645. --- 146,155 ----
  646.       Reg2 int fromfd;
  647.       Reg1 int i;
  648.   
  649. !     tofd = open(to, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY,S_IWRITE|S_IREAD);
  650.       if (tofd < 0)
  651.       fatal2("patch: can't create %s.\n", to);
  652. !     fromfd = open(from, O_RDONLY|O_BINARY);
  653.       if (fromfd < 0)
  654.       fatal2("patch: internal error, can't reopen %s\n", from);
  655.       while ((i=read(fromfd, buf, sizeof buf)) > 0)
  656. ***************
  657. *** 157,162 ****
  658. --- 199,230 ----
  659.   
  660.   /* Vanilla terminal output (buffered). */
  661.   
  662. + #ifdef OS2
  663. + #include <stdarg.h>
  664. + void say(char *pat,...)
  665. + {
  666. +     va_list argptr;
  667. +     va_start(argptr, pat);
  668. +     vfprintf(stderr, pat, argptr);
  669. +     va_end(argptr);
  670. +     Fflush(stderr);
  671. + }
  672. + void fatal(char *pat,...)
  673. + {
  674. +     void my_exit();
  675. +     va_list argptr;
  676. +     va_start(argptr, pat);
  677. +     vfprintf(stderr, pat, argptr);
  678. +     va_end(argptr);
  679. +     Fflush(stderr);
  680. +     my_exit(1);
  681. + }
  682. + #else
  683.   void
  684.   say(pat,arg1,arg2,arg3)
  685.   char *pat;
  686. ***************
  687. *** 178,186 ****
  688. --- 246,267 ----
  689.       say(pat, arg1, arg2, arg3);
  690.       my_exit(1);
  691.   }
  692. + #endif
  693.   
  694.   /* Get a response from the user, somehow or other. */
  695.   
  696. + #ifdef OS2
  697. + void ask(char *pat,...)
  698. + {
  699. +     int ttyfd;
  700. +     int r;
  701. +     bool tty2 = isatty(2);
  702. +     va_list argptr;
  703. +     va_start(argptr, pat);
  704. +     vsprintf(buf, pat, argptr);
  705. +     va_end(argptr);
  706. + #else
  707.   void
  708.   ask(pat,arg1,arg2,arg3)
  709.   char *pat;
  710. ***************
  711. *** 191,196 ****
  712. --- 272,278 ----
  713.       bool tty2 = isatty(2);
  714.   
  715.       Sprintf(buf, pat, arg1, arg2, arg3);
  716. + #endif
  717.       Fflush(stderr);
  718.       write(2, buf, strlen(buf));
  719.       if (tty2) {                /* might be redirected to a file */
  720. ***************
  721. *** 201,207 ****
  722.       write(1, buf, strlen(buf));
  723.       r = read(1, buf, sizeof buf);
  724.       }
  725. !     else if ((ttyfd = open("/dev/tty", 2)) >= 0 && isatty(ttyfd)) {
  726.                       /* might be deleted or unwriteable */
  727.       write(ttyfd, buf, strlen(buf));
  728.       r = read(ttyfd, buf, sizeof buf);
  729. --- 283,293 ----
  730.       write(1, buf, strlen(buf));
  731.       r = read(1, buf, sizeof buf);
  732.       }
  733. ! #ifdef OS2
  734. !     else if ((ttyfd = open("con", O_RDWR)) >= 0 && isatty(ttyfd)) {
  735. ! #else
  736. !     else if ((ttyfd = open("/dev/tty", O_RDWR)) >= 0 && isatty(ttyfd)) {
  737. ! #endif
  738.                       /* might be deleted or unwriteable */
  739.       write(ttyfd, buf, strlen(buf));
  740.       r = read(ttyfd, buf, sizeof buf);
  741. ***************
  742. *** 240,245 ****
  743. --- 326,332 ----
  744.   #endif
  745.   
  746.       if (!reset) {
  747. + #ifndef OS2
  748.       hupval = signal(SIGHUP, SIG_IGN);
  749.       if (hupval != SIG_IGN)
  750.   #ifdef VOIDSIG
  751. ***************
  752. *** 247,252 ****
  753. --- 334,340 ----
  754.   #else
  755.           hupval = (int(*)())my_exit;
  756.   #endif
  757. + #endif
  758.       intval = signal(SIGINT, SIG_IGN);
  759.       if (intval != SIG_IGN)
  760.   #ifdef VOIDSIG
  761. ***************
  762. *** 255,261 ****
  763. --- 343,351 ----
  764.           intval = (int(*)())my_exit;
  765.   #endif
  766.       }
  767. + #ifndef OS2
  768.       Signal(SIGHUP, hupval);
  769. + #endif
  770.       Signal(SIGINT, intval);
  771.   #endif
  772.   }
  773. ***************
  774. *** 266,272 ****
  775. --- 356,364 ----
  776.   ignore_signals()
  777.   {
  778.   #ifndef lint
  779. + #ifndef OS2
  780.       Signal(SIGHUP, SIG_IGN);
  781. + #endif
  782.       Signal(SIGINT, SIG_IGN);
  783.   #endif
  784.   }
  785. ***************
  786. *** 285,291 ****
  787. --- 377,387 ----
  788.       Reg4 int dirvp = 0;
  789.   
  790.       while (*filename) {
  791. + #ifdef OS2
  792. +         if (*filename == '/' || *filename == '\\') {
  793. + #else
  794.       if (*filename == '/') {
  795. + #endif
  796.           filename++;
  797.           dirv[dirvp++] = s;
  798.           *s++ = '\0';
  799. ***************
  800. *** 336,346 ****
  801. --- 432,450 ----
  802.       if (strnEQ(name, "/dev/null", 9))    /* so files can be created by diffing */
  803.       return Nullch;            /*   against /dev/null. */
  804.       for (; *t && !isspace(*t); t++)
  805. + #ifdef OS2
  806. +         if (*t == '/' || *t == '\\')
  807. + #else
  808.       if (*t == '/')
  809. + #endif
  810.           if (--strip_leading >= 0)
  811.           name = t+1;
  812.       *t = '\0';
  813. + #ifdef OS2
  814. +     if (name != s && *s != '/' && *s != '\\') {
  815. + #else
  816.       if (name != s && *s != '/') {
  817. + #endif
  818.       name[-1] = '\0';
  819.       if (stat(s, &filestat) && filestat.st_mode & S_IFDIR) {
  820.           name[-1] = '/';
  821. ***************
  822. *** 362,364 ****
  823. --- 466,527 ----
  824.       }
  825.       return name;
  826.   }
  827. + #ifdef OS2
  828. + /* only one pipe can be open at a time */
  829. + /* In fact, this is a pipe simulation for the dumb MS-DOS */
  830. + /* but it works good enough for the situation where it is */
  831. + /* needed in patch, even if OS/2 has real pipes. */
  832. + static char pipename[128], command[128];
  833. + static int wrpipe;
  834. + FILE *popen(char *cmd, char *flags)
  835. + {
  836. +   wrpipe = (strchr(flags, 'w') != NULL);
  837. +   if ( wrpipe )
  838. +   {
  839. +     strcpy(command, cmd);
  840. +     strcpy(pipename, "~WXXXXXX");
  841. +     Mktemp(pipename);
  842. +     return fopen(pipename, flags);  /* ordinary file */
  843. +   }
  844. +   else
  845. +   {
  846. +     strcpy(pipename, "~RXXXXXX");
  847. +     Mktemp(pipename);
  848. +     strcpy(command, cmd);
  849. +     strcat(command, ">");
  850. +     strcat(command, pipename);
  851. +     system(command);
  852. +     return fopen(pipename, flags);  /* ordinary file */
  853. +   }
  854. + }
  855. + int pclose(FILE *pipe)
  856. + {
  857. +   int rc;
  858. +   if ( fclose(pipe) == EOF )
  859. +     return EOF;
  860. +   if ( wrpipe )
  861. +   {
  862. +     strcat(command, "<");
  863. +     strcat(command, pipename);
  864. +     rc = system(command);
  865. +     unlink(pipename);
  866. +     return rc;
  867. +   }
  868. +   else
  869. +   {
  870. +     unlink(pipename);
  871. +     return 0;
  872. +   }
  873. + }
  874. + #endif
  875.