zmore revision 1.3
11.1Smrg#!/bin/sh -
21.1Smrg#
31.3Swiz# $NetBSD: zmore,v 1.3 2004/03/29 09:59:42 wiz Exp $
41.2Swiz#
51.1Smrg# $OpenBSD: zmore,v 1.4 2003/07/29 07:42:45 otto 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.1Smrg# No files means read from stdin
451.1Smrgif [ $# -eq 0 ]; then
461.3Swiz	gzip -cdfq 2>&1 | ${PAGER-more} $flags
471.1Smrg	exit 0
481.1Smrgfi
491.1Smrg
501.1Smrgoterm=`stty -g 2>/dev/null`
511.1Smrgwhile test $# -ne 0; do
521.3Swiz	gzip -cdfq "$1" 2>&1 | ${PAGER-more} $flags
531.1Smrg	prev="$1"
541.1Smrg	shift
551.1Smrg	if tty -s && test -n "$oterm" -a $# -gt 0; then
561.1Smrg		#echo -n "--More--(Next file: $1)"
571.1Smrg		echo -n "$prev (END) - Next: $1 "
581.1Smrg		trap "stty $oterm 2>/dev/null" 0 1 2 3 13 15
591.1Smrg		stty cbreak -echo 2>/dev/null
601.1Smrg		REPLY=`dd bs=1 count=1 2>/dev/null`
611.1Smrg		stty $oterm 2>/dev/null
621.1Smrg		trap - 0 1 2 3 13 15
631.1Smrg		echo
641.1Smrg		case "$REPLY" in
651.1Smrg			s)
661.1Smrg				shift
671.1Smrg				;;
681.1Smrg			e|q)
691.1Smrg				break
701.1Smrg				;;
711.1Smrg		esac
721.1Smrg	fi
731.1Smrgdone
741.1Smrgexit 0
75