/* Zgrep - search compressed files for a regular expression Copyright (C) 2010-2022 Antonio Diaz Diaz. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #define _FILE_OFFSET_BITS 64 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #if defined __MSVCRT__ || defined __OS2__ #include #endif #include "arg_parser.h" #include "rc.h" #include "zutils.h" namespace { #include "recursive.cc" #include "zcatgrep.cc" void show_help() { std::printf( "zgrep is a front end to the program grep that allows transparent search\n" "on any combination of compressed and uncompressed files. If any file\n" "given is compressed, its decompressed content is used. If a file given\n" "does not exist, and its name does not end with one of the known\n" "extensions, zgrep tries the compressed file names corresponding to the\n" "formats supported. If a file fails to decompress, zgrep continues\n" "searching the rest of the files.\n" "\nIf a file is specified as '-', data are read from standard input,\n" "decompressed if needed, and fed to grep. Data read from standard input\n" "must be of the same type; all uncompressed or all in the same\n" "compressed format.\n" "\nIf no files are specified, recursive searches examine the current\n" "working directory, and nonrecursive searches read standard input.\n" "\n'zgrep --verbose -V' prints the version of the grep program used.\n" "\nThe formats supported are bzip2, gzip, lzip, xz, and zstd.\n" "\nUsage: zgrep [options] [files]\n" "\nExit status is 0 if match, 1 if no match, 2 if trouble.\n" "Some options only work if the grep program used supports them.\n" "\nOptions:\n" " --help display this help and exit\n" " -V, --version output version information and exit\n" " -a, --text treat all files as text\n" " -A, --after-context= print lines of trailing context\n" " -b, --byte-offset print the byte offset of each line\n" " -B, --before-context= print lines of leading context\n" " -c, --count only print a count of matching lines per file\n" " -C, --context= print lines of output context\n" " --color[=] show matched strings in color\n" " -e, --regexp= use as the pattern to match\n" " -E, --extended-regexp is an extended regular expression\n" " -f, --file= obtain patterns from \n" " -F, --fixed-strings is a set of newline-separated strings\n" " -G, --basic-regexp is a basic regular expression (default)\n" " -h, --no-filename suppress the prefixing file name on output\n" " -H, --with-filename print the file name for each match\n" " -i, --ignore-case ignore case distinctions\n" " -I ignore binary files\n" " -l, --files-with-matches only print names of files containing matches\n" " -L, --files-without-match only print names of files containing no matches\n" " --label=