c9b5cbd48e3fdadef30d964655e2c0fb4c649a17
[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
56   files=`find $SRC -name "DIRECTORY"`
57   for i in $files
58   do
59     # Get library name
60     name=`grep "@LIBRARY=" $i |cut -d=  -f2`
61     fname=`grep "@FILENAME=" $i |cut -d=  -f2`
62     links=`grep "@LINK=" $i |cut -d=  -f2 |cut -d:  -f1`
63
64     # Generate links to template file that can be included into various
65     # places on the webpage.
66     echo "<A HREF="$fname"><IMG SRC="box.gif" border="0" alt="">$name</A><BR>" >>$DST/index.tmpl
67     for k in $links
68     do
69       n=`grep $k $i |cut -d=  -f2 |cut -d:  -f2`
70       echo "<LI><A HREF="$k">$n</A>" >>$DST/$fname.links
71       echo "&nbsp;&nbsp;&nbsp; <A HREF="$k"><IMG SRC="box2.gif" border="0" alt="">$n</A><BR>" >>$DST/index.tmpl
72     done
73   done
74
75   # Copy all HTML files to destination
76   htmlfiles=`find $SRC -name "silc*.html"`
77   for i in $htmlfiles
78   do
79     cp $i /tmp/silcdoc_html.html
80   done
81   path=`pwd`
82   cd /tmp/silcdoc_html.html
83   htmlfiles=`find . -name "silc*.html" | cut -d/  -f2`
84   cd $path
85   for i in $htmlfiles
86   do
87     # Generate the details and the layout
88     f="/tmp/silcdoc_html.html/$i"
89     sh gen.sh $DST gen_html_index.php $f $f
90     cp /tmp/silcdoc_html.html/$i $DST
91 echo $f
92   done
93
94   # Generate the actual detailed documentation
95   path=`pwd`
96   cd /tmp/silcdoc.html
97   headers=`find . -name "silc*.h" |cut -d/  -f2 |cut -d.  -f1`
98   cd $path
99   for i in $headers
100   do
101     $ROBO /tmp/silcdoc.html/$i.h $DST/$i.html $TYPE
102
103     # Generate the TOC file
104     sh gen.sh $DST gen_toc.php $DST/$i.html $DST/$i.html
105     sh gen.sh $DST gen_html_index.php $DST/$i.html $DST/$i.html
106
107     # Generate the details and the layout
108     files=`find $DST -name ""$i"__*.html"`
109     for k in $files
110     do
111       sh gen.sh $DST gen_index.php $k $k
112     done
113
114     rm -f $DST/$i__index.tmpl
115   done
116
117   # Generate the index and TOC files from the DIRECTORY files
118   files=`find $SRC -name "DIRECTORY"`
119   for i in $files
120   do
121     # Get library name
122     name=`grep "@LIBRARY=" $i |cut -d=  -f2`
123     fname=`grep "@FILENAME=" $i |cut -d=  -f2`
124
125     # Generate links for this library
126     sed -e "/@LINKS@/ r $DST/$fname.links" -e s/@LINKS@//g $i >$DST/$fname
127
128     # Generate the TOC file for the library
129     sh gen.sh $DST gen_toc.php $DST/$fname $DST/$fname
130     sh gen.sh $DST gen_html_index.php $DST/$fname $DST/$fname
131
132     # Generate the link for the top index.html for this library
133     echo "<LI><A HREF="$fname">$name</A>" >>$DST/index.html.tmp
134     rm -f $DST/$fname.links
135   done
136
137   # Generate the top index.html file
138   index=`find $SRC -name "LIBINDEX"`
139   version=`grep SILC_VERSION_STRING $SRC/../includes/version_internal.h |cut -d\"  -f2`
140   curdate=`date`
141   sed -e "/@VERSION@/s//$version/" -e "/@DATE@/s//$curdate/" -e "/@BODY@/ r $DST/index.html.tmp" -e s/@BODY@//g $index >$DST/index.html
142   sh gen.sh $DST gen_toc.php $DST/index.html $DST/index.html
143   sh gen.sh $DST gen_html_index.php $DST/index.html $DST/index.html
144
145   rm -rf $DST/index.html.tmp
146   rm -rf /tmp/silcdoc.html
147   rm -rf /tmp/silcdoc_html.html
148 fi