r5977 - trunk/eda/boom

werner at docs.openmoko.org werner at docs.openmoko.org
Sun Sep 12 21:41:15 CEST 2010


Author: werner
Date: 2010-09-12 21:41:14 +0200 (Sun, 12 Sep 2010)
New Revision: 5977

Modified:
   trunk/eda/boom/parser.pl
Log:
Added recursive includes to BOM parser. Syntax: include filename

- boom/parser.pl (parse, parse_one): explicitly switch from file to file and 
  call parse_one for only one file at a time
- boom/parser.pl (parse_one): added recursive includes



Modified: trunk/eda/boom/parser.pl
===================================================================
--- trunk/eda/boom/parser.pl	2010-09-12 02:52:04 UTC (rev 5976)
+++ trunk/eda/boom/parser.pl	2010-09-12 19:41:14 UTC (rev 5977)
@@ -1,6 +1,7 @@
 #!/usr/bin/perl
 
 use re 'eval';
+use IO::File;
 
 
 #
@@ -362,10 +363,24 @@
 }
 
 
-sub parse
+sub parse_one
 {
-    $mode = *skip;
-    while (<>) {
+    local ($name) = @_;
+
+    my $file = new IO::File->new($name) || die "$name: $!";
+    while (1) {
+	$_ = <$file>;
+	if (!defined $_) {
+	    $file->close();
+	    return unless @inc;
+	    $file = pop @inc;
+	    next;
+	}
+	if (/^\s*include\s+(.*?)\s*$/) {
+	    push(@inc, $file);
+	    $file = new IO::File->new($1) || die "$1: $!";
+	    next;
+	}
 	chop;
 
 # ----- KiCad BOM parsing. Alas, the BOM is localized, so there are almost no
@@ -442,4 +457,14 @@
     }
 }
 
+
+sub parse
+{
+    $mode = *skip;
+    for (@ARGV) {
+	&parse_one($_);
+    }
+}
+
+
 return 1;




More information about the commitlog mailing list