So I was poking at porting this to BusyBox, and I see you've already done 2/3 
of the work.

This is the only toybox app I still maintain because I use it in aboriginal 
LInux (the alternative is gnu patch), and it keeps #*%(&#% breaking every few 
months as I apply new random patches and discover yet another insane corner 
case in gnu diff.

Speaking of which,

1) How do I make it actually work in busybox?  (The FAQ hasn't been updated 
for the new inline stuff yet.)

2) Does BusyBox currently have any equivalent for the streaming infrastructure 
and such?  (The library stuff has been copied, not converted.  I dunno what's 
available these days, I'm ~4 years out of date.)

3) you may want these patches:


http://landley.net/hg/toybox/rev/362
http://landley.net/hg/toybox/rev/375

And optionally some debug crap:
http://landley.net/hg/toybox/rev/376

And then two _more_ patches are attached which apply after those, I never 
checked them into the toybox repo (I'm applying from the aboriginal patch list 
instead) because cutting a new toybox release seems kinda pointless.

I'm also working on a patch to implement -l support (squash whitespace) if 
you're interested.  And at some point I should do fuzz factor support, and 
better error reporting.  And add a CONFIG symbol to chop out most of the 
command line options...

Rob
-- 
GPLv3: as worthy a successor as The Phantom Menace, as timely as Duke Nukem 
Forever, and as welcome as New Coke.
diff -r 633a5bf9509d toys/patch.c
--- a/toys/patch.c	Wed Jan 06 05:29:53 2010 -0600
+++ b/toys/patch.c	Tue Jan 26 01:01:20 2010 -0600
@@ -272,7 +272,7 @@
 			for (s = patchline+4; *s && *s!='\t'; s++)
 				if (*s=='\\' && s[1]) s++;
 			i = atoi(s);
-			if (i && i<=1970)
+			if (i>1900 && i<=1970)
 				*name = xstrdup("/dev/null");
 			else {
 				*s = 0;
The @@ -1,2 +3,4 @@ lines treat ,1 as implied, so the format isn't regular.
(Yes, this was designed by the FSF, what gave it away?)

diff -r 35c8beb54800 toys/patch.c
--- a/toys/patch.c	Sun Feb 28 14:11:41 2010 -0600
+++ b/toys/patch.c	Wed Jun 30 14:26:46 2010 -0500
@@ -51,7 +51,8 @@
 	long prefix;
 
 	struct double_list *current_hunk;
-	long oldline, oldlen, newline, newlen, linenum;
+	long oldline, oldlen, newline, newlen;
+	long linenum;
 	int context, state, filein, fileout, filepatch, hunknum;
 	char *tempname;
 )
@@ -308,14 +309,19 @@
 			// way the patch man page says, so you have to read the first hunk
 			// and _guess_.
 
-		// Start a new hunk?
+		// Start a new hunk?  Usually @@ -oldline,oldlen +newline,newlen @@
+		// but a missing ,value means the value is 1.
 		} else if (state == 1 && !strncmp("@@ -", patchline, 4)) {
 			int i;
+			char *s = patchline+4;
 
-			i = sscanf(patchline+4, "%ld,%ld +%ld,%ld", &TT.oldline,
-						&TT.oldlen, &TT.newline, &TT.newlen);
-			if (i != 4)
-				error_exit("Corrupt hunk %d at %ld\n", TT.hunknum, TT.linenum);
+			// Read oldline[,oldlen] +newline[,newlen]
+
+			TT.oldlen = TT.newlen = 1;
+			TT.oldline = strtol(s, &s, 10);
+			if (*s == ',') TT.oldlen=strtol(s+1, &s, 10);
+			TT.newline = strtol(s+2, &s, 10);
+			if (*s == ',') TT.newlen = strtol(s+1, &s, 10);
 
 			TT.context = 0;
 			state = 2;
@@ -323,7 +329,7 @@
 			// If this is the first hunk, open the file.
 			if (TT.filein == -1) {
 				int oldsum, newsum, del = 0;
-				char *s, *name;
+				char *name;
 
  				oldsum = TT.oldline + TT.oldlen;
 				newsum = TT.newline + TT.newlen;
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to