[Lxr-commits] CVS: lxr/lib/LXR Lang.pm,1.26,1.27
Brought to you by:
ajlittoz
|
From: Malcolm B. <mb...@us...> - 2002-01-23 14:59:27
|
Update of /cvsroot/lxr/lxr/lib/LXR
In directory usw-pr-cvs1:/tmp/cvs-serv10443/lib/LXR
Modified Files:
Lang.pm
Log Message:
Add mapping from interpreter names to languages. If the file extension does
not select a language, then the first line of the file is checked for a #!
If one is found, then the interpreter name is matched against the 'interpreters'
map in lxr.conf, and the relevant language module loaded.
Index: Lang.pm
===================================================================
RCS file: /cvsroot/lxr/lxr/lib/LXR/Lang.pm,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- Lang.pm 2002/01/23 08:12:05 1.26
+++ Lang.pm 2002/01/23 14:59:21 1.27
@@ -37,22 +37,32 @@
last;
}
}
-
+
if (!defined $lang) {
# Try to see if it's a script
my $fh = $files->getfilehandle($pathname, $release);
- $fh->getline =~ /^#!\s*(\S+)/s;
+ $fh->getline =~ /^\#!\s*(\S+)/s;
my $shebang = $1;
+ my %filetype = %{$config->filetype};
+ my %inter = %{$config->interpreters};
- if ($shebang =~ /perl/) {
- require LXR::Lang::Generic;
- $lang = new LXR::Lang::Generic($pathname, $release, 'Perl');
- } else {
- $lang = undef;
+ foreach my $patt (keys %inter) {
+ if ($shebang =~ /$patt/) {
+ eval "require $filetype{$inter{$patt}}[2]";
+ die "Unable to load $filetype{$inter{$patt}}[2] Lang class, $@" if $@;
+ my $create = "new ".
+ $filetype{$inter{$patt}}[2].'($pathname, $release, $filetype{$inter{$patt}}[0])';
+ $lang = eval($create);
+ last if defined $lang;
+ die "Unable to create $filetype{$inter{$patt}}[2] Lang object, $@";
+ }
}
}
+ # No match for this file
+ return undef if !defined $lang;
+
$$lang{'itag'} = \@itag if $lang;
return $lang;
|