diff src/config/settings-get.pl @ 9002:9d0037a997f4 HEAD

Initial commit for config rewrite.
author Timo Sirainen <tss@iki.fi>
date Tue, 27 Jan 2009 18:21:53 -0500
parents
children c37f7113b1ee
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/config/settings-get.pl	Tue Jan 27 18:21:53 2009 -0500
@@ -0,0 +1,87 @@
+#!/usr/bin/env perl
+use strict;
+
+print '#include "lib.h"'."\n";
+print '#include "settings-parser.h"'."\n";
+print '#include "all-settings.h"'."\n";
+print '#include <stddef.h>'."\n";
+print '#define CONFIG_BINARY'."\n";
+
+my %parsers = {};
+
+foreach my $file (@ARGV) {
+  my $f;
+  open($f, $file) || die "Can't open $file: $@";
+  
+  my $state = 0;
+  my $file_contents = "";
+  my $externs = "";
+  
+  while (<$f>) {
+    my $write = 0;
+    if ($state == 0) {
+      if (/struct .*_settings {/ ||
+	  /struct setting_define.*{/ ||
+	  /struct .*_default_settings = {/) {
+	$state++;
+      } elsif (/^(static )?struct setting_parser_info (.*) = {/) {
+	$state++;
+	$parsers{$2} = 1;
+      } elsif (/^extern struct setting_parser_info (.*);/) {
+	$externs .= "extern struct setting_parser_info $1;\n";
+      }
+
+      if (/#define.*DEF/ || /^#undef.*DEF/) {
+	$write = 1;
+	$state = 2 if (/\\$/);
+      }
+    } elsif ($state == 2) {
+      $write = 1;
+      $state = 0 if (!/\\$/);
+    }
+    
+    if ($state == 1 || $state == 3) {
+      if ($state == 1) {
+	if (/DEFLIST.*".*",(.*)$/) {
+	  my $value = $1;
+	  if ($value =~ /.*&(.*)\)/) {
+	    $parsers{$1} = 0;
+	    $externs .= "extern struct setting_parser_info $1;\n";
+	  } else {
+	    $state = 3;
+	  }
+	}
+      } elsif ($state == 3) {
+	if (/.*&(.*)\)/) {
+	  $parsers{$1} = 0;
+	}        
+      }
+      
+      $write = 1;
+      if (/};/) {
+	$state = 0;
+      }
+    }
+  
+    $file_contents .= $_ if ($write);
+  }
+  
+  print "/* $file */\n";
+  print $externs;
+  print $file_contents;
+
+  close $f;
+}
+
+print "struct config_setting_parser_list config_setting_parsers[] = {\n";
+foreach my $name (keys %parsers) {
+  next if (!$parsers{$name});
+
+  my $module = "";
+  if ($name =~ /^([^_]*)/) {
+    $module = $1;
+  }
+  print "  { \"$module\", &".$name.", NULL, NULL }, \n";
+}
+print "  { NULL, NULL, NULL, NULL }\n";
+print "};\n";