# (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
-zcat=zstdcat
+grep=${GREP:-grep}
+zcat=${ZCAT:-zstdcat}
endofopts=0
pattern_found=0
hyphen=0
silent=0
-prg=$(basename "$0")
+prog=${0##*/}
# handle being called 'zegrep' or 'zfgrep'
-case "${prg}" in
- *zegrep) grep_args="-E";;
- *zfgrep) grep_args="-F";;
+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
# from GNU grep-2.5.1 -- keep in sync!
-[ABCDXdefm])
if [ "$#" -lt 2 ]; then
- printf '%s: missing argument for %s flag\n' "${prg}" "$1" >&2
+ printf '%s: missing argument for %s flag\n' "${prog}" "$1" >&2
exit 1
fi
case "$1" in
elif [ "${hyphen}" -gt 0 ]; then
pattern="-"
else
- printf '%s: missing pattern\n' "${prg}" >&2
+ printf '%s: missing pattern\n' "${prog}" >&2
exit 1
fi
fi
if [ "${silent}" -lt 1 ] && [ "$#" -gt 1 ]; then
grep_args="-H ${grep_args}"
fi
- CUR_EXIT_CODE=0
- EXIT_CODE=1
set -f
while [ "$#" -gt 0 ]; do
# shellcheck disable=SC2086
"${zcat}" -fq -- "$1" | "${grep}" --label="${1}" ${grep_args} -- "${pattern}" -
- CUR_EXIT_CODE=$?
- if [ "${CUR_EXIT_CODE}" -eq 0 ] && [ "${EXIT_CODE}" -ne 1 ]; then
- EXIT_CODE=0
- fi
+ [ "$?" -ne 0 ] && EXIT_CODE=1
shift
done
set +f
$(RM) *.gz *.zst README2.md gz_zstd zstd_gz hello.txt
test-zstdgrep: gzstd
- @echo a | $(PRGDIR)/zstd | $(PRGDIR)/zstdgrep a
- @echo a | $(PRGDIR)/zstd | $(PRGDIR)/zstdgrep b && return 1 || return 0
+ -[ -f /tmp/zstdcat ] || ln -s $(PWD)/$(PRGDIR)/zstd /tmp/zstdcat
+ echo a | $(PRGDIR)/zstd | env ZCAT=/tmp/zstdcat $(PRGDIR)/zstdgrep a
+ echo a | $(PRGDIR)/zstd | env ZCAT=/tmp/zstdcat $(PRGDIR)/zstdgrep b && return 1 || return 0
+ -echo 'hello world' > test.txt && $(PRGDIR)/zstd test.txt
+ env ZCAT=/tmp/zstdcat $(PRGDIR)/zstdgrep hello test.txt.zst
+ env ZCAT=/tmp/zstdcat $(PRGDIR)/zstdgrep weird test.txt.zst && return 1 || return 0
test-fullbench: fullbench datagen
$(QEMU_SYS) ./fullbench -i1