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
37 # a utility for manipulating manual pages
39 # compress uncompressed man pages (elliminating .so's)
40 # this is now two-pass. If possible, .so's
41 # are replaced with hard links
42 # uncompress compressed man pages
43 # Things to watch out for:
44 # Hard links - careful with g(un)zipping!
45 # .so's - throw everything through soelim before gzip!
46 # symlinks - ignore these - eg: expn is its own man page:
47 # don't want to compress this!
49 PATH=/bin:/sbin:/usr/bin:/usr/sbin; export PATH
64 # less than 3 fields - don't know what to do with this
65 if [ $# -lt 3 ] ; then
66 IFS=" " ; echo ignoring $pname 1>&2 ; return 0 ;
68 # construct name and section
70 while [ $# -gt 2 ] ; do
80 IFS=" " ; set `file $pname`
81 if [ $2 != "gzip" ] ; then
82 echo moving hard link $pname 1>&2
83 mv $pname $fname.$ext # link
85 if [ $2 != "symbolic" ] ; then
86 echo gunzipping page $pname 1>&2
87 temp=`mktemp -t manager` || exit 1
88 gunzip -c $pname > $temp
92 mv $pname $fname.$sect
95 # skip symlinks - this can be
96 # a program like expn, which is
98 echo skipping symlink $pname 1>&2
103 echo skipping file $pname 1>&2
106 # reset IFS - this is important!
112 # Uncompress manpages in paths
121 while [ $# != 0 ] ; do
127 *cat?) ;; # ignore cat directories
140 echo "directory $1 not found" 1>&2
147 # Remove .so's from one file
155 so_entries=`grep "^\.so" $1 | wc -l`
156 if [ $so_entries -eq 0 ] ; then return 0 ; fi
158 # we have a page with a .so in it
159 echo $1 contains a .so entry 2>&1
161 # now check how many lines in the file
164 # if the file is only one line long, we can replace it
166 if [ $lines -eq 1 ] ; then
168 echo replacing $fname with a hard link
173 echo inlining page $fname 1>&2
174 temp=`mktemp -t manager` || exit 1
176 (cd .. ; soelim ) > $temp
185 # Remove .so entries from man pages
186 # If a page consists of just one line with a .so,
187 # replace it with a hard link
198 if [ $# -lt 2 ] ; then
199 IFS=" " ; echo ignoring $pname 1>&2 ; return 0 ;
201 # construct name and section
203 while [ $# -gt 1 ] ; do
211 gz) { echo file $pname already gzipped 1>&2 ; } ;;
212 Z) { echo file $pname already compressed 1>&2 ; } ;;
214 IFS=" " ; set `file $pname`
215 if [ $2 = "gzip" ] ; then
216 echo moving hard link $pname 1>&2
217 mv $pname $pname.gz # link
219 if [ $2 != "symbolic" ] ; then
220 echo "removing .so's in page $pname" 1>&2
223 # skip symlink - this can be
224 # a program like expn, which is
226 echo skipping symlink $pname 1>&2
231 echo skipping file $pname 1>&2
234 # reset IFS - this is important!
241 # We need to watch out for hard links here.
252 if [ $# -lt 2 ] ; then
253 IFS=" " ; echo ignoring $pname 1>&2 ; return 0 ;
255 # construct name and section
257 while [ $# -gt 1 ] ; do
265 gz) { echo file $pname already gzipped 1>&2 ; } ;;
266 Z) { echo file $pname already compressed 1>&2 ; } ;;
268 IFS=" " ; set `file $pname`
269 if [ $2 = "gzip" ] ; then
270 echo moving hard link $pname 1>&2
271 mv $pname $pname.gz # link
273 if [ $2 != "symbolic" ] ; then
274 echo gzipping page $pname 1>&2
275 temp=`mktemp -t manager` || exit 1
277 (cd .. ; soelim )| gzip -c -- > $temp
284 # skip symlink - this can be
285 # a program like expn, which is
287 echo skipping symlink $pname 1>&2
292 echo skipping file $pname 1>&2
295 # reset IFS - this is important!
300 # Compress man pages in paths
312 while [ $# != 0 ] ; do
318 *cat?) ;; # ignore cat directories
321 do_compress_so $what $i
331 echo "directory $1 not found" 1>&2
338 # Display a usage message
342 echo "usage: $1 -compress <path> ... " 1>&2
343 echo " $1 -uncompress <path> ... " 1>&2
348 # remove .so's and do compress
352 # First remove all so's from the pages to be compressed
353 do_compress_so remove_so "$@"
354 # now do ahead and compress the pages
355 do_compress_so compress_page "$@"
361 if [ $# -lt 2 ] ; then ctl_usage $0 ; fi ;
364 -compress) shift ; do_compress "$@" ;;
365 -uncompress) shift ; do_uncompress "$@" ;;