1#!/bin/sh - 2# 3# $NetBSD: zmore,v 1.2 2003/12/28 12:43:43 wiz Exp $ 4# $OpenBSD: zmore,v 1.4 2003/07/29 07:42:45 otto Exp $ 5# 6# Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com> 7# 8# Permission to use, copy, modify, and distribute this software for any 9# purpose with or without fee is hereby granted, provided that the above 10# copyright notice and this permission notice appear in all copies. 11# 12# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 13# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 14# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 15# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 16# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19# 20# Sponsored in part by the Defense Advanced Research Projects 21# Agency (DARPA) and Air Force Research Laboratory, Air Force 22# Materiel Command, USAF, under agreement number F39502-99-1-0512. 23# 24 25# Pull out any command line flags so we can pass them to more/less 26flags= 27while test $# -ne 0; do 28 case "$1" in 29 --) 30 shift 31 break 32 ;; 33 -*) 34 flags="$flags $1" 35 shift 36 ;; 37 *) 38 break 39 ;; 40 esac 41done 42 43pager=${PAGER-more} 44 45# No files means read from stdin 46if [ $# -eq 0 ]; then 47 gzip -cdfq 2>&1 | $pager $flags 48 exit 0 49fi 50 51oterm=`stty -g 2>/dev/null` 52while test $# -ne 0; do 53 gzip -cdfq "$1" 2>&1 | $pager $flags 54 prev="$1" 55 shift 56 if tty -s && test -n "$oterm" -a $# -gt 0; then 57 #echo -n "--More--(Next file: $1)" 58 echo -n "$prev (END) - Next: $1 " 59 trap "stty $oterm 2>/dev/null" 0 1 2 3 13 15 60 stty cbreak -echo 2>/dev/null 61 REPLY=`dd bs=1 count=1 2>/dev/null` 62 stty $oterm 2>/dev/null 63 trap - 0 1 2 3 13 15 64 echo 65 case "$REPLY" in 66 s) 67 shift 68 ;; 69 e|q) 70 break 71 ;; 72 esac 73 fi 74done 75exit 0 76