[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#29124: [PATCH] grep: simplify out_file handling
From: |
Zev Weiss |
Subject: |
bug#29124: [PATCH] grep: simplify out_file handling |
Date: |
Fri, 3 Nov 2017 03:09:25 -0500 |
* src/grep.c (grepdirent): Don't twiddle out_file back and forth
during recursion.
(main): Set out_file once based on command-line arguments.
* bootstrap.conf (gnulib_modules): Add isdir gnulib module.
---
bootstrap.conf | 1 +
src/grep.c | 18 ++++++++----------
2 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/bootstrap.conf b/bootstrap.conf
index 1c50974..da7b711 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -50,6 +50,7 @@ intprops
inttypes
isatty
isblank
+isdir
iswctype
largefile
locale
diff --git a/src/grep.c b/src/grep.c
index 0643a7e..66d9e91 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -42,6 +42,7 @@
#include "getprogname.h"
#include "grep.h"
#include "intprops.h"
+#include "isdir.h"
#include "propername.h"
#include "quote.h"
#include "safe-read.h"
@@ -1590,11 +1591,7 @@ grepdirent (FTS *fts, FTSENT *ent, bool command_line)
command_line &= ent->fts_level == FTS_ROOTLEVEL;
if (ent->fts_info == FTS_DP)
- {
- if (directories == RECURSE_DIRECTORIES && command_line)
- out_file &= ~ (2 * !no_filenames);
- return true;
- }
+ return true;
if (!command_line
&& skipped_file (ent->fts_name, false,
@@ -1615,10 +1612,7 @@ grepdirent (FTS *fts, FTSENT *ent, bool command_line)
{
case FTS_D:
if (directories == RECURSE_DIRECTORIES)
- {
- out_file |= 2 * !no_filenames;
- return true;
- }
+ return true;
fts_set (fts, ent, FTS_SKIP);
break;
@@ -2885,7 +2879,11 @@ main (int argc, char **argv)
&match_size, NULL) == 0)
== out_invert);
- if ((argc - optind > 1 && !no_filenames) || with_filenames)
+ if (((argc - optind > 1
+ || (directories == RECURSE_DIRECTORIES
+ && !(argc - optind == 1 && !isdir (argv[optind]))))
+ && !no_filenames)
+ || with_filenames)
out_file = 1;
if (binary)
--
2.15.0
- bug#29124: [PATCH] grep: simplify out_file handling,
Zev Weiss <=