home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / patch / patches.dos < prev    next >
Text File  |  1990-03-24  |  29KB  |  1,076 lines

  1. diff -cN orig/common.h src/common.h
  2. *** orig/common.h    Sat Mar 24 19:42:28 1990
  3. --- src/common.h    Wed Dec 27 14:03:26 1989
  4. ***************
  5. *** 28,34 ****
  6. --- 28,36 ----
  7.   #define Fclose (void)fclose
  8.   #define Fflush (void)fflush
  9.   #define Sprintf (void)sprintf
  10. + #ifndef MSDOS
  11.   #define Mktemp (void)mktemp
  12. + #endif
  13.   #define Strcpy (void)strcpy
  14.   #define Strcat (void)strcat
  15.   
  16. ***************
  17. *** 38,43 ****
  18. --- 40,47 ----
  19.   #include <sys/stat.h>
  20.   #include <ctype.h>
  21.   #include <signal.h>
  22. + #include <io.h>
  23. + #include <fcntl.h>
  24.   
  25.   /* constants */
  26.   
  27. ***************
  28. *** 54,61 ****
  29. --- 58,70 ----
  30.   #define CHECKOUT "co -l %s"
  31.   
  32.   #ifdef FLEXFILENAMES
  33. + #ifdef MSDOS
  34. + #define ORIGEXT ".org"
  35. + #define REJEXT ".rej"
  36. + #else
  37.   #define ORIGEXT ".orig"
  38.   #define REJEXT ".rej"
  39. + #endif
  40.   #else
  41.   #define ORIGEXT "~"
  42.   #define REJEXT "#"
  43. ***************
  44. *** 110,119 ****
  45. --- 119,136 ----
  46.   EXT char *origext INIT(Nullch);
  47.   EXT char *origprae INIT(Nullch);
  48.   
  49. + #ifdef MSDOS
  50. + EXT char TMPOUTNAME[80] INIT("poXXXXXX");
  51. + EXT char TMPINNAME[80] INIT("piXXXXXX"); /* might want /usr/tmp here */
  52. + EXT char TMPREJNAME[80] INIT("prXXXXXX");
  53. + EXT char TMPPATNAME[80] INIT("ppXXXXXX");
  54. + #else
  55.   EXT char TMPOUTNAME[] INIT("/tmp/patchoXXXXXX");
  56.   EXT char TMPINNAME[] INIT("/tmp/patchiXXXXXX");    /* might want /usr/tmp here */
  57.   EXT char TMPREJNAME[] INIT("/tmp/patchrXXXXXX");
  58.   EXT char TMPPATNAME[] INIT("/tmp/patchpXXXXXX");
  59. + #endif
  60.   EXT bool toutkeep INIT(FALSE);
  61.   EXT bool trejkeep INIT(FALSE);
  62.   
  63. ***************
  64. *** 144,156 ****
  65.   
  66.   EXT char *revision INIT(Nullch);    /* prerequisite revision, if any */
  67.   
  68. ! char *malloc();
  69. ! char *realloc();
  70.   char *strcpy();
  71.   char *strcat();
  72.   long atol();
  73.   long lseek();
  74.   char *mktemp();
  75.   #ifdef CHARSPRINTF
  76.   char *sprintf();
  77.   #else
  78. --- 161,178 ----
  79.   
  80.   EXT char *revision INIT(Nullch);    /* prerequisite revision, if any */
  81.   
  82. ! void *malloc();
  83. ! void *realloc();
  84.   char *strcpy();
  85.   char *strcat();
  86.   long atol();
  87.   long lseek();
  88.   char *mktemp();
  89. + #ifdef MSDOS
  90. + #undef stderr
  91. + FILE *stderr;
  92. + #endif
  93.   #ifdef CHARSPRINTF
  94.   char *sprintf();
  95.   #else
  96. diff -cN orig/config.h src/config.h
  97. *** orig/config.h    
  98. --- src/config.h    Wed Dec 27 14:03:26 1989
  99. ***************
  100. *** 0 ****
  101. --- 1,123 ----
  102. + /* config.h
  103. +  * This file was produced by running the config.h.SH script, which
  104. +  * gets its values from config.sh, which is generally produced by
  105. +  * running Configure.
  106. +  *
  107. +  * Feel free to modify any of this as the need arises.  Note, however,
  108. +  * that running config.h.SH again will wipe out any changes you've made.
  109. +  * For a more permanent change edit config.sh and rerun config.h.SH.
  110. +  */
  111. + /* EUNICE:
  112. +  *    This symbol, if defined, indicates that the program is being compiled
  113. +  *    under the EUNICE package under VMS.  The program will need to handle
  114. +  *    things like files that don't go away the first time you unlink them,
  115. +  *    due to version numbering.  It will also need to compensate for lack
  116. +  *    of a respectable link() command.
  117. +  */
  118. + /* VMS:
  119. +  *    This symbol, if defined, indicates that the program is running under
  120. +  *    VMS.  It is currently only set in conjunction with the EUNICE symbol.
  121. +  */
  122. + #/*undef    EUNICE        /**/
  123. + #/*undef    VMS        /**/
  124. + /* CPPSTDIN:
  125. +  *    This symbol contains the first part of the string which will invoke
  126. +  *    the C preprocessor on the standard input and produce to standard
  127. +  *    output.     Typical value of "cc -E" or "/lib/cpp".
  128. +  */
  129. + /* CPPMINUS:
  130. +  *    This symbol contains the second part of the string which will invoke
  131. +  *    the C preprocessor on the standard input and produce to standard
  132. +  *    output.  This symbol will have the value "-" if CPPSTDIN needs a minus
  133. +  *    to specify standard input, otherwise the value is "".
  134. +  */
  135. + #define CPPSTDIN "/usr/lib/cpp"
  136. + #define CPPMINUS ""
  137. + /* CHARSPRINTF:
  138. +  *    This symbol is defined if this system declares "char *sprintf()" in
  139. +  *    stdio.h.  The trend seems to be to declare it as "int sprintf()".  It
  140. +  *    is up to the package author to declare sprintf correctly based on the
  141. +  *    symbol.
  142. +  */
  143. + /*#define    CHARSPRINTF     /**/
  144. + /* FLEXFILENAMES:
  145. +  *    This symbol, if defined, indicates that the system supports filenames
  146. +  *    longer than 14 characters.
  147. +  */
  148. + #define    FLEXFILENAMES        /**/
  149. + /* index:
  150. +  *    This preprocessor symbol is defined, along with rindex, if the system
  151. +  *    uses the strchr and strrchr routines instead.
  152. +  */
  153. + /* rindex:
  154. +  *    This preprocessor symbol is defined, along with index, if the system
  155. +  *    uses the strchr and strrchr routines instead.
  156. +  */
  157. + #define    index strchr    /* cultural */
  158. + #define    rindex strrchr    /*  differences? */
  159. + /* VOIDSIG:
  160. +  *    This symbol is defined if this system declares "void (*signal())()" in
  161. +  *    signal.h.  The old way was to declare it as "int (*signal())()".  It
  162. +  *    is up to the package author to declare things correctly based on the
  163. +  *    symbol.
  164. +  */
  165. + #define    VOIDSIG     /**/
  166. + /* Reg1:
  167. +  *    This symbol, along with Reg2, Reg3, etc. is either the word "register"
  168. +  *    or null, depending on whether the C compiler pays attention to this
  169. +  *    many register declarations.  The intent is that you don't have to
  170. +  *    order your register declarations in the order of importance, so you
  171. +  *    can freely declare register variables in sub-blocks of code and as
  172. +  *    function parameters.  Do not use Reg<n> more than once per routine.
  173. +  */
  174. + #define Reg1 register        /**/
  175. + #define Reg2 register        /**/
  176. + #define Reg3 /* register        /**/
  177. + #define Reg4 /* register        /**/
  178. + #define Reg5 /* register        /**/
  179. + #define Reg6 /* register        /**/
  180. + #define Reg7         /**/
  181. + #define Reg8         /**/
  182. + #define Reg9         /**/
  183. + #define Reg10         /**/
  184. + #define Reg11         /**/
  185. + #define Reg12         /**/
  186. + #define Reg13         /**/
  187. + #define Reg14         /**/
  188. + #define Reg15         /**/
  189. + #define Reg16         /**/
  190. + /* VOIDFLAGS:
  191. +  *    This symbol indicates how much support of the void type is given by this
  192. +  *    compiler.  What various bits mean:
  193. +  *
  194. +  *        1 = supports declaration of void
  195. +  *        2 = supports arrays of pointers to functions returning void
  196. +  *        4 = supports comparisons between pointers to void functions and
  197. +  *            addresses of void functions
  198. +  *
  199. +  *    The package designer should define VOIDUSED to indicate the requirements
  200. +  *    of the package.  This can be done either by #defining VOIDUSED before
  201. +  *    including config.h, or by defining defvoidused in Myinit.U.  If the
  202. +  *    level of void support necessary is not present, defines void to int.
  203. +  */
  204. + #ifndef VOIDUSED
  205. + #define VOIDUSED 7
  206. + #endif
  207. + #define VOIDFLAGS 7
  208. + #if (VOIDFLAGS & VOIDUSED) != VOIDUSED
  209. + #define void int        /* is void to be avoided? */
  210. + #define M_VOID        /* Xenix strikes again */
  211. + #endif
  212. diff -cN orig/inp.c src/inp.c
  213. *** orig/inp.c    Sat Mar 24 19:42:30 1990
  214. --- src/inp.c    Sat Mar 10 20:19:38 1990
  215. ***************
  216. *** 79,84 ****
  217. --- 79,87 ----
  218.       int ifd;
  219.       Reg1 char *s;
  220.       Reg2 LINENUM iline;
  221. + #ifdef MSDOS
  222. +     int i_res;
  223. + #endif
  224.   
  225.       if (ok_to_create_file && stat(filename, &filestat) < 0) {
  226.       if (verbose)
  227. ***************
  228. *** 115,120 ****
  229. --- 118,127 ----
  230.       if ((filemode & S_IFMT) & ~S_IFREG)
  231.       fatal2("%s is not a normal file--can't patch.\n", filename);
  232.       i_size = filestat.st_size;
  233. + #ifdef MSDOS
  234. +     if ( i_size > 65500L )
  235. +       return FALSE;
  236. + #endif
  237.       if (out_of_mem) {
  238.       set_hunkmax();        /* make sure dynamic arrays are allocated */
  239.       out_of_mem = FALSE;
  240. ***************
  241. *** 131,136 ****
  242. --- 138,153 ----
  243.       if ((ifd = open(filename, 0)) < 0)
  244.       fatal2("Can't open file %s\n", filename);
  245.   #ifndef lint
  246. + #ifdef MSDOS
  247. +     if ((i_res = read(ifd, i_womp, (int)i_size)) == -1) {
  248. +     Close(ifd);    /* probably means i_size > 15 or 16 bits worth */
  249. +     free(i_womp);    /* at this point it doesn't matter if i_womp was */
  250. +     return FALSE;    /*   undersized. */
  251. +     }
  252. +     else
  253. +       /* cr/lf-translations would bomb here (i_res is != file size)! */
  254. +       i_size = i_res;
  255. + #else
  256.       if (read(ifd, i_womp, (int)i_size) != i_size) {
  257.       Close(ifd);    /* probably means i_size > 15 or 16 bits worth */
  258.       free(i_womp);    /* at this point it doesn't matter if i_womp was */
  259. ***************
  260. *** 137,142 ****
  261. --- 154,160 ----
  262.       return FALSE;    /*   undersized. */
  263.       }
  264.   #endif
  265. + #endif
  266.       Close(ifd);
  267.       if (i_size && i_womp[i_size-1] != '\n')
  268.       i_womp[i_size++] = '\n';
  269. ***************
  270. *** 208,214 ****
  271.       using_plan_a = FALSE;
  272.       if ((ifp = fopen(filename, "r")) == Nullfp)
  273.       fatal2("Can't open file %s\n", filename);
  274. !     if ((tifd = creat(TMPINNAME, 0666)) < 0)
  275.       fatal2("Can't open file %s\n", TMPINNAME);
  276.       while (fgets(buf, sizeof buf, ifp) != Nullch) {
  277.       if (revision != Nullch && !found_revision && rev_in_string(buf))
  278. --- 226,233 ----
  279.       using_plan_a = FALSE;
  280.       if ((ifp = fopen(filename, "r")) == Nullfp)
  281.       fatal2("Can't open file %s\n", filename);
  282. !     if ((tifd = open(TMPINNAME, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY,
  283. !                      S_IWRITE|S_IREAD)) < 0)
  284.       fatal2("Can't open file %s\n", TMPINNAME);
  285.       while (fgets(buf, sizeof buf, ifp) != Nullch) {
  286.       if (revision != Nullch && !found_revision && rev_in_string(buf))
  287. ***************
  288. *** 236,242 ****
  289.           say2("Good.  This file appears to be the %s version.\n",
  290.           revision);
  291.       }
  292. !     Fseek(ifp, 0L, 0);        /* rewind file */
  293.       lines_per_buf = BUFFERSIZE / maxlen;
  294.       tireclen = maxlen;
  295.       tibuf[0] = malloc((MEM)(BUFFERSIZE + 1));
  296. --- 255,261 ----
  297.           say2("Good.  This file appears to be the %s version.\n",
  298.           revision);
  299.       }
  300. !     rewind(ifp);          /* rewind file */
  301.       lines_per_buf = BUFFERSIZE / maxlen;
  302.       tireclen = maxlen;
  303.       tibuf[0] = malloc((MEM)(BUFFERSIZE + 1));
  304. ***************
  305. *** 258,264 ****
  306.       }
  307.       Fclose(ifp);
  308.       Close(tifd);
  309. !     if ((tifd = open(TMPINNAME, 0)) < 0) {
  310.       fatal2("Can't reopen file %s\n", TMPINNAME);
  311.       }
  312.   }
  313. --- 277,284 ----
  314.       }
  315.       Fclose(ifp);
  316.       Close(tifd);
  317. !     if ((tifd = open(TMPINNAME, O_RDONLY|O_BINARY)) < 0) {
  318.       fatal2("Can't reopen file %s\n", TMPINNAME);
  319.       }
  320.   }
  321. diff -cN orig/patch.c src/patch.c
  322. *** orig/patch.c    Sat Mar 24 19:42:32 1990
  323. --- src/patch.c    Wed Dec 27 14:03:26 1989
  324. ***************
  325. *** 111,117 ****
  326. --- 111,120 ----
  327.   bool similar();
  328.   void re_input();
  329.   void my_exit();
  330. + char *strchr();
  331.   
  332. + static char *myname;
  333.   /* Apply a set of diffs as appropriate. */
  334.   
  335.   main(argc,argv)
  336. ***************
  337. *** 126,133 ****
  338. --- 129,141 ----
  339.       int failed = 0;
  340.       int failtotal = 0;
  341.       int i;
  342. +     char *s;
  343.   
  344. + #ifdef MSDOS
  345. +     stderr = fopen("con", "w");
  346. + #endif
  347.       setbuf(stderr, serrbuf);
  348.       for (i = 0; i<MAXFILEC; i++)
  349.       filearg[i] = Nullch;
  350.       Mktemp(TMPOUTNAME);
  351. ***************
  352. *** 138,143 ****
  353. --- 146,152 ----
  354.       /* parse switches */
  355.       Argc = argc;
  356.       Argv = argv;
  357. +     myname = argv[0];
  358.       get_some_switches();
  359.    
  360.       /* make sure we clean up /tmp in case of disaster */
  361. ***************
  362. *** 300,307 ****
  363.               if (s[12] == '.')    /* try to preserve difference */
  364.                   s[12] = s[13];    /* between .h, .c, .y, etc. */
  365.               s[13] = '\0';
  366. !         }
  367.   #endif
  368.           Strcat(rejname, REJEXT);
  369.           }
  370.           if (skip_rest_of_patch) {
  371. --- 309,321 ----
  372.               if (s[12] == '.')    /* try to preserve difference */
  373.                   s[12] = s[13];    /* between .h, .c, .y, etc. */
  374.               s[13] = '\0';
  375. !                 }
  376. ! #else
  377. ! #ifdef MSDOS
  378. !                 if ((s=strchr(rejname,'.'))!=NULL)
  379. !                   *s=0;
  380.   #endif
  381. + #endif
  382.           Strcat(rejname, REJEXT);
  383.           }
  384.           if (skip_rest_of_patch) {
  385. ***************
  386. *** 460,465 ****
  387. --- 474,483 ----
  388.           case 'v':
  389.           version();
  390.           break;
  391. +             case 'h':
  392. +                 Usage();
  393. +                 exit(0);
  394. +         break;
  395.   #ifdef DEBUGGING
  396.           case 'x':
  397.           debug = atoi(s+1);
  398. ***************
  399. *** 468,473 ****
  400. --- 486,492 ----
  401.           default:
  402.                   /*fatal2("Unrecognized switch: %s\n", Argv[0]);*/
  403.                   printf("\nUnrecognized switch: %s.\n", Argv[0]);
  404. +                 Usage();
  405.                   exit(1);
  406.                   break;
  407.           }
  408. ***************
  409. *** 475,480 ****
  410. --- 494,524 ----
  411.       }
  412.   }
  413.   
  414. + Usage()
  415. + {
  416. +   printf("\nUsage: %s [options] orig patchfile [+ [options] orig]\n\n", myname);
  417. +   printf("-b   next argument is the extension to be used in place of '.orig'\n");
  418. +   printf("-c   forces patch to interpret the patch file as a context diff\n");
  419. +   printf("-d   next argument is a directory, cd to it before doing anything else\n");
  420. +   printf("-D   next argument is the symbol for '#ifdef...#endif' to mark changes\n");
  421. +   printf("-e   forces patch to interpret the patch file as an ed script\n");
  422. +   printf("-f   do not ask any questions\n");
  423. +   printf("-l   more loosely whitespace matching\n");
  424. +   printf("-n   forces patch to interpret the patch file as a normal diff\n");
  425. +   printf("-N   ignore patches that are reversed or already applied, see -R\n");
  426. +   printf("-o   next argument is the output file name\n");
  427. +   printf("-r   next argument is the reject file name\n");
  428. +   printf("-R   patch was created with the old and new files swapped\n");
  429. +   printf("-s   makes patch do its work silently, unless an error occurs\n");
  430. +   printf("-S   ignore this patch from the patch file\n");
  431. +   printf("-v   print out revision header and patch level\n\n");
  432. +   printf("-F<number>    maximum fuzz factor for context diffs (default 2)\n");
  433. +   printf("-p<number>    sets the pathname strip count\n");
  434. +   printf("-x<number>    set internal debugging flags\n");
  435. + }
  436.   /* Attempt to find the right place to apply this hunk of patch. */
  437.   
  438.   LINENUM
  439. ***************
  440. *** 822,827 ****
  441.       if (!trejkeep) {
  442.       Unlink(TMPREJNAME);
  443.       }
  444. !     Unlink(TMPPATNAME);
  445.       exit(status);
  446.   }
  447. --- 866,877 ----
  448.       if (!trejkeep) {
  449.       Unlink(TMPREJNAME);
  450.       }
  451. !     if ( pfp != NULL )
  452. !     {
  453. !       Fclose(pfp);
  454. !       Unlink(TMPPATNAME);
  455. !     }
  456.       exit(status);
  457.   }
  458. diff -cN orig/patch.cs src/patch.cs
  459. *** orig/patch.cs    
  460. --- src/patch.cs    Sat Mar 10 20:04:48 1990
  461. ***************
  462. *** 0 ****
  463. --- 1,5 ----
  464. + (-W1 -Oxn -DCANVARARG PATCH.C PCH.C INP.C VERSION.C)
  465. + (-W1 -Od -DCANVARARG UTIL.C)
  466. + PATCH.DEF
  467. + PATCH.EXE
  468. + -AC -LB -S0x4000
  469. diff -cN orig/patch.def src/patch.def
  470. *** orig/patch.def    
  471. --- src/patch.def    Wed Dec 27 14:03:26 1989
  472. ***************
  473. *** 0 ****
  474. --- 1,2 ----
  475. + NAME PATCH WINDOWCOMPAT
  476. + DESCRIPTION 'Patches original files with diffs - for MS-DOS and OS/2'
  477. diff -cN orig/pch.c src/pch.c
  478. *** orig/pch.c    Sat Mar 24 19:42:36 1990
  479. --- src/pch.c    Wed Dec 27 14:03:26 1989
  480. ***************
  481. *** 81,87 ****
  482.   {
  483.       if (filename == Nullch || !*filename || strEQ(filename, "-"))
  484.       {
  485. !         pfp = fopen(TMPPATNAME, "w");
  486.       if (pfp == Nullfp)
  487.           fatal2("patch: can't create %s.\n", TMPPATNAME);
  488.       while (fgets(buf, sizeof buf, stdin) != Nullch)
  489. --- 81,93 ----
  490.   {
  491.       if (filename == Nullch || !*filename || strEQ(filename, "-"))
  492.       {
  493. !         if ( isatty(fileno(stdin)) )
  494. !         {
  495. !           Usage();
  496. !           exit(1);
  497. !         }
  498. !     pfp = fopen(TMPPATNAME, "wb");
  499.       if (pfp == Nullfp)
  500.           fatal2("patch: can't create %s.\n", TMPPATNAME);
  501.       while (fgets(buf, sizeof buf, stdin) != Nullch)
  502. ***************
  503. *** 793,799 ****
  504.           if (*buf != '-')
  505.           fatal2("--- expected at line %ld of patch.\n", p_input_line);
  506.       }
  507. !         Sprintf(buf, "--- %ld,%ld\n", min, max);
  508.       p_line[i] = savestr(buf);
  509.       if (out_of_mem) {
  510.           p_end = i-1;
  511. --- 799,805 ----
  512.           if (*buf != '-')
  513.           fatal2("--- expected at line %ld of patch.\n", p_input_line);
  514.       }
  515. !         Sprintf(buf, "--- %ld,%ld\n", (long) min, (long) max);
  516.       p_line[i] = savestr(buf);
  517.       if (out_of_mem) {
  518.           p_end = i-1;
  519. ***************
  520. *** 1073,1082 ****
  521. --- 1079,1095 ----
  522.       if (!skip_rest_of_patch) {
  523.       Unlink(TMPOUTNAME);
  524.           copy_file(filearg[0], TMPOUTNAME);
  525. + #ifdef MSDOS
  526. +     if (verbose)
  527. +             Sprintf(buf, "ed %s", TMPOUTNAME);
  528. +     else
  529. +             Sprintf(buf, "ed - %s", TMPOUTNAME);
  530. + #else
  531.       if (verbose)
  532.           Sprintf(buf, "/bin/ed %s", TMPOUTNAME);
  533.       else
  534.               Sprintf(buf, "/bin/ed - %s", TMPOUTNAME);
  535. + #endif
  536.       pipefp = popen(buf, "w");
  537.       }
  538.       for (;;) {
  539. diff -cN orig/util.c src/util.c
  540. *** orig/util.c    Sat Mar 24 19:42:38 1990
  541. --- src/util.c    Sat Mar 24 20:02:38 1990
  542. ***************
  543. *** 5,10 ****
  544. --- 5,12 ----
  545.   
  546.   /* Rename a file, copying it if necessary. */
  547.   
  548. + char *strchr();
  549.   int
  550.   move_file(from,to)
  551.   char *from, *to;
  552. ***************
  553. *** 21,27 ****
  554.       if (debug & 4)
  555.           say2("Moving %s to stdout.\n", from);
  556.   #endif
  557. !     fromfd = open(from, 0);
  558.       if (fromfd < 0)
  559.           fatal2("patch: internal error, can't reopen %s\n", from);
  560.       while ((i=read(fromfd, buf, sizeof buf)) > 0)
  561. --- 23,29 ----
  562.       if (debug & 4)
  563.           say2("Moving %s to stdout.\n", from);
  564.   #endif
  565. !         fromfd = open(from, O_RDONLY|O_BINARY);
  566.       if (fromfd < 0)
  567.           fatal2("patch: internal error, can't reopen %s\n", from);
  568.       while ((i=read(fromfd, buf, sizeof buf)) > 0)
  569. ***************
  570. *** 31,50 ****
  571.       return 0;
  572.       }
  573.   
  574. !     if (origprae) {
  575. !         Strcpy (bakname, origprae);
  576. !         Strcat(bakname, to);
  577. !     } else {
  578. !            Strcpy(bakname, to);
  579. !         Strcat(bakname, origext?origext:ORIGEXT);
  580. !     }
  581.       if (stat(to, &filestat) >= 0) {    /* output file exists */
  582.       dev_t to_device = filestat.st_dev;
  583.       ino_t to_inode  = filestat.st_ino;
  584.       char *simplename = bakname;
  585.       
  586. !     for (s=bakname; *s; s++) {
  587. !         if (*s == '/')
  588.           simplename = s+1;
  589.       }
  590.       /* find a backup name that is not the same file */
  591. --- 33,61 ----
  592.       return 0;
  593.       }
  594.   
  595. !     if (origprae) {
  596. !         Strcpy (bakname, origprae);
  597. !         Strcat(bakname, to);
  598. !     } else {
  599. !         Strcpy(bakname, to);
  600. ! #ifdef MSDOS
  601. !         if ((s=strchr(bakname,'.'))!=NULL)
  602. !           *s=0;
  603. ! #endif
  604. !         Strcat(bakname, origext?origext:ORIGEXT);
  605. !     }
  606.       if (stat(to, &filestat) >= 0) {    /* output file exists */
  607.       dev_t to_device = filestat.st_dev;
  608.       ino_t to_inode  = filestat.st_ino;
  609.       char *simplename = bakname;
  610.       
  611. !         for (s=bakname; *s; s++) {
  612. ! #ifdef MSDOS
  613. !             if (*s == '/' || *s == '\\')
  614. ! #else
  615. !             if (*s == '/')
  616. ! #endif
  617.           simplename = s+1;
  618.       }
  619.       /* find a backup name that is not the same file */
  620. ***************
  621. *** 56,87 ****
  622.           else
  623.           Strcpy(simplename, simplename+1);
  624.       }
  625.       while (unlink(bakname) >= 0) ;    /* while() is for benefit of Eunice */
  626.   #ifdef DEBUGGING
  627.       if (debug & 4)
  628.           say3("Moving %s to %s.\n", to, bakname);
  629.   #endif
  630.       if (link(to, bakname) < 0) {
  631.           say3("patch: can't backup %s, output is in %s\n",
  632.           to, from);
  633.           return -1;
  634.       }
  635.       while (unlink(to) >= 0) ;
  636.       }
  637.   #ifdef DEBUGGING
  638.       if (debug & 4)
  639.       say3("Moving %s to %s.\n", from, to);
  640.   #endif
  641.       if (link(from, to) < 0) {        /* different file system? */
  642.       Reg4 int tofd;
  643.       
  644. !     tofd = creat(to, 0666);
  645.       if (tofd < 0) {
  646.           say3("patch: can't create %s, output is in %s.\n",
  647.             to, from);
  648.           return -1;
  649.       }
  650. !     fromfd = open(from, 0);
  651.       if (fromfd < 0)
  652.           fatal2("patch: internal error, can't reopen %s\n", from);
  653.       while ((i=read(fromfd, buf, sizeof buf)) > 0)
  654. --- 67,115 ----
  655.           else
  656.           Strcpy(simplename, simplename+1);
  657.       }
  658.       while (unlink(bakname) >= 0) ;    /* while() is for benefit of Eunice */
  659.   #ifdef DEBUGGING
  660.       if (debug & 4)
  661.           say3("Moving %s to %s.\n", to, bakname);
  662.   #endif
  663. + #ifdef MSDOS
  664. +         if (rename(to, bakname) < 0) {
  665. + #else
  666.       if (link(to, bakname) < 0) {
  667. + #endif
  668.           say3("patch: can't backup %s, output is in %s\n",
  669.           to, from);
  670.           return -1;
  671.       }
  672. + #ifndef MSDOS
  673.       while (unlink(to) >= 0) ;
  674. + #endif
  675.       }
  676.   #ifdef DEBUGGING
  677.       if (debug & 4)
  678.       say3("Moving %s to %s.\n", from, to);
  679.   #endif
  680. + #ifdef MSDOS
  681. +     if (rename(from, to) < 0) {           /* different file system? */
  682. + #else
  683.       if (link(from, to) < 0) {        /* different file system? */
  684. + #endif
  685.       Reg4 int tofd;
  686.       
  687. !         tofd = open(to, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY,S_IWRITE|S_IREAD);
  688.       if (tofd < 0) {
  689.           say3("patch: can't create %s, output is in %s.\n",
  690.             to, from);
  691.           return -1;
  692.       }
  693. !         fromfd = open(from, O_RDONLY|O_BINARY);
  694.       if (fromfd < 0)
  695.           fatal2("patch: internal error, can't reopen %s\n", from);
  696.       while ((i=read(fromfd, buf, sizeof buf)) > 0)
  697. ***************
  698. *** 89,96 ****
  699. --- 117,129 ----
  700.           fatal1("patch: write failed\n");
  701.       Close(fromfd);
  702.       Close(tofd);
  703. + #ifdef MSDOS
  704. +     Unlink(from);
  705.       }
  706. + #else
  707. +     }
  708.       Unlink(from);
  709. + #endif
  710.       return 0;
  711.   }
  712.   
  713. ***************
  714. *** 104,113 ****
  715.       Reg2 int fromfd;
  716.       Reg1 int i;
  717.    
  718. !     tofd = creat(to, 0666);
  719.       if (tofd < 0)
  720.       fatal2("patch: can't create %s.\n", to);
  721. !     fromfd = open(from, 0);
  722.       if (fromfd < 0)
  723.       fatal2("patch: internal error, can't reopen %s\n", from);
  724.       while ((i=read(fromfd, buf, sizeof buf)) > 0)
  725. --- 137,146 ----
  726.       Reg2 int fromfd;
  727.       Reg1 int i;
  728.    
  729. !     tofd = open(to, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY,S_IWRITE|S_IREAD);
  730.       if (tofd < 0)
  731.       fatal2("patch: can't create %s.\n", to);
  732. !     fromfd = open(from, O_RDONLY|O_BINARY);
  733.       if (fromfd < 0)
  734.       fatal2("patch: internal error, can't reopen %s\n", from);
  735.       while ((i=read(fromfd, buf, sizeof buf)) > 0)
  736. ***************
  737. *** 157,162 ****
  738. --- 190,221 ----
  739.   
  740.   /* Vanilla terminal output (buffered). */
  741.   
  742. + #ifdef MSDOS
  743. + #include <stdarg.h>
  744. + void say(char *pat,...)
  745. + {
  746. +     va_list argptr;
  747. +     va_start(argptr, pat);
  748. +     vfprintf(stderr, pat, argptr);
  749. +     va_end(argptr);
  750. +     Fflush(stderr);
  751. + }
  752. + void fatal(char *pat,...)
  753. + {
  754. +     void my_exit();
  755. +     va_list argptr;
  756. +     va_start(argptr, pat);
  757. +     vfprintf(stderr, pat, argptr);
  758. +     va_end(argptr);
  759. +     Fflush(stderr);
  760. +     my_exit(1);
  761. + }
  762. + #else
  763.   void
  764.   say(pat,arg1,arg2,arg3)
  765.   char *pat;
  766. ***************
  767. *** 178,186 ****
  768. --- 237,258 ----
  769.       say(pat, arg1, arg2, arg3);
  770.       my_exit(1);
  771.   }
  772. + #endif
  773.   
  774.   /* Get a response from the user, somehow or other. */
  775.   
  776. + #ifdef MSDOS
  777. + void ask(char *pat,...)
  778. + {
  779. +     int ttyfd;
  780. +     int r;
  781. +     bool tty2 = isatty(2);
  782. +     va_list argptr;
  783. +     va_start(argptr, pat);
  784. +     vsprintf(buf, pat, argptr);
  785. +     va_end(argptr);
  786. + #else
  787.   void
  788.   ask(pat,arg1,arg2,arg3)
  789.   char *pat;
  790. ***************
  791. *** 191,196 ****
  792. --- 263,269 ----
  793.       bool tty2 = isatty(2);
  794.   
  795.       Sprintf(buf, pat, arg1, arg2, arg3);
  796. + #endif
  797.       Fflush(stderr);
  798.       write(2, buf, strlen(buf));
  799.       if (tty2) {                /* might be redirected to a file */
  800. ***************
  801. *** 201,207 ****
  802.       write(1, buf, strlen(buf));
  803.       r = read(1, buf, sizeof buf);
  804.       }
  805. !     else if ((ttyfd = open("/dev/tty", 2)) >= 0 && isatty(ttyfd)) {
  806.                       /* might be deleted or unwriteable */
  807.       write(ttyfd, buf, strlen(buf));
  808.       r = read(ttyfd, buf, sizeof buf);
  809. --- 274,284 ----
  810.       write(1, buf, strlen(buf));
  811.       r = read(1, buf, sizeof buf);
  812.       }
  813. ! #ifdef MSDOS
  814. !     else if ((ttyfd = open("con", O_RDWR)) >= 0 && isatty(ttyfd)) {
  815. ! #else
  816. !     else if ((ttyfd = open("/dev/tty", O_RDWR)) >= 0 && isatty(ttyfd)) {
  817. ! #endif
  818.                       /* might be deleted or unwriteable */
  819.       write(ttyfd, buf, strlen(buf));
  820.       r = read(ttyfd, buf, sizeof buf);
  821. ***************
  822. *** 240,245 ****
  823. --- 317,323 ----
  824.   #endif
  825.   
  826.       if (!reset) {
  827. + #ifndef MSDOS
  828.       hupval = signal(SIGHUP, SIG_IGN);
  829.       if (hupval != SIG_IGN)
  830.   #ifdef VOIDSIG
  831. ***************
  832. *** 247,252 ****
  833. --- 325,331 ----
  834.   #else
  835.           hupval = (int(*)())my_exit;
  836.   #endif
  837. + #endif
  838.       intval = signal(SIGINT, SIG_IGN);
  839.       if (intval != SIG_IGN)
  840.   #ifdef VOIDSIG
  841. ***************
  842. *** 255,261 ****
  843. --- 334,342 ----
  844.           intval = (int(*)())my_exit;
  845.   #endif
  846.       }
  847. + #ifndef MSDOS
  848.       Signal(SIGHUP, hupval);
  849. + #endif
  850.       Signal(SIGINT, intval);
  851.   #endif
  852.   }
  853. ***************
  854. *** 266,272 ****
  855. --- 347,355 ----
  856.   ignore_signals()
  857.   {
  858.   #ifndef lint
  859. + #ifndef MSDOS
  860.       Signal(SIGHUP, SIG_IGN);
  861. + #endif
  862.       Signal(SIGINT, SIG_IGN);
  863.   #endif
  864.   }
  865. ***************
  866. *** 285,291 ****
  867.       Reg4 int dirvp = 0;
  868.   
  869.       while (*filename) {
  870. !     if (*filename == '/') {
  871.           filename++;
  872.           dirv[dirvp++] = s;
  873.           *s++ = '\0';
  874. --- 368,378 ----
  875.       Reg4 int dirvp = 0;
  876.   
  877.       while (*filename) {
  878. ! #ifdef MSDOS
  879. !         if (*filename == '/' || *filename == '\\') {
  880. ! #else
  881. !         if (*filename == '/') {
  882. ! #endif
  883.           filename++;
  884.           dirv[dirvp++] = s;
  885.           *s++ = '\0';
  886. ***************
  887. *** 336,346 ****
  888.       if (strnEQ(name, "/dev/null", 9))    /* so files can be created by diffing */
  889.       return Nullch;            /*   against /dev/null. */
  890.       for (; *t && !isspace(*t); t++)
  891. !     if (*t == '/')
  892.           if (--strip_leading >= 0)
  893.           name = t+1;
  894.       *t = '\0';
  895.       if (name != s && *s != '/') {
  896.       name[-1] = '\0';
  897.       if (stat(s, &filestat) && filestat.st_mode & S_IFDIR) {
  898.           name[-1] = '/';
  899. --- 423,441 ----
  900.       if (strnEQ(name, "/dev/null", 9))    /* so files can be created by diffing */
  901.       return Nullch;            /*   against /dev/null. */
  902.       for (; *t && !isspace(*t); t++)
  903. ! #ifdef MSDOS
  904. !         if (*t == '/' || *t == '\\')
  905. ! #else
  906. !         if (*t == '/')
  907. ! #endif
  908.           if (--strip_leading >= 0)
  909.           name = t+1;
  910.       *t = '\0';
  911. + #ifdef MSDOS
  912. +     if (name != s && *s != '/' && *s != '\\') {
  913. + #else
  914.       if (name != s && *s != '/') {
  915. + #endif
  916.       name[-1] = '\0';
  917.       if (stat(s, &filestat) && filestat.st_mode & S_IFDIR) {
  918.           name[-1] = '/';
  919. ***************
  920. *** 362,364 ****
  921. --- 457,536 ----
  922.       }
  923.       return name;
  924.   }
  925. + #ifdef MSDOS
  926. + char *getenv();
  927. + Mktemp(char *file)
  928. + {
  929. +   char fname[32], *tmp;
  930. +   tmp = getenv("TMP");
  931. +   if ( tmp != NULL )
  932. +   {
  933. +     strcpy(fname, file);
  934. +     strcpy(file, tmp);
  935. +     if ( file[strlen(file) - 1] != '\\' )
  936. +       strcat(file, "\\");
  937. +     strcat(file, fname);
  938. +   }
  939. +   mktemp(file);
  940. + }
  941. + /* only one pipe can be open at a time */
  942. + static char pipename[128], command[128];
  943. + static int wrpipe;
  944. + FILE *popen(char *cmd, char *flags)
  945. + {
  946. +   wrpipe = (strchr(flags, 'w') != NULL);
  947. +   if ( wrpipe )
  948. +   {
  949. +     strcpy(command, cmd);
  950. +     strcpy(pipename, "~WXXXXXX");
  951. +     Mktemp(pipename);
  952. +     return fopen(pipename, flags);  /* ordinary file */
  953. +   }
  954. +   else
  955. +   {
  956. +     strcpy(pipename, "~RXXXXXX");
  957. +     Mktemp(pipename);
  958. +     strcpy(command, cmd);
  959. +     strcat(command, ">");
  960. +     strcat(command, pipename);
  961. +     system(command);
  962. +     return fopen(pipename, flags);  /* ordinary file */
  963. +   }
  964. + }
  965. + int pclose(FILE *pipe)
  966. + {
  967. +   int rc;
  968. +   if ( fclose(pipe) == EOF )
  969. +     return EOF;
  970. +   if ( wrpipe )
  971. +   {
  972. +     strcat(command, "<");
  973. +     strcat(command, pipename);
  974. +     rc = system(command);
  975. +     unlink(pipename);
  976. +     return rc;
  977. +   }
  978. +   else
  979. +   {
  980. +     unlink(pipename);
  981. +     return 0;
  982. +   }
  983. + }
  984. + #endif
  985. diff -cN orig/version.c src/version.c
  986. *** orig/version.c    Sat Mar 24 19:42:40 1990
  987. --- src/version.c    Wed Dec 27 14:03:26 1989
  988. ***************
  989. *** 10,16 ****
  990.   #include "common.h"
  991.   #include "util.h"
  992.   #include "INTERN.h"
  993. ! #include "patchlevel.h"
  994.   #include "version.h"
  995.   
  996.   /* Print out the version number and die. */
  997. --- 10,16 ----
  998.   #include "common.h"
  999.   #include "util.h"
  1000.   #include "INTERN.h"
  1001. ! #include "patchlev.h"
  1002.   #include "version.h"
  1003.   
  1004.   /* Print out the version number and die. */
  1005. ***************
  1006. *** 23,28 ****
  1007.   #ifdef lint
  1008.       rcsid[0] = rcsid[0];
  1009.   #else
  1010. !     fatal3("\n%s\nPatch level: %d\n", rcsid, PATCHLEVEL);
  1011.   #endif
  1012.   }
  1013. --- 23,28 ----
  1014.   #ifdef lint
  1015.       rcsid[0] = rcsid[0];
  1016.   #else
  1017. !     fatal3("\n%s\nPatch level: %d (DOS & OS/2)\n", rcsid, PATCHLEVEL);
  1018.   #endif
  1019.   }
  1020.