xref: /dragonfly/usr.bin/gzip/zmore (revision 36a3d1d6)
1#!/bin/sh -
2#
3# $NetBSD: zmore,v 1.2 2003/12/28 12:43:43 wiz Exp $
4# $DragonFly: src/usr.bin/gzip/zmore,v 1.1 2004/10/26 11:19:31 joerg Exp $
5# $OpenBSD: zmore,v 1.4 2003/07/29 07:42:45 otto Exp $
6#
7# Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
8#
9# Permission to use, copy, modify, and distribute this software for any
10# purpose with or without fee is hereby granted, provided that the above
11# copyright notice and this permission notice appear in all copies.
12#
13# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20#
21# Sponsored in part by the Defense Advanced Research Projects
22# Agency (DARPA) and Air Force Research Laboratory, Air Force
23# Materiel Command, USAF, under agreement number F39502-99-1-0512.
24#
25
26# Pull out any command line flags so we can pass them to more/less
27flags=
28while test $# -ne 0; do
29	case "$1" in
30		--)
31			shift
32			break
33			;;
34		-*)
35			flags="$flags $1"
36			shift
37			;;
38		*)
39			break
40			;;
41	esac
42done
43
44if [ `basename $0` = "zless" ] ; then
45	pager=${PAGER-less}
46else
47	pager=${PAGER-more}
48fi
49
50# No files means read from stdin
51if [ $# -eq 0 ]; then
52	gzip -cdfq 2>&1 | $pager $flags
53	exit 0
54fi
55
56oterm=`stty -g 2>/dev/null`
57while test $# -ne 0; do
58	gzip -cdfq "$1" 2>&1 | $pager $flags
59	prev="$1"
60	shift
61	if tty -s && test -n "$oterm" -a $# -gt 0; then
62		#echo -n "--More--(Next file: $1)"
63		echo -n "$prev (END) - Next: $1 "
64		trap "stty $oterm 2>/dev/null" 0 1 2 3 13 15
65		stty cbreak -echo 2>/dev/null
66		REPLY=`dd bs=1 count=1 2>/dev/null`
67		stty $oterm 2>/dev/null
68		trap - 0 1 2 3 13 15
69		echo
70		case "$REPLY" in
71			s)
72				shift
73				;;
74			e|q)
75				break
76				;;
77		esac
78	fi
79done
80exit 0
81