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