0405a7fa6ec2c8ccb8c9ef45ed5fbe631f599e35
[silc.git] / scripts / silcdoc / silcdoc
1 #!/bin/sh
2 #
3 # Author: Pekka Riikonen <priikone@silcnet.org>
4 #
5 # Copyright (C) GNU GPL 2001 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> <robodoc>"
25   echo "Supported types: HTML"
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 # ASCII documentation
40 #
41 #if [ "$TYPE" = "ASCII" ]; then
42 #
43 #fi
44
45 #
46 # HTML documentation
47 #
48 if [ "$TYPE" = "HTML" ]; then
49   rm -rf /tmp/silcdoc.html
50   rm -rf /tmp/silcdoc_html.html
51   mkdir /tmp/silcdoc.html
52   mkdir /tmp/silcdoc_html.html
53   cp $headers /tmp/silcdoc.html
54
55   # Generate index template from the DIRECTORY files. The template for
56   # the generated index template is INDEX.tmpl.
57   files=`find $SRC -name "DIRECTORY"`
58   for i in $files
59   do
60     # Get library name
61     name=`grep "@LIBRARY=" $i |cut -d=  -f2`
62     fname=`grep "@FILENAME=" $i |cut -d=  -f2`
63     links=`grep "@LINK=" $i |cut -d=  -f2 |cut -d:  -f1`
64
65     # Generate links to template file that can be included into various
66     # places on the webpage.
67     echo "<a href="$fname"><img src="box.gif" border="0" alt="">$name</a><br />" >>$DST/index.tmpl
68     for k in $links
69     do
70       n=`grep $k $i |cut -d=  -f2 |cut -d:  -f2`
71       echo "<li><a href="$k">$n</a>" >>$DST/$fname.links
72       echo "&nbsp;&nbsp;&nbsp; <a href="$k"><img src="box2.gif" border="0" alt="">$n</a><br />" >>$DST/index.tmpl
73     done
74   done
75   # Now get the template for the link template, and generate the final index
76   # template file
77   temp=`find $SRC -name "INDEX.tmpl"`
78   sed -e "/@BODY@/ r $DST/index.tmpl" -e s/@BODY@//g $temp >$DST/index.tmpl.tmp
79   mv $DST/index.tmpl.tmp $DST/index.tmpl
80
81   # Copy all HTML files to destination
82   htmlfiles=`find $SRC -name "*.html"`
83   for i in $htmlfiles
84   do
85     cp $i /tmp/silcdoc_html.html
86   done
87   path=`pwd`
88   cd /tmp/silcdoc_html.html
89   htmlfiles=`find . -name "*.html" | cut -d/  -f2`
90   cd $path
91   for i in $htmlfiles
92   do
93     # Generate the details and the layout
94     f="/tmp/silcdoc_html.html/$i"
95     sh gen.sh $DST gen_index.php 1 $f $f
96     cp /tmp/silcdoc_html.html/$i $DST
97 echo $f
98   done
99
100   # Generate the actual detailed documentation
101   path=`pwd`
102   cd /tmp/silcdoc.html
103   headers=`find . -name "silc*.h" |cut -d/  -f2 |cut -d.  -f1`
104   cd $path
105   for i in $headers
106   do
107     $ROBO /tmp/silcdoc.html/$i.h $DST/$i.html $TYPE
108
109     # Generate the TOC file
110     sh gen.sh $DST gen_index.php 1 $DST/$i.html $DST/$i.html
111
112     # Generate the details and the layout
113     files=`find $DST -name ""$i"-*.html"`
114     for k in $files
115     do
116       sh gen.sh $DST gen_index.php 0 $k $k
117     done
118
119     rm -f $DST/$i-index.tmpl
120   done
121
122   # Generate the index and TOC files from the DIRECTORY files
123   files=`find $SRC -name "DIRECTORY"`
124   for i in $files
125   do
126     # Get library name
127     name=`grep "@LIBRARY=" $i |cut -d=  -f2`
128     fname=`grep "@FILENAME=" $i |cut -d=  -f2`
129
130     # Generate links for this library
131     sed -e "/@LINKS@/ r $DST/$fname.links" -e s/@LINKS@//g $i >$DST/$fname
132
133     # Generate the TOC file for the library
134     sh gen.sh $DST gen_index.php 1 $DST/$fname $DST/$fname
135
136     # Generate the link for the top index.html for this library
137     echo "<li><a href="$fname">$name</a>" >>$DST/index.html.tmp
138     rm -f $DST/$fname.links
139   done
140
141   # Generate the top index.html file
142   index=`find $SRC -name "LIBINDEX"`
143   version=`grep SILC_VERSION_STRING $SRC/../includes/version_internal.h |cut -d\"  -f2`
144   curdate=`date`
145   sed -e "/@VERSION@/s//$version/" -e "/@DATE@/s//$curdate/" -e "/@BODY@/ r $DST/index.html.tmp" -e s/@BODY@//g $index >$DST/index.html
146   sh gen.sh $DST gen_index.php 2 $DST/index.html $DST/index.html
147
148   rm -rf $DST/index.html.tmp
149   rm -rf /tmp/silcdoc.html
150   rm -rf /tmp/silcdoc_html.html
151 fi