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 | |
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')
-rw-r--r-- | apps/plugins/lib/SOURCES | 2 | ||||
-rw-r--r-- | apps/plugins/lib/action_helper.c | 1 | ||||
-rw-r--r-- | apps/plugins/lib/action_helper.h | 34 | ||||
-rwxr-xr-x | apps/plugins/lib/action_helper.pl | 209 | ||||
-rw-r--r-- | apps/plugins/lib/button_helper.c | 1 | ||||
-rw-r--r-- | apps/plugins/lib/button_helper.h | 38 | ||||
-rwxr-xr-x | apps/plugins/lib/button_helper.pl | 98 |
7 files changed, 383 insertions, 0 deletions
diff --git a/apps/plugins/lib/SOURCES b/apps/plugins/lib/SOURCES index bdea07315e..1cd092f8df 100644 --- a/apps/plugins/lib/SOURCES +++ b/apps/plugins/lib/SOURCES | |||
@@ -1,6 +1,8 @@ | |||
1 | sha1.c | 1 | sha1.c |
2 | gcc-support.c | 2 | gcc-support.c |
3 | pluginlib_actions.c | 3 | pluginlib_actions.c |
4 | action_helper.c | ||
5 | button_helper.c | ||
4 | helper.c | 6 | helper.c |
5 | icon_helper.c | 7 | icon_helper.c |
6 | arg_helper.c | 8 | arg_helper.c |
diff --git a/apps/plugins/lib/action_helper.c b/apps/plugins/lib/action_helper.c new file mode 100644 index 0000000000..906051c1ea --- /dev/null +++ b/apps/plugins/lib/action_helper.c | |||
@@ -0,0 +1 @@ | |||
/*DUMMY_FILE_DONT_CHANGEME*/ | |||
diff --git a/apps/plugins/lib/action_helper.h b/apps/plugins/lib/action_helper.h new file mode 100644 index 0000000000..58d9c6c303 --- /dev/null +++ b/apps/plugins/lib/action_helper.h | |||
@@ -0,0 +1,34 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2021 William Wilgus | ||
11 | * | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or | ||
14 | * modify it under the terms of the GNU General Public License | ||
15 | * as published by the Free Software Foundation; either version 2 | ||
16 | * of the License, or (at your option) any later version. | ||
17 | * | ||
18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
19 | * KIND, either express or implied. | ||
20 | * | ||
21 | ****************************************************************************/ | ||
22 | /* action_helper provides a way to turn numeric action/context into strings | ||
23 | * the file action_helper.c is generated at compile time | ||
24 | * ACTION_ and CONTEXT_ are stripped from the strings and replaced when | ||
25 | * action_name and context_name are called, | ||
26 | * NOTE: both share the same static buffer sized as the largest string possible | ||
27 | */ | ||
28 | #ifndef _ACTION_HELPER_H_ | ||
29 | #define _ACTION_HELPER_H_ | ||
30 | |||
31 | char* action_name(int action); | ||
32 | char* context_name(int context); | ||
33 | |||
34 | #endif /* _ACTION_HELPER_H_ */ | ||
diff --git a/apps/plugins/lib/action_helper.pl b/apps/plugins/lib/action_helper.pl new file mode 100755 index 0000000000..1dfdcfd070 --- /dev/null +++ b/apps/plugins/lib/action_helper.pl | |||
@@ -0,0 +1,209 @@ | |||
1 | #!/usr/bin/env perl | ||
2 | ############################################################################ | ||
3 | # __________ __ ___. | ||
4 | # Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
5 | # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
6 | # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
7 | # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
8 | # \/ \/ \/ \/ \/ | ||
9 | # $action_helper$ | ||
10 | # | ||
11 | # Copyright (C) 2021 William Wilgus | ||
12 | # | ||
13 | # All files in this archive are subject to the GNU General Public License. | ||
14 | # See the file COPYING in the source tree root for full license agreement. | ||
15 | # | ||
16 | # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
17 | # KIND, either express or implied. | ||
18 | # | ||
19 | ############################################################################ | ||
20 | #expects -E source input on STDIN | ||
21 | use strict; | ||
22 | use warnings; | ||
23 | |||
24 | my @actions = (); | ||
25 | my @contexts = (); | ||
26 | my @action_offset = (); | ||
27 | my @context_offset = (); | ||
28 | my $action_ct = 0; | ||
29 | my $context_ct = 0; | ||
30 | my $len_max_action = 0; | ||
31 | my $len_max_context = 0; | ||
32 | my $len_min_action = -1; | ||
33 | my $len_min_context = -1; | ||
34 | while(my $line = <STDIN>) | ||
35 | { | ||
36 | chomp($line); | ||
37 | if($line =~ /^\s*(ACTION_[^\s]+)(\s*=.*)?,\s*$/) | ||
38 | { | ||
39 | $actions[$action_ct] = $1; | ||
40 | $action_ct++; | ||
41 | } | ||
42 | elsif($line =~ /^\s*(LAST_ACTION_PLACEHOLDER)(\s*=.*)?,\s*$/) | ||
43 | { #special case don't save actual name | ||
44 | $actions[$action_ct] = ""; | ||
45 | $action_ct++; | ||
46 | } | ||
47 | elsif($line =~ /^\s*(PLA_[^\s]+)(\s*=.*)?,\s*$/) | ||
48 | { | ||
49 | $actions[$action_ct] = $1; | ||
50 | $action_ct++; | ||
51 | } | ||
52 | elsif($line =~ /^\s*(CONTEXT_[^\s]+)(\s*=.*)?,\s*$/) | ||
53 | { | ||
54 | $contexts[$context_ct] = $1; | ||
55 | $context_ct++; | ||
56 | } | ||
57 | } | ||
58 | |||
59 | print <<EOF | ||
60 | /* Don't change this file! */ | ||
61 | /* It is automatically generated of action.h */ | ||
62 | #include "plugin.h" | ||
63 | #include "action_helper.h" | ||
64 | EOF | ||
65 | ; | ||
66 | #dump actions | ||
67 | my $offset = 0; | ||
68 | print "static const char action_names[]= \n"; | ||
69 | for(my $i = 0; $i < $action_ct; $i++){ | ||
70 | my $act = $actions[$i]; | ||
71 | $act =~ s/ACTION_USB_HID_/%s/ig; # strip the common part | ||
72 | $act =~ s/ACTION_/%s/ig; # strip the common part | ||
73 | my $actlen = length($act); | ||
74 | if ($actlen < $len_min_action or $len_min_action == -1){ | ||
75 | $len_min_action = $actlen; | ||
76 | } | ||
77 | if ($actions[$i] ne $act){ | ||
78 | printf "/*%s*/\"%s\\0\"\n", substr($actions[$i], 0, -($actlen - 2)), $act; | ||
79 | } else { | ||
80 | print "\"$act\\0\" \n"; | ||
81 | } | ||
82 | my $slen = length($actions[$i]) + 1; #NULL terminator | ||
83 | if ($slen > $len_max_action) { $len_max_action = $slen; } | ||
84 | push(@action_offset, {'name' => $actions[$i], 'offset' => $offset}); | ||
85 | $offset += length($act) + 1; # NULL terminator | ||
86 | } | ||
87 | printf "\"\";/* %d + \\0 */\n\n", $offset; | ||
88 | @actions = (); | ||
89 | |||
90 | #dump contexts | ||
91 | $offset = 0; | ||
92 | print "static const char context_names[]= \n"; | ||
93 | for(my $i = 0; $i < $context_ct; $i++){ | ||
94 | my $ctx = $contexts[$i]; | ||
95 | $ctx =~ s/CONTEXT_/%s/ig; # strip the common part | ||
96 | my $ctxlen = length($ctx); | ||
97 | |||
98 | if ($ctxlen < 5){ | ||
99 | $ctx = $contexts[$i]; | ||
100 | $ctxlen = length($ctx); | ||
101 | } | ||
102 | |||
103 | if ($ctxlen < $len_min_context or $len_min_context == -1){ | ||
104 | $len_min_context = $ctxlen; | ||
105 | } | ||
106 | if ($contexts[$i] ne $ctx){ | ||
107 | printf "/*%s*/\"%s\\0\"\n", substr($contexts[$i], 0, -($ctxlen - 2)), $ctx; | ||
108 | } else { | ||
109 | print "\"$ctx\\0\" \n"; | ||
110 | } | ||
111 | my $slen = length($contexts[$i]) + 1; # NULL terminator | ||
112 | if ($slen > $len_max_context) { $len_max_context = $slen; } | ||
113 | push(@context_offset, {'name' => $contexts[$i], 'offset' => $offset}); | ||
114 | $offset += length($ctx) + 1; # NULL terminator | ||
115 | } | ||
116 | printf "\"\";/* %d + \\0 */\n\n", $offset; | ||
117 | @contexts = (); | ||
118 | |||
119 | printf "#define ACTION_CT %d\n", $action_ct; | ||
120 | print "static const uint16_t action_offsets[ACTION_CT] = {\n"; | ||
121 | foreach my $define (@action_offset) | ||
122 | { | ||
123 | printf("%d, /*%s*/\n", @$define{'offset'}, @$define{'name'}); | ||
124 | } | ||
125 | print "};\n\n"; | ||
126 | @action_offset = (); | ||
127 | |||
128 | printf "#define CONTEXT_CT %d\n", $context_ct; | ||
129 | print "#if 0 /* context_names is small enough to walk the string instead */\n"; | ||
130 | print "static const uint16_t context_offsets[CONTEXT_CT] = {\n"; | ||
131 | foreach my $define (@context_offset) | ||
132 | { | ||
133 | printf("%d, /*%s*/\n", @$define{'offset'}, @$define{'name'}); | ||
134 | } | ||
135 | print "};\n#endif\n\n"; | ||
136 | @context_offset = (); | ||
137 | |||
138 | printf "#define ACTIONBUFSZ %d\n", $len_max_action; | ||
139 | printf "#define CONTEXTBUFSZ %d\n\n", $len_max_context; | ||
140 | |||
141 | if ($len_max_action > $len_max_context) | ||
142 | { | ||
143 | print "static char name_buf[ACTIONBUFSZ];\n"; | ||
144 | } | ||
145 | else | ||
146 | { | ||
147 | print "static char name_buf[CONTEXTBUFSZ];\n"; | ||
148 | } | ||
149 | print <<EOF | ||
150 | |||
151 | char* action_name(int action) | ||
152 | { | ||
153 | if (action >= 0 && action < ACTION_CT) | ||
154 | { | ||
155 | uint16_t offset = action_offsets[action]; | ||
156 | const char *act = &action_names[offset]; | ||
157 | if (action < ACTION_USB_HID_FIRST) | ||
158 | rb->snprintf(name_buf, ACTIONBUFSZ, act, "ACTION_"); | ||
159 | else | ||
160 | rb->snprintf(name_buf, ACTIONBUFSZ, act, "ACTION_USB_HID_"); | ||
161 | } | ||
162 | else | ||
163 | rb->snprintf(name_buf, ACTIONBUFSZ, "ACTION_UNKNOWN"); | ||
164 | return name_buf; | ||
165 | } | ||
166 | |||
167 | /* walk string increment offset for each NULL if desired offset found, return */ | ||
168 | static const char *context_getoffset(int offset) | ||
169 | { | ||
170 | const char *names = context_names; | ||
171 | const size_t len = sizeof(context_names) - 1; | ||
172 | int current = 0; | ||
173 | if (offset > 0) | ||
174 | { | ||
175 | const char *pos = names; | ||
176 | const char *end = names + len; | ||
177 | while (pos < end) | ||
178 | { | ||
179 | if (*pos++ == '\\0') | ||
180 | { | ||
181 | current++; | ||
182 | if (offset == current) | ||
183 | return pos; | ||
184 | pos += $len_min_context; /* each string is at least this long */ | ||
185 | } | ||
186 | } | ||
187 | } | ||
188 | return names; | ||
189 | } | ||
190 | |||
191 | char* context_name(int context) | ||
192 | { | ||
193 | const char *ctx; | ||
194 | if (context >= 0 && context < CONTEXT_CT) | ||
195 | { | ||
196 | #if 0 | ||
197 | uint16_t offset = context_offsets[context]; | ||
198 | ctx = &context_names[offset]; | ||
199 | #else | ||
200 | ctx = context_getoffset(context); | ||
201 | #endif | ||
202 | } | ||
203 | else | ||
204 | ctx = "%sUNKNOWN"; | ||
205 | rb->snprintf(name_buf, CONTEXTBUFSZ, ctx, "CONTEXT_"); | ||
206 | return name_buf; | ||
207 | } | ||
208 | EOF | ||
209 | ; | ||
diff --git a/apps/plugins/lib/button_helper.c b/apps/plugins/lib/button_helper.c new file mode 100644 index 0000000000..906051c1ea --- /dev/null +++ b/apps/plugins/lib/button_helper.c | |||
@@ -0,0 +1 @@ | |||
/*DUMMY_FILE_DONT_CHANGEME*/ | |||
diff --git a/apps/plugins/lib/button_helper.h b/apps/plugins/lib/button_helper.h new file mode 100644 index 0000000000..1197b172b0 --- /dev/null +++ b/apps/plugins/lib/button_helper.h | |||
@@ -0,0 +1,38 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2021 William Wilgus | ||
11 | * | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or | ||
14 | * modify it under the terms of the GNU General Public License | ||
15 | * as published by the Free Software Foundation; either version 2 | ||
16 | * of the License, or (at your option) any later version. | ||
17 | * | ||
18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
19 | * KIND, either express or implied. | ||
20 | * | ||
21 | ****************************************************************************/ | ||
22 | #ifndef _BUTTON_HELPER_H_ | ||
23 | #define _BUTTON_HELPER_H_ | ||
24 | struct available_button | ||
25 | { | ||
26 | const char* name; | ||
27 | unsigned long value; | ||
28 | }; | ||
29 | |||
30 | /* *available_buttons is holding a pointer to the first element of an array | ||
31 | * of struct available_button it is set up in such a way due to the file being | ||
32 | * generated at compile time you can still call it as such though | ||
33 | * eg available_buttons[0] or available_buttons[available_button_count] (NULL SENTINEL, 0)*/ | ||
34 | |||
35 | extern const struct available_button * const available_buttons; | ||
36 | extern const int available_button_count; | ||
37 | int get_button_names(char *buf, size_t bufsz, unsigned long button); | ||
38 | #endif /* _BUTTON_HELPER_H_ */ | ||
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 | ; | ||