xref: /dragonfly/contrib/xz/src/scripts/xzmore.in (revision 5fb3968e)
1#!@POSIX_SHELL@
2
3# Copyright (C) 2001, 2002, 2007 Free Software Foundation
4# Copyright (C) 1992, 1993 Jean-loup Gailly
5
6# Modified for XZ Utils by Andrew Dudman and Lasse Collin.
7
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17
18@enable_path_for_scripts@
19#SET_PATH - This line is a placeholder to ease patching this script.
20
21# Instead of unsetting XZ_OPT, just make sure that xz will use file format
22# autodetection. This way memory usage limit and thread limit can be
23# specified via XZ_OPT.
24xz='@xz@ --format=auto'
25
26version='xzmore (@PACKAGE_NAME@) @VERSION@'
27
28usage="Usage: ${0##*/} [OPTION]... [FILE]...
29Like 'more', but operate on the uncompressed contents of xz compressed FILEs.
30
31Report bugs to <@PACKAGE_BUGREPORT@>."
32
33case $1 in
34	--help)    echo "$usage" || exit 2; exit;;
35	--version) echo "$version" || exit 2; exit;;
36esac
37
38oldtty=`stty -g 2>/dev/null`
39if stty -cbreak 2>/dev/null; then
40	cb='cbreak'; ncb='-cbreak'
41else
42	# 'stty min 1' resets eof to ^a on both SunOS and SysV!
43	cb='min 1 -icanon'; ncb='icanon eof ^d'
44fi
45if test $? -eq 0 && test -n "$oldtty"; then
46	trap 'stty $oldtty 2>/dev/null; exit' 0 2 3 5 10 13 15
47else
48	trap 'stty $ncb echo 2>/dev/null; exit' 0 2 3 5 10 13 15
49fi
50
51if test $# = 0; then
52	if test -t 0; then
53		echo "$usage"; exit 1
54	else
55		$xz -cdfq | eval "${PAGER:-more}"
56	fi
57else
58	FIRST=1
59	for FILE; do
60		< "$FILE" || continue
61		if test $FIRST -eq 0; then
62			printf "%s--More--(Next file: %s)" "" "$FILE"
63			stty $cb -echo 2>/dev/null
64			ANS=`dd bs=1 count=1 2>/dev/null`
65			stty $ncb echo 2>/dev/null
66			echo " "
67			case "$ANS" in
68				[eq]) exit;;
69			esac
70		fi
71		if test "$ANS" != 's'; then
72			echo "------> $FILE <------"
73			$xz -cdfq -- "$FILE" | eval "${PAGER:-more}"
74		fi
75		if test -t 1; then
76			FIRST=0
77		fi
78	done
79fi
80