summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/rbdefines_helper.pl
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/lua/rbdefines_helper.pl')
-rwxr-xr-xapps/plugins/lua/rbdefines_helper.pl98
1 files changed, 70 insertions, 28 deletions
diff --git a/apps/plugins/lua/rbdefines_helper.pl b/apps/plugins/lua/rbdefines_helper.pl
index ba15346a8a..b55609077d 100755
--- a/apps/plugins/lua/rbdefines_helper.pl
+++ b/apps/plugins/lua/rbdefines_helper.pl
@@ -20,28 +20,46 @@
20 20
21#rockbox to lua define generator, add names of constants to the array to include 21#rockbox to lua define generator, add names of constants to the array to include
22 22
23my @rockbox_defines = ( 23if ($#ARGV + 1 != 1) {
24 '^HZ$', 24 warn "no definition type defined";
25 '^LCD_(DEPTH|HEIGHT|WIDTH)$', 25 exit;
26 '^MODEL_NAME$', 26}
27 '^SCREEN_MAIN$', 27
28 '^LCD_DEFAULT_(FG|BG)$', 28my $def_type = $ARGV[0];
29 '^LCD_REMOTE_(DEPTH|HEIGHT|WIDTH)$', 29#warn "$def_type\n";
30 '^LCD_.+(BRIGHT|DARK)COLOR', 30my $lua_table;
31 '^SCREEN_REMOTE$', 31my @rockbox_defines;
32 '^FONT_SYSFIXED$', 32
33 '^FONT_UI$', 33if ($def_type eq "rb_defines") {
34 '^PLAYBACK_EVENT_.*', 34 $lua_table = "rb";
35 '^PLAYLIST_(INSERT|PREPEND|REPLACE)', 35 @rockbox_defines = (
36 '^TOUCHSCREEN_(POINT|BUTTON)$', 36 '^HZ$',
37 '^SYS_CHARGER_(DIS|)CONNECTED$', 37 '^LCD_(DEPTH|HEIGHT|WIDTH)$',
38 '^SYS_(TIMEOUT|POWEROFF)$', 38 '^MODEL_NAME$',
39 '^SYS_USB_(DIS|)CONNECTED$', 39 '^SCREEN_MAIN$',
40 '^HOME_DIR$', 40 '^LCD_DEFAULT_(FG|BG)$',
41 '^PLUGIN_DIR$', 41 '^LCD_REMOTE_(DEPTH|HEIGHT|WIDTH)$',
42 '^PLUGIN(_APPS_|_GAMES_|_)DATA_DIR$', 42 '^LCD_.+(BRIGHT|DARK)COLOR',
43 '^ROCKBOX_DIR$', 43 '^SCREEN_REMOTE$',
44 '^VIEWERS_DATA_DIR$'); 44 '^FONT_SYSFIXED$',
45 '^FONT_UI$',
46 '^PLAYBACK_EVENT_.*',
47 '^PLAYLIST_(INSERT|PREPEND|REPLACE)',
48 '^TOUCHSCREEN_(POINT|BUTTON)$',
49 '^SYS_CHARGER_(DIS|)CONNECTED$',
50 '^SYS_(TIMEOUT|POWEROFF)$',
51 '^SYS_USB_(DIS|)CONNECTED$',
52 '^HOME_DIR$',
53 '^PLUGIN_DIR$',
54 '^PLUGIN(_APPS_|_GAMES_|_)DATA_DIR$',
55 '^ROCKBOX_DIR$',
56 '^VIEWERS_DATA_DIR$');
57}
58elsif ($def_type eq "sound_defines") {
59 $lua_table = "rb.sound_settings";
60 @rockbox_defines = (
61 '^(?!.*LAST_SETTING)SOUND_');
62}
45 63
46my @captured_defines; 64my @captured_defines;
47my @names_seen; 65my @names_seen;
@@ -115,7 +133,12 @@ while(my $line = <STDIN>)
115 else { next; } 133 else { next; }
116 do_enum($line) 134 do_enum($line)
117 } 135 }
118 136 elsif($line =~ /^enum.*{[^;]+};.*/) #enum {
137 {
138 next if($line =~ /enum\s*__.*/); #don't add reserved
139 next if(do_enum($line));
140
141 }
119} 142}
120#warn "total defines: ".scalar @all_defines; 143#warn "total defines: ".scalar @all_defines;
121#warn "captured defines: ".scalar @captured_defines; 144#warn "captured defines: ".scalar @captured_defines;
@@ -123,17 +146,18 @@ while(my $line = <STDIN>)
123my @sorted_defines = sort { @$a{'name'} cmp @$b{'name'} } @captured_defines; 146my @sorted_defines = sort { @$a{'name'} cmp @$b{'name'} } @captured_defines;
124 147
125printf "int main(void)\n{\n"; 148printf "int main(void)\n{\n";
126printf "\tprintf(\"--[[Autogenerated rockbox constants]]\\n\\n\");"; 149printf "\tprintf(\"--[[Autogenerated rockbox constants]]\\n\\n\");\n\n";
150printf "\tprintf(\"%s = %s or {}\\n\");\n", $lua_table, $lua_table;
127# Print the C array 151# Print the C array
128foreach my $define (@sorted_defines) 152foreach my $define (@sorted_defines)
129{ 153{
130 if(@$define{'value'} =~ /^0[xX][0-9a-fA-F]+$/) #hex number 154 if(@$define{'value'} =~ /^0[xX][0-9a-fA-F]+$/) #hex number
131 { 155 {
132 printf "\tprintf(\"rb[\\\"%%s\\\"] = 0x%%x\\n\", stringify(%s), %s);\n", @$define{'name'}, @$define{'name'}; 156 printf "\tprintf(\"%s[\\\"%%s\\\"] = 0x%%x\\n\", stringify(%s), %s);\n", $lua_table, @$define{'name'}, @$define{'name'};
133 } 157 }
134 elsif(@$define{'value'} =~ /^[0-9]+$/) #number 158 elsif(@$define{'value'} =~ /^[0-9]+$/) #number
135 { 159 {
136 printf "\tprintf(\"rb[\\\"%%s\\\"] = %%d\\n\", stringify(%s), %s);\n", @$define{'name'}, @$define{'name'}; 160 printf "\tprintf(\"%s[\\\"%%s\\\"] = %%d\\n\", stringify(%s), %s);\n", $lua_table, @$define{'name'}, @$define{'name'};
137 } 161 }
138 else #might be a string but we don't know since the macro isn't expanded far enough 162 else #might be a string but we don't know since the macro isn't expanded far enough
139 { 163 {
@@ -167,11 +191,11 @@ foreach my $define (@sorted_defines)
167 if ($var =~$quot_regex) #has a quote it is a string 191 if ($var =~$quot_regex) #has a quote it is a string
168 { 192 {
169 #guard with empty literals "" so gcc throws an error if it isn't a string 193 #guard with empty literals "" so gcc throws an error if it isn't a string
170 printf "\tprintf(\"rb[\\\"%%s\\\"] = \\\"%%s\\\"\\n\", stringify(%s), \"\" %s \"\");\n", @$define{'name'}, @$define{'name'}; 194 printf "\tprintf(\"%s[\\\"%%s\\\"] = \\\"%%s\\\"\\n\", stringify(%s), \"\" %s \"\");\n", $lua_table, @$define{'name'}, @$define{'name'};
171 } 195 }
172 elsif ($var =~$num_regex) #it must be a number 196 elsif ($var =~$num_regex) #it must be a number
173 { 197 {
174 printf "\tprintf(\"rb[\\\"%%s\\\"] = %%d\\n\", stringify(%s), %s);\n", @$define{'name'}, @$define{'name'}; 198 printf "\tprintf(\"%s[\\\"%%s\\\"] = %%d\\n\", stringify(%s), %s);\n", $lua_table, @$define{'name'}, @$define{'name'};
175 } 199 }
176 else { warn "Skipping ".@$define{'name'}." indeterminate macro type\n"; } 200 else { warn "Skipping ".@$define{'name'}." indeterminate macro type\n"; }
177 } 201 }
@@ -186,6 +210,23 @@ EOF
186 210
187sub do_enum { 211sub do_enum {
188 my ($line) = @_; 212 my ($line) = @_;
213 if($line =~ /.*enum.*{(.*)};.*/) #single line enums
214 {
215 print $line;
216 $value = "0"; #enums are always integers
217 my $enum = $1;
218 $enum =~ s/\s+//g;;
219 my @values = split(',', $enum);
220
221 foreach my $name(@values) {
222 if(grep($name =~ $_, @rockbox_defines))
223 {
224 push(@names_seen, $name);
225 push(@captured_defines, {'name' => $name, 'value' => $value});
226 }
227 }
228 return 1;
229 }
189 230
190 while($line = <STDIN>) 231 while($line = <STDIN>)
191 { 232 {
@@ -209,4 +250,5 @@ sub do_enum {
209 } 250 }
210 251
211 } 252 }
253 return 0;
212} 254}