pch.c (275553) | pch.c (275582) |
---|---|
1 2/*- 3 * Copyright 1986, Larry Wall 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following condition is met: 7 * 1. Redistributions of source code must retain the above copyright notice, 8 * this condition and the following disclaimer. --- 10 unchanged lines hidden (view full) --- 19 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 20 * SUCH DAMAGE. 21 * 22 * patch - a program to apply diffs to original files 23 * 24 * -C option added in 1998, original code by Marc Espie, based on FreeBSD 25 * behaviour 26 * | 1 2/*- 3 * Copyright 1986, Larry Wall 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following condition is met: 7 * 1. Redistributions of source code must retain the above copyright notice, 8 * this condition and the following disclaimer. --- 10 unchanged lines hidden (view full) --- 19 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 20 * SUCH DAMAGE. 21 * 22 * patch - a program to apply diffs to original files 23 * 24 * -C option added in 1998, original code by Marc Espie, based on FreeBSD 25 * behaviour 26 * |
27 * $OpenBSD: pch.c,v 1.40 2013/07/11 12:39:31 otto Exp $ 28 * $FreeBSD: head/usr.bin/patch/pch.c 275553 2014-12-06 01:21:12Z pfg $ | 27 * $OpenBSD: pch.c,v 1.43 2014/11/18 17:03:35 tobias Exp $ 28 * $FreeBSD: head/usr.bin/patch/pch.c 275582 2014-12-07 20:32:24Z pfg $ |
29 */ 30 31#include <sys/types.h> 32#include <sys/stat.h> 33 34#include <ctype.h> 35#include <libgen.h> 36#include <limits.h> --- 277 unchanged lines hidden (view full) --- 314 &names[OLD_FILE].exists, strippath); 315 else if (strnEQ(s, "Index:", 6)) 316 names[INDEX_FILE].path = fetchname(s + 6, 317 &names[INDEX_FILE].exists, strippath); 318 else if (strnEQ(s, "Prereq:", 7)) { 319 for (t = s + 7; isspace((unsigned char)*t); t++) 320 ; 321 revision = savestr(t); | 29 */ 30 31#include <sys/types.h> 32#include <sys/stat.h> 33 34#include <ctype.h> 35#include <libgen.h> 36#include <limits.h> --- 277 unchanged lines hidden (view full) --- 314 &names[OLD_FILE].exists, strippath); 315 else if (strnEQ(s, "Index:", 6)) 316 names[INDEX_FILE].path = fetchname(s + 6, 317 &names[INDEX_FILE].exists, strippath); 318 else if (strnEQ(s, "Prereq:", 7)) { 319 for (t = s + 7; isspace((unsigned char)*t); t++) 320 ; 321 revision = savestr(t); |
322 for (t = revision; *t && !isspace((unsigned char)*t); t++) | 322 for (t = revision; 323 *t && !isspace((unsigned char)*t); t++) |
323 ; 324 *t = '\0'; 325 if (*revision == '\0') { 326 free(revision); 327 revision = NULL; 328 } 329 } else if (strnEQ(s, "==== ", 5)) { 330 /* Perforce-style diffs. */ --- 249 unchanged lines hidden (view full) --- 580 p_input_line, buf); 581 } 582 context = 0; 583 p_line[p_end] = savestr(buf); 584 if (out_of_mem) { 585 p_end--; 586 return false; 587 } | 324 ; 325 *t = '\0'; 326 if (*revision == '\0') { 327 free(revision); 328 revision = NULL; 329 } 330 } else if (strnEQ(s, "==== ", 5)) { 331 /* Perforce-style diffs. */ --- 249 unchanged lines hidden (view full) --- 581 p_input_line, buf); 582 } 583 context = 0; 584 p_line[p_end] = savestr(buf); 585 if (out_of_mem) { 586 p_end--; 587 return false; 588 } |
588 for (s = buf; *s && !isdigit((unsigned char)*s); s++) | 589 for (s = buf; 590 *s && !isdigit((unsigned char)*s); s++) |
589 ; 590 if (!*s) 591 malformed(); 592 if (strnEQ(s, "0,0", 3)) 593 memmove(s, s + 2, strlen(s + 2) + 1); 594 p_first = (LINENUM) atol(s); 595 while (isdigit((unsigned char)*s)) 596 s++; 597 if (*s == ',') { | 591 ; 592 if (!*s) 593 malformed(); 594 if (strnEQ(s, "0,0", 3)) 595 memmove(s, s + 2, strlen(s + 2) + 1); 596 p_first = (LINENUM) atol(s); 597 while (isdigit((unsigned char)*s)) 598 s++; 599 if (*s == ',') { |
598 for (; *s && !isdigit((unsigned char)*s); s++) | 600 for (; 601 *s && !isdigit((unsigned char)*s); s++) |
599 ; 600 if (!*s) 601 malformed(); 602 p_ptrn_lines = ((LINENUM) atol(s)) - p_first + 1; 603 } else if (p_first) 604 p_ptrn_lines = 1; 605 else { 606 p_ptrn_lines = 0; --- 80 unchanged lines hidden (view full) --- 687 } 688 goto change_line; 689 case '+': 690 case '!': 691 repl_could_be_missing = false; 692 change_line: 693 if (buf[1] == '\n' && canonicalize) 694 strlcpy(buf + 1, " \n", buf_size - 1); | 602 ; 603 if (!*s) 604 malformed(); 605 p_ptrn_lines = ((LINENUM) atol(s)) - p_first + 1; 606 } else if (p_first) 607 p_ptrn_lines = 1; 608 else { 609 p_ptrn_lines = 0; --- 80 unchanged lines hidden (view full) --- 690 } 691 goto change_line; 692 case '+': 693 case '!': 694 repl_could_be_missing = false; 695 change_line: 696 if (buf[1] == '\n' && canonicalize) 697 strlcpy(buf + 1, " \n", buf_size - 1); |
695 if (!isspace((unsigned char)buf[1]) && buf[1] != '>' && 696 buf[1] != '<' && | 698 if (!isspace((unsigned char)buf[1]) && 699 buf[1] != '>' && buf[1] != '<' && |
697 repl_beginning && repl_could_be_missing) { 698 repl_missing = true; 699 goto hunk_done; 700 } 701 if (context >= 0) { 702 if (context < p_context) 703 p_context = context; 704 context = -1000; --- 712 unchanged lines hidden (view full) --- 1417 if (pgets(true) == 0) { 1418 next_intuit_at(beginning_of_this_line, p_input_line); 1419 break; 1420 } 1421 p_input_line++; 1422 for (t = buf; isdigit((unsigned char)*t) || *t == ','; t++) 1423 ; 1424 /* POSIX defines allowed commands as {a,c,d,i,s} */ | 700 repl_beginning && repl_could_be_missing) { 701 repl_missing = true; 702 goto hunk_done; 703 } 704 if (context >= 0) { 705 if (context < p_context) 706 p_context = context; 707 context = -1000; --- 712 unchanged lines hidden (view full) --- 1420 if (pgets(true) == 0) { 1421 next_intuit_at(beginning_of_this_line, p_input_line); 1422 break; 1423 } 1424 p_input_line++; 1425 for (t = buf; isdigit((unsigned char)*t) || *t == ','; t++) 1426 ; 1427 /* POSIX defines allowed commands as {a,c,d,i,s} */ |
1425 if (isdigit((unsigned char)*buf) && (*t == 'a' || *t == 'c' || 1426 *t == 'd' || *t == 'i' || *t == 's')) { | 1428 if (isdigit((unsigned char)*buf) && 1429 (*t == 'a' || *t == 'c' || *t == 'd' || *t == 'i' || *t == 's')) { |
1427 if (pipefp != NULL) 1428 fputs(buf, pipefp); 1429 if (*t != 'd') { 1430 while (pgets(true)) { 1431 p_input_line++; 1432 if (pipefp != NULL) 1433 fputs(buf, pipefp); 1434 if (strEQ(buf, ".\n")) --- 147 unchanged lines hidden --- | 1430 if (pipefp != NULL) 1431 fputs(buf, pipefp); 1432 if (*t != 'd') { 1433 while (pgets(true)) { 1434 p_input_line++; 1435 if (pipefp != NULL) 1436 fputs(buf, pipefp); 1437 if (strEQ(buf, ".\n")) --- 147 unchanged lines hidden --- |