changeset 10986:b218d4ec6996 HEAD

config: Parser script now supports preserving #ifdefs around service_settings.
author Timo Sirainen <tss@iki.fi>
date Thu, 25 Mar 2010 20:03:52 +0200
parents 93be85bb9db8
children 8f5bc2a21f99
files src/config/settings-get.pl
diffstat 1 files changed, 28 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/config/settings-get.pl	Thu Mar 25 19:28:56 2010 +0200
+++ b/src/config/settings-get.pl	Thu Mar 25 20:03:52 2010 +0200
@@ -13,6 +13,7 @@
 print 'extern buffer_t config_all_services_buf;';
 
 my @services = ();
+my @service_ifdefs = ();
 my %parsers = {};
 
 foreach my $file (@ARGV) {
@@ -25,6 +26,8 @@
   my $code = "";
   my %funcs;
   my $cur_name = "";
+  my $ifdef = "";
+  my $state_ifdef = 0;
   
   while (<$f>) {
     my $write = 0;
@@ -35,7 +38,14 @@
 	$state++;
       } elsif (/^struct service_settings (.*) = {/) {
 	$state++;
+	if ($ifdef eq "") {
+	  $state_ifdef = 0;
+	} else {
+	  $_ = $ifdef."\n".$_;
+	  $state_ifdef = 1;
+	}
 	push @services, $1;
+	push @service_ifdefs, $ifdef;
       } elsif (/^(static )?const struct setting_parser_info (.*) = {/) {
 	$cur_name = $2;
 	$state++ if ($cur_name !~ /^\*default_/);
@@ -45,7 +55,13 @@
 	$state = 4;
 	$code .= $_;
       }
-
+      
+      if (/(^#ifdef .*)$/ || /^(#if .*)$/) {
+	$ifdef = $1;
+      } else {
+	$ifdef = "";
+      }
+      
       if (/#define.*DEF/ || /^#undef.*DEF/ || /ARRAY_DEFINE_TYPE.*_settings/) {
 	$write = 1;
 	$state = 2 if (/\\$/);
@@ -83,6 +99,10 @@
       $write = 1;
       if (/};/) {
 	$state = 0;
+	if ($state_ifdef) {
+	  $_ .= "#endif\n";
+	  $state_ifdef = 0;
+	}
       }
     }
   
@@ -99,8 +119,13 @@
 
 print "static struct service_settings *config_all_services[] = {\n";
 
-foreach my $name (@services) {
-  print "\t&$name,\n";
+for (my $i = 0; $i < scalar(@services); $i++) {
+  my $ifdef = $service_ifdefs[$i];
+  print "$ifdef\n" if ($ifdef ne "");
+  print "\t";
+  print "," if ($i > 0);
+  print "&".$services[$i]."\n";
+  print "#endif\n" if ($ifdef ne "");
 }
 print "};\n";
 print "buffer_t config_all_services_buf = {\n";