summaryrefslogtreecommitdiff
path: root/apps/plugins/lib/button_helper.pl
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/lib/button_helper.pl')
-rwxr-xr-xapps/plugins/lib/button_helper.pl98
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
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;