diff options
author | William Wilgus <wilgus.william@gmail.com> | 2021-11-12 20:50:20 -0500 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2021-11-22 21:39:45 -0500 |
commit | b39acee3abd199d80b84c68ebfa7301b7e7a957e (patch) | |
tree | 5e0ed2b152acd41d4b7e8335f31ba8b65d6e5f06 /apps/plugins/lib/button_helper.pl | |
parent | 3d07ec46eed738e6dac6109598766f6568ac4669 (diff) | |
download | rockbox-b39acee3abd199d80b84c68ebfa7301b7e7a957e.tar.gz rockbox-b39acee3abd199d80b84c68ebfa7301b7e7a957e.zip |
rb_info plugin and button,action+context name helper
rb_info is just a test plugin
just some info from the running rockbox install
the real star here is the generator scripts to make actions_helper.c and button_helper.c
Change-Id: I23f7bbdae3f2cffca2490c4df40bb13b0b5d5064
Diffstat (limited to 'apps/plugins/lib/button_helper.pl')
-rwxr-xr-x | apps/plugins/lib/button_helper.pl | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/apps/plugins/lib/button_helper.pl b/apps/plugins/lib/button_helper.pl new file mode 100755 index 0000000000..45c3fd9073 --- /dev/null +++ b/apps/plugins/lib/button_helper.pl | |||
@@ -0,0 +1,98 @@ | |||
1 | #!/usr/bin/env perl | ||
2 | ############################################################################ | ||
3 | # __________ __ ___. | ||
4 | # Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
5 | # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
6 | # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
7 | # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
8 | # \/ \/ \/ \/ \/ | ||
9 | # $Id$ | ||
10 | # | ||
11 | # Copyright (C) 2009 by Maurus Cuelenaere | ||
12 | # Copyright (C) 2021 by William Wilgus | ||
13 | # | ||
14 | # All files in this archive are subject to the GNU General Public License. | ||
15 | # See the file COPYING in the source tree root for full license agreement. | ||
16 | # | ||
17 | # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | # KIND, either express or implied. | ||
19 | # | ||
20 | ############################################################################ | ||
21 | #expects -dM -E source input on STDIN | ||
22 | use strict; | ||
23 | use warnings; | ||
24 | my $svnrev = '$Revision$'; | ||
25 | my @buttons = (); | ||
26 | my $count = 1; #null sentinel | ||
27 | my $val; | ||
28 | my $def; | ||
29 | while(my $line = <STDIN>) | ||
30 | { | ||
31 | chomp($line); | ||
32 | if($line =~ /^#define (BUTTON_[^\s]+) (.+)$/) | ||
33 | { | ||
34 | $def = "{\"$1\", $2},\n"; | ||
35 | $val = $2; | ||
36 | if($val =~ /^0/) | ||
37 | { | ||
38 | $val = oct($val) | ||
39 | } | ||
40 | else | ||
41 | { | ||
42 | $val = 0xFFFFFFFF; #only used for sorting | ||
43 | } | ||
44 | push(@buttons, {'name' => $1, 'value' => $val, 'def' => $def}); | ||
45 | $count = $count + 1; | ||
46 | } | ||
47 | } | ||
48 | my @sorted = sort { @$a{'value'} <=> @$b{'value'} } @buttons; | ||
49 | print <<EOF | ||
50 | /* Don't change this file! */ | ||
51 | /* It is automatically generated of button.h */ | ||
52 | #include "plugin.h" | ||
53 | #include "button.h" | ||
54 | #include "button_helper.h" | ||
55 | |||
56 | static const struct available_button buttons[$count] = { | ||
57 | EOF | ||
58 | ; | ||
59 | $count--; # don't count the sentinel | ||
60 | foreach my $button (@sorted) | ||
61 | { | ||
62 | printf " %s", @$button{'def'}; | ||
63 | } | ||
64 | |||
65 | print <<EOF | ||
66 | {"\\0", 0} /* sentinel */ | ||
67 | }; | ||
68 | const int available_button_count = $count; | ||
69 | const struct available_button * const available_buttons = buttons; | ||
70 | |||
71 | int get_button_names(char *buf, size_t bufsz, unsigned long button) | ||
72 | { | ||
73 | int len = 0; | ||
74 | buf[0] = '\\0'; | ||
75 | const struct available_button *btn = buttons; | ||
76 | while(btn->name[0] != '\\0') | ||
77 | { | ||
78 | if(btn->value == 0) | ||
79 | { | ||
80 | if (button == 0) | ||
81 | { | ||
82 | buf[0] = '\\0'; | ||
83 | len = rb->strlcat(buf, btn->name, bufsz); | ||
84 | return len; | ||
85 | } | ||
86 | } | ||
87 | else if ((button & btn->value) == btn->value) | ||
88 | { | ||
89 | if (len > 0) | ||
90 | rb->strlcat(buf, " | ", bufsz); | ||
91 | len = rb->strlcat(buf, btn->name, bufsz); | ||
92 | } | ||
93 | btn++; | ||
94 | } | ||
95 | return len; | ||
96 | } | ||
97 | EOF | ||
98 | ; | ||