The Perl version is *a lot* faster than the shell version, so we'll
authorJoey Schulze <joey@infodrom.org>
Tue, 9 Dec 2003 18:19:09 +0000 (18:19 +0000)
committerJoey Schulze <joey@infodrom.org>
Tue, 9 Dec 2003 18:19:09 +0000 (18:19 +0000)
finally switch.

bin/wmldepend.pl [new file with mode: 0755]
src/Makefile

diff --git a/bin/wmldepend.pl b/bin/wmldepend.pl
new file mode 100755 (executable)
index 0000000..fad3960
--- /dev/null
@@ -0,0 +1,93 @@
+#! /usr/bin/perl
+
+$INCPATH = "";
+$FILES = "";
+
+# expandfile() {
+#        for i in $INCPATH
+#        do
+#                if [ -f $i/$1 ] 
+#                then
+#                        echo $i/$1
+#                        exit 0
+#                fi
+#        done
+#        echo "Error: Include file \`$1' does not exist" > /dev/stderr
+# #    echo "Fehler: Includedatei $1 existiert nicht" > /dev/stderr
+#        exit 1
+# }
+# 
+
+sub expandfile
+{
+    my $f = shift;
+    my %var = @_;
+    my $p;
+
+    if ($f =~ m,\$\((.*)\),) {
+       $pivot = $1;
+       $f =~ s,\$\($1\),$var{$pivot},;
+    }
+
+    return "$f" if (-f "$f");
+
+    foreach $p (@INCPATH) {
+       return "$p/$f" if (-f "$p/$f");
+    }
+
+    printf STDERR "Error: Include file `$f' does not exist.\n"
+}
+
+sub findincludes
+{
+    my $f = shift;
+    my %var = @_;
+    my @lines = ();
+    my ($l, $foo, $p);
+    my ($v, $e, $pivot);
+
+    open (F, $f) || printf STDERR "Error: Can't open $f, $!\n";
+    while (<F>) {
+       push (@lines, $_) if (m,^#(include|read)\s+[<"][^><"]*[>"].*,);
+    }
+    close (F);
+
+    foreach $l (@lines) {
+       if ($l =~ m,^#(include|read)\s+[<"]([^>"]*)[><"]\s+(.*),) {
+           $p = $2;
+           $foo = expandfile ($p, %var);
+           if ($3 =~ m,(\S+)="([^"]*)",) {
+               $v=$1; $e=$2;
+               if ($e =~ m,\$\((.*)\),) {
+                   $pivot = $1;
+                   $e =~ s,\$\($1\),$var{$pivot},;
+               }
+               $var{$v} = $e;
+           }
+       } elsif ($l =~ m,^#(include|read)\s+[<"]([^><"]*)[>"].*,) {
+           $p = $2;
+           $foo = expandfile ($p, %var);
+       }
+       printf " \\\n\t%s", $foo;
+       findincludes ($foo, %var);
+    }
+}
+
+# Argument parsing
+#
+while ($foo = shift (@ARGV)) {
+    if ($foo =~ m,-I(.*),) {
+       push (@INCPATH, $1);
+    } else {
+       push (@FILES, $foo);
+    }
+}
+
+%var=();
+for $f (@FILES) {
+    $foo = $f;
+    $foo =~ s/\.wml$/\.html/;
+    printf "%s: %s", $foo, $f;
+    findincludes ($f, %var);
+    print "\n";
+}
index 40e83d9..2e58cda 100644 (file)
@@ -40,7 +40,7 @@ test:
        make -C $(ROOT_PREFIX).. test
 
 depend .depend:
-       $(ROOT_PREFIX)../bin/wmldepend.sh $(IFLAGS) $(WML_FILES) > .depend
+       $(ROOT_PREFIX)../bin/wmldepend.pl $(IFLAGS) $(WML_FILES) > .depend
 
 rdepend:
        make depend