zmore revision 1.5
11.1Smrg#!/bin/sh -
21.1Smrg#
31.5Spettai# $NetBSD: zmore,v 1.5 2013/12/06 13:33:15 pettai Exp $
41.2Swiz#
51.4Spettai# $OpenBSD: zmore,v 1.6 2008/08/20 09:22:02 mpf Exp $
61.1Smrg#
71.1Smrg# Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
81.1Smrg#
91.1Smrg# Permission to use, copy, modify, and distribute this software for any
101.1Smrg# purpose with or without fee is hereby granted, provided that the above
111.1Smrg# copyright notice and this permission notice appear in all copies.
121.1Smrg#
131.1Smrg# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
141.1Smrg# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
151.1Smrg# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
161.1Smrg# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
171.1Smrg# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
181.1Smrg# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
191.1Smrg# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
201.1Smrg#
211.1Smrg# Sponsored in part by the Defense Advanced Research Projects
221.1Smrg# Agency (DARPA) and Air Force Research Laboratory, Air Force
231.1Smrg# Materiel Command, USAF, under agreement number F39502-99-1-0512.
241.1Smrg#
251.1Smrg
261.1Smrg# Pull out any command line flags so we can pass them to more/less
271.1Smrgflags=
281.1Smrgwhile test $# -ne 0; do
291.1Smrg	case "$1" in
301.1Smrg		--)
311.1Smrg			shift
321.1Smrg			break
331.1Smrg			;;
341.1Smrg		-*)
351.1Smrg			flags="$flags $1"
361.1Smrg			shift
371.1Smrg			;;
381.1Smrg		*)
391.1Smrg			break
401.1Smrg			;;
411.1Smrg	esac
421.1Smrgdone
431.1Smrg
441.5Spettaiif [ `basename $0` = "zless" ] ; then
451.4Spettai	pager=${PAGER-less}
461.4Spettaielse
471.4Spettai	pager=${PAGER-more}
481.4Spettaifi
491.4Spettai
501.1Smrg# No files means read from stdin
511.1Smrgif [ $# -eq 0 ]; then
521.5Spettai	gzip -cdfq 2>&1 | $pager $flags
531.1Smrg	exit 0
541.1Smrgfi
551.1Smrg
561.1Smrgoterm=`stty -g 2>/dev/null`
571.1Smrgwhile test $# -ne 0; do
581.5Spettai	gzip -cdfq "$1" 2>&1 | $pager $flags
591.1Smrg	prev="$1"
601.1Smrg	shift
611.1Smrg	if tty -s && test -n "$oterm" -a $# -gt 0; then
621.1Smrg		#echo -n "--More--(Next file: $1)"
631.1Smrg		echo -n "$prev (END) - Next: $1 "
641.1Smrg		trap "stty $oterm 2>/dev/null" 0 1 2 3 13 15
651.1Smrg		stty cbreak -echo 2>/dev/null
661.1Smrg		REPLY=`dd bs=1 count=1 2>/dev/null`
671.1Smrg		stty $oterm 2>/dev/null
681.1Smrg		trap - 0 1 2 3 13 15
691.1Smrg		echo
701.1Smrg		case "$REPLY" in
711.1Smrg			s)
721.1Smrg				shift
731.1Smrg				;;
741.1Smrg			e|q)
751.1Smrg				break
761.1Smrg				;;
771.1Smrg		esac
781.1Smrg	fi
791.1Smrgdone
801.1Smrgexit 0
81