A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 103 lines 2.9 kB view raw
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; 29my $len_max_button = 0; 30while(my $line = <STDIN>) 31{ 32 chomp($line); 33 if($line =~ /^#define (BUTTON_[^\s]+) (.+)$/) 34 { 35 $def = "{\"$1\", $2},\n"; 36 my $slen = length($1) + 1; # NULL terminator 37 if ($slen > $len_max_button) { $len_max_button = $slen; } 38 $val = $2; 39 if($val =~ /^0/) 40 { 41 $val = oct($val) 42 } 43 else 44 { 45 $val = 0xFFFFFFFF; #only used for sorting 46 } 47 push(@buttons, {'name' => $1, 'value' => $val, 'def' => $def}); 48 $count = $count + 1; 49 } 50} 51my @sorted = sort { @$a{'value'} <=> @$b{'value'} } @buttons; 52print <<EOF 53/* Don't change this file! */ 54/* It is automatically generated of button.h */ 55#include "plugin.h" 56#include "button.h" 57#include "button_helper.h" 58 59const size_t button_helper_maxbuffer = $len_max_button; 60 61static const struct available_button buttons[$count] = { 62EOF 63; 64$count--; # don't count the sentinel 65foreach my $button (@sorted) 66{ 67 printf " %s", @$button{'def'}; 68} 69 70print <<EOF 71 {"\\0", 0} /* sentinel */ 72}; 73const int available_button_count = $count; 74const struct available_button * const available_buttons = buttons; 75 76int get_button_names(char *buf, size_t bufsz, unsigned long button) 77{ 78 int len = 0; 79 buf[0] = '\\0'; 80 const struct available_button *btn = buttons; 81 while(btn->name[0] != '\\0') 82 { 83 if(btn->value == 0) 84 { 85 if (button == 0) 86 { 87 buf[0] = '\\0'; 88 len = rb->strlcat(buf, btn->name, bufsz); 89 return len; 90 } 91 } 92 else if ((button & btn->value) == btn->value) 93 { 94 if (len > 0) 95 rb->strlcat(buf, " | ", bufsz); 96 len = rb->strlcat(buf, btn->name, bufsz); 97 } 98 btn++; 99 } 100 return len; 101} 102EOF 103;