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