Initial files
[infodrom.org/luonnotar.infodrom.org] / bin / wmldepend.sh
1 #!/bin/sh
2
3 INCPATH=.
4 FILES=''
5
6 expandfile() {
7         for i in $INCPATH
8         do
9                 if [ -f $i/$1 ] 
10                 then
11                         echo $i/$1
12                         exit 0
13                 fi
14         done
15         echo "Error: Include file \`$1' does not exist" > /dev/stderr
16 #       echo "Fehler: Includedatei $1 existiert nicht" > /dev/stderr
17         exit 1
18 }
19
20 findincludes() {
21         for i in $*
22         do
23                 for j in `sed -n 's/^#[Ii][Nn][Cc][Ll][Uu][Dd][Ee] *[<"]\([^>"]*\).*/\1/p' $i` \
24                          `sed -n 's/^#[Rr][Ee][Aa][Dd] *[<"]\([^>"]*\).*/\1/p' $i`
25                 do
26                         echo ' \'
27                         foo=`expandfile $j`
28                         echo -n ' '$foo
29                         findincludes $foo
30                 done
31         done
32 }
33
34 while [ "x$1" != "x" ]
35 do
36         case "$1" in
37                 -I*)
38                         INCPATH=$INCPATH' '${1##-I}
39                         #INCPATH=$INCPATH' '$(1)
40                         ;;
41                 *)
42                         FILES=$FILES' '$1
43                         ;;
44         esac
45         shift
46 done
47
48 addmenu() {
49         root_prefix=`perl -MCwd -e '$_ = cwd;s/^.*src\/?//;@f=split /\//;$n=$#f+1;print "../"x $n;'`
50         menu_prefix=${root_prefix##../}
51
52         if [ -f ${menu_prefix}menu.def ]
53         then
54                 echo ' \'
55                 echo -n ' '${menu_prefix}menu.def
56         fi
57 }
58
59 export INCPATH
60 export FILES
61
62 for i in $FILES
63 do
64         echo -n `echo $i | sed 's/.wml/.html/'`: $i
65         findincludes $i
66         addmenu
67         echo
68 done