r5987 - trunk/eda/boom
werner at docs.openmoko.org
werner at docs.openmoko.org
Sun Oct 17 02:19:52 CEST 2010
Author: werner
Date: 2010-10-17 02:19:52 +0200 (Sun, 17 Oct 2010)
New Revision: 5987
Modified:
trunk/eda/boom/parser.pl
Log:
Make include relative to the includer, facilitating use of subdirectories.
- boom/parser.pl: make relative paths in includes relative to the directory
containing the file from which we include
Modified: trunk/eda/boom/parser.pl
===================================================================
--- trunk/eda/boom/parser.pl 2010-10-16 13:52:50 UTC (rev 5986)
+++ trunk/eda/boom/parser.pl 2010-10-17 00:19:52 UTC (rev 5987)
@@ -363,22 +363,43 @@
}
+sub dirname
+{
+ local ($name) = @_;
+
+ return $name =~ m|/[^/]*$| ? $` : ".";
+}
+
+
+sub rel_path
+{
+ local ($cwd, $path) = @_;
+
+ return $path =~ m|^/| ? $path : "$cwd/$path";
+}
+
+
sub parse_one
{
local ($name) = @_;
my $file = new IO::File->new($name) || die "$name: $!";
+ my $dir = &dirname($name);
+
while (1) {
$_ = <$file>;
if (!defined $_) {
$file->close();
return unless @inc;
$file = pop @inc;
+ $dir = pop @dir;
next;
}
if (/^\s*include\s+(.*?)\s*$/) {
push(@inc, $file);
- $file = new IO::File->new($1) || die "$1: $!";
+ push(@dir, $dir);
+ $name = &rel_path($dir, $1);
+ $file = new IO::File->new($name) || die "$name: $!";
next;
}
chop;
More information about the commitlog
mailing list