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 temp
=`mktemp -t manager` ||
exit 1
98 gunzip
-c $pname > $temp
102 mv $pname $fname.
$sect
105 # skip symlinks - this can be
106 # a program like expn, which is
108 echo skipping symlink
$pname 1>&2
113 echo skipping
file $pname 1>&2
116 # reset IFS - this is important!
122 # Uncompress manpages in paths
131 while [ $# != 0 ] ; do
137 *cat?
) ;; # ignore cat directories
150 echo "directory $1 not found" 1>&2
157 # Remove .so's from one file
165 so_entries
=`grep "^\.so" $1 | wc -l`
166 if [ $so_entries -eq 0 ] ; then return 0 ; fi
168 # we have a page with a .so in it
169 echo $1 contains a .so entry
2>&1
171 # now check how many lines in the file
174 # if the file is only one line long, we can replace it
176 if [ $lines -eq 1 ] ; then
178 echo replacing
$fname with a hard link
183 echo inlining page
$fname 1>&2
184 temp
=`mktemp -t manager` ||
exit 1
186 (cd ..
; soelim
) > $temp
195 # Remove .so entries from man pages
196 # If a page consists of just one line with a .so,
197 # replace it with a hard link
208 if [ $# -lt 2 ] ; then
209 IFS
=" " ; echo ignoring
$pname 1>&2 ; return 0 ;
211 # construct name and section
213 while [ $# -gt 1 ] ; do
221 gz
) { echo file $pname already gzipped
1>&2 ; } ;;
222 Z
) { echo file $pname already compressed
1>&2 ; } ;;
224 IFS
=" " ; set `file $pname`
225 if [ $2 = "gzip" ] ; then
226 echo moving hard link
$pname 1>&2
227 mv $pname $pname.gz
# link
229 if [ $2 != "symbolic" ] ; then
230 echo "removing .so's in page $pname" 1>&2
233 # skip symlink - this can be
234 # a program like expn, which is
236 echo skipping symlink
$pname 1>&2
241 echo skipping
file $pname 1>&2
244 # reset IFS - this is important!
251 # We need to watch out for hard links here.
262 if [ $# -lt 2 ] ; then
263 IFS
=" " ; echo ignoring
$pname 1>&2 ; return 0 ;
265 # construct name and section
267 while [ $# -gt 1 ] ; do
275 gz
) { echo file $pname already gzipped
1>&2 ; } ;;
276 Z
) { echo file $pname already compressed
1>&2 ; } ;;
278 IFS
=" " ; set `file $pname`
279 if [ $2 = "gzip" ] ; then
280 echo moving hard link
$pname 1>&2
281 mv $pname $pname.gz
# link
283 if [ $2 != "symbolic" ] ; then
284 echo gzipping page
$pname 1>&2
285 temp
=`mktemp -t manager` ||
exit 1
287 (cd ..
; soelim
)|
gzip -c -- > $temp
294 # skip symlink - this can be
295 # a program like expn, which is
297 echo skipping symlink
$pname 1>&2
302 echo skipping
file $pname 1>&2
305 # reset IFS - this is important!
310 # Compress man pages in paths
322 while [ $# != 0 ] ; do
328 *cat?
) ;; # ignore cat directories
331 do_compress_so
$what $i
341 echo "directory $1 not found" 1>&2
348 # Display a usage message
352 echo "usage: $1 -compress <path> ... " 1>&2
353 echo " $1 -uncompress <path> ... " 1>&2
354 echo " $1 -purge <days> <path> ... " 1>&2
355 echo " $1 -purge expire <path> ... " 1>&2
360 # remove .so's and do compress
364 # First remove all so's from the pages to be compressed
365 do_compress_so remove_so
"$@"
366 # now do ahead and compress the pages
367 do_compress_so compress_page
"$@"
373 if [ $# -lt 2 ] ; then ctl_usage
$0 ; fi ;
376 -compress) shift ; do_compress
"$@" ;;
377 -uncompress) shift ; do_uncompress
"$@" ;;
378 -purge) shift ; do_purge
"$@" ;;