3 # SPDX-License-Identifier: BSD-4-Clause
5 # Copyright (c) 1994 Geoffrey M. Rehmet, Rhodes University
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
11 # 1. Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
16 # 3. All advertising materials mentioning features or use of this software
17 # must display the following acknowledgement:
18 # This product includes software developed by Geoffrey M. Rehmet
19 # 4. Neither the name of Geoffrey M. Rehmet nor that of Rhodes University
20 # may be used to endorse or promote products derived from this software
21 # without specific prior written permission.
23 # THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
24 # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 # IN NO EVENT SHALL GEOFFREY M. REHMET OR RHODES UNIVERSITY BE LIABLE
27 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 # a utility for manipulating manual pages
40 # compress uncompressed man pages (elliminating .so's)
41 # this is now two-pass. If possible, .so's
42 # are replaced with hard links
43 # uncompress compressed man pages
44 # Things to watch out for:
45 # Hard links - careful with g(un)zipping!
46 # .so's - throw everything through soelim before gzip!
47 # symlinks - ignore these - eg: expn is its own man page:
48 # don't want to compress this!
50 PATH=/bin:/sbin:/usr/bin:/usr/sbin; export PATH
65 # less than 3 fields - don't know what to do with this
66 if [ $# -lt 3 ] ; then
67 IFS=" " ; echo ignoring $pname 1>&2 ; return 0 ;
69 # construct name and section
71 while [ $# -gt 2 ] ; do
81 IFS=" " ; set `file $pname`
82 if [ $2 != "gzip" ] ; then
83 echo moving hard link $pname 1>&2
84 mv $pname $fname.$ext # link
86 if [ $2 != "symbolic" ] ; then
87 echo gunzipping page $pname 1>&2
88 temp=`mktemp -t manager` || exit 1
89 gunzip -c $pname > $temp
93 mv $pname $fname.$sect
96 # skip symlinks - this can be
97 # a program like expn, which is
99 echo skipping symlink $pname 1>&2
104 echo skipping file $pname 1>&2
107 # reset IFS - this is important!
113 # Uncompress manpages in paths
122 while [ $# != 0 ] ; do
128 *cat?) ;; # ignore cat directories
141 echo "directory $1 not found" 1>&2
148 # Remove .so's from one file
156 so_entries=`grep "^\.so" $1 | wc -l`
157 if [ $so_entries -eq 0 ] ; then return 0 ; fi
159 # we have a page with a .so in it
160 echo $1 contains a .so entry 2>&1
162 # now check how many lines in the file
165 # if the file is only one line long, we can replace it
167 if [ $lines -eq 1 ] ; then
169 echo replacing $fname with a hard link
174 echo inlining page $fname 1>&2
175 temp=`mktemp -t manager` || exit 1
177 (cd .. ; soelim ) > $temp
186 # Remove .so entries from man pages
187 # If a page consists of just one line with a .so,
188 # replace it with a hard link
199 if [ $# -lt 2 ] ; then
200 IFS=" " ; echo ignoring $pname 1>&2 ; return 0 ;
202 # construct name and section
204 while [ $# -gt 1 ] ; do
212 gz) { echo file $pname already gzipped 1>&2 ; } ;;
213 Z) { echo file $pname already compressed 1>&2 ; } ;;
215 IFS=" " ; set `file $pname`
216 if [ $2 = "gzip" ] ; then
217 echo moving hard link $pname 1>&2
218 mv $pname $pname.gz # link
220 if [ $2 != "symbolic" ] ; then
221 echo "removing .so's in page $pname" 1>&2
224 # skip symlink - this can be
225 # a program like expn, which is
227 echo skipping symlink $pname 1>&2
232 echo skipping file $pname 1>&2
235 # reset IFS - this is important!
242 # We need to watch out for hard links here.
253 if [ $# -lt 2 ] ; then
254 IFS=" " ; echo ignoring $pname 1>&2 ; return 0 ;
256 # construct name and section
258 while [ $# -gt 1 ] ; do
266 gz) { echo file $pname already gzipped 1>&2 ; } ;;
267 Z) { echo file $pname already compressed 1>&2 ; } ;;
269 IFS=" " ; set `file $pname`
270 if [ $2 = "gzip" ] ; then
271 echo moving hard link $pname 1>&2
272 mv $pname $pname.gz # link
274 if [ $2 != "symbolic" ] ; then
275 echo gzipping page $pname 1>&2
276 temp=`mktemp -t manager` || exit 1
278 (cd .. ; soelim )| gzip -c -- > $temp
285 # skip symlink - this can be
286 # a program like expn, which is
288 echo skipping symlink $pname 1>&2
293 echo skipping file $pname 1>&2
296 # reset IFS - this is important!
301 # Compress man pages in paths
313 while [ $# != 0 ] ; do
319 *cat?) ;; # ignore cat directories
322 do_compress_so $what $i
332 echo "directory $1 not found" 1>&2
339 # Display a usage message
343 echo "usage: $1 -compress <path> ... " 1>&2
344 echo " $1 -uncompress <path> ... " 1>&2
349 # remove .so's and do compress
353 # First remove all so's from the pages to be compressed
354 do_compress_so remove_so "$@"
355 # now do ahead and compress the pages
356 do_compress_so compress_page "$@"
362 if [ $# -lt 2 ] ; then ctl_usage $0 ; fi ;
365 -compress) shift ; do_compress "$@" ;;
366 -uncompress) shift ; do_uncompress "$@" ;;