75136813db79e31bbf0532838c2765282c9bd272
[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 # HTML documentation
40 #
41 if [ "$TYPE" = "HTML" ]; then
42   mkdir /tmp/silcdoc.html
43   cp $headers /tmp/silcdoc.html
44
45   # Generate the actual detailed documentation
46   path=`pwd`
47   cd /tmp/silcdoc.html
48   headers=`find . -name "silc*.h" |cut -d/  -f2 |cut -d.  -f1`
49   cd $path
50   for i in $headers
51   do
52     $ROBO /tmp/silcdoc.html/$i.h $DST/$i.html $TYPE
53
54     # Generate the TOC file
55     sh gen.sh gen_toc.php $DST/$i.html $DST/$i.html
56     sh gen.sh index.php $DST/$i.html $DST/$i.html
57
58     # Generate the details and the layour
59     files=`find $DST -name ""$i"_*.html"`
60     for k in $files
61     do
62       sh gen.sh gen_detail.php $k $k
63       sh gen.sh index.php $k $k
64     done
65
66     rm -f $DST/$i_index.tmpl
67   done
68
69   # Generate the index and TOC files from the DIRECTORY files
70   files=`find $SRC -name "DIRECTORY"`
71   touch $DST/index.html.tmp
72   for i in $files
73   do
74     # Get library name
75     name=`grep "@LIBRARY=" $i |cut -d=  -f2`
76     fname=`grep "@FILENAME" $i |cut -d=  -f2`
77
78     # Generate the TOC file for the library
79     sh gen.sh gen_toc.php $i $DST/$fname
80     sh gen.sh index.php $DST/$fname $DST/$fname
81
82     # Generate the link for the top index.html for this library
83     echo "<LI><A HREF="$fname">$name</A>" >>$DST/index.html.tmp
84   done
85
86   # Generate the top index.html file
87   index=`find $SRC -name "LIBINDEX"`
88   curdate=`date`
89   sed -e "/@DATE@/s//$curdate/" -e "/@BODY@/ r $DST/index.html.tmp" -e s/@BODY@//g $index >$DST/index.html
90   sh gen.sh gen_toc.php $DST/index.html $DST/index.html
91   sh gen.sh index.php $DST/index.html $DST/index.html
92
93   rm -rf $DST/index.html.tmp
94   rm -rf /tmp/silcdoc.html
95 fi