Allow Plus sign instead of tab for faster typing
[infodrom.org/service.infodrom.org] / bin / wmldepend.pl
1 #! /usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 my @INCPATH;
7 my @FILES;
8
9 # expandfile() {
10 #         for i in $INCPATH
11 #         do
12 #                 if [ -f $i/$1 ] 
13 #                 then
14 #                         echo $i/$1
15 #                         exit 0
16 #                 fi
17 #         done
18 #         echo "Error: Include file \`$1' does not exist" > /dev/stderr
19 # #     echo "Fehler: Includedatei $1 existiert nicht" > /dev/stderr
20 #         exit 1
21 # }
22
23
24 sub expandfile
25 {
26     my $f = shift;
27     my %var = @_;
28     my $p;
29     my $pivot;
30
31     if ($f =~ m,\$\((.*)\),) {
32         $pivot = $1;
33         $f =~ s,\$\($1\),$var{$pivot},;
34     }
35
36     return "$f" if (-f "$f");
37
38     foreach $p (@INCPATH) {
39         return "$p/$f" if (-f "$p/$f");
40     }
41
42     printf STDERR "Error: Include file `$f' does not exist.\n"
43 }
44
45 sub findincludes
46 {
47     my $f = shift;
48     my %var = @_;
49     my @lines = ();
50     my ($l, $foo, $p);
51     my ($v, $e, $pivot);
52
53     open (F, $f) || printf STDERR "Error: Can't open $f, $!\n";
54     while (<F>) {
55         push (@lines, $_) if (m,^#(include|read)\s+[<"][^><"]*[>"].*,);
56     }
57     close (F);
58
59     foreach $l (@lines) {
60         if ($l =~ m,^#(include|read)\s+[<"]([^>"]*)[><"]\s+(.*),) {
61             $p = $2;
62             $foo = expandfile ($p, %var);
63             if ($3 =~ m,(\S+)="([^"]*)",) {
64                 $v=$1; $e=$2;
65                 if ($e =~ m,\$\((.*)\),) {
66                     $pivot = $1;
67                     $e =~ s,\$\($1\),$var{$pivot},;
68                 }
69                 $var{$v} = $e;
70             }
71         } elsif ($l =~ m,^#(include|read)\s+[<"]([^><"]*)[>"].*,) {
72             $p = $2;
73             $foo = expandfile ($p, %var);
74         }
75         printf " \\\n\t%s", $foo;
76         findincludes ($foo, %var);
77     }
78 }
79
80 # Argument parsing
81 #
82 while (my $foo = shift (@ARGV)) {
83     if ($foo =~ m,-I(.*),) {
84         push (@INCPATH, $1);
85     } else {
86         push (@FILES, $foo);
87     }
88 }
89
90 my %var;
91 foreach my $f (@FILES) {
92     my $foo = $f;
93     $foo =~ s/\.wml$/\.php/;
94     printf "%s: %s", $foo, $f;
95     findincludes ($f, %var);
96     print "\n";
97 }