Lines 501-506
another_hunk(void)
Link Here
|
501 |
long repl_backtrack_position; /* file pos of first repl line */ |
501 |
long repl_backtrack_position; /* file pos of first repl line */ |
502 |
LINENUM repl_patch_line; /* input line number for same */ |
502 |
LINENUM repl_patch_line; /* input line number for same */ |
503 |
LINENUM ptrn_copiable; /* # of copiable lines in ptrn */ |
503 |
LINENUM ptrn_copiable; /* # of copiable lines in ptrn */ |
|
|
504 |
const char *p_err; |
504 |
char *s; |
505 |
char *s; |
505 |
size_t len; |
506 |
size_t len; |
506 |
int context = 0; |
507 |
int context = 0; |
Lines 589-595
another_hunk(void)
Link Here
|
589 |
malformed(); |
590 |
malformed(); |
590 |
if (strnEQ(s, "0,0", 3)) |
591 |
if (strnEQ(s, "0,0", 3)) |
591 |
memmove(s, s + 2, strlen(s + 2) + 1); |
592 |
memmove(s, s + 2, strlen(s + 2) + 1); |
592 |
p_first = (LINENUM) atol(s); |
593 |
p_first = (LINENUM) strtonum(s, 0, LINENUM_MAX, &p_err); |
|
|
594 |
if (p_err != NULL) |
595 |
fatal("at line %ld: bad line number %s", |
596 |
p_input_line, s); |
593 |
while (isdigit((unsigned char)*s)) |
597 |
while (isdigit((unsigned char)*s)) |
594 |
s++; |
598 |
s++; |
595 |
if (*s == ',') { |
599 |
if (*s == ',') { |
Lines 597-603
another_hunk(void)
Link Here
|
597 |
; |
601 |
; |
598 |
if (!*s) |
602 |
if (!*s) |
599 |
malformed(); |
603 |
malformed(); |
600 |
p_ptrn_lines = ((LINENUM) atol(s)) - p_first + 1; |
604 |
p_ptrn_lines = ((LINENUM) strtonum(s, 0, |
|
|
605 |
LINENUM_MAX, &p_err)) - p_first + 1; |
606 |
if (p_err != NULL) |
607 |
fatal("at line %ld: bad line number %s", |
608 |
p_input_line, s); |
601 |
} else if (p_first) |
609 |
} else if (p_first) |
602 |
p_ptrn_lines = 1; |
610 |
p_ptrn_lines = 1; |
603 |
else { |
611 |
else { |
Lines 605-610
another_hunk(void)
Link Here
|
605 |
p_first = 1; |
613 |
p_first = 1; |
606 |
} |
614 |
} |
607 |
|
615 |
|
|
|
616 |
if (p_first >= LINENUM_MAX - p_ptrn_lines || |
617 |
p_ptrn_lines >= LINENUM_MAX - 6) |
618 |
malformed(); |
608 |
/* we need this much at least */ |
619 |
/* we need this much at least */ |
609 |
p_max = p_ptrn_lines + 6; |
620 |
p_max = p_ptrn_lines + 6; |
610 |
while (p_max >= hunkmax) |
621 |
while (p_max >= hunkmax) |
Lines 656-662
another_hunk(void)
Link Here
|
656 |
; |
667 |
; |
657 |
if (!*s) |
668 |
if (!*s) |
658 |
malformed(); |
669 |
malformed(); |
659 |
p_newfirst = (LINENUM) atol(s); |
670 |
p_newfirst = (LINENUM) strtonum(s, 0, LINENUM_MAX, &p_err); |
|
|
671 |
if (p_err != NULL) |
672 |
fatal("at line %ld: bad line number %s", |
673 |
p_input_line, s); |
660 |
while (isdigit((unsigned char)*s)) |
674 |
while (isdigit((unsigned char)*s)) |
661 |
s++; |
675 |
s++; |
662 |
if (*s == ',') { |
676 |
if (*s == ',') { |
Lines 664-677
another_hunk(void)
Link Here
|
664 |
; |
678 |
; |
665 |
if (!*s) |
679 |
if (!*s) |
666 |
malformed(); |
680 |
malformed(); |
667 |
p_repl_lines = ((LINENUM) atol(s)) - |
681 |
p_repl_lines = ((LINENUM) strtonum(s, 0, |
668 |
p_newfirst + 1; |
682 |
LINENUM_MAX, &p_err)) - p_newfirst + 1; |
|
|
683 |
if (p_err != NULL) |
684 |
fatal("at line %ld: bad line number %s", |
685 |
p_input_line, s); |
669 |
} else if (p_newfirst) |
686 |
} else if (p_newfirst) |
670 |
p_repl_lines = 1; |
687 |
p_repl_lines = 1; |
671 |
else { |
688 |
else { |
672 |
p_repl_lines = 0; |
689 |
p_repl_lines = 0; |
673 |
p_newfirst = 1; |
690 |
p_newfirst = 1; |
674 |
} |
691 |
} |
|
|
692 |
|
693 |
if (p_newfirst >= LINENUM_MAX - p_repl_lines || |
694 |
p_repl_lines >= LINENUM_MAX - p_end) |
695 |
malformed(); |
675 |
p_max = p_repl_lines + p_end; |
696 |
p_max = p_repl_lines + p_end; |
676 |
if (p_max > MAXHUNKSIZE) |
697 |
if (p_max > MAXHUNKSIZE) |
677 |
fatal("hunk too large (%ld lines) at line %ld: %s", |
698 |
fatal("hunk too large (%ld lines) at line %ld: %s", |
Lines 864-874
hunk_done:
Link Here
|
864 |
s = buf + 4; |
885 |
s = buf + 4; |
865 |
if (!*s) |
886 |
if (!*s) |
866 |
malformed(); |
887 |
malformed(); |
867 |
p_first = (LINENUM) atol(s); |
888 |
p_first = (LINENUM) strtonum(s, 0, LINENUM_MAX, &p_err); |
|
|
889 |
if (p_err != NULL) |
890 |
fatal("at line %ld: bad line number %s", |
891 |
p_input_line, s); |
868 |
while (isdigit((unsigned char)*s)) |
892 |
while (isdigit((unsigned char)*s)) |
869 |
s++; |
893 |
s++; |
870 |
if (*s == ',') { |
894 |
if (*s == ',') { |
871 |
p_ptrn_lines = (LINENUM) atol(++s); |
895 |
p_ptrn_lines = (LINENUM) strtonum(++s, 0, LINENUM_MAX, |
|
|
896 |
&p_err); |
897 |
if (p_err != NULL) |
898 |
fatal("at line %ld: bad line number %s", |
899 |
p_input_line, s); |
872 |
while (isdigit((unsigned char)*s)) |
900 |
while (isdigit((unsigned char)*s)) |
873 |
s++; |
901 |
s++; |
874 |
} else |
902 |
} else |
Lines 877-887
hunk_done:
Link Here
|
877 |
s++; |
905 |
s++; |
878 |
if (*s != '+' || !*++s) |
906 |
if (*s != '+' || !*++s) |
879 |
malformed(); |
907 |
malformed(); |
880 |
p_newfirst = (LINENUM) atol(s); |
908 |
p_newfirst = (LINENUM) strtonum(s, 0, LINENUM_MAX, &p_err); |
|
|
909 |
if (p_err != NULL) |
910 |
fatal("at line %ld: bad line number %s", |
911 |
p_input_line, s); |
881 |
while (isdigit((unsigned char)*s)) |
912 |
while (isdigit((unsigned char)*s)) |
882 |
s++; |
913 |
s++; |
883 |
if (*s == ',') { |
914 |
if (*s == ',') { |
884 |
p_repl_lines = (LINENUM) atol(++s); |
915 |
p_repl_lines = (LINENUM) strtonum(++s, 0, LINENUM_MAX, &p_err); |
|
|
916 |
if (p_err != NULL) |
917 |
fatal("at line %ld: bad line number %s", |
918 |
p_input_line, s); |
885 |
while (isdigit((unsigned char)*s)) |
919 |
while (isdigit((unsigned char)*s)) |
886 |
s++; |
920 |
s++; |
887 |
} else |
921 |
} else |
Lines 890-895
hunk_done:
Link Here
|
890 |
s++; |
924 |
s++; |
891 |
if (*s != '@') |
925 |
if (*s != '@') |
892 |
malformed(); |
926 |
malformed(); |
|
|
927 |
if (p_first >= LINENUM_MAX - p_ptrn_lines || |
928 |
p_newfirst > LINENUM_MAX - p_repl_lines || |
929 |
p_ptrn_lines >= LINENUM_MAX - p_repl_lines - 1) |
930 |
malformed(); |
893 |
if (!p_ptrn_lines) |
931 |
if (!p_ptrn_lines) |
894 |
p_first++; /* do append rather than insert */ |
932 |
p_first++; /* do append rather than insert */ |
895 |
p_max = p_ptrn_lines + p_repl_lines + 1; |
933 |
p_max = p_ptrn_lines + p_repl_lines + 1; |
Lines 1029-1063
hunk_done:
Link Here
|
1029 |
next_intuit_at(line_beginning, p_input_line); |
1067 |
next_intuit_at(line_beginning, p_input_line); |
1030 |
return false; |
1068 |
return false; |
1031 |
} |
1069 |
} |
1032 |
p_first = (LINENUM) atol(buf); |
1070 |
p_first = (LINENUM) strtonum(buf, 0, LINENUM_MAX, &p_err); |
|
|
1071 |
if (p_err != NULL) |
1072 |
fatal("at line %ld: bad line number %s", |
1073 |
p_input_line, buf); |
1033 |
for (s = buf; isdigit((unsigned char)*s); s++) |
1074 |
for (s = buf; isdigit((unsigned char)*s); s++) |
1034 |
; |
1075 |
; |
1035 |
if (*s == ',') { |
1076 |
if (*s == ',') { |
1036 |
p_ptrn_lines = (LINENUM) atol(++s) - p_first + 1; |
1077 |
p_ptrn_lines = (LINENUM) strtonum(++s, 0, |
|
|
1078 |
LINENUM_MAX, &p_err) - p_first + 1; |
1079 |
if (p_err != NULL) |
1080 |
malformed(); |
1037 |
while (isdigit((unsigned char)*s)) |
1081 |
while (isdigit((unsigned char)*s)) |
1038 |
s++; |
1082 |
s++; |
1039 |
} else |
1083 |
} else |
1040 |
p_ptrn_lines = (*s != 'a'); |
1084 |
p_ptrn_lines = (*s != 'a'); |
|
|
1085 |
if (p_first >= LINENUM_MAX - p_ptrn_lines) |
1086 |
malformed(); |
1041 |
hunk_type = *s; |
1087 |
hunk_type = *s; |
1042 |
if (hunk_type == 'a') |
1088 |
if (hunk_type == 'a') |
1043 |
p_first++; /* do append rather than insert */ |
1089 |
p_first++; /* do append rather than insert */ |
1044 |
min = (LINENUM) atol(++s); |
1090 |
min = (LINENUM) strtonum(++s, 0, LINENUM_MAX, &p_err); |
|
|
1091 |
if (p_err != NULL) |
1092 |
malformed(); |
1045 |
for (; isdigit((unsigned char)*s); s++) |
1093 |
for (; isdigit((unsigned char)*s); s++) |
1046 |
; |
1094 |
; |
1047 |
if (*s == ',') |
1095 |
if (*s == ',') { |
1048 |
max = (LINENUM) atol(++s); |
1096 |
max = (LINENUM) strtonum(++s, 0, LINENUM_MAX, &p_err); |
1049 |
else |
1097 |
if (p_err != NULL) |
|
|
1098 |
malformed(); |
1099 |
} else |
1050 |
max = min; |
1100 |
max = min; |
|
|
1101 |
if (min < 0 || min > max || max - min == LINENUM_MAX) |
1102 |
malformed(); |
1051 |
if (hunk_type == 'd') |
1103 |
if (hunk_type == 'd') |
1052 |
min++; |
1104 |
min++; |
1053 |
p_end = p_ptrn_lines + 1 + max - min + 1; |
1105 |
p_newfirst = min; |
|
|
1106 |
p_repl_lines = max - min + 1; |
1107 |
if (p_newfirst > LINENUM_MAX - p_repl_lines || |
1108 |
p_ptrn_lines >= LINENUM_MAX - p_repl_lines - 1) |
1109 |
malformed(); |
1110 |
p_end = p_ptrn_lines + p_repl_lines + 1; |
1054 |
if (p_end > MAXHUNKSIZE) |
1111 |
if (p_end > MAXHUNKSIZE) |
1055 |
fatal("hunk too large (%ld lines) at line %ld: %s", |
1112 |
fatal("hunk too large (%ld lines) at line %ld: %s", |
1056 |
p_end, p_input_line, buf); |
1113 |
p_end, p_input_line, buf); |
1057 |
while (p_end >= hunkmax) |
1114 |
while (p_end >= hunkmax) |
1058 |
grow_hunkmax(); |
1115 |
grow_hunkmax(); |
1059 |
p_newfirst = min; |
|
|
1060 |
p_repl_lines = max - min + 1; |
1061 |
snprintf(buf, buf_size, "*** %ld,%ld\n", p_first, |
1116 |
snprintf(buf, buf_size, "*** %ld,%ld\n", p_first, |
1062 |
p_first + p_ptrn_lines - 1); |
1117 |
p_first + p_ptrn_lines - 1); |
1063 |
p_line[0] = savestr(buf); |
1118 |
p_line[0] = savestr(buf); |