diff options
author | William Wilgus <wilgus.william@gmail.com> | 2021-08-24 07:50:32 -0400 |
---|---|---|
committer | William Wilgus <me.theuser@yahoo.com> | 2021-08-27 05:19:28 +0000 |
commit | 965572705beb4a0789970a44e11fce94654ad4b9 (patch) | |
tree | 183ed4a8c4e02a0b317357901d647bfbe56a2017 /apps/plugins/lib/arg_helper.h | |
parent | cab8cea0f0b241c9221e220bf53c30c8b212274a (diff) | |
download | rockbox-965572705beb4a0789970a44e11fce94654ad4b9.tar.gz rockbox-965572705beb4a0789970a44e11fce94654ad4b9.zip |
plugin lib/arg_helper parse 'command line' args
add a helper function to allow plugins to parse the parameter string
passed into plugins
support included for bool, char, string and numbers+decimals
Change-Id: I39f35c8bd3c21b83097a538c19f46d362c468fa4
Diffstat (limited to 'apps/plugins/lib/arg_helper.h')
-rw-r--r-- | apps/plugins/lib/arg_helper.h | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/apps/plugins/lib/arg_helper.h b/apps/plugins/lib/arg_helper.h new file mode 100644 index 0000000000..7c770e0162 --- /dev/null +++ b/apps/plugins/lib/arg_helper.h | |||
@@ -0,0 +1,53 @@ | |||
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 | /* fills buf with a string upto buf_sz, null terminates the buffer | ||
27 | * strings break on WS by default but can be enclosed in single or double quotes | ||
28 | * opening and closing quotes will not be included in the buffer but will be counted | ||
29 | * use alternating quotes if you really want them included '"text"' or "'text'" | ||
30 | * failure to close the string will result in eating all remaining args till \0 | ||
31 | * If buffer full remaining chars are discarded till stopchar or \0 is reached */ | ||
32 | int string_parse(const char **parameter, char* buf, size_t buf_sz); | ||
33 | /* passes *character a single character eats remaining non-WS characters */ | ||
34 | int char_parse(const char **parameter, char* character); | ||
35 | /* determine true false using the first character the rest are skipped/ignored */ | ||
36 | int bool_parse(const char **parameter, bool *choice); | ||
37 | /* passes number and or decimal portion of number base 10 only.. */ | ||
38 | int longnum_parse(const char **parameter, long *number, long *decimal); | ||
39 | int num_parse(const char **parameter, int *number, int *decimal); | ||
40 | |||
41 | /* | ||
42 | *argparse(const char *parameter, int parameter_len, | ||
43 | * int (*arg_callback)(char argchar, const char **parameter)) | ||
44 | * parameter : constant char string of arguments | ||
45 | * parameter_len : may be set to -1 if your parameter string is NULL (\0) terminated | ||
46 | * arg_callback : function gets called for each SWCHAR found in the parameter string | ||
47 | * Note: WS at beginning is stripped, **parameter starts at the first NON WS char | ||
48 | * return 0 for arg_callback to quit parsing immediately | ||
49 | */ | ||
50 | void argparse(const char *parameter, int parameter_len, | ||
51 | int (*arg_callback)(char argchar, const char **parameter)); | ||
52 | |||
53 | #endif /* _LIB_ARG_HELPER_H_ */ | ||