diff options
Diffstat (limited to 'editors/patch.c')
-rw-r--r-- | editors/patch.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/editors/patch.c b/editors/patch.c index 988021d77..731a8c58a 100644 --- a/editors/patch.c +++ b/editors/patch.c | |||
@@ -247,7 +247,7 @@ static int apply_one_hunk(void) | |||
247 | // Figure out which line of hunk to compare with next. (Skip lines | 247 | // Figure out which line of hunk to compare with next. (Skip lines |
248 | // of the hunk we'd be adding.) | 248 | // of the hunk we'd be adding.) |
249 | while (plist && *plist->data == "+-"[reverse]) { | 249 | while (plist && *plist->data == "+-"[reverse]) { |
250 | if (data && !strcmp(data, plist->data+1)) { | 250 | if (data && strcmp(data, plist->data+1) == 0) { |
251 | if (!backwarn) { | 251 | if (!backwarn) { |
252 | backwarn = TT.linenum; | 252 | backwarn = TT.linenum; |
253 | if (option_mask32 & FLAG_IGNORE) { | 253 | if (option_mask32 & FLAG_IGNORE) { |
@@ -290,12 +290,24 @@ static int apply_one_hunk(void) | |||
290 | // out of buffer. | 290 | // out of buffer. |
291 | 291 | ||
292 | for (;;) { | 292 | for (;;) { |
293 | while (plist && *plist->data == "+-"[reverse]) { | ||
294 | if (strcmp(check->data, plist->data+1) == 0 | ||
295 | && !backwarn | ||
296 | ) { | ||
297 | backwarn = TT.linenum; | ||
298 | if (option_mask32 & FLAG_IGNORE) { | ||
299 | dummy_revert = 1; | ||
300 | reverse ^= 1; | ||
301 | } | ||
302 | } | ||
303 | plist = plist->next; | ||
304 | } | ||
293 | if (!plist || strcmp(check->data, plist->data+1)) { | 305 | if (!plist || strcmp(check->data, plist->data+1)) { |
294 | // Match failed. Write out first line of buffered data and | 306 | // Match failed. Write out first line of buffered data and |
295 | // recheck remaining buffered data for a new match. | 307 | // recheck remaining buffered data for a new match. |
296 | 308 | ||
297 | if (PATCH_DEBUG) | 309 | if (PATCH_DEBUG) |
298 | fdprintf(2, "NOT: %s\n", plist->data); | 310 | fdprintf(2, "NOT: %s\n", plist ? plist->data : "EOF"); |
299 | 311 | ||
300 | TT.state = 3; | 312 | TT.state = 3; |
301 | check = buf; | 313 | check = buf; |
@@ -480,7 +492,7 @@ int patch_main(int argc UNUSED_PARAM, char **argv) | |||
480 | 492 | ||
481 | // We're deleting oldname if new file is /dev/null (before -p) | 493 | // We're deleting oldname if new file is /dev/null (before -p) |
482 | // or if new hunk is empty (zero context) after patching | 494 | // or if new hunk is empty (zero context) after patching |
483 | if (!strcmp(name, "/dev/null") || !(reverse ? oldsum : newsum)) { | 495 | if (strcmp(name, "/dev/null") == 0 || !(reverse ? oldsum : newsum)) { |
484 | name = reverse ? newname : oldname; | 496 | name = reverse ? newname : oldname; |
485 | empty = 1; | 497 | empty = 1; |
486 | } | 498 | } |
@@ -516,7 +528,7 @@ int patch_main(int argc UNUSED_PARAM, char **argv) | |||
516 | struct stat statbuf; | 528 | struct stat statbuf; |
517 | 529 | ||
518 | // If the old file was null, we're creating a new one. | 530 | // If the old file was null, we're creating a new one. |
519 | if (!strcmp(oldname, "/dev/null") || !oldsum) { | 531 | if (strcmp(oldname, "/dev/null") == 0 || !oldsum) { |
520 | printf("creating %s\n", name); | 532 | printf("creating %s\n", name); |
521 | s = strrchr(name, '/'); | 533 | s = strrchr(name, '/'); |
522 | if (s) { | 534 | if (s) { |