5 # @(#) p.ksh 1.1 93/11/09
6 # p: page compressed & plain files in the order given
7 # 92/01/23 john h. dubois iii (john@armory.com)
8 # 92/02/14 changed incorrect zpack to pcat
10 # 92/10/11 search for file.Z and file.z if file not found
11 # 92/10/18 pass options to pager
12 # 93/11/09 Understand gzipped files too
13 # Wait after printing message about unreadable files
14 # Make less prompt include name of file being uncompressed
16 # conversion to bash v2 by Chet Ramey; renamed to pf
18 DefPager
=/local
/bin
/less
30 if [ "$1" = -h ]; then
33 Usage: $0 [pager-option ...] [filename ...]
34 Files are paged by the program specified in the user's PAGER
35 environment variable, or by $DefPager if PAGER is not set.
36 If no filename is given, text to page is read from the standard input.
37 If filenames are given, they are either paged directly, or unpacked/
38 uncompressed and then paged. Files are assumed to be in packed, compressed,
39 or gzipped format if the filename ends in .Z, .z, or .gz respectively.
40 If a filename that does not end in .Z, .z, or .gz is not found, it is
41 searched for with one of those extensions attached.
42 Each group of plain files is paged by a single instance of the pager.
43 Each packed or compressed file is paged by a separate instance of the
45 Initial arguments beginning with + or - are taken to be pager options and
46 are passed to each instance of the pager.
47 If a pager option takes a value it should be given with the option as a
48 single argument (with no space between the option and the value)."
53 while [ $# -gt 0 ]; do
55 -*|
+*) Opts
="$Opts $1" ; shift;;
60 [ -z "$PAGER" ] && PAGER
=$DefPager
63 [ $# = 0 ] && exec $PAGER $Opts
65 typeset
-i filenum
=0 badfile
=0
68 if [ ! -r "$file" ]; then
71 # Check if user specified a compressed file without giving its extension
73 if [ -r "$file.$ext" ]; then
80 if [ ! -r "$file" ]; then
81 warn
"$file: cannot read."
89 if istrue
$badfile && [ $filenum -gt 0 ]; then
90 echo -n "Press return to continue..." 1>&2
96 for file in "${files[@]}"; do
99 set -- Z zcat z pcat gz gzcat
100 # Find correct uncompression program
101 while [ $# -gt 0 ]; do
104 # Page any uncompressed files so that they will be read
105 # in the correct order
106 [ ${#plain[@]} -gt 0 ] && $PAGER $Opts "${plain[@]}"
108 # If page is less, set the prompt to include the name of
109 # the file being uncompressed. Escape the . in the extension
110 # because less treats is specially in prompts (other dots
111 # in filenames will still be mucked with).
113 *less) Prompt
="-P[${file%.$1}\\.$1] (%pb\\%)" ;;
116 $2 "$file" |
$PAGER "$Prompt" $Opts
122 *) plain
[${#plain[@]}]=$file;;
126 # Page any uncompressed files that haven't been paged yet
127 [ ${#plain[@]} -gt 0 ] && exec $PAGER $Opts "${plain[@]}"