xref: /netbsd-src/usr.bin/gzip/zmore (revision 515a14aba776087bb8acb9c1a8ccfcfa99da3902)
15ddb4360Smrg#!/bin/sh -
25ddb4360Smrg#
3*515a14abSpettai# $NetBSD: zmore,v 1.5 2013/12/06 13:33:15 pettai Exp $
43a92ef57Swiz#
554844dd5Spettai# $OpenBSD: zmore,v 1.6 2008/08/20 09:22:02 mpf Exp $
65ddb4360Smrg#
75ddb4360Smrg# Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
85ddb4360Smrg#
95ddb4360Smrg# Permission to use, copy, modify, and distribute this software for any
105ddb4360Smrg# purpose with or without fee is hereby granted, provided that the above
115ddb4360Smrg# copyright notice and this permission notice appear in all copies.
125ddb4360Smrg#
135ddb4360Smrg# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
145ddb4360Smrg# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
155ddb4360Smrg# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
165ddb4360Smrg# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
175ddb4360Smrg# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
185ddb4360Smrg# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
195ddb4360Smrg# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
205ddb4360Smrg#
215ddb4360Smrg# Sponsored in part by the Defense Advanced Research Projects
225ddb4360Smrg# Agency (DARPA) and Air Force Research Laboratory, Air Force
235ddb4360Smrg# Materiel Command, USAF, under agreement number F39502-99-1-0512.
245ddb4360Smrg#
255ddb4360Smrg
265ddb4360Smrg# Pull out any command line flags so we can pass them to more/less
275ddb4360Smrgflags=
285ddb4360Smrgwhile test $# -ne 0; do
295ddb4360Smrg	case "$1" in
305ddb4360Smrg		--)
315ddb4360Smrg			shift
325ddb4360Smrg			break
335ddb4360Smrg			;;
345ddb4360Smrg		-*)
355ddb4360Smrg			flags="$flags $1"
365ddb4360Smrg			shift
375ddb4360Smrg			;;
385ddb4360Smrg		*)
395ddb4360Smrg			break
405ddb4360Smrg			;;
415ddb4360Smrg	esac
425ddb4360Smrgdone
435ddb4360Smrg
44*515a14abSpettaiif [ `basename $0` = "zless" ] ; then
4554844dd5Spettai	pager=${PAGER-less}
4654844dd5Spettaielse
4754844dd5Spettai	pager=${PAGER-more}
4854844dd5Spettaifi
4954844dd5Spettai
505ddb4360Smrg# No files means read from stdin
515ddb4360Smrgif [ $# -eq 0 ]; then
52*515a14abSpettai	gzip -cdfq 2>&1 | $pager $flags
535ddb4360Smrg	exit 0
545ddb4360Smrgfi
555ddb4360Smrg
565ddb4360Smrgoterm=`stty -g 2>/dev/null`
575ddb4360Smrgwhile test $# -ne 0; do
58*515a14abSpettai	gzip -cdfq "$1" 2>&1 | $pager $flags
595ddb4360Smrg	prev="$1"
605ddb4360Smrg	shift
615ddb4360Smrg	if tty -s && test -n "$oterm" -a $# -gt 0; then
625ddb4360Smrg		#echo -n "--More--(Next file: $1)"
635ddb4360Smrg		echo -n "$prev (END) - Next: $1 "
645ddb4360Smrg		trap "stty $oterm 2>/dev/null" 0 1 2 3 13 15
655ddb4360Smrg		stty cbreak -echo 2>/dev/null
665ddb4360Smrg		REPLY=`dd bs=1 count=1 2>/dev/null`
675ddb4360Smrg		stty $oterm 2>/dev/null
685ddb4360Smrg		trap - 0 1 2 3 13 15
695ddb4360Smrg		echo
705ddb4360Smrg		case "$REPLY" in
715ddb4360Smrg			s)
725ddb4360Smrg				shift
735ddb4360Smrg				;;
745ddb4360Smrg			e|q)
755ddb4360Smrg				break
765ddb4360Smrg				;;
775ddb4360Smrg		esac
785ddb4360Smrg	fi
795ddb4360Smrgdone
805ddb4360Smrgexit 0
81