diff options
author | Keir Fraser <keir.fraser@citrix.com> | 2010-06-18 14:09:14 +0100 |
---|---|---|
committer | Keir Fraser <keir.fraser@citrix.com> | 2010-06-18 14:09:14 +0100 |
commit | f20cacf6dc20a60d5512b08aba49b4d6bc1cdc7f (patch) | |
tree | cd56ef2721a558ebee781b87a623452f684fa592 /tools/libxl/xl_cmdtable.c | |
parent | 20ad53b196b3a11969e6891f70647788a339605a (diff) | |
download | xen-f20cacf6dc20a60d5512b08aba49b4d6bc1cdc7f.tar.gz xen-f20cacf6dc20a60d5512b08aba49b4d6bc1cdc7f.tar.bz2 xen-f20cacf6dc20a60d5512b08aba49b4d6bc1cdc7f.zip |
xl: allow truncation of xl subcommands
for those of us who are used to typing "xm cr foo"
Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com>
Diffstat (limited to 'tools/libxl/xl_cmdtable.c')
-rw-r--r-- | tools/libxl/xl_cmdtable.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tools/libxl/xl_cmdtable.c b/tools/libxl/xl_cmdtable.c index d14993e25b..da00cda663 100644 --- a/tools/libxl/xl_cmdtable.c +++ b/tools/libxl/xl_cmdtable.c @@ -12,6 +12,8 @@ * GNU Lesser General Public License for more details. */ +#include <string.h> + #include "xl.h" struct cmd_spec cmd_table[] = { @@ -308,3 +310,24 @@ struct cmd_spec cmd_table[] = { }; int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec); + +/* Look up a command in the table, allowing unambiguous truncation */ +struct cmd_spec *cmdtable_lookup(const char *s) +{ + struct cmd_spec *cmd = NULL; + size_t len; + int i; + + if (!s) + return NULL; + len = strlen(s); + for (i = 0; i < cmdtable_len; i++) { + if (!strncmp(s, cmd_table[i].cmd_name, len)) { + if (cmd == NULL) + cmd = &cmd_table[i]; + else + return NULL; + } + } + return cmd; +} |