diff options
author | Mike Frysinger <vapier@gentoo.org> | 2011-04-15 03:43:44 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2011-04-15 03:43:44 +0000 |
commit | 3d507852fa6fa9de029669efdd2c2a9ce17370bd (patch) | |
tree | 36bb62b198982aa60b17b5a3cd467ec721eed2dc /sim/common | |
parent | 24dae6cda822f56855ce0b149424d583d585d4be (diff) | |
download | gdb-3d507852fa6fa9de029669efdd2c2a9ce17370bd.tar.gz |
gdb: sim: add command line completion
For now, only the sub-command name is completed. No support yet for
completing options to that command. But even this is a huge step as
currently, nothing is completed, and the basic "help sim" is fairly
obtuse as to what exactly the "sim" command accepts.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'sim/common')
-rw-r--r-- | sim/common/ChangeLog | 5 | ||||
-rw-r--r-- | sim/common/sim-options.c | 51 |
2 files changed, 56 insertions, 0 deletions
diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog index 6c236f51dba..25e758ba7bd 100644 --- a/sim/common/ChangeLog +++ b/sim/common/ChangeLog @@ -1,3 +1,8 @@ +2011-04-14 Mike Frysinger <vapier@gentoo.org> + + * sim-options.c (complete_option_list, sim_complete_command): + New functions. + 2011-04-02 Mike Frysinger <vapier@gentoo.org> * dv-glue.c: Fix up style. diff --git a/sim/common/sim-options.c b/sim/common/sim-options.c index 0b4d4eee6de..ee8a8ec69ce 100644 --- a/sim/common/sim-options.c +++ b/sim/common/sim-options.c @@ -915,6 +915,57 @@ find_match (SIM_DESC sd, sim_cpu *cpu, char *argv[], int *pargi) return matching_opt; } +static char ** +complete_option_list (char **ret, size_t *cnt, const struct option_list *ol, + char *text, char *word) +{ + const OPTION *opt = NULL; + int argi; + size_t len = strlen (word); + + for ( ; ol != NULL; ol = ol->next) + for (opt = ol->options; OPTION_VALID_P (opt); ++opt) + { + const char *name = opt->opt.name; + + /* A long option to match against? */ + if (!name) + continue; + + /* Does this option actually match? */ + if (strncmp (name, word, len)) + continue; + + ret = xrealloc (ret, ++*cnt * sizeof (ret[0])); + ret[*cnt - 2] = xstrdup (name); + } + + return ret; +} + +/* All leading text is stored in @text, while the current word being + completed is stored in @word. Trailing text of @word is not. */ +char ** +sim_complete_command (SIM_DESC sd, char *text, char *word) +{ + char **ret = NULL; + size_t cnt = 1; + sim_cpu *cpu; + + /* Only complete first word for now. */ + if (text != word) + return ret; + + cpu = STATE_CPU (sd, 0); + if (cpu) + ret = complete_option_list (ret, &cnt, CPU_OPTIONS (cpu), text, word); + ret = complete_option_list (ret, &cnt, STATE_OPTIONS (sd), text, word); + + if (ret) + ret[cnt - 1] = NULL; + return ret; +} + SIM_RC sim_args_command (SIM_DESC sd, char *cmd) { |