grep --label=stdin_label

YONETANI Tomokazu qhwt+dfly at les.ath.cx
Mon Nov 15 22:04:27 PST 2004


Hello.
Can I commit the following patch that adds --label=stdin_label option to grep?
New zgrep/zfgrep script relies on this option in grep when it's fed multiple
files and the grep in our tree doesn't have one. At first I tried to change
the script, but I couldn't come up with a simple and efficient way to emulate
it.

Index: gnu/usr.bin/grep/grep.c
===================================================================
RCS file: /dragonfly/cvs/src/gnu/usr.bin/grep/grep.c,v
retrieving revision 1.2
diff -u -r1.2 grep.c
--- gnu/usr.bin/grep/grep.c	17 Jun 2003 04:25:45 -0000	1.2
+++ gnu/usr.bin/grep/grep.c	16 Nov 2004 05:51:51 -0000
@@ -65,6 +65,9 @@
 /* If zero, output nulls after filenames.  */
 static int filename_mask;
 
+/* filename to use when the input was stdin */
+static const char *stdin_label = NULL;
+
 /* Short options.  */
 static char const short_options[] =
 "0123456789A:B:C::EFGHIRUVX:abcd:e:f:hiLlnqrsuvwxyZz";
@@ -72,7 +75,8 @@
 /* Non-boolean long options that have no corresponding short equivalents.  */
 enum
 {
-  BINARY_FILES_OPTION = CHAR_MAX + 1
+  BINARY_FILES_OPTION = CHAR_MAX + 1,
+  STDIN_LABEL_OPTION,
 };
 
 /* Long options equivalences. */
@@ -94,6 +98,7 @@
   {"fixed-strings", no_argument, NULL, 'F'},
   {"help", no_argument, &show_help, 1},
   {"ignore-case", no_argument, NULL, 'i'},
+  {"label", required_argument, NULL, STDIN_LABEL_OPTION},
   {"line-number", no_argument, NULL, 'n'},
   {"line-regexp", no_argument, NULL, 'x'},
   {"mmap", no_argument, &mmap_option, 1},
@@ -829,6 +834,8 @@
     {
       desc = 0;
       filename = _("(standard input)");
+      if (stdin_label != NULL)
+	filename = stdin_label;
     }
   else
     {
@@ -1415,6 +1422,9 @@
 	else
 	  fatal (_("unknown binary-files type"), 0);
 	break;
+      case STDIN_LABEL_OPTION:
+	stdin_label = optarg;
+	break;
       case 0:
 	/* long options */
 	break;





More information about the Submit mailing list