bug-gnu-utils
[Top][All Lists]
Advanced

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

diff user messages to stderr enhancement ?


From: Heiko Voigt
Subject: diff user messages to stderr enhancement ?
Date: Thu, 29 Nov 2007 18:19:31 +0100
User-agent: Icedove 1.5.0.8 (X11/20061208)

Hi,

i recently had to diff two trees. Some files were only present in the
target tree and my goal was to diff the existent files. Maybe someone
finds this patch useful, the -z  as option is probably discussable. Was
the first one that I found as free ;) Could the output of (user)
messages to stderr be the default behaviour?

Maybe its useful for someone else as well. Find attached a patch to the
cygwin version of diff.

cheers Heiko


This small and simple patch adds an option -z to diff which redirects
messages like "Only in ..." 
to stderr. This is useful in case you only want the diff information on
stdout. 
 
diff -urz diffutils-2.8.7-1/src/diff.c diffutils-2.8.7-2-h/src/diff.c
--- diffutils-2.8.7-1/src/diff.c    2004-04-12 09:44:35.001000000 +0200
+++ diffutils-2.8.7-2-h/src/diff.c    2007-11-29 15:03:21.206770400 +0100
@@ -62,6 +62,9 @@
 static void check_stdout (void);
 static void usage (void);
 
+/* all output concerning the user goes to stderr */ 
+bool diff_messages_to_stderr=false;
+
 /* If comparing directories, compare their common subdirectories
    recursively.  */
 static bool recursive;
@@ -137,7 +140,7 @@
 }
 
 static char const shortopts[] =
-"0123456789abBcC:dD:eEfF:hHiI:lL:nNpPqrsS:tTuU:vwW:x:X:y";
+"0123456789abBcC:dD:eEfF:hHiI:lL:nNpPqrsS:tTuU:vwW:x:X:yz";
 
 /* Values for long options that do not have single-letter equivalents.  */
 enum
@@ -312,6 +315,10 @@
       ignore_blank_lines = true;
       break;
 
+    case 'z':
+      diff_messages_to_stderr = true;
+      break;
+
     case 'C':
     case 'U':
       {
diff -urz diffutils-2.8.7-1/src/diff.h diffutils-2.8.7-2-h/src/diff.h
--- diffutils-2.8.7-1/src/diff.h    2004-04-12 09:44:35.001000000 +0200
+++ diffutils-2.8.7-2-h/src/diff.h    2007-11-29 12:30:05.019280600 +0100
@@ -85,6 +85,9 @@
 
 XTERN enum output_style output_style;
 
+/* all output concerning the user goes to stderr */ 
+XTERN bool diff_messages_to_stderr;
+
 /* Nonzero if output cannot be generated for identical files.  */
 XTERN bool no_diff_means_no_output;
 
diff -urz diffutils-2.8.7-1/src/util.c diffutils-2.8.7-2-h/src/util.c
--- diffutils-2.8.7-1/src/util.c    2004-04-12 09:44:35.001000000 +0200
+++ diffutils-2.8.7-2-h/src/util.c    2007-11-29 12:28:25.942198700 +0100
@@ -119,7 +119,10 @@
     {
       if (sdiff_merge_assist)
     putchar (' ');
-      printf (_(format_msgid), arg1, arg2, arg3, arg4);
+      if (diff_messages_to_stderr)
+        fprintf(stderr,_(format_msgid), arg1, arg2, arg3, arg4);
+      else
+        printf (_(format_msgid), arg1, arg2, arg3, arg4);
     }
 }
 
@@ -138,7 +141,10 @@
       arg[0] = m->args;
       for (i = 0;  i < 4;  i++)
     arg[i + 1] = arg[i] + strlen (arg[i]) + 1;
-      printf (_(arg[0]), arg[1], arg[2], arg[3], arg[4]);
+      if (diff_messages_to_stderr)
+        fprintf (stderr,_(arg[0]), arg[1], arg[2], arg[3], arg[4]);
+      else
+        printf (_(arg[0]), arg[1], arg[2], arg[3], arg[4]);
       free (m);
       m = next;
     }





reply via email to

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