updates.
[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   mkdir /tmp/silcdoc.html
50   cp $headers /tmp/silcdoc.html
51
52   # Generate indes template from the DIRECTORY files
53   files=`find $SRC -name "DIRECTORY"`
54   for i in $files
55   do
56     # Get library name
57     name=`grep "@LIBRARY=" $i |cut -d=  -f2`
58     fname=`grep "@FILENAME=" $i |cut -d=  -f2`
59     links=`grep "@LINK=" $i |cut -d=  -f2 |cut -d:  -f1`
60
61     # Generate links to template file that can be included into various
62     # places on the webpage.
63     echo "<A HREF="$fname">$name</A><BR>" >>$DST/index.tmpl
64     for k in $links
65     do
66       n=`grep $k $i |cut -d=  -f2 |cut -d:  -f2`
67       echo "<LI><A HREF="$k">$n</A>" >>$DST/$fname.links
68       echo "&nbsp;&nbsp;&nbsp; <A HREF="$k">$n</A><BR>" >>$DST/index.tmpl
69     done
70   done
71
72   # Generate the actual detailed documentation
73   path=`pwd`
74   cd /tmp/silcdoc.html
75   headers=`find . -name "silc*.h" |cut -d/  -f2 |cut -d.  -f1`
76   cd $path
77   for i in $headers
78   do
79     $ROBO /tmp/silcdoc.html/$i.h $DST/$i.html $TYPE
80
81     # Generate the TOC file
82     sh gen.sh $DST gen_toc.php $DST/$i.html $DST/$i.html
83     sh gen.sh $DST index.php $DST/$i.html $DST/$i.html
84
85     # Generate the details and the layour
86     files=`find $DST -name ""$i"_*.html"`
87     for k in $files
88     do
89       sh gen.sh $DST gen_detail.php $k $k
90       sh gen.sh $DST index.php $k $k
91     done
92
93     rm -f $DST/$i_index.tmpl
94   done
95
96   # Generate the index and TOC files from the DIRECTORY files
97   files=`find $SRC -name "DIRECTORY"`
98   for i in $files
99   do
100     # Get library name
101     name=`grep "@LIBRARY=" $i |cut -d=  -f2`
102     fname=`grep "@FILENAME=" $i |cut -d=  -f2`
103
104     # Generate links for this library
105     sed -e "/@LINKS@/ r $DST/$fname.links" -e s/@LINKS@//g $i >$DST/$fname
106
107     # Generate the TOC file for the library
108     sh gen.sh $DST gen_toc.php $DST/$fname $DST/$fname
109     sh gen.sh $DST index.php $DST/$fname $DST/$fname
110
111     # Generate the link for the top index.html for this library
112     echo "<LI><A HREF="$fname">$name</A>" >>$DST/index.html.tmp
113     rm -f $DST/$fname.links
114   done
115
116   # Generate the top index.html file
117   index=`find $SRC -name "LIBINDEX"`
118   curdate=`date`
119   sed -e "/@DATE@/s//$curdate/" -e "/@BODY@/ r $DST/index.html.tmp" -e s/@BODY@//g $index >$DST/index.html
120   sh gen.sh $DST gen_toc.php $DST/index.html $DST/index.html
121   sh gen.sh $DST index.php $DST/index.html $DST/index.html
122
123   rm -rf $DST/index.html.tmp
124   rm -rf /tmp/silcdoc.html
125 fi