3 # Copyright (c) 1994 Geoffrey M. Rehmet, Rhodes University
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 # 3. All advertising materials mentioning features or use of this software
15 # must display the following acknowledgement:
16 # This product includes software developed by Geoffrey M. Rehmet
17 # 4. Neither the name of Geoffrey M. Rehmet nor that of Rhodes University
18 # may be used to endorse or promote products derived from this software
19 # without specific prior written permission.
21 # THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 # IN NO EVENT SHALL GEOFFREY M. REHMET OR RHODES UNIVERSITY BE LIABLE
25 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 # a utility for manipulating manual pages
38 # compress uncompressed man pages (elliminating .so's)
39 # this is now two-pass. If possible, .so's
40 # are replaced with hard links
41 # uncompress compressed man pages
42 # Things to watch out for:
43 # Hard links - careful with g(un)zipping!
44 # .so's - throw everything through soelim before gzip!
45 # symlinks - ignore these - eg: expn is its own man page:
46 # don't want to compress this!
48 PATH=/bin:/sbin:/usr/bin:/usr/sbin; export PATH
63 # less than 3 fields - don't know what to do with this
64 if [ $# -lt 3 ] ; then
65 IFS=" " ; echo ignoring $pname 1>&2 ; return 0 ;
67 # construct name and section
69 while [ $# -gt 2 ] ; do
79 IFS=" " ; set `file $pname`
80 if [ $2 != "gzip" ] ; then
81 echo moving hard link $pname 1>&2
82 mv $pname $fname.$ext # link
84 if [ $2 != "symbolic" ] ; then
85 echo gunzipping page $pname 1>&2
86 temp=`mktemp -t manager` || exit 1
87 gunzip -c $pname > $temp
91 mv $pname $fname.$sect
94 # skip symlinks - this can be
95 # a program like expn, which is
97 echo skipping symlink $pname 1>&2
102 echo skipping file $pname 1>&2
105 # reset IFS - this is important!
111 # Uncompress manpages in paths
120 while [ $# != 0 ] ; do
126 *cat?) ;; # ignore cat directories
139 echo "directory $1 not found" 1>&2
146 # Remove .so's from one file
154 so_entries=`grep "^\.so" $1 | wc -l`
155 if [ $so_entries -eq 0 ] ; then return 0 ; fi
157 # we have a page with a .so in it
158 echo $1 contains a .so entry 2>&1
160 # now check how many lines in the file
163 # if the file is only one line long, we can replace it
165 if [ $lines -eq 1 ] ; then
167 echo replacing $fname with a hard link
172 echo inlining page $fname 1>&2
173 temp=`mktemp -t manager` || exit 1
175 (cd .. ; soelim ) > $temp
184 # Remove .so entries from man pages
185 # If a page consists of just one line with a .so,
186 # replace it with a hard link
197 if [ $# -lt 2 ] ; then
198 IFS=" " ; echo ignoring $pname 1>&2 ; return 0 ;
200 # construct name and section
202 while [ $# -gt 1 ] ; do
210 gz) { echo file $pname already gzipped 1>&2 ; } ;;
211 Z) { echo file $pname already compressed 1>&2 ; } ;;
213 IFS=" " ; set `file $pname`
214 if [ $2 = "gzip" ] ; then
215 echo moving hard link $pname 1>&2
216 mv $pname $pname.gz # link
218 if [ $2 != "symbolic" ] ; then
219 echo "removing .so's in page $pname" 1>&2
222 # skip symlink - this can be
223 # a program like expn, which is
225 echo skipping symlink $pname 1>&2
230 echo skipping file $pname 1>&2
233 # reset IFS - this is important!
240 # We need to watch out for hard links here.
251 if [ $# -lt 2 ] ; then
252 IFS=" " ; echo ignoring $pname 1>&2 ; return 0 ;
254 # construct name and section
256 while [ $# -gt 1 ] ; do
264 gz) { echo file $pname already gzipped 1>&2 ; } ;;
265 Z) { echo file $pname already compressed 1>&2 ; } ;;
267 IFS=" " ; set `file $pname`
268 if [ $2 = "gzip" ] ; then
269 echo moving hard link $pname 1>&2
270 mv $pname $pname.gz # link
272 if [ $2 != "symbolic" ] ; then
273 echo gzipping page $pname 1>&2
274 temp=`mktemp -t manager` || exit 1
276 (cd .. ; soelim )| gzip -c -- > $temp
283 # skip symlink - this can be
284 # a program like expn, which is
286 echo skipping symlink $pname 1>&2
291 echo skipping file $pname 1>&2
294 # reset IFS - this is important!
299 # Compress man pages in paths
311 while [ $# != 0 ] ; do
317 *cat?) ;; # ignore cat directories
320 do_compress_so $what $i
330 echo "directory $1 not found" 1>&2
337 # Display a usage message
341 echo "usage: $1 -compress <path> ... " 1>&2
342 echo " $1 -uncompress <path> ... " 1>&2
347 # remove .so's and do compress
351 # First remove all so's from the pages to be compressed
352 do_compress_so remove_so "$@"
353 # now do ahead and compress the pages
354 do_compress_so compress_page "$@"
360 if [ $# -lt 2 ] ; then ctl_usage $0 ; fi ;
363 -compress) shift ; do_compress "$@" ;;
364 -uncompress) shift ; do_uncompress "$@" ;;