Commit 6681455c authored by Adam Wujek's avatar Adam Wujek Committed by Grzegorz Daniluk

sw/petalinux/diot-util: handle empty and starting with spaces lines

Signed-off-by: 's avatarAdam Wujek <dev_public@wujek.eu>
parent 3f535105
......@@ -204,6 +204,7 @@ int main(int argc, char **argv)
int ret;
char *line_read = NULL;
char *cmd_start_p = NULL;
int cmd_len;
char *params;
char *script_commands = NULL;
......@@ -263,7 +264,7 @@ int main(int argc, char **argv)
} else
cmd_len = strlen(curr_script_cmd);
/* Coppy comand like readline would do */
/* Copy command like readline would do */
line_read = strndup(curr_script_cmd, cmd_len);
}
} else {
......@@ -279,20 +280,29 @@ int main(int argc, char **argv)
if (line_read && *line_read)
add_history (line_read);
cmd_start_p = line_read;
params = strchr(line_read, ' ');
/* Skip spaces at the beginning of the line */
while (*cmd_start_p == ' ')
cmd_start_p++;
/* Prompt for another command if the line is empty */
if (*cmd_start_p == '\0')
continue;
params = strchr(cmd_start_p, ' ');
if (params) {
cmd_len = params - line_read;
cmd_len = params - cmd_start_p;
/* skip spaces for params */
while (*params && (*params == ' '))
params++;
} else
cmd_len = strlen(line_read);
cmd_len = strlen(cmd_start_p);
entry = commands_list;
while (entry && entry->cmd_name) {
if (cmd_len == strlen(entry->cmd_name)
&& !strncmp(entry->cmd_name, line_read, cmd_len)
&& !strncmp(entry->cmd_name, cmd_start_p, cmd_len)
) {
ret = entry->cmd_func(params);
if (ret < 0)
......@@ -303,7 +313,7 @@ int main(int argc, char **argv)
entry++;
}
if (!(entry && entry->cmd_name)) {
printf("Commad \"%s\" not found\n", line_read);
printf("Commad \"%s\" not found\n", cmd_start_p);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment