From c3131e01f04901f007091e0cce95fb84d1cf4787 Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 27 May 2021 21:48:35 +0200 Subject: [PATCH] Add setting to suppress this-is-not-an-EPUB errors. --- man/epubgrep.1.adoc | 13 ++++++++++--- src/main.cpp | 5 +++++ src/options.cpp | 3 +++ src/options.hpp | 1 + 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/man/epubgrep.1.adoc b/man/epubgrep.1.adoc index 71ce86e..c84d8a6 100644 --- a/man/epubgrep.1.adoc +++ b/man/epubgrep.1.adoc @@ -73,6 +73,11 @@ readable by the user. Read all files under each directory, recursively. Follow all symbolic links. Silently skips directories that are not readable by the user. +*--ignore-archive-errors*:: +Ignore errors about wrong file formats. When you search directories recursively, +it is likely that there are files which are not EPUB files. This setting +suppresses errors related to them. + == USAGE [source,shellsession] @@ -104,12 +109,14 @@ occur more than once are merged. ==== Example configuration file -This example makes epubgrep always suppress the file names on output, print 2 -words of context around matches (unless overridden on the command line) and -search for mentions of the words thyme and oregano in every book. +This example makes epubgrep ignore files which are not EPUB, suppress the file +names on output, print 2 words of context around matches (unless overridden on +the command line) and search for mentions of the words thyme and oregano in +every book. [source,cfg] -------------------------------------------------------------------------------- +ignore-archive-errors no-filename context = 2 regexp = [Tt]hyme diff --git a/src/main.cpp b/src/main.cpp index cc018ab..371a4b4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -148,6 +148,11 @@ int main(int argc, char *argv[]) } catch (const zip::exception &e) { + if (opts.ignore_archive_errors && e.code == 1) + { + return EXIT_SUCCESS; + } + cerr << translate("ERROR: ") << e.what() << '\n'; cerr << format(translate("Error while searching {0:s}.") .str(), diff --git a/src/options.cpp b/src/options.cpp index ca19743..1670631 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -84,6 +84,8 @@ options parse_options(int argc, char *argv[]) ("dereference-recursive,R", translate("Read all files under each directory, recursively, " "following symlinks.") .str().data()) + ("ignore-archive-errors", + translate("Ignore errors about wrong file formats.") .str().data()) ; po::options_description options_hidden("Hidden options"); @@ -223,6 +225,7 @@ options parse_again(const po::variables_map &vm) } opts.recursive = vm.count("recursive") > 0; opts.dereference_recursive = vm.count("dereference-recursive") > 0; + opts.ignore_archive_errors = vm.count("ignore-archive-errors") > 0; if (vm.count("regexp") > 0) { diff --git a/src/options.hpp b/src/options.hpp index 71eb3d3..ee43d80 100644 --- a/src/options.hpp +++ b/src/options.hpp @@ -54,6 +54,7 @@ struct options bool recursive{false}; bool dereference_recursive{false}; std::vector input_file; + bool ignore_archive_errors{false}; }; //! Parse options and return them.