From: Tobias Leich Date: Wed, 11 Nov 2009 20:25:52 +0000 (+0100) Subject: more, but not ready yet X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1d701addd190b69d68ce6ce26e52554b4dfa99d9;p=sdlgit%2FSDL_perl.git more, but not ready yet --- diff --git a/scripts/auto_constants.pl b/scripts/auto_constants.pl index a998e00..dceffbe 100644 --- a/scripts/auto_constants.pl +++ b/scripts/auto_constants.pl @@ -8,19 +8,47 @@ my $head_loc = `sdl-config --cflags`; print "# Getting header constants from $head_loc\n"; -my @header = <$head_loc/*>; +#my @header = <$head_loc/*>; +my @header = <$head_loc/SDL_events.h>; + +my $is_enum = 0; +my $enum_val = -1; foreach (@header) { - print "# from $_:\n"; + print "\n# from $_:\n"; open FH, $_; while() { - # pattern: "#define SDL_RELEASED 0" (decimal) - printf("sub %s{ return %s; }\n", $1, $2) if($_ =~ /^#define\s+([^_]\w+)\s+(\d+)\s*$/); + # found an enum + if($_ =~ /^typedef\s+enum\s*{\s*$/) + { + $is_enum = 1; + $enum_val = -1; + print("\n#{\n"); + } + + # closed enum + if($is_enum && $_ =~ /^\s*}\s+(\w+)\s*;\s*$/) + { + $is_enum = 0; + printf("#} enum %s\n\n", $1); + } + + # inside an enum (without value) + printf("sub %s{ return %s; }\n", $1, ++$enum_val) if($is_enum && $_ =~ /^\s*(\w+)\s*,{0,1}\s*(\/.*){0,1}$/); + + # inside an enum (decimal) + printf("sub %s{ return %s; }\n", $1, $enum_val = $2) if($is_enum && $_ =~ /^\s*(\w+)\s*=\s*(\d+)\s*,{0,1}.*$/i); + + # inside an enum (hex) + printf("sub %s{ return %s; }\n", $1, $2) if($is_enum && $_ =~ /^\s*(\w+)\s*=\s*(0x[\dA-F]+)\s*,{0,1}.*$/i); + + # inside an enum (function) + printf("sub %s{ return %s; }\n", $1, $2) if($is_enum && $_ =~ /^\s*(\w+)\s*=\s*([A-Z_\(\)\|]+)\s*,{0,1}.*$/i); - # pattern: "#define SDL_RELEASED 0x1234" (hex) - printf("sub %s{ return %s; }\n", $1, $2) if($_ =~ /^#define\s+([^_]\w+)\s+(0x\d+)\s*$/); + # pattern: "#define SDL_RELEASED 0" (decimal or hex) + printf("sub %s{ return %s; }\n", $1, $2) if($_ =~ /^#define\s+([^_]\w+)\s+(\d+|0x[\dA-F]+)\s*$/i); } close FH; }