xref: /dflybsd-src/contrib/xz/src/scripts/xzmore.in (revision b5feb3da7c498482b19d14ac6f2b1901005f7d94)
1114db65bSPeter Avalos#!@POSIX_SHELL@
2114db65bSPeter Avalos
3114db65bSPeter Avalos# Copyright (C) 2001, 2002, 2007 Free Software Foundation
4114db65bSPeter Avalos# Copyright (C) 1992, 1993 Jean-loup Gailly
5114db65bSPeter Avalos
6114db65bSPeter Avalos# Modified for XZ Utils by Andrew Dudman and Lasse Collin.
7114db65bSPeter Avalos
8114db65bSPeter Avalos# This program is free software; you can redistribute it and/or modify
9114db65bSPeter Avalos# it under the terms of the GNU General Public License as published by
10114db65bSPeter Avalos# the Free Software Foundation; either version 2 of the License, or
11114db65bSPeter Avalos# (at your option) any later version.
12114db65bSPeter Avalos
13114db65bSPeter Avalos# This program is distributed in the hope that it will be useful,
14114db65bSPeter Avalos# but WITHOUT ANY WARRANTY; without even the implied warranty of
15114db65bSPeter Avalos# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16114db65bSPeter Avalos# GNU General Public License for more details.
17114db65bSPeter Avalos
18*e151908bSDaniel Fojt@enable_path_for_scripts@
19114db65bSPeter Avalos#SET_PATH - This line is a placeholder to ease patching this script.
20114db65bSPeter Avalos
21114db65bSPeter Avalos# Instead of unsetting XZ_OPT, just make sure that xz will use file format
22114db65bSPeter Avalos# autodetection. This way memory usage limit and thread limit can be
23114db65bSPeter Avalos# specified via XZ_OPT.
24114db65bSPeter Avalosxz='@xz@ --format=auto'
25114db65bSPeter Avalos
26114db65bSPeter Avalosversion='xzmore (@PACKAGE_NAME@) @VERSION@'
27114db65bSPeter Avalos
28114db65bSPeter Avalosusage="Usage: ${0##*/} [OPTION]... [FILE]...
29114db65bSPeter AvalosLike 'more', but operate on the uncompressed contents of xz compressed FILEs.
30114db65bSPeter Avalos
31114db65bSPeter AvalosReport bugs to <@PACKAGE_BUGREPORT@>."
32114db65bSPeter Avalos
33114db65bSPeter Avaloscase $1 in
34114db65bSPeter Avalos	--help)    echo "$usage" || exit 2; exit;;
35114db65bSPeter Avalos	--version) echo "$version" || exit 2; exit;;
36114db65bSPeter Avalosesac
37114db65bSPeter Avalos
38114db65bSPeter Avalosoldtty=`stty -g 2>/dev/null`
39114db65bSPeter Avalosif stty -cbreak 2>/dev/null; then
40114db65bSPeter Avalos	cb='cbreak'; ncb='-cbreak'
41114db65bSPeter Avaloselse
42114db65bSPeter Avalos	# 'stty min 1' resets eof to ^a on both SunOS and SysV!
43114db65bSPeter Avalos	cb='min 1 -icanon'; ncb='icanon eof ^d'
44114db65bSPeter Avalosfi
45114db65bSPeter Avalosif test $? -eq 0 && test -n "$oldtty"; then
46114db65bSPeter Avalos	trap 'stty $oldtty 2>/dev/null; exit' 0 2 3 5 10 13 15
47114db65bSPeter Avaloselse
48114db65bSPeter Avalos	trap 'stty $ncb echo 2>/dev/null; exit' 0 2 3 5 10 13 15
49114db65bSPeter Avalosfi
50114db65bSPeter Avalos
51114db65bSPeter Avalosif test $# = 0; then
52114db65bSPeter Avalos	if test -t 0; then
53114db65bSPeter Avalos		echo "$usage"; exit 1
54114db65bSPeter Avalos	else
55114db65bSPeter Avalos		$xz -cdfq | eval "${PAGER:-more}"
56114db65bSPeter Avalos	fi
57114db65bSPeter Avaloselse
58114db65bSPeter Avalos	FIRST=1
59114db65bSPeter Avalos	for FILE; do
60114db65bSPeter Avalos		< "$FILE" || continue
61114db65bSPeter Avalos		if test $FIRST -eq 0; then
62114db65bSPeter Avalos			printf "%s--More--(Next file: %s)" "" "$FILE"
63114db65bSPeter Avalos			stty $cb -echo 2>/dev/null
64114db65bSPeter Avalos			ANS=`dd bs=1 count=1 2>/dev/null`
65114db65bSPeter Avalos			stty $ncb echo 2>/dev/null
66114db65bSPeter Avalos			echo " "
67114db65bSPeter Avalos			case "$ANS" in
68114db65bSPeter Avalos				[eq]) exit;;
69114db65bSPeter Avalos			esac
70114db65bSPeter Avalos		fi
71114db65bSPeter Avalos		if test "$ANS" != 's'; then
72114db65bSPeter Avalos			echo "------> $FILE <------"
73114db65bSPeter Avalos			$xz -cdfq -- "$FILE" | eval "${PAGER:-more}"
74114db65bSPeter Avalos		fi
75114db65bSPeter Avalos		if test -t 1; then
76114db65bSPeter Avalos			FIRST=0
77114db65bSPeter Avalos		fi
78114db65bSPeter Avalos	done
79114db65bSPeter Avalosfi
80