#!/bin/sh # # Copyright (c) 1994 Geoffrey M. Rehmet, Rhodes University # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. All advertising materials mentioning features or use of this software # must display the following acknowledgement: # This product includes software developed by Geoffrey M. Rehmet # 4. Neither the name of Geoffrey M. Rehmet nor that of Rhodes University # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL GEOFFREY M. REHMET OR RHODES UNIVERSITY BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD: stable/11/usr.sbin/manctl/manctl.sh 71293 2001-01-20 04:30:41Z jedgar $ # # manctl: # a utility for manipulating manual pages # functions: # compress uncompressed man pages (elliminating .so's) # this is now two-pass. If possible, .so's # are replaced with hard links # uncompress compressed man pages # purge old formatted man pages (not implemented yet) # Things to watch out for: # Hard links - careful with g(un)zipping! # .so's - throw everything through soelim before gzip! # symlinks - ignore these - eg: expn is its own man page: # don't want to compress this! # setglobal PATH = '/bin:/sbin:/usr/bin:/usr/sbin'; export PATH # # purge cat? directories # proc do_purge { echo "purge $ifsjoin(Argv)" !2 > !1 echo "not implemented yet\n" !2 > !1 } # # Uncompress one page # proc uncompress_page { var pname = '' var fname = '' var sect = '' var ext = '' # break up file name set pname = $1 setglobal IFS = ''.'' ; set $pname # less than 3 fields - don't know what to do with this if test $Argc -lt 3 { setglobal IFS = '" '" ; echo ignoring $pname !1 > !2 ; return 0 ; } # construct name and section set fname = $1 ; shift while test $Argc -gt 2 { set fname = "$fname.$1" shift } set sect = $1 set ext = $2 setglobal IFS = '" '" match $ext { with gz|Z do { setglobal IFS = '" '" ; set $[file $pname] if test $2 != "gzip" { echo moving hard link $pname !1 > !2 mv $pname $fname.$ext # link } else { if test $2 != "symbolic" { echo gunzipping page $pname !1 > !2 setglobal temp = $[mktemp -t manager] || exit 1 gunzip -c $pname > $temp chmod u+w $pname cp $temp $pname chmod 444 $pname mv $pname $fname.$sect rm -f $temp } else { # skip symlinks - this can be # a program like expn, which is # its own man page ! echo skipping symlink $pname !1 > !2 } } } with * do { setglobal IFS = '" '" echo skipping file $pname !1 > !2 } } # reset IFS - this is important! setglobal IFS = '" '" } # # Uncompress manpages in paths # proc do_uncompress { var i = '' var dir = '' var workdir = '' set workdir = $[pwd] while test $Argc != 0 { if test -d $1 { set dir = $1 cd $dir for i in [*] { match $i { with *cat? # ignore cat directories with * do { if test -d $i { do_uncompress $i } else { if test -e $i { uncompress_page $i } } } } } cd $workdir } else { echo "directory $1 not found" !1 > !2 } shift } } # # Remove .so's from one file # proc so_purge_page { var so_entries = '' var lines = '' var fname = '' set so_entries = $[grep "^\.so" $1 | wc -l] if test $so_entries -eq 0 { return 0 ; } # we have a page with a .so in it echo $1 contains a .so entry !2 > !1 # now check how many lines in the file set lines = $[wc -l < $1] # if the file is only one line long, we can replace it # with a hard link! if test $lines -eq 1 { set fname = $1; echo replacing $fname with a hard link set $[cat $fname]; rm -f $fname ln ../$2 $fname } else { echo inlining page $fname !1 > !2 setglobal temp = $[mktemp -t manager] || exit 1 cat $fname | \ shell {cd .. ; soelim } > $temp chmod u+w $fname cp $temp $fname chmod 444 $fname rm -f $temp } } # # Remove .so entries from man pages # If a page consists of just one line with a .so, # replace it with a hard link # proc remove_so { var pname = '' var fname = '' var sect = '' # break up file name set pname = $1 setglobal IFS = ''.'' ; set $pname if test $Argc -lt 2 { setglobal IFS = '" '" ; echo ignoring $pname !1 > !2 ; return 0 ; } # construct name and section set fname = $1 ; shift while test $Argc -gt 1 { set fname = "$fname.$1" shift } set sect = $1 setglobal IFS = '" '" match $sect { with gz do { echo file $pname already gzipped !1 > !2 ; } with Z do { echo file $pname already compressed !1 > !2 ; } with [12345678ln]*do { setglobal IFS = '" '" ; set $[file $pname] if test $2 = "gzip" { echo moving hard link $pname !1 > !2 mv $pname $pname.gz # link } else { if test $2 != "symbolic" { echo "removing .so's in page $pname" !1 > !2 so_purge_page $pname } else { # skip symlink - this can be # a program like expn, which is # its own man page ! echo skipping symlink $pname !1 > !2 } } } with * do { setglobal IFS = '" '" echo skipping file $pname !1 > !2 } } # reset IFS - this is important! setglobal IFS = '" '" } # # compress one page # We need to watch out for hard links here. # proc compress_page { var pname = '' var fname = '' var sect = '' # break up file name set pname = $1 setglobal IFS = ''.'' ; set $pname if test $Argc -lt 2 { setglobal IFS = '" '" ; echo ignoring $pname !1 > !2 ; return 0 ; } # construct name and section set fname = $1 ; shift while test $Argc -gt 1 { set fname = "$fname.$1" shift } set sect = $1 setglobal IFS = '" '" match $sect { with gz do { echo file $pname already gzipped !1 > !2 ; } with Z do { echo file $pname already compressed !1 > !2 ; } with [12345678ln]*do { setglobal IFS = '" '" ; set $[file $pname] if test $2 = "gzip" { echo moving hard link $pname !1 > !2 mv $pname $pname.gz # link } else { if test $2 != "symbolic" { echo gzipping page $pname !1 > !2 setglobal temp = $[mktemp -t manager] || exit 1 cat $pname | \ shell {cd .. ; soelim }| gzip -c -- > $temp chmod u+w $pname cp $temp $pname chmod 444 $pname mv $pname $pname.gz rm -f $temp } else { # skip symlink - this can be # a program like expn, which is # its own man page ! echo skipping symlink $pname !1 > !2 } } } with * do { setglobal IFS = '" '" echo skipping file $pname !1 > !2 } } # reset IFS - this is important! setglobal IFS = '" '" } # # Compress man pages in paths # proc do_compress_so { var i = '' var dir = '' var workdir = '' var what = '' set what = $1 shift set workdir = $[pwd] while test $Argc != 0 { if test -d $1 { set dir = $1 cd $dir for i in [*] { match $i { with *cat? # ignore cat directories with * do { if test -d $i { do_compress_so $what $i } else { if test -e $i { $what $i } } } } } cd $workdir } else { echo "directory $1 not found" !1 > !2 } shift } } # # Display a usage message # proc ctl_usage { echo "usage: $1 -compress ... " !1 > !2 echo " $1 -uncompress ... " !1 > !2 echo " $1 -purge ... " !1 > !2 echo " $1 -purge expire ... " !1 > !2 exit 1 } # # remove .so's and do compress # proc do_compress { # First remove all so's from the pages to be compressed do_compress_so remove_so @Argv # now do ahead and compress the pages do_compress_so compress_page @Argv } # # dispatch options # if test $Argc -lt 2 { ctl_usage $0 ; } ; match $1 { with -compress shift ; do_compress @Argv with -uncompress shift ; do_uncompress @Argv with -purge shift ; do_purge @Argv with * ctl_usage $0 }