From 81571c718dc064561b99e250825bd93444cec4aa Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@fb.com>
Date: Mon, 11 May 2015 08:07:20 -0700
Subject: [PATCH] maint: unify three argv-processing calls

* src/grep.c (main): Unify three calls to grep_commandline_arg.
---
 src/grep.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/src/grep.c b/src/grep.c
index 4c3aa28..77ddce5 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -2589,20 +2589,27 @@ main (int argc, char **argv)
   if (fts_options & FTS_LOGICAL && devices == READ_COMMAND_LINE_DEVICES)
     devices = READ_DEVICES;

+  char **files;
   if (optind < argc)
     {
-      ok = true;
-      do
-        ok &= grep_command_line_arg (argv[optind]);
-      while (++optind < argc);
+      files = argv + optind;
     }
   else if (directories == RECURSE_DIRECTORIES && prepended < last_recursive)
     {
+      static char *cwd_only[] = { (char *) ".", NULL };
+      files = cwd_only;
       omit_dot_slash = true;
-      ok = grep_command_line_arg (".");
     }
   else
-    ok = grep_command_line_arg ("-");
+    {
+      static char *stdin_only[] = { (char *) "-", NULL };
+      files = stdin_only;
+    }
+
+  ok = true;
+  do
+    ok &= grep_command_line_arg (*files++);
+  while (*files != NULL);

   /* We register via atexit() to test stdout.  */
   exit (errseen ? EXIT_TROUBLE : ok);
-- 
2.3.7

