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)
{
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) {
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");
return ERROR_FAIL;
case '(':
in_bracket = 1;
goto parse_char;
in_bracket = true;
break;
case ')':
in_bracket = 0;
goto parse_char;
in_bracket = false;
break;
default:
parse_char:
if (!in_bracket && isspace((int) str[pos])) {
space_found = 1;
str[pos] = '\0';
} else if (space_found) {
argus[num++] = &str[pos];
space_found = 0;
}
break;
}
if (!in_bracket && isspace((int)str[pos])) {
space_found = true;
str[pos] = '\0';
} else if (space_found) {
argus[num++] = &str[pos];
space_found = false;
}
pos++;
}