7 Getopts
('dc:p:o:') || die "foo";
13 die "missing arg" if (!defined $opt_c || !defined $opt_p || !defined $opt_o);
19 print "parse config.h\n" if ($debug);
21 open IN
, $opt_c || die "failed open ${opt_c}";
28 if (m/\s*#ifdef\s+(.*)/) {
30 if (defined $defines{$var}) {
36 } elsif (m/\s*#ifndef\s+(.*)/) {
38 if (defined $defines{$var}) {
44 } elsif (m/\s*#else/) {
45 my $var = pop @nesting;
49 } elsif ($nesting[$#nesting] and m/\s*#define\s+(\w+)\s+(\S+)/) {
51 $res = 1 if (!defined $res);
59 foreach my $i (keys %defines) {
60 print "k: $i v: $defines{$i}\n";
64 open IN
, "$opt_p" || die "failed open ${opt_p}";
65 open OUT
, ">$opt_o" || die "failed open ${opt_o}";
67 print "parse roken.h.in\n" if ($debug);
69 print OUT
"/* This is an OS dependent, generated file */\n";
72 print OUT
"#ifndef __ROKEN_H__\n";
73 print OUT
"#define __ROKEN_H__\n";
79 if (m/\s*#ifdef\s+(.*)/) {
81 if (defined $defines{$var}) {
87 } elsif (m/\s*#ifndef\s+(.*)/) {
89 if (defined $defines{$var}) {
95 } elsif (m/\s*#if\s+(.*)/) {
96 my $res = parse_if
($1);
97 print "line = $res: $1\n" if ($debug);
100 } elsif (m/\s*#elif\s+(.*)/) {
101 my $res = pop @nesting;
105 my $res = parse_if
($1);
109 } elsif (m/\s*#else/) {
110 my $var = pop @nesting;
114 } elsif (m/\s*#endif/) {
118 print "line: $_\n" if ($debug);
119 print "nesting dep $#{nesting}\n" if ($debug);
121 while ($i le $#nesting) {
122 $t = 0 if ($nesting[$i] le 0);
123 print "nesting $i val $nesting[$i] -> $t\n" if ($debug);
132 print OUT
"#endif /* __ROKEN_H__ */\n";
146 print "end $_\n" if ($debug);
148 } elsif (m/^([^&]+)\&\&(.*)$/) {
149 print "$1 and $2\n" if ($debug);
150 return parse_if
($1) and parse_if
($2);
151 } elsif (m/^([^\|]+)\|\|(.*)$/) {
152 print "$1 or $2\n" if ($debug);
153 return parse_if
($1) or parse_if
($2);
154 } elsif (m/^\s*(\!)?\s*defined\((\w+)\)/) {
155 ($neg, $var) = ($1, $2);
156 print "def: ${neg}-defined(${var})\n" if ($debug);
157 my $res = defined $defines{$var};
165 print "res: $res\n" if ($debug);
167 } elsif (m/^\s*(\!)?(\w+)/) {
168 ($neg, $var) = ($1, $2);
169 print "var: $neg $var\n" if ($debug);
171 if (defined $defines{$var}) {
172 $res = $defines{$var};
176 $res = ! $res if ($neg =~ m/!/);
177 print "res: $res\n" if ($debug);
180 die "failed parse: $_\n";