version 1.44, 2014/11/22 15:49:28 |
version 1.45, 2014/11/25 10:26:07 |
|
|
static char *best_name(const struct file_name *, bool); |
static char *best_name(const struct file_name *, bool); |
static char *posix_name(const struct file_name *, bool); |
static char *posix_name(const struct file_name *, bool); |
static size_t num_components(const char *); |
static size_t num_components(const char *); |
|
static LINENUM strtolinenum(char *, char **); |
|
|
/* |
/* |
* Prepare to look for the next patch in the patch file. |
* Prepare to look for the next patch in the patch file. |
|
|
stars_this_line = strnEQ(s, "********", 8); |
stars_this_line = strnEQ(s, "********", 8); |
if ((!diff_type || diff_type == CONTEXT_DIFF) && stars_last_line && |
if ((!diff_type || diff_type == CONTEXT_DIFF) && stars_last_line && |
strnEQ(s, "*** ", 4)) { |
strnEQ(s, "*** ", 4)) { |
if (atol(s + 4) == 0) |
if (strtolinenum(s + 4, &s) == 0) |
ok_to_create_file = true; |
ok_to_create_file = true; |
/* |
/* |
* If this is a new context diff the character just |
* If this is a new context diff the character just |
|
|
malformed(); |
malformed(); |
if (strnEQ(s, "0,0", 3)) |
if (strnEQ(s, "0,0", 3)) |
memmove(s, s + 2, strlen(s + 2) + 1); |
memmove(s, s + 2, strlen(s + 2) + 1); |
p_first = (LINENUM) atol(s); |
p_first = strtolinenum(s, &s); |
while (isdigit((unsigned char)*s)) |
|
s++; |
|
if (*s == ',') { |
if (*s == ',') { |
for (; *s && !isdigit((unsigned char)*s); s++) |
for (; *s && !isdigit((unsigned char)*s); s++) |
; |
; |
if (!*s) |
if (!*s) |
malformed(); |
malformed(); |
p_ptrn_lines = ((LINENUM) atol(s)) - p_first + 1; |
p_ptrn_lines = strtolinenum(s, &s) - p_first + 1; |
} else if (p_first) |
} else if (p_first) |
p_ptrn_lines = 1; |
p_ptrn_lines = 1; |
else { |
else { |
|
|
; |
; |
if (!*s) |
if (!*s) |
malformed(); |
malformed(); |
p_newfirst = (LINENUM) atol(s); |
p_newfirst = strtolinenum(s, &s); |
while (isdigit((unsigned char)*s)) |
|
s++; |
|
if (*s == ',') { |
if (*s == ',') { |
for (; *s && !isdigit((unsigned char)*s); s++) |
for (; *s && !isdigit((unsigned char)*s); s++) |
; |
; |
if (!*s) |
if (!*s) |
malformed(); |
malformed(); |
p_repl_lines = ((LINENUM) atol(s)) - |
p_repl_lines = strtolinenum(s, &s) - |
p_newfirst + 1; |
p_newfirst + 1; |
} else if (p_newfirst) |
} else if (p_newfirst) |
p_repl_lines = 1; |
p_repl_lines = 1; |
|
|
s = buf + 4; |
s = buf + 4; |
if (!*s) |
if (!*s) |
malformed(); |
malformed(); |
p_first = (LINENUM) atol(s); |
p_first = strtolinenum(s, &s); |
while (isdigit((unsigned char)*s)) |
|
s++; |
|
if (*s == ',') { |
if (*s == ',') { |
p_ptrn_lines = (LINENUM) atol(++s); |
p_ptrn_lines = strtolinenum(s + 1, &s); |
while (isdigit((unsigned char)*s)) |
|
s++; |
|
} else |
} else |
p_ptrn_lines = 1; |
p_ptrn_lines = 1; |
if (*s == ' ') |
if (*s == ' ') |
s++; |
s++; |
if (*s != '+' || !*++s) |
if (*s != '+' || !*++s) |
malformed(); |
malformed(); |
p_newfirst = (LINENUM) atol(s); |
p_newfirst = strtolinenum(s, &s); |
while (isdigit((unsigned char)*s)) |
|
s++; |
|
if (*s == ',') { |
if (*s == ',') { |
p_repl_lines = (LINENUM) atol(++s); |
p_repl_lines = strtolinenum(s + 1, &s); |
while (isdigit((unsigned char)*s)) |
|
s++; |
|
} else |
} else |
p_repl_lines = 1; |
p_repl_lines = 1; |
if (*s == ' ') |
if (*s == ' ') |
|
|
next_intuit_at(line_beginning, p_input_line); |
next_intuit_at(line_beginning, p_input_line); |
return false; |
return false; |
} |
} |
p_first = (LINENUM) atol(buf); |
p_first = strtolinenum(buf, &s); |
for (s = buf; isdigit((unsigned char)*s); s++) |
|
; |
|
if (*s == ',') { |
if (*s == ',') { |
p_ptrn_lines = (LINENUM) atol(++s) - p_first + 1; |
p_ptrn_lines = strtolinenum(s + 1, &s) - p_first + 1; |
while (isdigit((unsigned char)*s)) |
|
s++; |
|
} else |
} else |
p_ptrn_lines = (*s != 'a'); |
p_ptrn_lines = (*s != 'a'); |
hunk_type = *s; |
hunk_type = *s; |
if (hunk_type == 'a') |
if (hunk_type == 'a') |
p_first++; /* do append rather than insert */ |
p_first++; /* do append rather than insert */ |
min = (LINENUM) atol(++s); |
min = strtolinenum(s + 1, &s); |
for (; isdigit((unsigned char)*s); s++) |
|
; |
|
if (*s == ',') |
if (*s == ',') |
max = (LINENUM) atol(++s); |
max = strtolinenum(s + 1, &s); |
else |
else |
max = min; |
max = min; |
if (hunk_type == 'd') |
if (hunk_type == 'd') |
|
|
cp++; /* skip consecutive slashes */ |
cp++; /* skip consecutive slashes */ |
} |
} |
return n; |
return n; |
|
} |
|
|
|
/* |
|
* Convert number at NPTR into LINENUM and save address of first |
|
* character that is not a digit in ENDPTR. If conversion is not |
|
* possible, call fatal. |
|
*/ |
|
static LINENUM |
|
strtolinenum(char *nptr, char **endptr) |
|
{ |
|
LINENUM rv; |
|
char c; |
|
char *p; |
|
const char *errstr; |
|
|
|
for (p = nptr; isdigit((unsigned char)*p); p++) |
|
; |
|
|
|
if (p == nptr) |
|
malformed(); |
|
|
|
c = *p; |
|
*p = '\0'; |
|
|
|
rv = strtonum(nptr, 0, LINENUM_MAX, &errstr); |
|
if (errstr != NULL) |
|
fatal("invalid line number at line %ld: `%s' is %s\n", |
|
p_input_line, nptr, errstr); |
|
|
|
*p = c; |
|
*endptr = p; |
|
|
|
return rv; |
} |
} |