From: Joey Schulze Date: Tue, 9 Dec 2003 18:19:09 +0000 (+0000) Subject: The Perl version is *a lot* faster than the shell version, so we'll X-Git-Url: https://git.infodrom.org/?p=infodrom.org%2Fwww.infodrom.org;a=commitdiff_plain;h=0362a9807377e14ab5f3d2b3e2adfc73fe860607;ds=sidebyside The Perl version is *a lot* faster than the shell version, so we'll finally switch. --- diff --git a/bin/wmldepend.pl b/bin/wmldepend.pl new file mode 100755 index 00000000..fad39607 --- /dev/null +++ b/bin/wmldepend.pl @@ -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 () { + 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"; +} diff --git a/src/Makefile b/src/Makefile index 40e83d90..2e58cda2 100644 --- a/src/Makefile +++ b/src/Makefile @@ -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