]> icculus.org git repositories - icculus/xz.git/blob - src/scripts/lzmore
Imported to git.
[icculus/xz.git] / src / scripts / lzmore
1 #!/bin/sh
2
3 # Copyright (C) 2001 Free Software Foundation
4 # Copyright (C) 1992, 1993 Jean-loup Gailly
5 # Adapted to LZMA utils from gzip-1.3.3 + Red Hat's security patches
6
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
10 # any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 # 02111-1307, USA.
21
22 if test "`echo "$0" | sed 's|.*/||'`" = "lzless"; then
23   PAGER=less
24 fi
25
26 if test "`echo -n a`" = "-n a"; then
27   # looks like a SysV system:
28   n1=''; n2='\c'
29 else
30   n1='-n'; n2=''
31 fi
32 oldtty=`stty -g 2>/dev/null`
33 if stty -cbreak 2>/dev/null; then
34   cb='cbreak'; ncb='-cbreak'
35 else
36   # 'stty min 1' resets eof to ^a on both SunOS and SysV!
37   cb='min 1 -icanon'; ncb='icanon eof ^d'
38 fi
39 if test $? -eq 0 -a -n "$oldtty"; then
40    trap 'stty $oldtty 2>/dev/null; exit' 0 2 3 5 10 13 15
41 else
42    trap 'stty $ncb echo 2>/dev/null; exit' 0 2 3 5 10 13 15
43 fi
44
45 if test $# = 0; then
46     if test -t 0; then
47         echo usage: zmore files...
48     else
49         lzma -dc | eval ${PAGER-more}
50     fi
51 else
52     FIRST=1
53     for FILE
54     do
55         < "$FILE" || continue
56         if test $FIRST -eq 0; then
57                 echo $n1 "--More--(Next file: $FILE)$n2"
58                 stty $cb -echo 2>/dev/null
59                 ANS=`dd bs=1 count=1 2>/dev/null`
60                 stty $ncb echo 2>/dev/null
61                 echo " "
62                 if test "$ANS" = 'e' -o "$ANS" = 'q'; then
63                         exit
64                 fi
65         fi
66         if test "$ANS" != 's'; then
67                 echo "------> $FILE <------"
68                 lzma -dc "$FILE" | eval ${PAGER-more}
69         fi
70         if test -t; then
71                 FIRST=0
72         fi
73     done
74 fi