6c3ed1785c43c3967b3b97b9ccd84ec7c95c6264
[crypto.git] / scripts / silcdoc / silcdoc
1 #!/bin/sh
2 #
3 # Author: Pekka Riikonen <priikone@silcnet.org>
4 #
5 # Copyright (C) GNU GPL 2001 - 2002 Pekka Riikonen
6 #
7 # SILC Toolkit Reference Manual documentation script.  This will automatically
8 # generate documentation from the source tree.  This will require the 
9 # robodoc compiled in util/robodoc and php utility installed in your system.
10 #
11 # This will tarverse the given directory and all subdirectories for the
12 # SILC style header files.  All header files starting with prefix `silc' 
13 # will be checked.  For example, silcpkcs.h.
14 #
15 # Usage: ./sildoc <type> <source directory> <destination directory> <robodoc>
16 #
17 # The <source directory> is the directory where this starts checking for
18 # the headers and will traverse all subdirectories.  The <destination
19 # directory> is the directory to where the documentation is generated.
20 #
21
22 # Arguments checking
23 if [ $# -lt "4" ]; then
24   echo "Usage: ./silcdoc <type> <source directory> <destination directory/file> <robodoc>"
25   echo "Supported types: HTML PS"
26 #  echo "Supported types: HTML, ASCII, LATEX or RTF"
27   exit 1
28 fi
29
30 TYPE=$1
31 SRC=$2
32 DST=$3
33 ROBO=$4
34
35 # Get all headers in the source directory
36 headers=`find $SRC -name "silc*.h"`
37
38 #
39 # PS documentation (from LATEX)
40 #
41 if [ "$TYPE" = "PS" ]; then
42   TYPE="LATEX"
43   rm -rf /tmp/silcdoc.tex
44   mkdir /tmp/silcdoc.tex
45   cp $headers /tmp/silcdoc.tex
46
47   path=`pwd`
48   cd /tmp/silcdoc.tex
49
50   # Generate cross reference files
51   headers=`find . -name "silc*.h" |cut -d/  -f2 |cut -d.  -f1`
52   touch silcdoc_xref
53   for i in $headers
54   do
55     $ROBO $i.h $i.h.tex $TYPE INTERNAL GENXREF $i.h.xref
56     echo $i.h.xref >>silcdoc_xref
57   done
58
59   # Generate the detailed documentation
60   headers=`find . -name "silc*.h" |cut -d/  -f2 |cut -d.  -f1`
61   for i in $headers
62   do
63     # remove internals
64     rm -rf $i_i.h
65     $ROBO $i.h $i.h.tex XREF silcdoc_xref $TYPE C SORT NOSOURCE SINGLEDOC
66   done
67
68   # Generate the index
69   $ROBO silcdoc_xref toolkit_mi INDEX $TYPE TITLE "SILC Toolkit Reference Manual"
70
71   # Generate the postscript
72   latex toolkit_mi
73   makeindex toolkit_mi
74   latex toolkit_mi
75   latex toolkit_mi
76   dvips toolkit_mi.dvi -o $DST
77
78   cd $path
79
80   rm -rf /tmp/silcdoc.tex
81 fi
82
83 #
84 # ASCII documentation
85 #
86 #if [ "$TYPE" = "ASCII" ]; then
87 #
88 #fi
89
90 #
91 # HTML documentation
92 #
93 if [ "$TYPE" = "HTML" ]; then
94   rm -rf /tmp/silcdoc.html
95   rm -rf /tmp/silcdoc_html.html
96   mkdir /tmp/silcdoc.html
97   mkdir /tmp/silcdoc_html.html
98   cp $headers /tmp/silcdoc.html
99
100   # Generate index template from the DIRECTORY files. The template for
101   # the generated index template is INDEX.tmpl.
102   files=`find $SRC -name "DIRECTORY"`
103   for i in $files
104   do
105     # Get library name
106     name=`grep "@LIBRARY=" $i |cut -d=  -f2`
107     fname=`grep "@FILENAME=" $i |cut -d=  -f2`
108     links=`grep "@LINK=" $i |cut -d=  -f2 |cut -d:  -f1`
109
110     # Generate links to template file that can be included into various
111     # places on the webpage.
112     echo "<a href="$fname"><img src="box.gif" border="0" alt="">$name</a><br />" >>$DST/index.tmpl
113     for k in $links
114     do
115       n=`grep $k $i |cut -d=  -f2 |cut -d:  -f2`
116       echo "<li><a href="$k">$n</a>" >>$DST/$fname.links
117       echo "&nbsp;&nbsp;&nbsp; <a href="$k"><img src="box2.gif" border="0" alt="">$n</a><br />" >>$DST/index.tmpl
118     done
119   done
120   # Now get the template for the link template, and generate the final index
121   # template file
122   temp=`find $SRC -name "INDEX.tmpl"`
123   sed -e "/@BODY@/ r $DST/index.tmpl" -e s/@BODY@//g $temp >$DST/index.tmpl.tmp
124   mv $DST/index.tmpl.tmp $DST/index.tmpl
125
126   # Copy all HTML files to destination
127   htmlfiles=`find $SRC -name "*.html"`
128   for i in $htmlfiles
129   do
130     cp $i /tmp/silcdoc_html.html
131   done
132   path=`pwd`
133   cd /tmp/silcdoc_html.html
134   htmlfiles=`find . -name "*.html" | cut -d/  -f2`
135   cd $path
136   for i in $htmlfiles
137   do
138     # Generate the details and the layout
139     f="/tmp/silcdoc_html.html/$i"
140     sh gen.sh $DST gen_index.php 1 $f $f
141     cp /tmp/silcdoc_html.html/$i $DST
142   done
143
144   # Generate cross reference files
145   path=`pwd`
146   cd /tmp/silcdoc.html
147   headers=`find . -name "silc*.h" |cut -d/  -f2 |cut -d.  -f1`
148   cd $path
149   touch $DST/silcdoc_xref
150   for i in $headers
151   do
152     $ROBO /tmp/silcdoc.html/$i.h $DST/$i.html $TYPE GENXREF $DST/$i.xref
153     echo $DST/$i.xref >>$DST/silcdoc_xref
154   done
155
156   # Generate the actual detailed documentation
157   path=`pwd`
158   cd /tmp/silcdoc.html
159   headers=`find . -name "silc*.h" |cut -d/  -f2 |cut -d.  -f1`
160   cd $path
161   for i in $headers
162   do
163     $ROBO /tmp/silcdoc.html/$i.h $DST/$i.html XREF $DST/silcdoc_xref $TYPE
164
165     # Generate the TOC file
166     sh gen.sh $DST gen_index.php 1 $DST/$i.html $DST/$i.html
167
168     # Generate the details and the layout
169     files=`find $DST -name ""$i"-*.html"`
170     for k in $files
171     do
172       sh gen.sh $DST gen_index.php 0 $k $k
173     done
174
175     rm -f $DST/$i-index.tmpl
176   done
177
178   # Generate the index and TOC files from the DIRECTORY files
179   files=`find $SRC -name "DIRECTORY"`
180   for i in $files
181   do
182     # Get library name
183     name=`grep "@LIBRARY=" $i |cut -d=  -f2`
184     fname=`grep "@FILENAME=" $i |cut -d=  -f2`
185
186     # Generate links for this library
187     sed -e "/@LINKS@/ r $DST/$fname.links" -e s/@LINKS@//g $i >$DST/$fname
188
189     # Generate the TOC file for the library
190     sh gen.sh $DST gen_index.php 1 $DST/$fname $DST/$fname
191
192     # Generate the link for the top index.html for this library
193     echo "<li><a href="$fname">$name</a>" >>$DST/index.html.tmp
194     rm -f $DST/$fname.links
195   done
196
197   # Generate the top index.html file
198   index=`find $SRC -name "LIBINDEX"`
199   version=`grep SILC_VERSION_STRING $SRC/../includes/version_internal.h |cut -d\"  -f2`
200   curdate=`date`
201   sed -e "/@VERSION@/s//$version/" -e "/@DATE@/s//$curdate/" -e "/@BODY@/ r $DST/index.html.tmp" -e s/@BODY@//g $index >$DST/index.html
202   sh gen.sh $DST gen_index.php 2 $DST/index.html $DST/index.html
203
204   # Generate the index toolkit_index.html file
205   $ROBO /tmp/silcdoc.html/silcdoc_xref $DST/toolkit_index.html INDEX HTML TITLE "SILC Toolkit Index"
206   sh gen.sh $DST gen_index.php 2 $DST/toolkit_index.html $DST/toolkit_index.html
207
208   # Cleanup
209   rm -rf $DST/index.html.tmp
210   rm -rf /tmp/silcdoc.html
211   rm -rf /tmp/silcdoc_html.html
212 fi