| 1 | #!/bin/sh |
| 2 | |
| 3 | ######################################################################## |
| 4 | ### Parse Options |
| 5 | ### |
| 6 | |
| 7 | Gzip=: |
| 8 | Sym="" |
| 9 | Loc="" |
| 10 | Gz="" |
| 11 | Suffix="" |
| 12 | |
| 13 | while true; do |
| 14 | case $1 in |
| 15 | -s | --symlinks ) Sym="-s " ;; |
| 16 | -z | --compress ) Gzip=$2; shift ;; |
| 17 | -e | --extension ) Gz=$2; shift ;; |
| 18 | -x | --suffix ) Suffix=$2; shift ;; |
| 19 | -*) cat <<EOF |
| 20 | Unknown option "$1". Supported options: |
| 21 | -s Use symbolic links for manpages with multiple names. |
| 22 | -z PROG Use PROG to compress manual pages. |
| 23 | -e EXT Defines the extension added by -z PROG when compressing. |
| 24 | -x SUFF Defines an extra extension suffix to use. |
| 25 | Option names may not be combined getopt-style. |
| 26 | EOF |
| 27 | exit 1 ;; |
| 28 | *) break ;; |
| 29 | esac |
| 30 | shift |
| 31 | done |
| 32 | if test "$#" != 2; then |
| 33 | echo "Usage: installManPages <options> file dir" |
| 34 | exit 1 |
| 35 | fi |
| 36 | |
| 37 | ######################################################################## |
| 38 | ### Parse Required Arguments |
| 39 | ### |
| 40 | |
| 41 | ManPage=$1 |
| 42 | Dir=$2 |
| 43 | if test -f $ManPage ; then : ; else |
| 44 | echo "source manual page file must exist" |
| 45 | exit 1 |
| 46 | fi |
| 47 | if test -d "$Dir" ; then : ; else |
| 48 | echo "target directory must exist" |
| 49 | exit 1 |
| 50 | fi |
| 51 | test -z "$Sym" && Loc="$Dir/" |
| 52 | |
| 53 | ######################################################################## |
| 54 | ### Extract Target Names from Manual Page |
| 55 | ### |
| 56 | |
| 57 | # A sed script to parse the alternative names out of a man page. |
| 58 | # |
| 59 | # Backslashes are trippled in the sed script, because it is in |
| 60 | # backticks which doesn't pass backslashes literally. |
| 61 | # |
| 62 | Names=`sed -n ' |
| 63 | # Look for a line that starts with .SH NAME |
| 64 | /^\.SH NAME/,/^\./{ |
| 65 | |
| 66 | |
| 67 | /^\./!{ |
| 68 | |
| 69 | # Remove all commas... |
| 70 | s/,//g |
| 71 | |
| 72 | # ... and backslash-escaped spaces. |
| 73 | s/\\\ //g |
| 74 | |
| 75 | /\\\-.*/{ |
| 76 | # Delete from \- to the end of line |
| 77 | s/ \\\-.*// |
| 78 | h |
| 79 | s/.*/./ |
| 80 | x |
| 81 | } |
| 82 | |
| 83 | # Convert all non-space non-alphanum sequences |
| 84 | # to single underscores. |
| 85 | s/[^ A-Za-z0-9][^ A-Za-z0-9]*/_/g |
| 86 | p |
| 87 | g |
| 88 | /^\./{ |
| 89 | q |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | }' $ManPage` |
| 94 | |
| 95 | if test -z "$Names" ; then |
| 96 | echo "warning: no target names found in $ManPage" |
| 97 | fi |
| 98 | |
| 99 | ######################################################################## |
| 100 | ### Remaining Set Up |
| 101 | ### |
| 102 | |
| 103 | case $ManPage in |
| 104 | *.1) Section=1 ;; |
| 105 | *.3) Section=3 ;; |
| 106 | *.n) Section=n ;; |
| 107 | *) echo "unknown section for $ManPage" |
| 108 | exit 2 ;; |
| 109 | esac |
| 110 | |
| 111 | Name=`basename $ManPage .$Section` |
| 112 | SrcDir=`dirname $ManPage` |
| 113 | |
| 114 | ######################################################################## |
| 115 | ### Process Page to Create Target Pages |
| 116 | ### |
| 117 | |
| 118 | Specials="DString Thread Notifier RegExp library packagens pkgMkIndex safesock FindPhoto FontId MeasureChar" |
| 119 | for n in $Specials; do |
| 120 | if [ "$Name" = "$n" ] ; then |
| 121 | Names="$n $Names" |
| 122 | fi |
| 123 | done |
| 124 | |
| 125 | First="" |
| 126 | for Target in $Names; do |
| 127 | Target=$Target.$Section$Suffix |
| 128 | rm -f "$Dir/$Target" "$Dir/$Target.*" |
| 129 | if test -z "$First" ; then |
| 130 | First=$Target |
| 131 | sed -e "/man\.macros/r $SrcDir/man.macros" -e "/man\.macros/d" \ |
| 132 | $ManPage > "$Dir/$First" |
| 133 | chmod 644 "$Dir/$First" |
| 134 | $Gzip "$Dir/$First" |
| 135 | else |
| 136 | ln $Sym"$Loc$First$Gz" "$Dir/$Target$Gz" |
| 137 | fi |
| 138 | done |
| 139 | |
| 140 | ######################################################################## |
| 141 | exit 0 |