🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sources.bugs
Article #345

REPOST: patch 12u8 to patch, part 01 of 02

#345
From: David J. MacKenzie
Date: Tue, 15 Sep 1992 20:07
1079 lines
33165 bytes
Apparently there was some corruption the first time.
Trying again:

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 <<EOSS >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 <<EOSS >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 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 <errno.h>
+ #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);
Technical Details
Message-ID: <DJM.92Sep15160709@nutrimat.gnu.ai.mit.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!snorkelwacker.mit.edu!ai-lab!life!djm

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!snorkelwacker.mit.edu!ai-lab!life!djm
From: djm@gnu.ai.mit.edu (David J. MacKenzie)
Newsgroups: comp.sources.bugs
Subject: REPOST: patch 12u8 to patch, part 01 of 02
Message-ID: <DJM.92Sep15160709@nutrimat.gnu.ai.mit.edu>
Date: 15 Sep 92 20:07:09 GMT
Sender: news@ai.mit.edu
Organization: Free Software Foundation
Lines: 1079