@ -854,6 +854,49 @@ static int find_header(char *line, unsigned long size, int *hdrsize, struct patc
@@ -854,6 +854,49 @@ static int find_header(char *line, unsigned long size, int *hdrsize, struct patc
return -1;
}
static void check_whitespace(const char *line, int len)
{
const char *err = "Adds trailing whitespace";
int seen_space = 0;
int i;
/*
* We know len is at least two, since we have a '+' and we
* checked that the last character was a '\n' before calling
* this function. That is, an addition of an empty line would
* check the '+' here. Sneaky...
*/
if (isspace(line[len-2]))
goto error;
/*
* Make sure that there is no space followed by a tab in
* indentation.
*/
err = "Space in indent is followed by a tab";
for (i = 1; i < len; i++) {
if (line[i] == '\t') {
if (seen_space)
goto error;
}
else if (line[i] == ' ')
seen_space = 1;
else
break;
}
return;
error:
whitespace_error++;
if (squelch_whitespace_errors &&
squelch_whitespace_errors < whitespace_error)
;
else
fprintf(stderr, "%s.\n%s:%d:%.*s\n",
err, patch_input_file, linenr, len-2, line+1);
}
/*
* Parse a unified diff. Note that this really needs to parse each
* fragment separately, since the only way to know the difference
@ -904,25 +947,8 @@ static int parse_fragment(char *line, unsigned long size, struct patch *patch, s
@@ -904,25 +947,8 @@ static int parse_fragment(char *line, unsigned long size, struct patch *patch, s
trailing = 0;
break;
case '+':
/*
* We know len is at least two, since we have a '+' and
* we checked that the last character was a '\n' above.
* That is, an addition of an empty line would check