Prereq: "12u7" diff -C2 -N patch-2.0.12u7/patchlevel.h patch-2.0.12u8/patchlevel.h *** patch-2.0.12u7/patchlevel.h Mon Jul 6 15:42:09 1992 --- patch-2.0.12u8/patchlevel.h Tue Sep 15 00:36:28 1992 *************** *** 1 **** ! #define PATCHLEVEL "12u7" --- 1 ---- ! #define PATCHLEVEL "12u8" diff -C2 -N patch-2.0.12u7/ChangeLog patch-2.0.12u8/ChangeLog *** patch-2.0.12u7/ChangeLog Mon Jul 6 15:42:24 1992 --- patch-2.0.12u8/ChangeLog Tue Sep 15 00:36:32 1992 *************** *** 1,3 **** --- 1,98 ---- + Tue Sep 15 00:36:15 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu) + + * patchlevel.h: PATCHLEVEL 12u8. + + Mon Sep 14 22:01:23 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu) + + * Makefile.SH: Add uninstall target. Simplify install target. + + * util.c (fatal, pfatal): Add some asterisks to make fatal + messages stand out more. + + Tue Aug 25 22:13:36 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu) + + * patch.c (main, get_some_switches), common.h, inp.c (plan_a, + plan_b), pch.c (there_is_another_aptch): Add -t option, + similar to -f. + + Mon Jul 27 11:27:07 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu) + + * inp.c (plan_a, util.c (fetchname): Use a macro to simplify code. + * common.h: Define SCCSDIFF and RCSDIFF. + * inp.c (plan_a): Use them to make sure it's safe to check out + the default RCS or SCCS version. + From Paul Eggert. + + Wed Jul 22 14:37:08 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu) + + * patch.man: Use the standard comment syntax -- '\" -- instead + of '''. + + Tue Jul 21 15:26:01 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu) + + * Configure: Add /etc /usr/lib /lib to pth. + + Mon Jul 20 14:10:32 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu) + + * util.h: Declare basename. + * inp.c (plan_a), util.c (fetchname): Use it to isolate the + leading path when testing for RCS and SCCS files. + + Sat Jul 11 18:03:26 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu) + + * Configure: Use the user's PATH and build pth from it. + + Fri Jul 10 16:03:23 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu) + + * Configure: Change cc -S to cc -c and tr '[ - ]' '[\012-\012]' + to tr ' ' '\012' for AIX 3.2. + From chip@tct.com (Chip Salzenberg). + + * util.c (makedirs): Only make the directories that don't exist. + From chip@tct.com (Chip Salzenberg). + + Wed Jul 8 01:21:15 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu) + + * util.c (fatal, pfatal): Print "patch: " before message. + * pch.c, inp.c, patch.c, util.c: Remove "patch: " from the + callers that had it. + + * util.c (pfatal): New function. + * util.h: Declare it and pfatal[1-4] macros. + * various files: Use it instead of fatal where appropriate. + + * Configure: Make /usr/local/man/man1 the first choice for the + man pages. + + * patch.c (main): Open ofp after checking for ed script. + Close ofp and rejfp before trying plan B. + From epang@sfu.ca (Eugene Pang). + + * backupfile.h: Declare get_version. + + * Move decls of rindex and popen to common.h. + + * common.h (myuid): New variable. + * patch.c (main): Initialize it. + * inp.c (myuid): Function removed. + (plan_a): Use the variable, not the function. + + * patch.c: Reinstate -E option. + + Tue Jul 7 23:19:28 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu) + + * inp.c (myuid): New function. + (plan_a): Call it. Optimize stat calls. Be smarter about + detecting checked out RCS and SCCS files. + From Paul Eggert (eggert@twinsun.com). + + * inp.c, util.c, patch.c: Don't bother checking for stat() > 0. + Mon Jul 6 13:01:52 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu) + + * version.c (version): Don't print the RCS stuff, since we're + not updating it regularly. + + * patch.c (get_some_switches): Make the usage message more accurate. * patchlevel.h: PATCHLEVEL 12u7. diff -C2 -N patch-2.0.12u7/Configure patch-2.0.12u8/Configure *** patch-2.0.12u7/Configure Sat Mar 14 22:05:34 1992 --- patch-2.0.12u8/Configure Wed Jul 22 14:51:32 1992 *************** *** 16,20 **** : sanity checks ! PATH='.:/bin:/usr/bin:/usr/local/bin:/usr/ucb:/usr/local:/usr/lbin:/etc:/usr/new:/usr/new/bin:/usr/nbin' export PATH || (echo "OOPS, this isn't sh. Desperation time. I will feed myself to sh."; sh $0; kill $$) --- 16,22 ---- : sanity checks ! : the user has a better chance than we do of setting a reasonable PATH ! : but add some directories we need that are probably not there ! PATH=.:${PATH}:/etc:/usr/lib:/lib export PATH || (echo "OOPS, this isn't sh. Desperation time. I will feed myself to sh."; sh $0; kill $$) *************** *** 147,151 **** attrlist="$attrlist nsc32000 sinix xenix venix posix ansi M_XENIX" attrlist="$attrlist mc68k m68k __STDC__" ! pth="/bin /usr/bin /usr/ccs/bin /usr/ucb /usr/local /usr/local/bin /usr/lbin /etc /usr/lib /lib" d_newshome="../../NeWS" defvoidused=7 --- 149,153 ---- attrlist="$attrlist nsc32000 sinix xenix venix posix ansi M_XENIX" attrlist="$attrlist mc68k m68k __STDC__" ! pth=`echo $PATH | tr : ' '` d_newshome="../../NeWS" defvoidused=7 *************** *** 742,746 **** } EOCP ! if cc -S -DTRY=7 try.c >.out 2>&1 ; then voidflags=7 echo "It appears to support void fully." --- 744,749 ---- } EOCP ! : Argh -- AIX 3.2 does not have cc -S! ! if cc -c -DTRY=7 try.c >.out 2>&1 ; then voidflags=7 echo "It appears to support void fully." *************** *** 751,757 **** else echo "Hmm, you compiler has some difficulty with void. Checking further..." ! if cc -S -DTRY=1 try.c >/dev/null 2>&1 ; then echo "It supports 1..." ! if cc -S -DTRY=3 try.c >/dev/null 2>&1 ; then voidflags=3 echo "And it supports 2 but not 4." --- 754,760 ---- else echo "Hmm, you compiler has some difficulty with void. Checking further..." ! if cc -c -DTRY=1 try.c >/dev/null 2>&1 ; then echo "It supports 1..." ! if cc -c -DTRY=3 try.c >/dev/null 2>&1 ; then voidflags=3 echo "And it supports 2 but not 4." *************** *** 758,762 **** else echo "It doesn't support 2..." ! if cc -S -DTRY=3 try.c >/dev/null 2>&1 ; then voidflags=5 echo "But it supports 4." --- 761,765 ---- else echo "It doesn't support 2..." ! if cc -c -DTRY=3 try.c >/dev/null 2>&1 ; then voidflags=5 echo "But it supports 4." *************** *** 869,873 **** : get C preprocessor symbols handy echo " " ! echo $attrlist | $tr '[ - ]' '[\012-\012]' >Cppsym.know $cat <Cppsym $startsh --- 872,877 ---- : get C preprocessor symbols handy echo " " ! : AIX 3.2 rejects tr '[ - ]' because the range endpoints are the same. ! echo $attrlist | $tr ' ' '\012' >Cppsym.know $cat <Cppsym $startsh *************** *** 896,900 **** 0) exit 1;; esac ! echo \$* | $tr '[ - ]' '[\012-\012]' | $sed -e 's/\(.*\)/\\ #ifdef \1\\ exit 0; _ _ _ _\1\\ \1\\ --- 900,904 ---- 0) exit 1;; esac ! echo \$* | $tr ' ' '\012' | $sed -e 's/\(.*\)/\\ #ifdef \1\\ exit 0; _ _ _ _\1\\ \1\\ *************** *** 1032,1036 **** case "$mansrc" in '') ! dflt=`loc . /usr/man/man1 /usr/man/mann /usr/man/local/man1 /usr/man/u_man/man1 /usr/man/man1` ;; *) dflt="$mansrc" --- 1036,1040 ---- case "$mansrc" in '') ! dflt=`loc . /usr/man/man1 /usr/local/man/man1 /usr/man/mann /usr/man/local/man1 /usr/man/u_man/man1` ;; *) dflt="$mansrc" diff -C2 -N patch-2.0.12u7/Makefile.SH patch-2.0.12u8/Makefile.SH *** patch-2.0.12u7/Makefile.SH Mon Jul 6 14:28:10 1992 --- patch-2.0.12u8/Makefile.SH Mon Sep 14 22:39:38 1992 *************** *** 66,78 **** install: patch export PATH || exit 1 ! - mv $(bin)/patch $(bin)/patch.old ! - if test `pwd` != $(bin); then cp $(public) $(bin); fi ! cd $(bin); chmod 755 $(public) ! - if test `pwd` != $(mansrc); then \ ! for page in $(manpages); do \ ! rm -f $(mansrc)/../cat$(manext)/`basename $$page .man`.$(manext); \ ! cp $$page $(mansrc)/`basename $$page .man`.$(manext); \ ! done; \ ! fi clean: --- 66,77 ---- install: patch export PATH || exit 1 ! -mv $(bin)/patch $(bin)/patch.old ! cp patch $(bin)/patch ! chmod 755 $(bin)/patch ! -cp patch.man $(mansrc)/patch.$(manext) ! ! uninstall: ! rm -f $(bin)/patch $(mansrc)/patch.$(manext) ! test ! -f $(bin)/patch.old || mv $(bin)/patch.old $(bin)/patch clean: *************** *** 93,97 **** dist: $(DISTFILES) ! echo patch-2.0.`sed -e '/PATCHLEVEL/!d' -e 's/[^0-9u.]*\([0-9u.]*\).*/\1/' -e q patchlevel.h` > .fname rm -rf `cat .fname` mkdir `cat .fname` --- 92,96 ---- dist: $(DISTFILES) ! echo patch-2.0.`sed -e '/PATCHLEVEL/!d' -e 's/[^0-9]*\([0-9a-z.]*\).*/\1/' -e q patchlevel.h` > .fname rm -rf `cat .fname` mkdir `cat .fname` diff -C2 -N patch-2.0.12u7/README patch-2.0.12u8/README *** patch-2.0.12u7/README Sat Jul 4 08:54:17 1992 --- patch-2.0.12u8/README Tue Sep 15 01:18:33 1992 *************** *** 3,11 **** support the unified context diff format that GNU diff can produce, and to support making GNU Emacs-style backup files. They also include ! fixes for some bugs. The FSF is distributing this version of patch ! independently because as of this writing, Larry Wall has not released ! a new version of patch since mid-1988. I have heard that he has been ! too busy working on other things, like Perl. Here is a wish list of some projects to improve patch: --- 3,21 ---- support the unified context diff format that GNU diff can produce, and to support making GNU Emacs-style backup files. They also include ! fixes for some bugs. + There are two GNU variants of patch: this one, which retains Larry + Wall's interactive Configure script and has patchlevels starting with + `12u'; and another one that has a GNU-style non-interactive configure + script and accepts long-named options, and has patchlevels starting + with `12g'. Unlike the 12g variant, the 12u variant contains no + copylefted code, for the paranoid. The two variants are otherwise the + same. They should be available from the same places. + + The FSF is distributing this version of patch independently because as + of this writing, Larry Wall has not released a new version of patch + since mid-1988. I have heard that he has been too busy working on + other things, like Perl. + Here is a wish list of some projects to improve patch: *************** *** 56,60 **** 2) Glance through config.h to make sure system dependencies are correct. ! Most of them should have been taken care of by running the Configure script. If you have any additional changes to make to the C definitions, they --- 66,71 ---- 2) Glance through config.h to make sure system dependencies are correct. ! Most of them should have been taken care of by running the ! Configure script. If you have any additional changes to make to the C definitions, they *************** *** 83,100 **** I've probably changed my copy since the version you have. ! Watch for patch patches in net.sources.bugs. Patches will generally be ! in a form usable by the patch program. If you are just now bringing up ! patch and aren't sure how many patches there are, write to me and I'll ! send any you don't have. Your current patch level is shown in patchlevel.h. ! ! ! NEW FEATURES IN THIS RELEASE ! ! (Correct) support for 4.3bsd-style context diffs. ! Files can be created from scratch. ! You can specify a fuzz-factor for context matching. ! You can force patch to ask no questions. ! You can specify how much of the leading pathname to strip off filenames. ! Uses a Configure script for greater portability. ! You are now asked if you want to apply a reversed patch. ! No limit (apart from memory) on the size of hunks. --- 94,98 ---- I've probably changed my copy since the version you have. ! Watch for patch patches in comp.sources.bugs. Patches will generally be ! in a form usable by the patch program. Your current patch level ! is shown in patchlevel.h. diff -C2 -N patch-2.0.12u7/backupfile.c patch-2.0.12u8/backupfile.c *** patch-2.0.12u7/backupfile.c Wed Apr 29 10:19:40 1992 --- patch-2.0.12u8/backupfile.c Wed Jul 8 18:48:29 1992 *************** *** 19,22 **** --- 19,23 ---- char *index (); char *rindex (); + char *malloc (); #ifdef DIRENT *************** *** 41,46 **** #endif /* !USG */ #endif /* !DIRENT */ - - char *malloc (); #ifndef isascii --- 42,45 ---- diff -C2 -N patch-2.0.12u7/backupfile.h patch-2.0.12u8/backupfile.h *** patch-2.0.12u7/backupfile.h Sat Mar 14 12:31:52 1992 --- patch-2.0.12u8/backupfile.h Wed Jul 8 18:49:27 1992 *************** *** 31,35 **** --- 31,37 ---- #ifdef __STDC__ char *find_backup_file_name (char *file); + enum backup_type get_version (char *version); #else char *find_backup_file_name (); + enum backup_type get_version (); #endif diff -C2 -N patch-2.0.12u7/common.h patch-2.0.12u8/common.h *** patch-2.0.12u7/common.h Fri Jul 3 23:48:36 1992 --- patch-2.0.12u8/common.h Tue Aug 25 22:29:31 1992 *************** *** 50,59 **** /* AIX predefines these. */ ! #ifndef TRUE ! #define TRUE (1) #endif ! #ifndef FALSE ! #define FALSE (0) #endif #define MAXHUNKSIZE 100000 /* is this enough lines? */ --- 50,61 ---- /* AIX predefines these. */ ! #ifdef TRUE ! #undef TRUE #endif ! #ifdef FALSE ! #undef FALSE #endif + #define TRUE (1) + #define FALSE (0) #define MAXHUNKSIZE 100000 /* is this enough lines? */ *************** *** 61,68 **** --- 63,74 ---- #define MAXLINELEN 1024 #define BUFFERSIZE 1024 + #define SCCSPREFIX "s." #define GET "get -e %s" + #define SCCSDIFF "get -p %s | diff - %s >/dev/null" + #define RCSSUFFIX ",v" #define CHECKOUT "co -l %s" + #define RCSDIFF "rcsdiff %s > /dev/null" #ifdef FLEXFILENAMES *************** *** 108,111 **** --- 114,119 ---- EXT FILE *rejfp INIT(Nullfp); /* reject file pointer */ + EXT int myuid; /* cache getuid return value */ + EXT bool using_plan_a INIT(TRUE); /* try to keep everything in memory */ EXT bool out_of_mem INIT(FALSE); /* ran out of memory in plan a */ *************** *** 135,138 **** --- 143,147 ---- EXT LINENUM maxfuzz INIT(2); EXT bool force INIT(FALSE); + EXT bool batch INIT(FALSE); EXT bool verbose INIT(TRUE); EXT bool reverse INIT(FALSE); *************** *** 157,168 **** EXT char *revision INIT(Nullch); /* prerequisite revision, if any */ char *malloc(); char *realloc(); char *strcpy(); char *strcat(); ! long atol(); long lseek(); char *mktemp(); ! #if 0 #ifdef CHARSPRINTF char *sprintf(); --- 166,185 ---- EXT char *revision INIT(Nullch); /* prerequisite revision, if any */ + #include + #ifndef errno + extern int errno; + #endif + + FILE *popen(); char *malloc(); char *realloc(); + long atol(); + char *getenv(); char *strcpy(); char *strcat(); ! char *rindex(); long lseek(); char *mktemp(); ! #if 0 /* This can cause a prototype conflict. */ #ifdef CHARSPRINTF char *sprintf(); *************** *** 171,175 **** #endif #endif - char *getenv(); #if !defined(S_ISDIR) && defined(S_IFDIR) --- 188,191 ---- diff -C2 -N patch-2.0.12u7/inp.c patch-2.0.12u8/inp.c *** patch-2.0.12u7/inp.c Mon Jul 6 13:05:31 1992 --- patch-2.0.12u8/inp.c Tue Aug 25 22:27:57 1992 *************** *** 77,85 **** char *filename; { ! int ifd; Reg1 char *s; Reg2 LINENUM iline; ! if (ok_to_create_file && stat(filename, &filestat) < 0) { if (verbose) say2("(Creating file %s...)\n",filename); --- 77,87 ---- char *filename; { ! int ifd, statfailed; Reg1 char *s; Reg2 LINENUM iline; + char lbuf[MAXLINELEN]; ! statfailed = stat(filename, &filestat); ! if (statfailed && ok_to_create_file) { if (verbose) say2("(Creating file %s...)\n",filename); *************** *** 86,113 **** makedirs(filename, TRUE); close(creat(filename, 0666)); } ! /* For read-only files, look for RCS or SCCS copies to check out. ! co or get will fail if someone else has already locked the file. */ ! if (stat(filename, &filestat) < 0 || access(filename, 2) < 0) { ! Sprintf(buf, "RCS/%s%s", filename, RCSSUFFIX); ! if (stat(buf, &filestat) >= 0 || stat(buf+4, &filestat) >= 0) { Sprintf(buf, CHECKOUT, filename); ! if (verbose) ! say2("Attempting to check out %s from RCS.\n", filename); ! if (system(buf) || stat(filename, &filestat)) ! fatal2("Can't check out %s.\n", filename); ! } ! else { ! Sprintf(buf+20, "SCCS/%s%s", SCCSPREFIX, filename); ! if (stat(s=buf+20, &filestat) >= 0 || ! stat(s=buf+25, &filestat) >= 0) { ! Sprintf(buf, GET, s); if (verbose) ! say2("Attempting to get %s from SCCS.\n", filename); ! if (system(buf) || stat(filename, &filestat)) ! fatal2("Can't get %s.\n", filename); } ! else if (stat(filename, &filestat) < 0) ! fatal2("Can't find %s.\n", filename); } } --- 88,147 ---- makedirs(filename, TRUE); close(creat(filename, 0666)); + statfailed = stat(filename, &filestat); } ! /* For nonexistent or read-only files, look for RCS or SCCS versions. */ ! if (statfailed ! /* No one can write to it. */ ! || (filestat.st_mode & 0222) == 0 ! /* I can't write to it. */ ! || ((filestat.st_mode & 0022) == 0 && filestat.st_uid != myuid)) { ! struct stat cstat; ! char *cs = Nullch; ! char *filebase; ! int pathlen; ! ! filebase = basename(filename); ! pathlen = filebase - filename; ! ! /* Put any leading path into `s'. ! Leave room in lbuf for the diff command. */ ! s = lbuf + 20; ! strncpy(s, filename, pathlen); ! ! #define try(f, a1, a2) (Sprintf(s + pathlen, f, a1, a2), stat(s, &cstat) == 0) ! if ( try("RCS/%s%s", filebase, RCSSUFFIX) ! || try("RCS/%s" , filebase, 0) ! || try( "%s%s", filebase, RCSSUFFIX)) { Sprintf(buf, CHECKOUT, filename); ! Sprintf(lbuf, RCSDIFF, filename); ! cs = "RCS"; ! } else if ( try("SCCS/%s%s", SCCSPREFIX, filebase) ! || try( "%s%s", SCCSPREFIX, filebase)) { ! Sprintf(buf, GET, s); ! Sprintf(lbuf, SCCSDIFF, s, filename); ! cs = "SCCS"; ! } else if (statfailed) ! fatal2("can't find %s\n", filename); ! /* else we can't write to it but it's not under a version ! control system, so just proceed. */ ! if (cs) { ! if (!statfailed) { ! if ((filestat.st_mode & 0222) != 0) ! /* The owner can write to it. */ ! fatal3("file %s seems to be locked by somebody else under %s\n", ! filename, cs); ! /* It might be checked out unlocked. See if it's safe to ! check out the default version locked. */ if (verbose) ! say3("Comparing file %s to default %s version...\n", ! filename, cs); ! if (system(lbuf)) ! fatal3("can't check out file %s: differs from default %s version\n", ! filename, cs); } ! if (verbose) ! say3("Checking out file %s from %s...\n", filename, cs); ! if (system(buf) || stat(filename, &filestat)) ! fatal3("can't check out file %s from %s\n", filename, cs); } } *************** *** 114,118 **** filemode = filestat.st_mode; if (!S_ISREG(filemode)) ! fatal2("%s is not a normal file--can't patch.\n", filename); i_size = filestat.st_size; if (out_of_mem) { --- 148,152 ---- filemode = filestat.st_mode; if (!S_ISREG(filemode)) ! fatal2("%s is not a normal file--can't patch\n", filename); i_size = filestat.st_size; if (out_of_mem) { *************** *** 130,134 **** return FALSE; if ((ifd = open(filename, 0)) < 0) ! fatal2("Can't open file %s\n", filename); #ifndef lint if (read(ifd, i_womp, (int)i_size) != i_size) { --- 164,168 ---- return FALSE; if ((ifd = open(filename, 0)) < 0) ! pfatal2("can't open file %s", filename); #ifndef lint if (read(ifd, i_womp, (int)i_size) != i_size) { *************** *** 180,183 **** --- 214,221 ---- revision); } + else if (batch) { + fatal2( + "this file doesn't appear to be the %s version--aborting.\n", revision); + } else { ask2( *************** *** 185,189 **** revision); if (*buf != 'y') ! fatal1("Aborted.\n"); } } --- 223,227 ---- revision); if (*buf != 'y') ! fatal1("aborted\n"); } } *************** *** 208,214 **** using_plan_a = FALSE; if ((ifp = fopen(filename, "r")) == Nullfp) ! fatal2("Can't open file %s\n", filename); if ((tifd = creat(TMPINNAME, 0666)) < 0) ! fatal2("Can't open file %s\n", TMPINNAME); while (fgets(buf, sizeof buf, ifp) != Nullch) { if (revision != Nullch && !found_revision && rev_in_string(buf)) --- 246,252 ---- using_plan_a = FALSE; if ((ifp = fopen(filename, "r")) == Nullfp) ! pfatal2("can't open file %s", filename); if ((tifd = creat(TMPINNAME, 0666)) < 0) ! pfatal2("can't open file %s", TMPINNAME); while (fgets(buf, sizeof buf, ifp) != Nullch) { if (revision != Nullch && !found_revision && rev_in_string(buf)) *************** *** 225,228 **** --- 263,270 ---- revision); } + else if (batch) { + fatal2( + "this file doesn't appear to be the %s version--aborting.\n", revision); + } else { ask2( *************** *** 230,234 **** revision); if (*buf != 'y') ! fatal1("Aborted.\n"); } } --- 272,276 ---- revision); if (*buf != 'y') ! fatal1("aborted\n"); } } *************** *** 243,251 **** tibuf[1] = malloc((MEM)(BUFFERSIZE + 1)); if (tibuf[1] == Nullch) ! fatal1("Can't seem to get enough memory.\n"); for (i=1; ; i++) { if (! (i % lines_per_buf)) /* new block */ if (write(tifd, tibuf[0], BUFFERSIZE) < BUFFERSIZE) ! fatal1("patch: can't write temp file.\n"); if (fgets(tibuf[0] + maxlen * (i%lines_per_buf), maxlen + 1, ifp) == Nullch) { --- 285,293 ---- tibuf[1] = malloc((MEM)(BUFFERSIZE + 1)); if (tibuf[1] == Nullch) ! fatal1("out of memory\n"); for (i=1; ; i++) { if (! (i % lines_per_buf)) /* new block */ if (write(tifd, tibuf[0], BUFFERSIZE) < BUFFERSIZE) ! pfatal1("can't write temp file"); if (fgets(tibuf[0] + maxlen * (i%lines_per_buf), maxlen + 1, ifp) == Nullch) { *************** *** 253,257 **** if (i % lines_per_buf) if (write(tifd, tibuf[0], BUFFERSIZE) < BUFFERSIZE) ! fatal1("patch: can't write temp file.\n"); break; } --- 295,299 ---- if (i % lines_per_buf) if (write(tifd, tibuf[0], BUFFERSIZE) < BUFFERSIZE) ! pfatal1("can't write temp file"); break; } *************** *** 260,264 **** Close(tifd); if ((tifd = open(TMPINNAME, 0)) < 0) { ! fatal2("Can't reopen file %s\n", TMPINNAME); } } --- 302,306 ---- Close(tifd); if ((tifd = open(TMPINNAME, 0)) < 0) { ! pfatal2("can't reopen file %s", TMPINNAME); } } *************** *** 289,293 **** #endif if (read(tifd, tibuf[whichbuf], BUFFERSIZE) < 0) ! fatal2("Error reading tmp file %s.\n", TMPINNAME); } return tibuf[whichbuf] + (tireclen*offline); --- 331,335 ---- #endif if (read(tifd, tibuf[whichbuf], BUFFERSIZE) < 0) ! pfatal2("error reading tmp file %s", TMPINNAME); } return tibuf[whichbuf] + (tireclen*offline); *************** *** 317,319 **** return FALSE; } - --- 359,360 ---- diff -C2 -N patch-2.0.12u7/patch.c patch-2.0.12u8/patch.c *** patch-2.0.12u7/patch.c Sat Jul 4 02:33:40 1992 --- patch-2.0.12u8/patch.c Tue Aug 25 22:30:28 1992 *************** *** 117,120 **** --- 117,123 ---- void my_exit(); + /* TRUE if -E was specified on command line. */ + static int remove_empty_files = FALSE; + /* TRUE if -R was specified on command line. */ static int reverse_flag_specified = FALSE; *************** *** 122,125 **** --- 125,129 ---- /* Apply a set of diffs as appropriate. */ + int main(argc,argv) int argc; *************** *** 139,142 **** --- 143,148 ---- filearg[i] = Nullch; + myuid = getuid(); + /* Cons up the names of the temporary files. */ { *************** *** 172,178 **** } - /* parse switches */ - Argc = argc; - Argv = argv; { char *v; --- 178,181 ---- *************** *** 188,191 **** --- 191,198 ---- #endif } + + /* parse switches */ + Argc = argc; + Argv = argv; get_some_switches(); *************** *** 202,209 **** outname = savestr(filearg[0]); - /* initialize the patched file */ - if (!skip_rest_of_patch) - init_output(TMPOUTNAME); - /* for ed script just up and do it and exit */ if (diff_type == ED_DIFF) { --- 209,212 ---- *************** *** 212,215 **** --- 215,222 ---- } + /* initialize the patched file */ + if (!skip_rest_of_patch) + init_output(TMPOUTNAME); + /* initialize reject file */ init_reject(TMPREJNAME); *************** *** 247,251 **** if (where == Nulline) { /* didn't find it swapped */ if (!pch_swap()) /* put it back to normal */ ! fatal1("Lost hunk on alloc error!\n"); reverse = !reverse; } --- 254,258 ---- if (where == Nulline) { /* didn't find it swapped */ if (!pch_swap()) /* put it back to normal */ ! fatal1("lost hunk on alloc error!\n"); reverse = !reverse; } *************** *** 252,256 **** else if (noreverse) { if (!pch_swap()) /* put it back to normal */ ! fatal1("Lost hunk on alloc error!\n"); reverse = !reverse; say1( --- 259,263 ---- else if (noreverse) { if (!pch_swap()) /* put it back to normal */ ! fatal1("lost hunk on alloc error!\n"); reverse = !reverse; say1( *************** *** 258,261 **** --- 265,275 ---- skip_rest_of_patch = TRUE; } + else if (batch) { + if (verbose) + say3( + "%seversed (or previously applied) patch detected! %s -R.", + reverse ? "R" : "Unr", + reverse ? "Assuming" : "Ignoring"); + } else { ask3( *************** *** 270,274 **** reverse = !reverse; if (!pch_swap()) /* put it back to normal */ ! fatal1("Lost hunk on alloc error!\n"); } } --- 284,288 ---- reverse = !reverse; if (!pch_swap()) /* put it back to normal */ ! fatal1("lost hunk on alloc error!\n"); } } *************** *** 314,317 **** --- 328,337 ---- Argv = Argv_last; say1("\n\nRan out of memory using Plan A--trying again...\n\n"); + if (ofp) + Fclose(ofp); + ofp = Nullfp; + if (rejfp) + Fclose(rejfp); + rejfp = Nullfp; continue; } *************** *** 337,341 **** chmod(outname, filemode); ! if (stat(realout, &statbuf) >= 0 && statbuf.st_size == 0) { if (verbose) say2("Removing %s (empty after patching).\n", realout); --- 357,362 ---- chmod(outname, filemode); ! if (remove_empty_files && stat(realout, &statbuf) == 0 ! && statbuf.st_size == 0) { if (verbose) say2("Removing %s (empty after patching).\n", realout); *************** *** 351,355 **** #ifndef FLEXFILENAMES { - char *rindex(); char *s = rindex(rejname,'/'); --- 372,375 ---- *************** *** 417,421 **** if (filec >= 2) ! fatal1("You may not change to a different patch file.\n"); } --- 437,441 ---- if (filec >= 2) ! fatal1("you may not change to a different patch file\n"); } *************** *** 424,428 **** { if (!--Argc) ! fatal2("patch: missing argument after `%s'\n", *Argv); return *++Argv; } --- 444,448 ---- { if (!--Argc) ! fatal2("missing argument after `%s'\n", *Argv); return *++Argv; } *************** *** 447,451 **** if (*s != '-' || !s[1]) { if (filec == MAXFILEC) ! fatal1("patch: Too many file arguments.\n"); filearg[filec++] = savestr(s); } --- 467,471 ---- if (*s != '-' || !s[1]) { if (filec == MAXFILEC) ! fatal1("too many file arguments\n"); filearg[filec++] = savestr(s); } *************** *** 465,469 **** s = nextarg(); if (chdir(s) < 0) ! fatal2("Can't cd to %s.\n", s); break; case 'D': --- 485,489 ---- s = nextarg(); if (chdir(s) < 0) ! pfatal2("can't cd to %s", s); break; case 'D': *************** *** 472,476 **** s = nextarg(); if (!isalpha(*s) && '_' != *s) ! fatal1("Argument to -D not an identifier.\n"); Sprintf(if_defined, "#ifdef %s\n", s); Sprintf(not_defined, "#ifndef %s\n", s); --- 492,496 ---- s = nextarg(); if (!isalpha(*s) && '_' != *s) ! fatal1("argument to -D is not an identifier\n"); Sprintf(if_defined, "#ifdef %s\n", s); Sprintf(not_defined, "#ifndef %s\n", s); *************** *** 480,483 **** --- 500,506 ---- diff_type = ED_DIFF; break; + case 'E': + remove_empty_files = TRUE; + break; case 'f': force = TRUE; *************** *** 518,521 **** --- 541,547 ---- skip_rest_of_patch = TRUE; break; + case 't': + batch = TRUE; + break; case 'u': diff_type = UNI_DIFF; *************** *** 537,544 **** fprintf(stderr, "patch: unrecognized option `%s'\n", Argv[0]); fprintf(stderr, "\ ! Usage: patch [-ceflnNRsSuv] [-b backup-ext] [-B backup-prefix] [-d directory]\n\ [-D symbol] [-Fmax-fuzz] [-o out-file] [-p[strip-count]]\n\ ! [-r rej-name] [-V {numbered,existing,simple}] [origfile] [patchfile]\n\ ! [[+] [options] [origfile]...]\n"); my_exit(1); } --- 563,571 ---- fprintf(stderr, "patch: unrecognized option `%s'\n", Argv[0]); fprintf(stderr, "\ ! Usage: patch [options] [origfile [patchfile]] [+ [options] [origfile]]...\n\ ! Options:\n\ ! [-ceEflnNRsStuv] [-b backup-ext] [-B backup-prefix] [-d directory]\n\ [-D symbol] [-Fmax-fuzz] [-o out-file] [-p[strip-count]]\n\ ! [-r rej-name] [-V {numbered,existing,simple}]\n"); my_exit(1); } *************** *** 633,638 **** break; default: ! say1("Fatal internal error in abort_hunk().\n"); ! abort(); } } --- 660,664 ---- break; default: ! fatal1("fatal internal error in abort_hunk\n"); } } *************** *** 767,771 **** ofp = fopen(name, "w"); if (ofp == Nullfp) ! fatal2("patch: can't create %s.\n", name); } --- 793,797 ---- ofp = fopen(name, "w"); if (ofp == Nullfp) ! pfatal2("can't create %s", name); } *************** *** 778,782 **** rejfp = fopen(name, "w"); if (rejfp == Nullfp) ! fatal2("patch: can't create %s.\n", name); } --- 804,808 ---- rejfp = fopen(name, "w"); if (rejfp == Nullfp) ! pfatal2("can't create %s", name); } *************** *** 790,794 **** if (R_last_frozen_line > lastline) ! fatal1("patch: misordered hunks! output will be garbled.\n"); while (R_last_frozen_line < lastline) { dump_line(++R_last_frozen_line); --- 816,820 ---- if (R_last_frozen_line > lastline) ! fatal1("misordered hunks! output would be garbled\n"); while (R_last_frozen_line < lastline) { dump_line(++R_last_frozen_line); diff -C2 -N patch-2.0.12u7/patch.man patch-2.0.12u8/patch.man *** patch-2.0.12u7/patch.man Sat Jul 4 04:47:57 1992 --- patch-2.0.12u8/patch.man Tue Aug 25 22:32:41 1992 *************** *** 1,38 **** .\" -*- nroff -*- .rn '' }` ! ''' $Header: patch.man,v 2.0.1.2 88/06/22 20:47:18 lwall Locked $ ! ''' ! ''' $Log: patch.man,v $ ! ''' Revision 2.0.1.2 88/06/22 20:47:18 lwall ! ''' patch12: now avoids Bell System Logo ! ''' ! ''' Revision 2.0.1.1 88/06/03 15:12:51 lwall ! ''' patch10: -B switch was contributed. ! ''' ! ''' Revision 2.0 86/09/17 15:39:09 lwall ! ''' Baseline for netwide release. ! ''' ! ''' Revision 1.4 86/08/01 19:23:22 lwall ! ''' Documented -v, -p, -F. ! ''' Added notes to patch senders. ! ''' ! ''' Revision 1.3 85/03/26 15:11:06 lwall ! ''' Frozen. ! ''' ! ''' Revision 1.2.1.4 85/03/12 16:14:27 lwall ! ''' Documented -p. ! ''' ! ''' Revision 1.2.1.3 85/03/12 16:09:41 lwall ! ''' Documented -D. ! ''' ! ''' Revision 1.2.1.2 84/12/05 11:06:55 lwall ! ''' Added -l switch, and noted bistability bug. ! ''' ! ''' Revision 1.2.1.1 84/12/04 17:23:39 lwall ! ''' Branch for sdcrdcf changes. ! ''' ! ''' Revision 1.2 84/12/04 17:22:02 lwall ! ''' Baseline version. ! ''' .de Sh .br --- 1,38 ---- .\" -*- nroff -*- .rn '' }` ! '\" $Header: patch.man,v 2.0.1.2 88/06/22 20:47:18 lwall Locked $ ! '\" ! '\" $Log: patch.man,v $ ! '\" Revision 2.0.1.2 88/06/22 20:47:18 lwall ! '\" patch12: now avoids Bell System Logo ! '\" ! '\" Revision 2.0.1.1 88/06/03 15:12:51 lwall ! '\" patch10: -B switch was contributed. ! '\" ! '\" Revision 2.0 86/09/17 15:39:09 lwall ! '\" Baseline for netwide release. ! '\" ! '\" Revision 1.4 86/08/01 19:23:22 lwall ! '\" Documented -v, -p, -F. ! '\" Added notes to patch senders. ! '\" ! '\" Revision 1.3 85/03/26 15:11:06 lwall ! '\" Frozen. ! '\" ! '\" Revision 1.2.1.4 85/03/12 16:14:27 lwall ! '\" Documented -p. ! '\" ! '\" Revision 1.2.1.3 85/03/12 16:09:41 lwall ! '\" Documented -D. ! '\" ! '\" Revision 1.2.1.2 84/12/05 11:06:55 lwall ! '\" Added -l switch, and noted bistability bug. ! '\" ! '\" Revision 1.2.1.1 84/12/04 17:23:39 lwall ! '\" Branch for sdcrdcf changes. ! '\" ! '\" Revision 1.2 84/12/04 17:22:02 lwall ! '\" Baseline version. ! '\" .de Sh .br *************** *** 46,54 **** .if n .sp .. ! ''' ! ''' Set up \*(-- to give an unbreakable dash; ! ''' string Tr holds user defined translation string. ! ''' Bell System Logo is used as a dummy character. ! ''' .ie n \{\ .tr \(*W-\*(Tr --- 46,56 ---- .if n .sp .. ! '\" ! '\" Set up \*(-- to give an unbreakable dash; ! '\" string Tr holds user defined translation string. ! '\" Bell System Logo is used as a dummy character. ! '\" ! '\" Shut up a groff -ww warning. ! .if \n(.g .if !dTr .ds Tr .ie n \{\ .tr \(*W-\*(Tr *************** *** 71,78 **** .TH PATCH 1 LOCAL .SH NAME ! patch - a program for applying a diff file to an original .SH SYNOPSIS .B patch ! [options] orig patchfile [+ [options] orig] .sp but usually just --- 73,80 ---- .TH PATCH 1 LOCAL .SH NAME ! patch - apply a diff file to an original .SH SYNOPSIS .B patch ! [options] [origfile [patchfile]] [+ [options] [origfile]]... .sp but usually just *************** *** 108,114 **** backup file that does not already exist. .PP - .I patch - removes output files that are empty after being patched. - .PP You may also specify where you want the output to go with a .B -o --- 110,113 ---- *************** *** 274,277 **** --- 273,281 ---- to interpret the patch file as an ed script. .TP 5 + .B \-E + causes + .I patch + to remove output files that are empty after the patches have been applied. + .TP 5 .B \-f forces *************** *** 278,286 **** .I patch to assume that the user knows exactly what he or she is doing, and to not ! ask any questions. ! It does not suppress commentary, however. ! Use .B \-s for that. .TP 5 .B \-F --- 282,301 ---- .I patch to assume that the user knows exactly what he or she is doing, and to not ! ask any questions. It assumes the following: skip patches for which a ! file to patch can't be found; patch files even though they have the ! wrong version for the ``Prereq:'' line in the patch; and assume that ! patches are not reversed even if they look like they are. ! This option does not suppress commentary; use .B \-s for that. + .TP 5 + .B \-t + similar to + .BR \-f , + in that it suppresses questions, but makes some different assumptions: + skip patches for which a file to patch can't be found (the same as \fB\-f\fP); + skip patches for which the file has the wrong version for the ``Prereq:'' line + in the patch; and assume that patches are reversed if they look like + they are. .TP 5 .B \-F diff -C2 -N patch-2.0.12u7/pch.c patch-2.0.12u8/pch.c *** patch-2.0.12u7/pch.c Tue Dec 3 11:27:06 1991 --- patch-2.0.12u8/pch.c Tue Aug 25 22:28:23 1992 *************** *** 86,90 **** pfp = fopen(TMPPATNAME, "w"); if (pfp == Nullfp) ! fatal2("patch: can't create %s.\n", TMPPATNAME); while (fgets(buf, sizeof buf, stdin) != Nullch) fputs(buf, pfp); --- 86,90 ---- pfp = fopen(TMPPATNAME, "w"); if (pfp == Nullfp) ! pfatal2("can't create %s", TMPPATNAME); while (fgets(buf, sizeof buf, stdin) != Nullch) fputs(buf, pfp); *************** *** 94,98 **** pfp = fopen(filename, "r"); if (pfp == Nullfp) ! fatal2("patch file %s not found\n", filename); Fstat(fileno(pfp), &filestat); p_filesize = filestat.st_size; --- 94,98 ---- pfp = fopen(filename, "r"); if (pfp == Nullfp) ! pfatal2("patch file %s not found", filename); Fstat(fileno(pfp), &filestat); p_filesize = filestat.st_size; *************** *** 136,140 **** return; if (!using_plan_a) ! fatal1("patch: out of memory (grow_hunkmax)\n"); out_of_mem = TRUE; /* whatever is null will be allocated again */ /* from within plan_a(), of all places */ --- 136,140 ---- return; if (!using_plan_a) ! fatal1("out of memory\n"); out_of_mem = TRUE; /* whatever is null will be allocated again */ /* from within plan_a(), of all places */ *************** *** 175,179 **** skip_to(p_start,p_sline); while (filearg[0] == Nullch) { ! if (force) { say1("No file to patch. Skipping...\n"); filearg[0] = savestr(bestguess); --- 175,179 ---- skip_to(p_start,p_sline); while (filearg[0] == Nullch) { ! if (force || batch) { say1("No file to patch. Skipping...\n"); filearg[0] = savestr(bestguess); *************** *** 427,431 **** malformed () { ! fatal3("Malformed patch at line %ld: %s", p_input_line, buf); /* about as informative as "Syntax error" in C */ } --- 427,431 ---- malformed () { ! fatal3("malformed patch at line %ld: %s", p_input_line, buf); /* about as informative as "Syntax error" in C */ } *************** *** 488,492 **** goto hunk_done; } ! fatal1("Unexpected end of file in patch.\n"); } } --- 488,492 ---- goto hunk_done; } ! fatal1("unexpected end of file in patch\n"); } } *************** *** 507,511 **** } else ! fatal2("Unexpected end of hunk at line %ld.\n", p_input_line); } --- 507,511 ---- } else ! fatal2("unexpected end of hunk at line %ld\n", p_input_line); } *************** *** 515,519 **** goto hunk_done; } ! fatal3("Unexpected *** at line %ld: %s", p_input_line, buf); } context = 0; --- 515,519 ---- goto hunk_done; } ! fatal3("unexpected *** at line %ld: %s", p_input_line, buf); } context = 0; *************** *** 567,571 **** } fatal3( ! "Duplicate \"---\" at line %ld--check line numbers at line %ld.\n", p_input_line, p_hunk_beg + repl_beginning); } --- 567,571 ---- } fatal3( ! "duplicate \"---\" at line %ld--check line numbers at line %ld\n", p_input_line, p_hunk_beg + repl_beginning); } *************** *** 572,576 **** else { fatal4( ! "%s \"---\" at line %ld--check line numbers at line %ld.\n", (p_end <= p_ptrn_lines ? "Premature" --- 572,576 ---- else { fatal4( ! "%s \"---\" at line %ld--check line numbers at line %ld\n", (p_end <= p_ptrn_lines ? "Premature" *************** *** 608,612 **** p_max = p_repl_lines + p_end; if (p_max > MAXHUNKSIZE) ! fatal4("Hunk too large (%ld lines) at line %ld: %s", p_max, p_input_line, buf); while (p_max >= hunkmax) --- 608,612 ---- p_max = p_repl_lines + p_end; if (p_max > MAXHUNKSIZE) ! fatal4("hunk too large (%ld lines) at line %ld: %s", p_max, p_input_line, buf); while (p_max >= hunkmax) *************** *** 690,694 **** hunk_done: if (p_end >=0 && !repl_beginning) ! fatal2("No --- found in patch at line %ld\n", pch_hunk_beg()); if (repl_missing) { --- 690,694 ---- hunk_done: if (p_end >=0 && !repl_beginning) ! fatal2("no --- found in patch at line %ld\n", pch_hunk_beg()); if (repl_missing) { *************** *** 720,724 **** filldst++; } ! /* repl_beginning--; /* this doesn't need to be fixed */ p_end--; p_first++; /* do append rather than insert */ --- 720,726 ---- filldst++; } ! #if 0 ! repl_beginning--; /* this doesn't need to be fixed */ ! #endif p_end--; p_first++; /* do append rather than insert */ *************** *** 745,749 **** fillsrc++; if (fillsrc > p_end) ! fatal2("Replacement text or line numbers mangled in hunk at line %ld\n", p_hunk_beg); p_line[filldst] = p_line[fillsrc]; --- 747,751 ---- fillsrc++; if (fillsrc > p_end) ! fatal2("replacement text or line numbers mangled in hunk at line %ld\n", p_hunk_beg); p_line[filldst] = p_line[fillsrc]; *************** *** 833,837 **** Strcpy(buf, " \n"); /* assume blank lines got chopped */ else { ! fatal1("Unexpected end of file in patch.\n"); } } --- 835,839 ---- Strcpy(buf, " \n"); /* assume blank lines got chopped */ else { ! fatal1("unexpected end of file in patch\n"); } } *************** *** 941,945 **** p_end = p_ptrn_lines + 1 + max - min + 1; if (p_end > MAXHUNKSIZE) ! fatal4("Hunk too large (%ld lines) at line %ld: %s", p_end, p_input_line, buf); while (p_end >= hunkmax) --- 943,947 ---- p_end = p_ptrn_lines + 1 + max - min + 1; if (p_end > MAXHUNKSIZE) ! fatal4("hunk too large (%ld lines) at line %ld: %s", p_end, p_input_line, buf); while (p_end >= hunkmax) *************** *** 958,965 **** p_input_line++; if (ret == Nullch) ! fatal2("Unexpected end of file in patch at line %ld.\n", p_input_line); if (*buf != '<') ! fatal2("< expected at line %ld of patch.\n", p_input_line); p_line[i] = savestr(buf+2); if (out_of_mem) { --- 960,967 ---- p_input_line++; if (ret == Nullch) ! fatal2("unexpected end of file in patch at line %ld\n", p_input_line); if (*buf != '<') ! fatal2("< expected at line %ld of patch\n", p_input_line); p_line[i] = savestr(buf+2); if (out_of_mem) { *************** *** 974,981 **** p_input_line++; if (ret == Nullch) ! fatal2("Unexpected end of file in patch at line %ld.\n", p_input_line); if (*buf != '-') ! fatal2("--- expected at line %ld of patch.\n", p_input_line); } Sprintf(buf, "--- %ld,%ld\n", min, max); --- 976,983 ---- p_input_line++; if (ret == Nullch) ! fatal2("unexpected end of file in patch at line %ld\n", p_input_line); if (*buf != '-') ! fatal2("--- expected at line %ld of patch\n", p_input_line); } Sprintf(buf, "--- %ld,%ld\n", min, max); *************** *** 990,997 **** p_input_line++; if (ret == Nullch) ! fatal2("Unexpected end of file in patch at line %ld.\n", p_input_line); if (*buf != '>') ! fatal2("> expected at line %ld of patch.\n", p_input_line); p_line[i] = savestr(buf+2); if (out_of_mem) { --- 992,999 ---- p_input_line++; if (ret == Nullch) ! fatal2("unexpected end of file in patch at line %ld\n", p_input_line); if (*buf != '>') ! fatal2("> expected at line %ld of patch\n", p_input_line); p_line[i] = savestr(buf+2); if (out_of_mem) { *************** *** 1249,1253 **** Reg3 bool this_line_is_command = FALSE; Reg4 FILE *pipefp; - FILE *popen(); if (!skip_rest_of_patch) { --- 1251,1254 ---- diff -C2 -N patch-2.0.12u7/util.c patch-2.0.12u8/util.c *** patch-2.0.12u7/util.c Mon Jul 6 15:25:27 1992 --- patch-2.0.12u8/util.c Mon Sep 14 22:04:46 1992 *************** *** 5,8 **** --- 5,23 ---- #include "backupfile.h" + void my_exit(); + + static char * + private_strerror (errnum) + int errnum; + { + extern char *sys_errlist[]; + extern int sys_nerr; + + if (errnum > 0 && errnum <= sys_nerr) + return sys_errlist[errnum]; + return "Unknown system error"; + } + #define strerror private_strerror + /* Rename a file, copying it if necessary. */ *************** *** 25,32 **** fromfd = open(from, 0); if (fromfd < 0) ! fatal2("patch: internal error, can't reopen %s\n", from); while ((i=read(fromfd, buf, sizeof buf)) > 0) if (write(1, buf, i) != 1) ! fatal1("patch: write failed\n"); Close(fromfd); return 0; --- 40,47 ---- fromfd = open(from, 0); if (fromfd < 0) ! pfatal2("internal error, can't reopen %s", from); while ((i=read(fromfd, buf, sizeof buf)) > 0) if (write(1, buf, i) != 1) ! pfatal1("write failed"); Close(fromfd); return 0; *************** *** 40,44 **** char *backupname = find_backup_file_name(to); if (backupname == (char *) 0) ! fatal1("Can't seem to get enough memory.\n"); Strcpy(bakname, backupname); free(backupname); --- 55,59 ---- char *backupname = find_backup_file_name(to); if (backupname == (char *) 0) ! fatal1("out of memory\n"); Strcpy(bakname, backupname); free(backupname); *************** *** 49,53 **** } ! if (stat(to, &filestat) >= 0) { /* output file exists */ dev_t to_device = filestat.st_dev; ino_t to_inode = filestat.st_ino; --- 64,68 ---- } ! if (stat(to, &filestat) == 0) { /* output file exists */ dev_t to_device = filestat.st_dev; ino_t to_inode = filestat.st_ino; *************** *** 61,65 **** Change the first lowercase char into uppercase; if that isn't sufficient, chop off the first char and try again. */ ! while (stat(bakname, &filestat) >= 0 && to_device == filestat.st_dev && to_inode == filestat.st_ino) { /* Skip initial non-lowercase chars. */ --- 76,80 ---- Change the first lowercase char into uppercase; if that isn't sufficient, chop off the first char and try again. */ ! while (stat(bakname, &filestat) == 0 && to_device == filestat.st_dev && to_inode == filestat.st_ino) { /* Skip initial non-lowercase chars. */ *************** *** 84,88 **** bakfd = creat(bakname, 0666); if (bakfd < 0) { ! say3("patch: can't backup %s, output is in %s.\n", to, from); return -1; } --- 99,104 ---- bakfd = creat(bakname, 0666); if (bakfd < 0) { ! say4("Can't backup %s, output is in %s: %s\n", to, from, ! strerror(errno)); return -1; } *************** *** 89,96 **** tofd = open(to, 0); if (tofd < 0) ! fatal2("patch: internal error, can't open %s\n", to); while ((i=read(tofd, buf, sizeof buf)) > 0) if (write(bakfd, buf, i) != i) ! fatal1("patch: write failed\n"); Close(tofd); Close(bakfd); --- 105,112 ---- tofd = open(to, 0); if (tofd < 0) ! pfatal2("internal error, can't open %s", to); while ((i=read(tofd, buf, sizeof buf)) > 0) if (write(bakfd, buf, i) != i) ! pfatal1("write failed"); Close(tofd); Close(bakfd); *************** *** 107,112 **** tofd = creat(to, 0666); if (tofd < 0) { ! say3("patch: can't create %s, output is in %s.\n", ! to, from); return -1; } --- 123,128 ---- tofd = creat(to, 0666); if (tofd < 0) { ! say4("Can't create %s, output is in %s: %s\n", ! to, from, strerror(errno)); return -1; } *************** *** 113,120 **** fromfd = open(from, 0); if (fromfd < 0) ! fatal2("patch: internal error, can't reopen %s\n", from); while ((i=read(fromfd, buf, sizeof buf)) > 0) if (write(tofd, buf, i) != i) ! fatal1("patch: write failed\n"); Close(fromfd); Close(tofd); --- 129,136 ---- fromfd = open(from, 0); if (fromfd < 0) ! pfatal2("internal error, can't reopen %s", from); while ((i=read(fromfd, buf, sizeof buf)) > 0) if (write(tofd, buf, i) != i) ! pfatal1("write failed"); Close(fromfd); Close(tofd); *************** *** 136,146 **** tofd = creat(to, 0666); if (tofd < 0) ! fatal2("patch: can't create %s.\n", to); fromfd = open(from, 0); if (fromfd < 0) ! fatal2("patch: internal error, can't reopen %s\n", from); while ((i=read(fromfd, buf, sizeof buf)) > 0) if (write(tofd, buf, i) != i) ! fatal2("patch: write (%s) failed\n", to); Close(fromfd); Close(tofd); --- 152,162 ---- tofd = creat(to, 0666); if (tofd < 0) ! pfatal2("can't create %s", to); fromfd = open(from, 0); if (fromfd < 0) ! pfatal2("internal error, can't reopen %s", from); while ((i=read(fromfd, buf, sizeof buf)) > 0) if (write(tofd, buf, i) != i) ! pfatal2("write to %s failed", to); Close(fromfd); Close(tofd); *************** *** 165,169 **** out_of_mem = TRUE; else ! fatal1("patch: out of memory (savestr)\n"); } else { --- 181,185 ---- out_of_mem = TRUE; else ! fatal1("out of memory\n"); } else { *************** *** 181,184 **** --- 197,202 ---- fatal(pat) char *pat; { ; } /*VARARGS ARGSUSED*/ + pfatal(pat) char *pat; { ; } + /*VARARGS ARGSUSED*/ ask(pat) char *pat; { ; } *************** *** 203,209 **** long arg1,arg2,arg3; { ! void my_exit(); ! say(pat, arg1, arg2, arg3); my_exit(1); } --- 221,241 ---- long arg1,arg2,arg3; { ! fprintf(stderr, "patch: **** "); ! fprintf(stderr, pat, arg1, arg2, arg3); ! my_exit(1); ! } ! ! /* Say something from patch, something from the system, then silence . . . */ ! ! void /* very void */ ! pfatal(pat,arg1,arg2,arg3) ! char *pat; ! long arg1,arg2,arg3; ! { ! int errnum = errno; ! fprintf(stderr, "patch: **** "); ! fprintf(stderr, pat, arg1, arg2, arg3); ! fprintf(stderr, ": %s\n", strerror(errnum)); my_exit(1); } *************** *** 261,265 **** int reset; { - void my_exit(); #ifndef lint #ifdef VOIDSIG --- 293,296 ---- *************** *** 301,305 **** } ! /* Make sure we'll have the directories to create a file. */ void --- 332,337 ---- } ! /* Make sure we'll have the directories to create a file. ! If `striplast' is TRUE, ignore the last element of `filename'. */ void *************** *** 310,317 **** char tmpbuf[256]; Reg2 char *s = tmpbuf; ! char *dirv[20]; Reg3 int i; ! Reg4 int dirvp = 0; while (*filename) { if (*filename == '/') { --- 342,351 ---- char tmpbuf[256]; Reg2 char *s = tmpbuf; ! char *dirv[20]; /* Point to the NULs between elements. */ Reg3 int i; ! Reg4 int dirvp = 0; /* Number of finished entries in dirv. */ + /* Copy `filename' into `tmpbuf' with a NUL instead of a slash + between the directories. */ while (*filename) { if (*filename == '/') { *************** *** 330,342 **** if (dirvp < 0) return; strcpy(buf, "mkdir"); s = buf; for (i=0; i<=dirvp; i++) { ! while (*s) s++; ! *s++ = ' '; ! strcpy(s, tmpbuf); *dirv[i] = '/'; } ! system(buf); } --- 364,382 ---- if (dirvp < 0) return; + strcpy(buf, "mkdir"); s = buf; for (i=0; i<=dirvp; i++) { ! struct stat sbuf; ! ! if (stat(tmpbuf, &sbuf) && errno == ENOENT) { ! while (*s) s++; ! *s++ = ' '; ! strcpy(s, tmpbuf); ! } *dirv[i] = '/'; } ! if (s != buf) ! system(buf); } *************** *** 380,384 **** if (strip_leading == 957 && name != fullname && *fullname != '/') { name[-1] = '\0'; ! if (stat(fullname, &filestat) >= 0 && S_ISDIR (filestat.st_mode)) { name[-1] = '/'; name=fullname; --- 420,424 ---- if (strip_leading == 957 && name != fullname && *fullname != '/') { name[-1] = '\0'; ! if (stat(fullname, &filestat) == 0 && S_ISDIR (filestat.st_mode)) { name[-1] = '/'; name=fullname; *************** *** 389,402 **** free(fullname); ! if (stat(name, &filestat) < 0 && !assume_exists) { ! Sprintf(tmpbuf, "RCS/%s%s", name, RCSSUFFIX); ! if (stat(tmpbuf, &filestat) < 0 && stat(tmpbuf+4, &filestat) < 0) { ! Sprintf(tmpbuf, "SCCS/%s%s", SCCSPREFIX, name); ! if (stat(tmpbuf, &filestat) < 0 && stat(tmpbuf+5, &filestat) < 0) { ! free(name); ! name = Nullch; ! } ! } } return name; } --- 429,450 ---- free(fullname); ! if (stat(name, &filestat) && !assume_exists) { ! char *filebase = basename(name); ! int pathlen = filebase - name; ! ! /* Put any leading path into `tmpbuf'. */ ! strncpy(tmpbuf, name, pathlen); ! ! #define try(f, a1, a2) (Sprintf(tmpbuf + pathlen, f, a1, a2), stat(tmpbuf, &filestat) == 0) ! if ( try("RCS/%s%s", filebase, RCSSUFFIX) ! || try("RCS/%s" , filebase, 0) ! || try( "%s%s", filebase, RCSSUFFIX) ! || try("SCCS/%s%s", SCCSPREFIX, filebase) ! || try( "%s%s", SCCSPREFIX, filebase)) ! return name; ! free(name); ! name = Nullch; } + return name; } diff -C2 -N patch-2.0.12u7/util.h patch-2.0.12u8/util.h *** patch-2.0.12u7/util.h Wed Aug 15 01:13:39 1990 --- patch-2.0.12u8/util.h Mon Jul 20 14:20:24 1992 *************** *** 23,26 **** --- 23,30 ---- #define fatal3 fatal #define fatal4 fatal + #define pfatal1 pfatal + #define pfatal2 pfatal + #define pfatal3 pfatal + #define pfatal4 pfatal #else /* hope they allow multi-line macro actual arguments */ *************** *** 40,43 **** --- 44,51 ---- #define fatal3(a,b,c) fatal(a, (b)==(b), (c)==(c), 0) #define fatal4(a,b,c,d) fatal(a, (b)==(b), (c)==(c), (d)==(d)) + #define pfatal1(a) pfatal(a, 0, 0, 0) + #define pfatal2(a,b) pfatal(a, (b)==(b), 0, 0) + #define pfatal3(a,b,c) pfatal(a, (b)==(b), (c)==(c), 0) + #define pfatal4(a,b,c,d) pfatal(a, (b)==(b), (c)==(c), (d)==(d)) #else /* lint */ *************** *** 55,58 **** --- 63,70 ---- #define fatal3(a,b,c) fatal(a, b, c, Nullch) #define fatal4 fatal + #define pfatal1(a) pfatal(a, Nullch, Nullch, Nullch) + #define pfatal2(a,b) pfatal(a, b, Nullch, Nullch) + #define pfatal3(a,b,c) pfatal(a, b, c, Nullch) + #define pfatal4 pfatal #endif /* lint */ *************** *** 68,71 **** --- 80,84 ---- void say(); void fatal(); + void pfatal(); void ask(); char *savestr(); *************** *** 73,74 **** --- 86,88 ---- void ignore_signals(); void makedirs(); + char *basename(); diff -C2 -N patch-2.0.12u7/version.c patch-2.0.12u8/version.c *** patch-2.0.12u7/version.c Sat Mar 14 14:44:29 1992 --- patch-2.0.12u8/version.c Wed Jul 8 19:17:26 1992 *************** *** 14,17 **** --- 14,19 ---- #include "version.h" + void my_exit(); + /* Print out the version number and die. */ *************** *** 19,30 **** version() { ! void my_exit(); ! extern char rcsid[]; ! ! #ifdef lint ! rcsid[0] = rcsid[0]; ! #else ! fprintf(stderr, "%s\nPatch level: %s\n", rcsid, PATCHLEVEL); my_exit(0); - #endif } --- 21,25 ---- version() { ! fprintf(stderr, "Patch version 2.0, patch level %s\n", PATCHLEVEL); my_exit(0); }