Skip to content
Browse files

added all constants from header files via script

  • Loading branch information...
1 parent 0efe4c9 commit 4a4c0cbdf8d28077dd4ef3e6c413571ebbef8e24 Tobias Leich committed Nov 12, 2009
Showing with 3,288 additions and 541 deletions.
  1. +3,123 −453 lib/SDL/Constants.pm
  2. +155 −46 scripts/auto_constants.pl
  3. +10 −42 t/constantspm.t
View
3,576 lib/SDL/Constants.pm
3,123 additions, 453 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
201 scripts/auto_constants.pl
@@ -8,95 +8,204 @@
print "# Getting header constants from $head_loc\n";
-my @header = <$head_loc/*>;
+my @header = <$head_loc/*.h>;
-my $is_enum = 0;
-my $is_comment = 0;
-my $enum_val = -1;
-my $line = '';
+my $is_enum = 0;
+my $is_comment = 0;
+my $enum_val = -1;
+my $line = '';
+my @names = ();
+my @values = ();
+my $maxNameLen = 0;
foreach (@header)
{
- print "\n# from $_:\n";
- open FH, $_;
+ #print "\n# from $_:\n";
+ open (FH, $_) || die "Can not open file $_: $!";
while(<FH>)
{
$_ =~ s/\/\*.*\*\///g;
$_ =~ s/\/\/.*$//g;
+ $_ =~ s/^\s+//;
+ $_ =~ s/\s+$//;
+ #print $_;
+
if($_ =~ /\/\*/)
{
$line .= $_;
$line =~ s/\/\*.*//;
$is_comment = 1;
+ #print(__LINE__);
}
- if($is_comment && $_ !~ /\*\//)
- {
- next;
- }
-
if($is_comment && $_ =~ /\*\//)
{
+ $_ =~ s/.*\*\///;
$line .= $_;
- $line =~ s/.*\*\///;
+ #print "heureka$line";
$is_comment = 0;
+ #print(__LINE__);
+ next;
}
+ next if($is_comment && $_ !~ /\*\//);
+
# if we are inside an enum, and there is an linebreak in value
- if($is_enum && $line !~ /,.*$/ && $_ !~ /,.*$/ && $_ !~ /^\s*}\s+(\w+)\s*;\s*$/ && $line !~ /^typedef\s+enum\s*{\s*$/)
+ if($is_enum && $line !~ /,\s*$/ && $_ !~ /,\s*$/ && $_ !~ /^\s*}\s+(\w+)\s*;\s*$/ && $line !~ /^typedef\s+enum\s*{\s*$/)
{
$line .= $_;
- $line =~ s/\s+//g;
+ #$line =~ s/\s+/ /g;
next;
}
- elsif($is_enum && $line !~ /,.*$/ && $_ =~ /,\s*(.*){0,1}$/ && $_ !~ /^\s*}\s+(\w+)\s*;\s*$/ && $line !~ /^typedef\s+enum\s*{\s*$/)
+ #elsif($is_enum && $line !~ /,\s*$/ && $_ =~ /,\s*$/ && $_ !~ /^\s*}\s+(\w+)\s*;\s*$/ && $line !~ /^typedef\s+enum\s*{\s*$/)
+ elsif($is_enum && $line !~ /,\s*$/ && $_ =~ /,\s*$/ && $line !~ /^typedef\s+enum\s*{\s*$/)
{
$line .= $_;
- $line =~ s/\s+//g;
+ #print(__LINE__);
+ #make_constant($line);
+ #$line =~ s/\s+/ /g;
}
- elsif($is_enum && $line !~ /,.*$/ && $_ =~ /^\s*}\s+(\w+)\s*;\s*$/)
+ elsif($is_enum && $line !~ /,\s*$/ && $_ =~ /^\s*}\s+(\w+)\s*;\s*$/)
{
+ #print(__LINE__);
+ make_constant($line);
+ #print(__LINE__);
+ make_constant($_);
$line = $_;
+ #next;
}
- else
+# elsif($is_enum && $_ =~ /,\s*$/)
+# {
+# print(__LINE__); make_constant($_);
+# $line = $_;
+# }
+ #else
{
+ #print(__LINE__);
+ make_constant($line);
$line = $_;
}
- #print("\n$line\n") if ($is_enum);
+ #make_constant($line);
+ }
+
+ close FH;
+}
+
+
+for(my $i = 0; $i < $#names; $i++)
+{
+ print("use constant {\n") unless $i ;
+
+ print("};\n\nuse constant {\n") if 'enum' eq $names[$i] && 'open' eq $values[$i];
- # found an enum
- if($line =~ /^typedef\s+enum\s*{\s*$/)
+ print("}; # $values[$i]\n\nuse constant {\n") if 'enum' eq $names[$i] && 'open' ne $values[$i];
+
+ printf("\t%-" . $maxNameLen . "s => %s,\n", $names[$i], $values[$i]) if 'CRAP!' ne $values[$i] && 'enum' ne $names[$i];
+
+ print("};\n") if($i == $#names - 1);
+}
+
+
+
+sub make_constant
+{
+ my $_line = shift;
+ my $name = '';
+ my $value = '';
+
+ # found an enum
+ if($_line =~ /^typedef\s+enum\s*{\s*$/)
+ {
+ $is_enum = 1;
+ $enum_val = -1;
+ push(@names, 'enum');
+ push(@values, 'open');
+ }
+
+ # closed enum
+ if($is_enum && $_line =~ /^\s*}\s+(\w+)\s*;\s*$/)
+ {
+ $is_enum = 0;
+ push(@names, 'enum');
+ push(@values, $1);
+ }
+
+ # inside an enum (without value)
+ if($is_enum && $_line =~ /^\s*(\w+)\s*,{0,1}\s*$/)
+ {
+ $name = $1;
+ $value = ++$enum_val;
+ }
+
+ # inside an enum (decimal)
+ if($is_enum && $_line =~ /^\s*(\w+)\s*=\s*([+-]{0,1}\d+)\s*,{0,1}\s*$/i)
+ {
+ $name = $1;
+ $value = $2;
+ $enum_val = $2;
+ }
+
+ # inside an enum (hex)
+ if($is_enum && $_line =~ /^\s*(\w+)\s*=\s*(0x[\dA-F]+)\s*,{0,1}\s*$/i)
+ {
+ $name = $1;
+ $value = $2;
+ }
+
+ # inside an enum (function)
+ if($is_enum && $_line =~ /^\s*(\w+)\s*=\s*([\w\(\)\|]+)\s*,{0,1}\s*$/i)
+ {
+ $name = $1;
+ $value = $2;
+ }
+
+ # pattern: "#define SDL_RELEASED 0" (decimal or hex or name)
+ if($_line =~ /^#define\s+([^_]\w+)\s+([+-]{0,1}\d+|0x[\dA-F]+|[\w\(\)\|]+)\s*$/i)
+ {
+ $name = $1;
+ $value = $2;
+ }
+
+ if($name !~ /^(_.*||[a-z_]+)$/ && $value !~ /^(_.*||[a-z_]+)$/)
+ {
+ my $index = index_of($name, @names);
+
+ if($index >= 0 && $name ne 'enum')
{
- $is_enum = 1;
- $enum_val = -1;
- print("\n#{\n");
+ $values[$index] = 'CRAP!' if $value ne $values[$index];
}
-
- # closed enum
- if($is_enum && $line =~ /^\s*}\s+(\w+)\s*;\s*$/)
+ else
{
- $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 && $line =~ /^\s*(\w+)\s*,{0,1}\s*$/);
-
- # inside an enum (decimal)
- printf("sub %s{ return %s; }\n", $1, $enum_val = $2) if($is_enum && $line =~ /^\s*(\w+)\s*=\s*(\d+)\s*,{0,1}.*$/i);
-
- # inside an enum (hex)
- printf("sub %s{ return %s; }\n", $1, $2) if($is_enum && $line =~ /^\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 && $line =~ /^\s*(\w+)\s*=\s*([A-Z_\(\)\|]+)\s*,{0,1}.*$/i);
+ while($value =~ /(\w*)/g)
+ {
+ my $index2 = index_of($1, @names);
+
+ if($index2 >= 0)
+ {
+ $value =~ s/$1/$values[$index2]/;
+ }
+ }
- # pattern: "#define SDL_RELEASED 0" (decimal or hex)
- printf("sub %s{ return %s; }\n", $1, $2) if($line =~ /^#define\s+([^_]\w+)\s+(\d+|0x[\dA-F]+)\s*$/i);
+ $maxNameLen = length($name) if $maxNameLen < length($name);
+ push(@names, $name);
+ push(@values, $value);
+ }
}
- close FH;
}
+
+sub index_of
+{
+ my $needle = shift;
+ my @array = @_;
+
+ for(my $i = 0; $i <= $#array; $i++)
+ {
+ return $i if $needle eq $array[$i];
+ }
+
+ return -1;
+}
View
52 t/constantspm.t
@@ -32,8 +32,8 @@ is( CD_TRAYEMPTY(), 0, 'CD_TRAYEMPTY() should also be available' );
is( INADDR_ANY, 0, 'INADDR_ANY should be imported' );
is( INADDR_ANY(), 0, 'INADDR_ANY() should also be available' );
-is( INADDR_NONE, -1, 'INADDR_NONE should be imported' );
-is( INADDR_NONE(), -1, 'INADDR_NONE() should also be available' );
+is( INADDR_NONE, 0xFFFFFFFF, 'INADDR_NONE should be imported' );
+is( INADDR_NONE(), 0xFFFFFFFF, 'INADDR_NONE() should also be available' );
is( KMOD_ALT, 768, 'KMOD_ALT should be imported' );
is( KMOD_ALT(), 768, 'KMOD_ALT() should also be available' );
@@ -584,12 +584,12 @@ is( SDL_BUTTON_LEFT, 1, 'SDL_BUTTON_LEFT should be imported' );
is( SDL_BUTTON_LEFT(), 1, 'SDL_BUTTON_LEFT() should also be available' );
is( SDL_BUTTON_MIDDLE, 2, 'SDL_BUTTON_MIDDLE should be imported' );
is( SDL_BUTTON_MIDDLE(), 2, 'SDL_BUTTON_MIDDLE() should also be available' );
-is( SDL_BUTTON_RIGHT, 4, 'SDL_BUTTON_RIGHT should be imported' );
-is( SDL_BUTTON_RIGHT(), 4, 'SDL_BUTTON_RIGHT() should also be available' );
-is( SDL_BUTTON_WHEELUP, 8, 'SDL_BUTTON_WHEELUP should be imported' );
-is( SDL_BUTTON_WHEELUP(), 8, 'SDL_BUTTON_WHEELUP() should also be available' );
-is( SDL_BUTTON_WHEELDOWN, 16, 'SDL_BUTTON_WHEELDOWN should be imported' );
-is( SDL_BUTTON_WHEELDOWN(), 16, 'SDL_BUTTON_WHEELDOWN() should also be available' );
+is( SDL_BUTTON_RIGHT, 3, 'SDL_BUTTON_RIGHT should be imported' );
+is( SDL_BUTTON_RIGHT(), 3, 'SDL_BUTTON_RIGHT() should also be available' );
+is( SDL_BUTTON_WHEELUP, 4, 'SDL_BUTTON_WHEELUP should be imported' );
+is( SDL_BUTTON_WHEELUP(), 4, 'SDL_BUTTON_WHEELUP() should also be available' );
+is( SDL_BUTTON_WHEELDOWN, 5, 'SDL_BUTTON_WHEELDOWN should be imported' );
+is( SDL_BUTTON_WHEELDOWN(), 5, 'SDL_BUTTON_WHEELDOWN() should also be available' );
is( SDL_DISABLE, 0, 'SDL_DISABLE should be imported' );
is( SDL_DISABLE(), 0, 'SDL_DISABLE() should also be available' );
@@ -615,8 +615,8 @@ is( SDL_EVENT_RESERVED6(), 22, 'SDL_EVENT_RESERVED6() should also be available')
is( SDL_EVENT_RESERVED7, 23, 'SDL_EVENT_RESERVED7 should be imported');
is( SDL_EVENT_RESERVED7(), 23, 'SDL_EVENT_RESERVED7() should also be available');
-is( SDL_FULLSCREEN, -2147483648, 'SDL_FULLSCREEN should be imported' );
-is( SDL_FULLSCREEN(), -2147483648, 'SDL_FULLSCREEN() should also be available' );
+is( SDL_FULLSCREEN, 0x80000000, 'SDL_FULLSCREEN should be imported' );
+is( SDL_FULLSCREEN(), 0x80000000, 'SDL_FULLSCREEN() should also be available' );
is( SDL_GETEVENT, 2, 'SDL_GETEVENT should be imported' );
is( SDL_GETEVENT(), 2, 'SDL_GETEVENT() should also be available' );
@@ -844,13 +844,6 @@ is( SMPEG_PLAYING(), 1, 'SMPEG_PLAYING() should also be available' );
is( SMPEG_STOPPED, 0, 'SMPEG_STOPPED should be imported' );
is( SMPEG_STOPPED(), 0, 'SMPEG_STOPPED() should also be available' );
-is( TEXT_BLENDED, 4, 'TEXT_BLENDED should be imported' );
-is( TEXT_BLENDED(), 4, 'TEXT_BLENDED() should also be available' );
-is( TEXT_SHADED, 2, 'TEXT_SHADED should be imported' );
-is( TEXT_SHADED(), 2, 'TEXT_SHADED() should also be available' );
-is( TEXT_SOLID, 1, 'TEXT_SOLID should be imported' );
-is( TEXT_SOLID(), 1, 'TEXT_SOLID() should also be available' );
-
is( TTF_STYLE_BOLD, 1, 'TTF_STYLE_BOLD should be imported' );
is( TTF_STYLE_BOLD(), 1, 'TTF_STYLE_BOLD() should also be available' );
is( TTF_STYLE_ITALIC, 2, 'TTF_STYLE_ITALIC should be imported' );
@@ -860,34 +853,9 @@ is( TTF_STYLE_NORMAL(), 0, 'TTF_STYLE_NORMAL() should also be available' );
is( TTF_STYLE_UNDERLINE, 4, 'TTF_STYLE_UNDERLINE should be imported' );
is( TTF_STYLE_UNDERLINE(), 4, 'TTF_STYLE_UNDERLINE() should also be available' );
-is( UNICODE_BLENDED, 256, 'UNICODE_BLENDED should be imported' );
-is( UNICODE_BLENDED(), 256, 'UNICODE_BLENDED() should also be available' );
-is( UNICODE_SHADED, 128, 'UNICODE_SHADED should be imported' );
-is( UNICODE_SHADED(), 128, 'UNICODE_SHADED() should also be available' );
-is( UNICODE_SOLID, 64, 'UNICODE_SOLID should be imported' );
-is( UNICODE_SOLID(), 64, 'UNICODE_SOLID() should also be available' );
-
-is( UTF8_BLENDED, 32, 'UTF8_BLENDED should be imported' );
-is( UTF8_BLENDED(), 32, 'UTF8_BLENDED() should also be available' );
-is( UTF8_SHADED, 16, 'UTF8_SHADED should be imported' );
-is( UTF8_SHADED(), 16, 'UTF8_SHADED() should also be available' );
-is( UTF8_SOLID, 8, 'UTF8_SOLID should be imported' );
-is( UTF8_SOLID(), 8, 'UTF8_SOLID() should also be available' );
-
is( SDL_SVG_FLAG_DIRECT, 0, 'SDL_SVG_FLAG_DIRECT should be imported' );
is( SDL_SVG_FLAG_DIRECT(), 0, 'SDL_SVG_FLAG_DIRECT() should also be available' );
is( SDL_SVG_FLAG_COMPOSITE, 1, 'SDL_SVG_FLAG_COMPOSITE should be imported' );
is( SDL_SVG_FLAG_COMPOSITE(), 1, 'SDL_SVG_FLAG_COMPOSITE() should also be available' );
-is( SDL_SAMPLEFLAG_NONE, 0, 'SDL_SAMPLEFLAG_NONE should be imported' );
-is( SDL_SAMPLEFLAG_NONE(), 0,'SDL_SAMPLEFLAG_NONE() should also be available' );
-is( SDL_SAMPLEFLAG_CANSEEK, 1, 'SDL_SAMPLEFLAG_CANSEEK should be imported' );
-is( SDL_SAMPLEFLAG_CANSEEK(), 1, 'SDL_SAMPLEFLAG_CANSEEK() should also be available' );
-is( SDL_SAMPLEFLAG_EOF, 1 << 29, 'SDL_SAMPLEFLAG_EOF should be imported' );
-is( SDL_SAMPLEFLAG_EOF(), 1 << 29, 'SDL_SAMPLEFLAG_EOF() should also be available' );
-is( SDL_SAMPLEFLAG_ERROR, 1 << 30, 'SDL_SAMPLEFLAG_ERROR should be imported' );
-is( SDL_SAMPLEFLAG_ERROR(), 1 << 30, 'SDL_SAMPLEFLAG_ERROR() should also be available' );
-is( SDL_SAMPLEFLAG_EAGAIN, 1 << 31, 'SDL_SAMPLEFLAG_EAGAIN should be imported' );
-is( SDL_SAMPLEFLAG_EAGAIN(), 1 << 31, 'SDL_SAMPLEFLAG_EAGAIN() should also be available' );
-
done_testing();

0 comments on commit 4a4c0cb

Please sign in to comment.
Something went wrong with that request. Please try again.