9002
|
1 #!/usr/bin/env perl
|
|
2 use strict;
|
|
3
|
|
4 print '#include "lib.h"'."\n";
|
|
5 print '#include "settings-parser.h"'."\n";
|
|
6 print '#include "all-settings.h"'."\n";
|
|
7 print '#include <stddef.h>'."\n";
|
|
8 print '#define CONFIG_BINARY'."\n";
|
|
9
|
|
10 my %parsers = {};
|
|
11
|
|
12 foreach my $file (@ARGV) {
|
|
13 my $f;
|
|
14 open($f, $file) || die "Can't open $file: $@";
|
|
15
|
|
16 my $state = 0;
|
|
17 my $file_contents = "";
|
|
18 my $externs = "";
|
|
19
|
|
20 while (<$f>) {
|
|
21 my $write = 0;
|
|
22 if ($state == 0) {
|
|
23 if (/struct .*_settings {/ ||
|
|
24 /struct setting_define.*{/ ||
|
|
25 /struct .*_default_settings = {/) {
|
|
26 $state++;
|
|
27 } elsif (/^(static )?struct setting_parser_info (.*) = {/) {
|
|
28 $state++;
|
|
29 $parsers{$2} = 1;
|
|
30 } elsif (/^extern struct setting_parser_info (.*);/) {
|
|
31 $externs .= "extern struct setting_parser_info $1;\n";
|
|
32 }
|
|
33
|
|
34 if (/#define.*DEF/ || /^#undef.*DEF/) {
|
|
35 $write = 1;
|
|
36 $state = 2 if (/\\$/);
|
|
37 }
|
|
38 } elsif ($state == 2) {
|
|
39 $write = 1;
|
|
40 $state = 0 if (!/\\$/);
|
|
41 }
|
|
42
|
|
43 if ($state == 1 || $state == 3) {
|
|
44 if ($state == 1) {
|
|
45 if (/DEFLIST.*".*",(.*)$/) {
|
|
46 my $value = $1;
|
|
47 if ($value =~ /.*&(.*)\)/) {
|
|
48 $parsers{$1} = 0;
|
|
49 $externs .= "extern struct setting_parser_info $1;\n";
|
|
50 } else {
|
|
51 $state = 3;
|
|
52 }
|
|
53 }
|
|
54 } elsif ($state == 3) {
|
|
55 if (/.*&(.*)\)/) {
|
|
56 $parsers{$1} = 0;
|
|
57 }
|
|
58 }
|
|
59
|
|
60 $write = 1;
|
|
61 if (/};/) {
|
|
62 $state = 0;
|
|
63 }
|
|
64 }
|
|
65
|
|
66 $file_contents .= $_ if ($write);
|
|
67 }
|
|
68
|
|
69 print "/* $file */\n";
|
|
70 print $externs;
|
|
71 print $file_contents;
|
|
72
|
|
73 close $f;
|
|
74 }
|
|
75
|
|
76 print "struct config_setting_parser_list config_setting_parsers[] = {\n";
|
|
77 foreach my $name (keys %parsers) {
|
|
78 next if (!$parsers{$name});
|
|
79
|
|
80 my $module = "";
|
|
81 if ($name =~ /^([^_]*)/) {
|
|
82 $module = $1;
|
|
83 }
|
|
84 print " { \"$module\", &".$name.", NULL, NULL }, \n";
|
|
85 }
|
|
86 print " { NULL, NULL, NULL, NULL }\n";
|
|
87 print "};\n";
|