[comp.sources.bugs] Bug in patch?

lichter@maui.cs.ucla.edu (Michael Lichter) (12/11/89)

I'm running patch (patchlevel 12):

	% patch -v
	$Header: patch.c,v 2.0.1.6 88/06/22 20:46:39 lwall Locked $
	Patch level: 12

I'm having a problem with the "-D" option.  According to the man page,
the "-D"  option "causes patch to use the "#ifdef...#endif" construct
to mark changes.  The argument following will be used as the
differentiating symbol."

I pared my problems down to the following two examples.  

I have a file with one line in it, and some diffs that bracket that line
between a couple of new lines:

	% cat x
	This is the original line
	% cat x.diffs
	*** x.old	Mon Dec 11 06:02:04 1989
	--- x	Mon Dec 11 06:02:10 1989
	***************
	*** 1 ****
	--- 1,3 ----
	+ 	This is a new line
		This is the original line
	+ 	This is another new line

I patch the file and look at the results

	% patch -D NEW < x.diffs
	Hmm...  Looks like a new-style context diff to me...
	The text leading up to this was:
	--------------------------
	|*** x.old	Mon Dec 11 06:02:04 1989
	|--- x	Mon Dec 11 06:02:10 1989
	--------------------------
	Patching file x using Plan A...
	Hunk #1 succeeded at 1.
	done
	% cat x
	#ifdef NEW
	This is a new line
	This is the original line
	This is another new line
	#endif /* NEW */

Hmm.  EVERYTHING is #ifdef'd.  This is not what I had in mind!  Seems to
me that we should have

	#ifdef NEW
	This is a new line
	#endif /* NEW */
	This is the original line
	#ifdef NEW
	This is another new line
	#endif /* NEW */

Oops!  Here's the other one, where the diffs add a line and then change a
line:

	% cat x
	This is the stable line
	This is the changed line
	% cat x.diffs
	*** x.old	Mon Dec 11 06:09:22 1989
	--- x	Mon Dec 11 06:09:38 1989
	***************
	*** 1,2 ****
	  This is the stable line
	! This is the changed line
	--- 1,3 ----
	+ This is a new line
	  This is the stable line
	! This is the CHANGED line
	% patch -D NEW < x.diffs
	Hmm...  Looks like a new-style context diff to me...
	The text leading up to this was:
	--------------------------
	|*** x.old	Mon Dec 11 06:09:22 1989
	|--- x	Mon Dec 11 06:09:38 1989
	--------------------------
	Patching file x using Plan A...
	Hunk #1 succeeded at 1.
	done
	% cat x
	#ifdef NEW
	This is a new line
	This is the stable line
	#ifndef NEW
	This is the changed line
	#else
	This is the CHANGED line
	#endif /* NEW */

Ack!  The first #if has no #endif!

So, am I using "patch -D" wrong, or are these bugs?

Michael