svf: rework svf_parse_cmd_string()

Rework the function to drop the goto in the switch statement.
While there, change some variable to boolean.

Change-Id: I37cbc8aafaeb8aef7f083ee6f5afa9eae71e0cd9
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/9042
Tested-by: jenkins
Reviewed-by: zapb <dev@zapb.de>
This commit is contained in:
Antonio Borneo
2025-06-30 00:22:28 +02:00
parent c22e1eb3ce
commit 880f234915

View File

@@ -780,7 +780,8 @@ static int svf_read_command_from_file(FILE *fd)
static int svf_parse_cmd_string(char *str, int len, char **argus, int *num_of_argu) static int svf_parse_cmd_string(char *str, int len, char **argus, int *num_of_argu)
{ {
int pos = 0, num = 0, space_found = 1, in_bracket = 0; bool space_found = true, in_bracket = false;
int pos = 0, num = 0;
while (pos < len) { while (pos < len) {
switch (str[pos]) { switch (str[pos]) {
@@ -789,22 +790,23 @@ static int svf_parse_cmd_string(char *str, int len, char **argus, int *num_of_ar
LOG_ERROR("fail to parse svf command"); LOG_ERROR("fail to parse svf command");
return ERROR_FAIL; return ERROR_FAIL;
case '(': case '(':
in_bracket = 1; in_bracket = true;
goto parse_char; break;
case ')': case ')':
in_bracket = 0; in_bracket = false;
goto parse_char; break;
default: default:
parse_char: break;
}
if (!in_bracket && isspace((int)str[pos])) { if (!in_bracket && isspace((int)str[pos])) {
space_found = 1; space_found = true;
str[pos] = '\0'; str[pos] = '\0';
} else if (space_found) { } else if (space_found) {
argus[num++] = &str[pos]; argus[num++] = &str[pos];
space_found = 0; space_found = false;
}
break;
} }
pos++; pos++;
} }