1166255Sdelphij#!/bin/sh - 2166255Sdelphij# 3273507Sdelphij# $NetBSD: zmore,v 1.5 2013/12/06 13:33:15 pettai Exp $ 4166255Sdelphij# 5273507Sdelphij# $OpenBSD: zmore,v 1.6 2008/08/20 09:22:02 mpf Exp $ 6273507Sdelphij# 7166255Sdelphij#- 8166255Sdelphij# Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com> 9166255Sdelphij# 10166255Sdelphij# Permission to use, copy, modify, and distribute this software for any 11166255Sdelphij# purpose with or without fee is hereby granted, provided that the above 12166255Sdelphij# copyright notice and this permission notice appear in all copies. 13166255Sdelphij# 14166255Sdelphij# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 15166255Sdelphij# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 16166255Sdelphij# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 17166255Sdelphij# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 18166255Sdelphij# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 19166255Sdelphij# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 20166255Sdelphij# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 21166255Sdelphij# 22166255Sdelphij# Sponsored in part by the Defense Advanced Research Projects 23166255Sdelphij# Agency (DARPA) and Air Force Research Laboratory, Air Force 24166255Sdelphij# Materiel Command, USAF, under agreement number F39502-99-1-0512. 25166255Sdelphij# 26166255Sdelphij# $FreeBSD$ 27166255Sdelphij 28166255Sdelphij# Pull out any command line flags so we can pass them to more/less 29166255Sdelphijflags= 30166255Sdelphijwhile test $# -ne 0; do 31166255Sdelphij case "$1" in 32166255Sdelphij --) 33166255Sdelphij shift 34166255Sdelphij break 35166255Sdelphij ;; 36166255Sdelphij -*) 37166255Sdelphij flags="$flags $1" 38166255Sdelphij shift 39166255Sdelphij ;; 40166255Sdelphij *) 41166255Sdelphij break 42166255Sdelphij ;; 43166255Sdelphij esac 44166255Sdelphijdone 45166255Sdelphij 46273507Sdelphijif [ `basename $0` = "zless" ] ; then 47273507Sdelphij pager=${PAGER-less} 48273507Sdelphijelse 49273507Sdelphij pager=${PAGER-more} 50273507Sdelphijfi 51273507Sdelphij 52166255Sdelphij# No files means read from stdin 53166255Sdelphijif [ $# -eq 0 ]; then 54273507Sdelphij gzip -cdfq 2>&1 | $pager $flags 55166255Sdelphij exit 0 56166255Sdelphijfi 57166255Sdelphij 58166255Sdelphijoterm=`stty -g 2>/dev/null` 59166255Sdelphijwhile test $# -ne 0; do 60273507Sdelphij gzip -cdfq "$1" 2>&1 | $pager $flags 61166255Sdelphij prev="$1" 62166255Sdelphij shift 63166255Sdelphij if tty -s && test -n "$oterm" -a $# -gt 0; then 64166255Sdelphij #echo -n "--More--(Next file: $1)" 65166255Sdelphij echo -n "$prev (END) - Next: $1 " 66166255Sdelphij trap "stty $oterm 2>/dev/null" 0 1 2 3 13 15 67166255Sdelphij stty cbreak -echo 2>/dev/null 68166255Sdelphij REPLY=`dd bs=1 count=1 2>/dev/null` 69166255Sdelphij stty $oterm 2>/dev/null 70166255Sdelphij trap - 0 1 2 3 13 15 71166255Sdelphij echo 72166255Sdelphij case "$REPLY" in 73166255Sdelphij s) 74166255Sdelphij shift 75166255Sdelphij ;; 76166255Sdelphij e|q) 77166255Sdelphij break 78166255Sdelphij ;; 79166255Sdelphij esac 80166255Sdelphij fi 81166255Sdelphijdone 82166255Sdelphijexit 0 83