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