add handle_command_parse_bool command helper
Rewrite arm11_handle_bool to provide a generic on/off command helper. Refactors COMMAND_PARSE_BOOL to use new command_parse_bool helper, which gets reused by the new command_parse_bool_any helper. This later helper is called by the new command helper function to accepts any on/off, enable/disable, true/false, yes/no, or 0/1 parameter.
This commit is contained in:
@@ -271,19 +271,22 @@ DECLARE_PARSE_WRAPPER(_s8, int8_t);
|
||||
*/
|
||||
#define COMMAND_PARSE_BOOL(in, out, on, off) \
|
||||
do { \
|
||||
if (strcmp(in, on) == 0) \
|
||||
out = true; \
|
||||
else if (strcmp(in, off) == 0) \
|
||||
out = false; \
|
||||
else { \
|
||||
bool value; \
|
||||
int retval = command_parse_bool(in, &value, on, off); \
|
||||
if (ERROR_OK != retval) { \
|
||||
command_print(CMD_CTX, stringify(out) \
|
||||
" option value ('%s') is not valid", in); \
|
||||
command_print(CMD_CTX, " choices are '%s' or '%s'", \
|
||||
on, off); \
|
||||
return ERROR_COMMAND_SYNTAX_ERROR; \
|
||||
return retval; \
|
||||
} \
|
||||
out = value; \
|
||||
} while (0)
|
||||
|
||||
int command_parse_bool(const char *in, bool *out,
|
||||
const char *on, const char *off);
|
||||
COMMAND_HELPER(handle_command_parse_bool, bool *out, const char *label);
|
||||
|
||||
/// parses an on/off command argument
|
||||
#define COMMAND_PARSE_ON_OFF(in, out) \
|
||||
COMMAND_PARSE_BOOL(in, out, "on", "off")
|
||||
|
||||
Reference in New Issue
Block a user