From 24cc227fa1900502d167a60a8325af576dfe5552 Mon Sep 17 00:00:00 2001 From: Yannick Moy Date: Thu, 4 Mar 2010 14:20:16 +0100 Subject: [PATCH] with -F or -p, emit better function lines: no leading white space * src/diff.c (print_context_function): For languages like Ada that allow local functions and procedures, the plain context function line may start with enough blank characters that the function name does not get completely printed in the 40 characters limit. This patch solves this problem by removing these useless initial blank characters. * NEWS (Changes in behavior): Mention this change. --- NEWS | 7 +++++++ src/context.c | 12 +++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index 569c4ef..2d20b40 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,13 @@ GNU diffutils NEWS -*- outline -*- ** Changes in behavior + In context-style diffs, diff prints a portion of a preceding "function" + line for each hunk, with --show-function-line=RE (-F) or + --show-c-function (-p). Now, it trims leading blanks from such lines + before extracting a prefix. This is useful especially when a function + line is so far indented that the name itself would be truncated or not + included in the limited-width substring that diff appends. + diff once again reports a difference with the diagnostic "Binary files A and B differ" when at least one of the files appears to be binary. From 2.8.4 through diffutils-2.9, it printed diff --git a/src/context.c b/src/context.c index e918134..84120f0 100644 --- a/src/context.c +++ b/src/context.c @@ -145,13 +145,15 @@ print_context_number_range (struct file_data const *file, lin a, lin b) static void print_context_function (FILE *out, char const *function) { - int i; + int i, j; putc (' ', out); - for (i = 0; i < 40 && function[i] != '\n'; i++) + for (i = 0; isspace ((unsigned char)function[i]) && function[i] != '\n'; i++) continue; - while (0 < i && isspace ((unsigned char) function[i - 1])) - i--; - fwrite (function, sizeof (char), i, out); + for (j = i; j < i + 40 && function[j] != '\n'; j++) + continue; + while (i < j && isspace ((unsigned char) function[j - 1])) + j--; + fwrite (function + i, sizeof (char), j - i, out); } /* Print a portion of an edit script in context format.