diff options
author | Rob Landley <rob@landley.net> | 2011-05-21 22:54:21 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2011-05-21 22:54:21 -0500 |
commit | 234f42adc016e8056a4a9f4466adea9072f0a7f6 (patch) | |
tree | 9640d2c43338b976c97e4edd46d6514d5b5bdfa7 | |
parent | 026212459ae63fedc60fb77cd65ae63ed19ebae5 (diff) | |
download | toybox-234f42adc016e8056a4a9f4466adea9072f0a7f6.tar.gz |
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?)
-rw-r--r-- | toys/patch.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/toys/patch.c b/toys/patch.c index 63599652..dab3fbfb 100644 --- a/toys/patch.c +++ b/toys/patch.c @@ -51,7 +51,8 @@ DEFINE_GLOBALS( 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 @@ void patch_main(void) // 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 @@ void patch_main(void) // 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; |