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