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 # purge old formatted man pages (not implemented yet)
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
52 # purge cat? directories
57 echo "not implemented yet\n" 2>&1
74 # less than 3 fields - don't know what to do with this
75 if [ $# -lt 3 ] ; then
76 IFS=" " ; echo ignoring $pname 1>&2 ; return 0 ;
78 # construct name and section
80 while [ $# -gt 2 ] ; do
90 IFS=" " ; set `file $pname`
91 if [ $2 != "gzip" ] ; then
92 echo moving hard link $pname 1>&2
93 mv $pname $fname.$ext # link
95 if [ $2 != "symbolic" ] ; then
96 echo gunzipping page $pname 1>&2
97 gunzip -c $pname > /tmp/manager.$$
99 cp /tmp/manager.$$ $pname
101 mv $pname $fname.$sect
104 # skip symlinks - this can be
105 # a program like expn, which is
107 echo skipping symlink $pname 1>&2
112 echo skipping file $pname 1>&2
115 # reset IFS - this is important!
121 # Uncompress manpages in paths
130 while [ $# != 0 ] ; do
136 *cat?) ;; # ignore cat directories
149 echo "directory $1 not found" 1>&2
156 # Remove .so's from one file
164 so_entries=`grep "^\.so" $1 | wc -l`
165 if [ $so_entries -eq 0 ] ; then return 0 ; fi
167 # we have a page with a .so in it
168 echo $1 contains a .so entry 2>&1
170 # now check how many lines in the file
173 # if the file is only one line long, we can replace it
175 if [ $lines -eq 1 ] ; then
177 echo replacing $fname with a hard link
182 echo inlining page $fname 1>&2
184 (cd .. ; soelim ) > /tmp/manager.$$
186 cp /tmp/manager.$$ $fname
192 # Remove .so entries from man pages
193 # If a page consists of just one line with a .so,
194 # replace it with a hard link
205 if [ $# -lt 2 ] ; then
206 IFS=" " ; echo ignoring $pname 1>&2 ; return 0 ;
208 # construct name and section
210 while [ $# -gt 1 ] ; do
218 gz) { echo file $pname already gzipped 1>&2 ; } ;;
219 Z) { echo file $pname already compressed 1>&2 ; } ;;
221 IFS=" " ; set `file $pname`
222 if [ $2 = "gzip" ] ; then
223 echo moving hard link $pname 1>&2
224 mv $pname $pname.gz # link
226 if [ $2 != "symbolic" ] ; then
227 echo "removing .so's in page $pname" 1>&2
230 # skip symlink - this can be
231 # a program like expn, which is
233 echo skipping symlink $pname 1>&2
238 echo skipping file $pname 1>&2
241 # reset IFS - this is important!
248 # We need to watch out for hard links here.
259 if [ $# -lt 2 ] ; then
260 IFS=" " ; echo ignoring $pname 1>&2 ; return 0 ;
262 # construct name and section
264 while [ $# -gt 1 ] ; do
272 gz) { echo file $pname already gzipped 1>&2 ; } ;;
273 Z) { echo file $pname already compressed 1>&2 ; } ;;
275 IFS=" " ; set `file $pname`
276 if [ $2 = "gzip" ] ; then
277 echo moving hard link $pname 1>&2
278 mv $pname $pname.gz # link
280 if [ $2 != "symbolic" ] ; then
281 echo gzipping page $pname 1>&2
283 (cd .. ; soelim )| gzip -c -- > /tmp/manager.$$
285 cp /tmp/manager.$$ $pname
290 # skip symlink - this can be
291 # a program like expn, which is
293 echo skipping symlink $pname 1>&2
298 echo skipping file $pname 1>&2
301 # reset IFS - this is important!
306 # Compress man pages in paths
318 while [ $# != 0 ] ; do
324 *cat?) ;; # ignore cat directories
327 do_compress_so $what $i
337 echo "directory $1 not found" 1>&2
344 # Display a usage message
348 echo "usage: $1 -compress <path> ... " 1>&2
349 echo " $1 -uncompress <path> ... " 1>&2
350 echo " $1 -purge <days> <path> ... " 1>&2
351 echo " $1 -purge expire <path> ... " 1>&2
356 # remove .so's and do compress
360 # First remove all so's from the pages to be compressed
361 do_compress_so remove_so "$@"
362 # now do ahead and compress the pages
363 do_compress_so compress_page "$@"
369 if [ $# -lt 2 ] ; then ctl_usage $0 ; fi ;
372 -compress) shift ; do_compress "$@" ;;
373 -uncompress) shift ; do_uncompress "$@" ;;
374 -purge) shift ; do_purge "$@" ;;