Added cross-reference support for document generator.
[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   done
98
99   # Generate cross reference files
100   path=`pwd`
101   cd /tmp/silcdoc.html
102   headers=`find . -name "silc*.h" |cut -d/  -f2 |cut -d.  -f1`
103   cd $path
104   touch $DST/silcdoc_xref
105   for i in $headers
106   do
107     $ROBO /tmp/silcdoc.html/$i.h $DST/$i.html $TYPE GENXREF $DST/$i.xref
108     echo $DST/$i.xref >>$DST/silcdoc_xref
109   done
110
111   # Generate the actual detailed documentation
112   path=`pwd`
113   cd /tmp/silcdoc.html
114   headers=`find . -name "silc*.h" |cut -d/  -f2 |cut -d.  -f1`
115   cd $path
116   for i in $headers
117   do
118     $ROBO /tmp/silcdoc.html/$i.h $DST/$i.html XREF $DST/silcdoc_xref $TYPE
119
120     # Generate the TOC file
121     sh gen.sh $DST gen_index.php 1 $DST/$i.html $DST/$i.html
122
123     # Generate the details and the layout
124     files=`find $DST -name ""$i"-*.html"`
125     for k in $files
126     do
127       sh gen.sh $DST gen_index.php 0 $k $k
128     done
129
130     rm -f $DST/$i-index.tmpl
131   done
132
133   # Generate the index and TOC files from the DIRECTORY files
134   files=`find $SRC -name "DIRECTORY"`
135   for i in $files
136   do
137     # Get library name
138     name=`grep "@LIBRARY=" $i |cut -d=  -f2`
139     fname=`grep "@FILENAME=" $i |cut -d=  -f2`
140
141     # Generate links for this library
142     sed -e "/@LINKS@/ r $DST/$fname.links" -e s/@LINKS@//g $i >$DST/$fname
143
144     # Generate the TOC file for the library
145     sh gen.sh $DST gen_index.php 1 $DST/$fname $DST/$fname
146
147     # Generate the link for the top index.html for this library
148     echo "<li><a href="$fname">$name</a>" >>$DST/index.html.tmp
149     rm -f $DST/$fname.links
150   done
151
152   # Generate the top index.html file
153   index=`find $SRC -name "LIBINDEX"`
154   version=`grep SILC_VERSION_STRING $SRC/../includes/version_internal.h |cut -d\"  -f2`
155   curdate=`date`
156   sed -e "/@VERSION@/s//$version/" -e "/@DATE@/s//$curdate/" -e "/@BODY@/ r $DST/index.html.tmp" -e s/@BODY@//g $index >$DST/index.html
157   sh gen.sh $DST gen_index.php 2 $DST/index.html $DST/index.html
158
159   rm -rf $DST/index.html.tmp
160   rm -rf /tmp/silcdoc.html
161   rm -rf /tmp/silcdoc_html.html
162 fi