Permalink
Browse files

regex for #define

  • Loading branch information...
Tobias Leich
Tobias Leich committed Nov 11, 2009
1 parent 409ac58 commit f14bf6bb1d0a59f94ba3fc5346466a77a63d3419
Showing with 19 additions and 15 deletions.
  1. +19 −15 scripts/auto_constants.pl
View
@@ -3,24 +3,28 @@
use warnings;
my $head_loc = `sdl-config --cflags`;
- $head_loc = (split ' ', $head_loc)[0];
- $head_loc =~ s/-I//;
-print 'Getting header constants from '.$head_loc."\n";
+ $head_loc = (split ' ', $head_loc)[0];
+ $head_loc =~ s/-I//;
+print "# Getting header constants from $head_loc\n";
-my @header = qw/ SDL.h /;
+my @header = qw/ SDL.h SDL_events.h /;
foreach (@header)
{
- open FH, $head_loc.'/'.$_;
- while(<FH>)
- {
- if ($_ =~ /#define SDL_/)
- {
- my $line = $_;
- my @cop = (split ' ', $line);
- print 'sub '.$cop[1].' {return '.$cop[2].'}'."\n" ;
- }
- }
- close FH;
+ print "# from $_:\n";
+ open FH, "$head_loc/$_";
+ while(<FH>)
+ {
+ if($_ =~ /#define SDL_/)
+ {
+ my $line = $_;
+ my @cop = (split ' ', $line);
+ print 'sub '.$cop[1].' {return '.$cop[2].'}'."\n" ;
+ }
+
+ # pattern: "#define SDL_RELEASED 0"
+ printf("sub %s{ return %s; }\n", $1, $2) if($_ =~ /^#define\s+(\w+)\s+(\w+)\s*$/);
+ }
+ close FH;
}

0 comments on commit f14bf6b

Please sign in to comment.