bug-diffutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-diffutils] [PATCH] remove initial blank characters in context funct


From: Yannick Moy
Subject: [bug-diffutils] [PATCH] remove initial blank characters in context function line
Date: Thu, 04 Mar 2010 14:20:16 +0100
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.23) Gecko/20090817 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666

* src/diff.c (print_context_function): For languages like Ada
which 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.
---
Hi,

Here is a patch that I hope you can integrate.

Besides, I'd really like the limit of 40 characters to be larger, say 60.
In Ada it is quite common to have long explicit function names.

I attached two files adacode.adb and adacode2.adb where the problem shows, when
diffing with

$ diff -c -F '^[[:space:]]*\(function\|procedure\)' adacode.adb adacode2.adb

the result starts with

***************                     procedure Local_Leve
*** 9,15 ****

Here is a possible description for the NEWS:

* Context function line skips initial blank characters, which arise
  in languages which allow the definition of local functions, in order
  to get the complete function name when possible.

Best regards,

Yannick Moy

 src/context.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)

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.
-- 
1.6.3.3


procedure AdaCode is
    procedure Local_Level_1 is
        procedure Local_Level_2 is
            procedure Local_Level_3 is
                procedure Local_Level_4 is
                    procedure Local_Level_5 is
                    begin
                        null;
                        null;
                        null;
                        null;
                        null;
                    end;
                begin
                    Local_Level_5;
                end;
            begin
                Local_Level_4;
            end;
        begin
            Local_Level_3;
        end;
    begin
        Local_Level_2;
    end;
begin
    Local_Level_1;
end;

procedure AdaCode is
    procedure Local_Level_1 is
        procedure Local_Level_2 is
            procedure Local_Level_3 is
                procedure Local_Level_4 is
                    procedure Local_Level_5 is
                    begin
                        null;
                        null;
                        null;
                        null;
                        if True then
                            null;
                        end if;   
                    end;
                begin
                    Local_Level_5;
                end;
            begin
                Local_Level_4;
            end;
        begin
            Local_Level_3;
        end;
    begin
        Local_Level_2;
    end;
begin
    Local_Level_1;
end;


reply via email to

[Prev in Thread] Current Thread [Next in Thread]