X-Git-Url: https://review.openocd.org/gitweb?a=blobdiff_plain;f=src%2Fhelper%2Fcommand.c;h=dbf3f2aa105c1e93a8a2c8c24b4aa7619d8d10bf;hb=4fc97d3f2726efa147cfdb0c456eace51550e1e3;hp=26eada62e70e659a392ca579c45828dc258522c0;hpb=8b4e882a1630d63bbc9840fa3f968e36b6ac3702;p=openocd.git diff --git a/src/helper/command.c b/src/helper/command.c index 26eada62e7..dbf3f2aa10 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -20,6 +20,12 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "replacements.h" + #include "command.h" #include "log.h" @@ -33,7 +39,7 @@ int handle_sleep_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -int build_unique_lenghts(command_context_t *context, command_t *commands) +int build_unique_lengths(command_context_t *context, command_t *commands) { command_t *c, *p; @@ -64,7 +70,7 @@ int build_unique_lenghts(command_context_t *context, command_t *commands) /* if the current command has children, build the unique lengths for them */ if (c->children) - build_unique_lenghts(context, c->children); + build_unique_lengths(context, c->children); } return ERROR_OK; @@ -122,7 +128,7 @@ command_t* register_command(command_context_t *context, command_t *parent, char } /* update unique lengths */ - build_unique_lenghts(context, (parent) ? parent : context->commands); + build_unique_lengths(context, (parent) ? parent : context->commands); return c; } @@ -194,12 +200,23 @@ int parse_line(char *line, char *words[], int max_words) /* we're inside a word or quote, and reached its end*/ if (word_start) { - int len = p - word_start; - - /* copy the word */ - memcpy(words[nwords] = malloc(len + 1), word_start, len); - /* add terminating NUL */ - words[nwords++][len] = 0; + int len; + char *word_end=p; + /* This will handle extra whitespace within quotes */ + while (isspace(*word_start)&&(word_start0) + { + /* copy the word */ + memcpy(words[nwords] = malloc(len + 1), word_start, len); + /* add terminating NUL */ + words[nwords++][len] = 0; + } } /* we're done parsing the line */ @@ -209,6 +226,8 @@ int parse_line(char *line, char *words[], int max_words) /* skip over trailing quote or whitespace*/ if (inquote || isspace(*p)) p++; + while (isspace(*p)) + p++; inquote = 0; word_start = 0; @@ -394,7 +413,7 @@ int command_run_file(command_context_t *context, FILE *file, enum command_mode m break; /* run line */ - if (command_run_line(context, cmd) == ERROR_COMMAND_CLOSE_CONNECTION) + if ((retval = command_run_line(context, cmd)) == ERROR_COMMAND_CLOSE_CONNECTION) break; } @@ -443,6 +462,15 @@ int command_print_help(command_context_t* context, char* name, char** args, int for (c = context->commands; c; c = c->next) { + if (argc == 1) + { + if (strncasecmp(c->name, args[0], c->unique_len)) + continue; + + if (strncasecmp(c->name, args[0], strlen(args[0]))) + continue; + } + command_print_help_line(context, c, 0); }