Use the logic refactored into ws.c rather than duplicating it. Signed-off-by: Wincent Colaiuta <win@xxxxxxxxxxx> --- diff.c | 49 +++++++++++-------------------------------------- 1 files changed, 11 insertions(+), 38 deletions(-) diff --git a/diff.c b/diff.c index c9b3884..7ad3c63 100644 --- a/diff.c +++ b/diff.c @@ -996,7 +996,7 @@ struct checkdiff_t { const char *filename; int lineno, color_diff; unsigned ws_rule; - int status; + unsigned status; }; static void checkdiff_consume(void *priv, char *line, unsigned long len) @@ -1005,45 +1005,18 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len) const char *ws = diff_get_color(data->color_diff, DIFF_WHITESPACE); const char *reset = diff_get_color(data->color_diff, DIFF_RESET); const char *set = diff_get_color(data->color_diff, DIFF_FILE_NEW); + char *err; if (line[0] == '+') { - int i, spaces = 0, space_before_tab = 0, white_space_at_end = 0; - - /* check space before tab */ - for (i = 1; i < len; i++) { - if (line[i] == ' ') - spaces++; - else if (line[i] == '\t') { - if (spaces) { - space_before_tab = 1; - break; - } - } - else - break; - } - - /* check whitespace at line end */ - if (line[len - 1] == '\n') - len--; - if (isspace(line[len - 1])) - white_space_at_end = 1; - - if (space_before_tab || white_space_at_end) { - data->status = 1; - printf("%s:%d: %s", data->filename, data->lineno, ws); - if (space_before_tab) { - printf("space before tab"); - if (white_space_at_end) - putchar(','); - } - if (white_space_at_end) - printf("whitespace at end"); - printf(":%s ", reset); - emit_line_with_ws(1, set, reset, ws, line, len, - data->ws_rule); - } - + data->status = check_whitespace(line, len, data->ws_rule); + if (!data->status) + return; + err = whitespace_error_string(data->status); + printf("%s:%d: %s%s:%s ", data->filename, data->lineno, + ws, err, reset); + free(err); + emit_line_with_ws(1, set, reset, ws, line, len, + data->ws_rule); data->lineno++; } else if (line[0] == ' ') data->lineno++; -- 1.5.3.7.1159.g2f071-dirty - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html