Merged silc_1_0_branch to trunk.
[silc.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   exit 0
82 fi
83
84 #
85 # ASCII documentation
86 #
87 #if [ "$TYPE" = "ASCII" ]; then
88 #
89 #fi
90
91 #
92 # HTML documentation
93 #
94 if [ "$TYPE" = "HTML" ]; then
95   rm -rf /tmp/silcdoc.html
96   rm -rf /tmp/silcdoc_html.html
97   mkdir /tmp/silcdoc.html
98   mkdir /tmp/silcdoc_html.html
99   cp $headers /tmp/silcdoc.html
100
101   # Generate index template from the DIRECTORY files. The template for
102   # the generated index template is INDEX.tmpl.
103   dfiles=`find $SRC -name "DIRECTORY"`
104   for i in $dfiles
105   do
106     # Get library name
107     name=`grep "@LIBRARY=" $i |cut -d=  -f2`
108     fname=`grep "@FILENAME=" $i |cut -d=  -f2`
109     links=`grep "@LINK=" $i |cut -d=  -f2 |cut -d:  -f1`
110
111     # Generate links to template file that can be included into various
112     # places on the webpage.
113     echo "<a href="$fname"><img src="box.gif" border="0" alt="">$name</a><br />" >>$DST/index.tmpl
114     for k in $links
115     do
116       n=`grep $k $i |cut -d=  -f2 |cut -d:  -f2`
117       echo "<li><a href="$k">$n</a>" >>$DST/$fname.links
118       echo "&nbsp;&nbsp;&nbsp; <a href="$k"><img src="box2.gif" border="0" alt="">$n</a><br />" >>$DST/index.tmpl
119     done
120   done
121   # Now get the template for the link template, and generate the final index
122   # template file
123   temp=`find $SRC -name "INDEX.tmpl"`
124   sed -e "/@BODY@/ r $DST/index.tmpl" -e s/@BODY@//g $temp >$DST/index.tmpl.tmp
125   mv $DST/index.tmpl.tmp $DST/index.tmpl
126
127   # Copy all HTML files to destination
128   htmlfiles=`find $SRC -name "*.html"`
129   for i in $htmlfiles
130   do
131     cp $i /tmp/silcdoc_html.html
132   done
133   path=`pwd`
134   cd /tmp/silcdoc_html.html
135   htmlfiles=`find . -name "*.html" | cut -d/  -f2`
136   cd $path
137   for i in $htmlfiles
138   do
139     # Generate the details and the layout
140     f="/tmp/silcdoc_html.html/$i"
141     sh gen.sh $DST gen_index.php 1 $f $f
142     cp /tmp/silcdoc_html.html/$i $DST
143   done
144
145   # Generate cross reference files
146   path=`pwd`
147   cd /tmp/silcdoc.html
148   headers=`find . -name "silc*.h" |cut -d/  -f2 |cut -d.  -f1`
149   cd $path
150   touch $DST/silcdoc_xref
151   for i in $headers
152   do
153     $ROBO /tmp/silcdoc.html/$i.h $DST/$i.html $TYPE GENXREF $DST/$i.xref
154     echo $DST/$i.xref >>$DST/silcdoc_xref
155   done
156
157   # Generate the actual detailed documentation
158   path=`pwd`
159   cd /tmp/silcdoc.html
160   headers=`find . -name "silc*.h" |cut -d/  -f2 |cut -d.  -f1`
161   cd $path
162   for i in $headers
163   do
164     $ROBO /tmp/silcdoc.html/$i.h $DST/$i.html XREF $DST/silcdoc_xref $TYPE
165
166     # Generate the TOC file
167     sh gen.sh $DST gen_index.php 1 $DST/$i.html $DST/$i.html
168
169     # Generate the details and the layout
170     files=`find $DST -name ""$i"-*.html"`
171     for k in $files
172     do
173       sh gen.sh $DST gen_index.php 0 $k $k
174     done
175
176     rm -f $DST/$i-index.tmpl
177   done
178
179   # Generate the index and TOC files from the DIRECTORY files
180   for i in $dfiles
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 $DST/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   exit 0
213 fi