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

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

grep patch


From: Stepan Koltsov
Subject: grep patch
Date: Thu, 17 Jan 2002 11:59:34 +0300
User-agent: Mutt/1.3.25i

Hi.

This is diff, that add option --fake-filename= for grep 2.5f, it prints
specified filename instead of real.

Example of using:

for fn in *.gz; do zcat $fn | grep --fake-filename=$fn -H; done

If you find it useful, I can write patch to man page, etc.

--- ../2/grep-2.5f/src/grep.c   Mon Nov 19 16:26:52 2001
+++ src/grep.c  Thu Jan 17 11:47:18 2002
@@ -90,7 +90,8 @@
   INCLUDE_OPTION,
   EXCLUDE_OPTION,
   EXCLUDE_FROM_OPTION,
-  LINE_BUFFERED_OPTION
+  LINE_BUFFERED_OPTION,
+  FAKE_FILENAME_OPTION
 };
 
 /* Long options equivalences. */
@@ -110,6 +111,7 @@
   {"extended-regexp", no_argument, NULL, 'E'},
   {"exclude", required_argument, NULL, EXCLUDE_OPTION},
   {"exclude-from", required_argument, NULL, EXCLUDE_FROM_OPTION},
+  {"fake-filename", required_argument, NULL, FAKE_FILENAME_OPTION},
   {"file", required_argument, NULL, 'f'},
   {"files-with-matches", no_argument, NULL, 'l'},
   {"files-without-match", no_argument, NULL, 'L'},
@@ -443,6 +445,8 @@
                                   lines from an input file.  */
 static int line_buffered;       /* If nonzero, use line buffering, i.e.
                                   fflush everyline out.  */
+static char *fake_filename = NULL; /* If nonnull, print this instead of
+                                  real filename.  */
 
 
 /* Internal variables to keep track of byte count, context, etc. */
@@ -878,7 +882,7 @@
   if (! file)
     {
       desc = 0;
-      filename = _("(standard input)");
+      filename = fake_filename == NULL ? _("(standard input)") : fake_filename;
     }
   else
     {
@@ -922,7 +926,7 @@
          return 1;
        }
 
-      filename = file;
+      filename = fake_filename == NULL ? file : fake_filename;
     }
 
 #if defined(SET_BINARY)
@@ -1072,6 +1076,7 @@
   -b, --byte-offset         print the byte offset with output lines\n\
   -n, --line-number         print line number with output lines\n\
       --line-buffered       flush output on every line\n\
+      --fake-filename=FILE  print this filename instead of real\n\
   -H, --with-filename       print the filename for each match\n\
   -h, --no-filename         suppress the prefixing filename on output\n\
   -o, --only-matching       show only the part of a line matching PATTERN\n\
@@ -1595,6 +1600,10 @@
 
       case LINE_BUFFERED_OPTION:
        line_buffered = 1;
+       break;
+      
+      case FAKE_FILENAME_OPTION:
+       fake_filename = optarg;
        break;
 
       case 0:
-- 
mailto:address@hidden
irc.openprojects.net/#debian-russian



reply via email to

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