OSDN Git Service

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