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