A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 60 lines 3.0 kB view raw
1/*************************************************************************** 2 * __________ __ ___. 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 * \/ \/ \/ \/ \/ 8 * $Id$ 9 * 10 * Copyright (C) 2021 William Wilgus 11 * 12 * This program is free software; you can redistribute it and/or 13 * modify it under the terms of the GNU General Public License 14 * as published by the Free Software Foundation; either version 2 15 * of the License, or (at your option) any later version. 16 * 17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 18 * KIND, either express or implied. 19 * 20 ****************************************************************************/ 21#ifndef _LIB_ARG_HELPER_H_ 22#define _LIB_ARG_HELPER_H_ 23 24#include "plugin.h" 25 26#define ARGPARSE_MAX_FRAC_DIGITS 9 /* Uses 30 bits max (0.999999999) */ 27 28#define ARGP_EXP(a, b) (a ##E## b) 29#define ARGP_FRAC_DEC_MULTIPLIER(n) ARGP_EXP(1,n) /*1x10^n*/ 30#define ARGPARSE_FRAC_DEC_MULTIPLIER \ 31 (long)ARGP_FRAC_DEC_MULTIPLIER(ARGPARSE_MAX_FRAC_DIGITS) 32 33/* fills buf with a string upto buf_sz, null terminates the buffer 34 * strings break on WS by default but can be enclosed in single or double quotes 35 * opening and closing quotes will not be included in the buffer but will be counted 36 * use alternating quotes if you really want them included '"text"' or "'text'" 37 * failure to close the string will result in eating all remaining args till \0 38 * If buffer full remaining chars are discarded till stopchar or \0 is reached */ 39int string_parse(const char **parameter, char* buf, size_t buf_sz); 40/* passes *character a single character eats remaining non-WS characters */ 41int char_parse(const char **parameter, char* character); 42/* determine true false using the first character the rest are skipped/ignored */ 43int bool_parse(const char **parameter, bool *choice); 44/* passes number and or decimal portion of number base 10 only.. */ 45int longnum_parse(const char **parameter, long *number, long *decimal); 46int num_parse(const char **parameter, int *number, int *decimal); 47 48/* 49*argparse(const char *parameter, int parameter_len, 50* int (*arg_callback)(char argchar, const char **parameter)) 51* parameter : constant char string of arguments 52* parameter_len : may be set to -1 if your parameter string is NULL (\0) terminated 53* arg_callback : function gets called for each SWCHAR found in the parameter string 54* Note: WS at beginning is stripped, **parameter starts at the first NON WS char 55* return 0 for arg_callback to quit parsing immediately 56*/ 57void argparse(const char *parameter, int parameter_len, void *userdata, 58 int (*arg_callback)(char argchar, const char **parameter, void *userdata)); 59 60#endif /* _LIB_ARG_HELPER_H_ */