summaryrefslogtreecommitdiff
path: root/apps/plugins/lib
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2021-11-12 20:50:20 -0500
committerWilliam Wilgus <me.theuser@yahoo.com>2021-11-22 21:39:45 -0500
commitb39acee3abd199d80b84c68ebfa7301b7e7a957e (patch)
tree5e0ed2b152acd41d4b7e8335f31ba8b65d6e5f06 /apps/plugins/lib
parent3d07ec46eed738e6dac6109598766f6568ac4669 (diff)
downloadrockbox-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/SOURCES2
-rw-r--r--apps/plugins/lib/action_helper.c1
-rw-r--r--apps/plugins/lib/action_helper.h34
-rwxr-xr-xapps/plugins/lib/action_helper.pl209
-rw-r--r--apps/plugins/lib/button_helper.c1
-rw-r--r--apps/plugins/lib/button_helper.h38
-rwxr-xr-xapps/plugins/lib/button_helper.pl98
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 @@
1sha1.c 1sha1.c
2gcc-support.c 2gcc-support.c
3pluginlib_actions.c 3pluginlib_actions.c
4action_helper.c
5button_helper.c
4helper.c 6helper.c
5icon_helper.c 7icon_helper.c
6arg_helper.c 8arg_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
31char* action_name(int action);
32char* 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
21use strict;
22use warnings;
23
24my @actions = ();
25my @contexts = ();
26my @action_offset = ();
27my @context_offset = ();
28my $action_ct = 0;
29my $context_ct = 0;
30my $len_max_action = 0;
31my $len_max_context = 0;
32my $len_min_action = -1;
33my $len_min_context = -1;
34while(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
59print <<EOF
60/* Don't change this file! */
61/* It is automatically generated of action.h */
62#include "plugin.h"
63#include "action_helper.h"
64EOF
65;
66#dump actions
67my $offset = 0;
68print "static const char action_names[]= \n";
69for(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}
87printf "\"\";/* %d + \\0 */\n\n", $offset;
88@actions = ();
89
90#dump contexts
91$offset = 0;
92print "static const char context_names[]= \n";
93for(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}
116printf "\"\";/* %d + \\0 */\n\n", $offset;
117@contexts = ();
118
119printf "#define ACTION_CT %d\n", $action_ct;
120print "static const uint16_t action_offsets[ACTION_CT] = {\n";
121foreach my $define (@action_offset)
122{
123 printf("%d, /*%s*/\n", @$define{'offset'}, @$define{'name'});
124}
125print "};\n\n";
126@action_offset = ();
127
128printf "#define CONTEXT_CT %d\n", $context_ct;
129print "#if 0 /* context_names is small enough to walk the string instead */\n";
130print "static const uint16_t context_offsets[CONTEXT_CT] = {\n";
131foreach my $define (@context_offset)
132{
133 printf("%d, /*%s*/\n", @$define{'offset'}, @$define{'name'});
134}
135print "};\n#endif\n\n";
136@context_offset = ();
137
138printf "#define ACTIONBUFSZ %d\n", $len_max_action;
139printf "#define CONTEXTBUFSZ %d\n\n", $len_max_context;
140
141if ($len_max_action > $len_max_context)
142{
143 print "static char name_buf[ACTIONBUFSZ];\n";
144}
145else
146{
147 print "static char name_buf[CONTEXTBUFSZ];\n";
148}
149print <<EOF
150
151char* 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 */
168static 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
191char* 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}
208EOF
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_
24struct 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
35extern const struct available_button * const available_buttons;
36extern const int available_button_count;
37int 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
22use strict;
23use warnings;
24my $svnrev = '$Revision$';
25my @buttons = ();
26my $count = 1; #null sentinel
27my $val;
28my $def;
29while(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}
48my @sorted = sort { @$a{'value'} <=> @$b{'value'} } @buttons;
49print <<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
56static const struct available_button buttons[$count] = {
57EOF
58;
59$count--; # don't count the sentinel
60foreach my $button (@sorted)
61{
62 printf " %s", @$button{'def'};
63}
64
65print <<EOF
66 {"\\0", 0} /* sentinel */
67};
68const int available_button_count = $count;
69const struct available_button * const available_buttons = buttons;
70
71int 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}
97EOF
98;