root/trunk/freewrt/scripts/genhtman.sh

Revision 3737, 6.0 kB (checked in by tg, 8 months ago)

TCL man pages (section n)

  • Property svn:keywords set to Id
Line 
1 # $FreeWRT: src/share/misc/licence.template,v 1.20 2006/12/11 21:04:56 tg Rel $
2 #-
3 # Copyright (c) 2007
4 #       Thorsten Glaser <tg@mirbsd.de>
5 #
6 # Provided that these terms and disclaimer and all copyright notices
7 # are retained or reproduced in an accompanying document, permission
8 # is granted to deal in this work without restriction, including un-
9 # limited rights to use, publicly perform, distribute, sell, modify,
10 # merge, give away, or sublicence.
11 #
12 # Advertising materials mentioning features or use of this work must
13 # display the following acknowledgement:
14 #       This product includes material provided by Thorsten Glaser.
15 #
16 # This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
17 # the utmost extent permitted by applicable law, neither express nor
18 # implied; without malicious intent or gross negligence. In no event
19 # may a licensor, author or contributor be held liable for indirect,
20 # direct, other damage, loss, or other issues arising in any way out
21 # of dealing in the work, even if advised of the possibility of such
22 # damage or existence of a defect, except proven that it results out
23 # of said person's immediate fault when using the work as intended.
24 #-
25 # Scan $1 (${WRKINST}) for man and catman pages and convert them in-
26 # to HTML man pages; generate a per-package index in $2/wman/
27
28 sd=$1
29 dd=$2/wman
30
31 . $(dirname "$0")/roff2htm
32
33 rm -rf $dd
34 mkdir -p $dd/{{man,cat}{1,2,3,3p,4,5,6,7,8,9,n},htman/pkgs}
35 # copy over manual pages (source and catman): ordinary files and hardlinks
36 find $sd -type f -a \( -path \*/man\* -o -path \*/cat\* \) | while read f; do
37         if [[ $f = *.gz ]]; then
38                 f=${f%.gz}
39                 gzip -cdf <$f.gz >$f
40         fi
41         case $f {
42         (*.1)           ln $f $dd/man1/ ;;
43         (*.2)           ln $f $dd/man2/ ;;
44         (*.3)           ln $f $dd/man3/ ;;
45         (*.3p)          ln $f $dd/man3p/ ;;
46         (*.4)           ln $f $dd/man4/ ;;
47         (*.5)           ln $f $dd/man5/ ;;
48         (*.6)           ln $f $dd/man6/ ;;
49         (*.7)           ln $f $dd/man7/ ;;
50         (*.8)           ln $f $dd/man8/ ;;
51         (*.9)           ln $f $dd/man9/ ;;
52         (*.n)           ln $f $dd/mann/ ;;
53         (*.1tbl)        tbl <$f >$dd/man1/${f%tbl} ;;
54         (*.2tbl)        tbl <$f >$dd/man2/${f%tbl} ;;
55         (*.3tbl)        tbl <$f >$dd/man3/${f%tbl} ;;
56         (*.4tbl)        tbl <$f >$dd/man4/${f%tbl} ;;
57         (*.5tbl)        tbl <$f >$dd/man5/${f%tbl} ;;
58         (*.6tbl)        tbl <$f >$dd/man6/${f%tbl} ;;
59         (*.7tbl)        tbl <$f >$dd/man7/${f%tbl} ;;
60         (*.8tbl)        tbl <$f >$dd/man8/${f%tbl} ;;
61         (*.9tbl)        tbl <$f >$dd/man9/${f%tbl} ;;
62         (*.1eqn)        neqn <$f | tbl >$dd/man1/${f%eqn} ;;
63         (*.2eqn)        neqn <$f | tbl >$dd/man2/${f%eqn} ;;
64         (*.3eqn)        neqn <$f | tbl >$dd/man3/${f%eqn} ;;
65         (*.4eqn)        neqn <$f | tbl >$dd/man4/${f%eqn} ;;
66         (*.5eqn)        neqn <$f | tbl >$dd/man5/${f%eqn} ;;
67         (*.6eqn)        neqn <$f | tbl >$dd/man6/${f%eqn} ;;
68         (*.7eqn)        neqn <$f | tbl >$dd/man7/${f%eqn} ;;
69         (*.8eqn)        neqn <$f | tbl >$dd/man8/${f%eqn} ;;
70         (*.9eqn)        neqn <$f | tbl >$dd/man9/${f%eqn} ;;
71         (*/cat1/*.0)    ln $f $dd/cat1/ ;;
72         (*/cat2/*.0)    ln $f $dd/cat2/ ;;
73         (*/cat3/*.0)    ln $f $dd/cat3/ ;;
74         (*/cat3p/*.0)   ln $f $dd/cat3p/ ;;
75         (*/cat4/*.0)    ln $f $dd/cat4/ ;;
76         (*/cat5/*.0)    ln $f $dd/cat5/ ;;
77         (*/cat6/*.0)    ln $f $dd/cat6/ ;;
78         (*/cat7/*.0)    ln $f $dd/cat7/ ;;
79         (*/cat8/*.0)    ln $f $dd/cat8/ ;;
80         (*/cat9/*.0)    ln $f $dd/cat9/ ;;
81         (*/catn/*.0)    ln $f $dd/catn/ ;;
82         (*)             print -u2 "file looks like manpage but ignored: ${f#$sd/}"
83                         continue ;;
84         }
85         print -u2 "processing manual page: ${f#$sd/}"
86 done
87 # copy over manual pages (source and catman): symbolic links
88 find $sd -type l -a \( -path \*/man\* -o -path \*/cat\* \) | while read f; do
89         t=$(readlink -f $f)
90         case $t {
91         (*.[123456789n]|*.3p)
92                 t=${t##*/}
93                 t=man${t##*.}/$t
94                 ;;
95         (*.[123456789n]tbl)
96                 t=${t##*/}
97                 t=${t%tbl}
98                 t=man${t##*.}/$t
99                 ;;
100         (*.[123456789n]eqn)
101                 t=${t##*/}
102                 t=${t%eqn}
103                 t=man${t##*.}/$t
104                 ;;
105         (*/cat[123456789n]/*.0|*/cat3p/*.0)
106                 x=${t%/*}
107                 t=${t##*/}
108                 t=cat${x##*cat}/$t
109                 ;;
110         (*)
111                 print -u2 "bad target '${t#$sd/}' for link '${f#$sd/}' ignored"
112                 continue ;;
113         }
114         case $f {
115         (*.[123456789n]|*.3p)
116                 f=${f##*/}
117                 f=man${f##*.}/$f
118                 ;;
119         (*.[123456789n]tbl)
120                 f=${f##*/}
121                 f=${f%tbl}
122                 f=man${f##*.}/$f
123                 ;;
124         (*.[123456789n]eqn)
125                 f=${f##*/}
126                 f=${f%eqn}
127                 f=man${f##*.}/$f
128                 ;;
129         (*/cat[123456789n]/*.0|*/cat3p/*.0)
130                 x=${f%/*}
131                 f=${f##*/}
132                 f=cat${x##*cat}/$f
133                 ;;
134         (*)
135                 print -u2 "link looks like manpage but ignored: ${f#$sd/}"
136                 continue ;;
137         }
138         if ! ln $dd/$t $dd/$f 2>/dev/null; then
139                 print -u2 "cannot link $f ← $t"
140                 rm -f $dd/$f
141         fi
142 done
143
144 # look for which nroff to use
145 if whence -p nroff >/dev/null; then
146         if whence -p nrcon >/dev/null; then
147                 NROFF="nroff -Tcol -mandoc"
148         elif [[ "$(print | nroff -v 2>&1)" = *GNU* ]]; then
149                 NROFF="nroff -c -Tascii -mandoc"
150         else
151                 NROFF="nroff -man"
152         fi
153 elif whence -p gnroff >/dev/null; then
154         NROFF="gnroff -c -Tascii -mandoc"
155 elif whence -p groff >/dev/null; then
156         NROFF="groff -c -Tascii -mandoc"
157 else
158         NROFF=cat
159         print -u2 warning: no nroff found, install GNU groff please
160 fi
161
162 # convert manpages from source format to catman pages
163 for sect in 1 2 3 3p 4 5 6 7 8 9 n; do
164         cd $dd/man$sect
165         for file in *; do
166                 [[ -e $file ]] || continue
167                 typeset -Uui ino=$(stat $roff2htm_statarg %i $file 2>/dev/null)
168                 typeset dn=$sect/${file%.*}.0
169
170                 (( ino )) && if [[ -n ${roff2htm_inodecache[ino]} ]]; then
171                         print -u2 linking page $dn ← ${roff2htm_inodecache[ino]}
172                         ln -f $dd/cat${roff2htm_inodecache[ino]} $dd/cat$dn
173                         continue
174                 else
175                         roff2htm_inodecache[ino]=$dn
176                 fi
177                 print -nu2 formatting manual page ${file%.*}.$sect ...
178                 $NROFF $file >$dd/cat$dn
179                 print -u2 \ done
180         done
181 done
182
183 # empty the inode cache again
184 set -A roff2htm_inodecache
185
186 # convert all catman pages to HTML
187 cd $dd; convert_all . ./htman
188
189 # generate an index page for the package
190 haveany=0
191 {
192         output_header | \
193             sed -e "/<title>/s/()/for package $3/" -e '/<h1>/d'
194         print "<h1>FreeWRT $3 package manual</h1>
195 <p>The $3 package comes with the following manual pages:</p><ul>"
196         (cd $dd/htman; find man* -name \*.htm | sort -f) |&
197         while read -p file; do
198                 haveany=1
199                 bn=${file%.htm}
200                 sect=${file#man}
201                 print "<li><a href=\"../$file\">${bn#*/}(${sect%/*})</a></li>"
202         done
203         print '</ul>'
204         #XXX TODO: insert link to package ${HOMEPAGE} here once we have it
205         output_footer | \
206             sed -e '/<tt>/s</tt>& and <tt>$Id$&'
207 } >$dd/htman/pkgs/$3.htm
208 [[ $haveany = 1 ]] || rm -f $dd/htman/pkgs/$3.htm
209
210 exit 0
Note: See TracBrowser for help on using the browser.