summaryrefslogtreecommitdiffstats
path: root/src/zstd/programs/zstdgrep
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:54:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:54:28 +0000
commite6918187568dbd01842d8d1d2c808ce16a894239 (patch)
tree64f88b554b444a49f656b6c656111a145cbbaa28 /src/zstd/programs/zstdgrep
parentInitial commit. (diff)
downloadceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz
ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rwxr-xr-xsrc/zstd/programs/zstdgrep134
-rw-r--r--src/zstd/programs/zstdgrep.123
-rw-r--r--src/zstd/programs/zstdgrep.1.md26
3 files changed, 183 insertions, 0 deletions
diff --git a/src/zstd/programs/zstdgrep b/src/zstd/programs/zstdgrep
new file mode 100755
index 000000000..61efaa947
--- /dev/null
+++ b/src/zstd/programs/zstdgrep
@@ -0,0 +1,134 @@
+#!/bin/sh
+#
+# Copyright (c) 2003 Thomas Klausner.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+grep=${GREP:-grep}
+zcat=${ZCAT:-zstdcat}
+
+endofopts=0
+pattern_found=0
+grep_args=""
+hyphen=0
+silent=0
+
+prog=${0##*/}
+
+# handle being called 'zegrep' or 'zfgrep'
+case $prog in
+ *egrep*) prog=zegrep; grep_args='-E';;
+ *fgrep*) prog=zfgrep; grep_args='-F';;
+ *) prog=zstdgrep;;
+esac
+
+# skip all options and pass them on to grep taking care of options
+# with arguments, and if -e was supplied
+
+while [ "$#" -gt 0 ] && [ "${endofopts}" -eq 0 ]; do
+ case "$1" in
+ # from GNU grep-2.5.1 -- keep in sync!
+ -[ABCDXdefm])
+ if [ "$#" -lt 2 ]; then
+ printf '%s: missing argument for %s flag\n' "${prog}" "$1" >&2
+ exit 1
+ fi
+ case "$1" in
+ -e)
+ pattern="$2"
+ pattern_found=1
+ shift 2
+ break
+ ;;
+ -f)
+ pattern_found=2
+ ;;
+ *)
+ ;;
+ esac
+ grep_args="${grep_args} $1 $2"
+ shift 2
+ ;;
+ --)
+ shift
+ endofopts=1
+ ;;
+ -)
+ hyphen=1
+ shift
+ ;;
+ -h)
+ silent=1
+ shift
+ ;;
+ -*)
+ grep_args="${grep_args} $1"
+ shift
+ ;;
+ *)
+ # pattern to grep for
+ endofopts=1
+ ;;
+ esac
+done
+
+# if no -e option was found, take next argument as grep-pattern
+if [ "${pattern_found}" -lt 1 ]; then
+ if [ "$#" -ge 1 ]; then
+ pattern="$1"
+ shift
+ elif [ "${hyphen}" -gt 0 ]; then
+ pattern="-"
+ else
+ printf '%s: missing pattern\n' "${prog}" >&2
+ exit 1
+ fi
+fi
+
+EXIT_CODE=0
+# call grep ...
+if [ "$#" -lt 1 ]; then
+ # ... on stdin
+ set -f # Disable file name generation (globbing).
+ # shellcheck disable=SC2086
+ "${zcat}" - | "${grep}" ${grep_args} -- "${pattern}" -
+ EXIT_CODE=$?
+ set +f
+else
+ # ... on all files given on the command line
+ if [ "${silent}" -lt 1 ] && [ "$#" -gt 1 ]; then
+ grep_args="-H ${grep_args}"
+ fi
+ set -f
+ while [ "$#" -gt 0 ]; do
+ # shellcheck disable=SC2086
+ if [ $pattern_found -eq 2 ]; then
+ "${zcat}" -- "$1" | "${grep}" --label="${1}" ${grep_args} -- -
+ else
+ "${zcat}" -- "$1" | "${grep}" --label="${1}" ${grep_args} -- "${pattern}" -
+ fi
+ [ "$?" -ne 0 ] && EXIT_CODE=1
+ shift
+ done
+ set +f
+fi
+
+exit "${EXIT_CODE}"
diff --git a/src/zstd/programs/zstdgrep.1 b/src/zstd/programs/zstdgrep.1
new file mode 100644
index 000000000..fe1d29bbb
--- /dev/null
+++ b/src/zstd/programs/zstdgrep.1
@@ -0,0 +1,23 @@
+.
+.TH "ZSTDGREP" "1" "May 2020" "zstd 1.4.5" "User Commands"
+.
+.SH "NAME"
+\fBzstdgrep\fR \- print lines matching a pattern in zstandard\-compressed files
+.
+.SH "SYNOPSIS"
+\fBzstdgrep\fR [\fIgrep\-flags\fR] [\-\-] \fIpattern\fR [\fIfiles\fR \.\.\.]
+.
+.SH "DESCRIPTION"
+\fBzstdgrep\fR runs \fBgrep (1)\fR on files or stdin, if no files argument is given, after decompressing them with \fBzstdcat (1)\fR\.
+.
+.P
+The grep\-flags and pattern arguments are passed on to \fBgrep (1)\fR\. If an \fB\-e\fR flag is found in the \fBgrep\-flags\fR, \fBzstdgrep\fR will not look for a pattern argument\.
+.
+.SH "EXIT STATUS"
+In case of missing arguments or missing pattern, 1 will be returned, otherwise 0\.
+.
+.SH "SEE ALSO"
+\fBzstd (1)\fR
+.
+.SH "AUTHORS"
+Thomas Klausner \fIwiz@NetBSD\.org\fR
diff --git a/src/zstd/programs/zstdgrep.1.md b/src/zstd/programs/zstdgrep.1.md
new file mode 100644
index 000000000..363ad4f99
--- /dev/null
+++ b/src/zstd/programs/zstdgrep.1.md
@@ -0,0 +1,26 @@
+zstdgrep(1) -- print lines matching a pattern in zstandard-compressed files
+============================================================================
+
+SYNOPSIS
+--------
+
+`zstdgrep` [*grep-flags*] [--] _pattern_ [_files_ ...]
+
+
+DESCRIPTION
+-----------
+`zstdgrep` runs `grep (1)` on files or stdin, if no files argument is given, after decompressing them with `zstdcat (1)`.
+
+The grep-flags and pattern arguments are passed on to `grep (1)`. If an `-e` flag is found in the `grep-flags`, `zstdgrep` will not look for a pattern argument.
+
+EXIT STATUS
+-----------
+In case of missing arguments or missing pattern, 1 will be returned, otherwise 0.
+
+SEE ALSO
+--------
+`zstd (1)`
+
+AUTHORS
+-------
+Thomas Klausner <wiz@NetBSD.org>