From 9f1a791be211f4733cccecfe044a5deb6b521ae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sat, 10 Apr 2021 14:10:17 +0200 Subject: [PATCH] Remove custom option checker and use the one of the shellmatta instead --- stm-firmware/shell.c | 50 ++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/stm-firmware/shell.c b/stm-firmware/shell.c index 7ab07c7..dac0404 100644 --- a/stm-firmware/shell.c +++ b/stm-firmware/shell.c @@ -53,28 +53,6 @@ static shellmatta_instance_t shell; static char shell_buffer[512]; static char IN_SECTION(.ccm.bss) history_buffer[512]; -static bool check_opt(const char *args, uint32_t len, const char *opt_to_check) -{ - (void)len; - char str[128]; - const char *ptr; - static const char * const tokens = "\t "; - - strncpy(str, args, sizeof(str)); - str[sizeof(str) - 1] = 0; - - /* Tokenize the string */ - ptr = strtok(str, tokens); - - while (ptr) { - if (strcmp(ptr, opt_to_check) == 0) - return true; - ptr = strtok(NULL, tokens); - } - - return false; -} - static shellmatta_retCode_t shell_cmd_ver(const shellmatta_handle_t handle, const char *arguments, uint32_t length) @@ -345,14 +323,36 @@ static shellmatta_retCode_t shell_cmd_read_flags(const shellmatta_handle_t handl uint32_t i; char name[64]; bool flag; - bool tryack; + bool tryack = false; int status; enum safety_flag flag_enum; struct analog_monitor_info amon_info; struct timing_monitor_info timing_info; + char *argument; + uint32_t len; + char option; + shellmatta_retCode_t opt_ret; + static const shellmatta_opt_long_t options[] = { + {"ack", 'a', SHELLMATTA_OPT_ARG_NONE}, + {NULL, '\0', SHELLMATTA_OPT_ARG_NONE} + }; + + do { + opt_ret = shellmatta_opt_long(handle, options, &option, &argument, &len); + if (opt_ret != SHELLMATTA_OK) { + break; + } + + switch (option) { + case 'a': + tryack = true; + break; + default: + break; + } + } while(1); + - /* Check for the --ack option */ - tryack = check_opt(arguments, length, "--ack"); shellmatta_printf(handle, "Error Flags\r\n" "-----------\r\n");