From: Andrzej Zaborowski <andrew.zaborowski@intel.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH v3] Add tab-completion for device_add.
Date: Mon, 20 Feb 2012 03:39:14 +0100 [thread overview]
Message-ID: <1329705554-22225-1-git-send-email-andrew.zaborowski@intel.com> (raw)
From: Andrzej Zaborowski <balrogg@gmail.com>
Signed-off-by: Andrzej Zaborowski <andrew.zaborowski@intel.com>
---
v2: pass only char *prop_name as qdev_driver_prop_foreach_func parameter,
Anthony noted Property was soon going away.
v3: use QOM.
---
monitor.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 58 insertions(+), 0 deletions(-)
diff --git a/monitor.c b/monitor.c
index aadbdcb..28f5b9a 100644
--- a/monitor.c
+++ b/monitor.c
@@ -3917,6 +3917,27 @@ static void block_completion_it(void *opaque, BlockDriverState *bs)
}
}
+static void class_completion_it(ObjectClass *klass, void *opaque)
+{
+ const char *input = opaque;
+ const char *name = object_class_get_name(klass);
+
+ if (input[0] == '\0' || !strncmp(name, input, strlen(input))) {
+ readline_add_completion(cur_mon->rs, name);
+ }
+}
+
+static int driver_prop_completion_it(Property *info, void *opaque)
+{
+ const char *input = opaque;
+
+ if (input[0] == '\0' || !strncmp(info->name, input, strlen(input))) {
+ readline_add_completion(cur_mon->rs, info->name);
+ }
+
+ return 0;
+}
+
/* NOTE: this parser is an approximate form of the real command parser */
static void parse_cmdline(const char *cmdline,
int *pnb_args, char **args)
@@ -3957,6 +3978,7 @@ static void monitor_find_completion(const char *cmdline)
const char *ptype, *str;
const mon_cmd_t *cmd;
const KeyDef *key;
+ char *pkey;
parse_cmdline(cmdline, &nb_args, args);
#ifdef DEBUG_COMPLETION
@@ -3995,6 +4017,7 @@ static void monitor_find_completion(const char *cmdline)
goto cleanup;
}
+ key_get_info(cmd->args_type, &pkey);
ptype = next_arg_type(cmd->args_type);
for(i = 0; i < nb_args - 2; i++) {
if (*ptype != '\0') {
@@ -4040,9 +4063,44 @@ static void monitor_find_completion(const char *cmdline)
}
}
break;
+ case 'O':
+ if (!strcmp(pkey, "device")) {
+ char *sep = strrchr(str, ',');
+
+ readline_set_completion_index(cur_mon->rs,
+ strlen(sep ? sep + 1 : str));
+ if (sep) {
+ char *driver = g_strndup(str, strchr(str, ',') - str);
+ ObjectClass *klass = object_class_by_name(driver);
+ DeviceClass *info;
+ Property *prop;
+
+ g_free(driver);
+ if (!klass) {
+ break;
+ }
+
+ info = DEVICE_CLASS(klass);
+ for (prop = info->props; prop && prop->name; prop++) {
+ driver_prop_completion_it(prop, sep + 1);
+ }
+ if (info->bus_info) {
+ for (prop = info->bus_info->props;
+ prop && prop->name; prop++) {
+ driver_prop_completion_it(prop, sep + 1);
+ }
+ }
+ break;
+ }
+
+ object_class_foreach(class_completion_it, TYPE_DEVICE, 0,
+ (void *) str);
+ }
+ break;
default:
break;
}
+ g_free(pkey);
}
cleanup:
--
1.7.4.4
---------------------------------------------------------------------
Intel Technology Poland sp. z o.o.
z siedziba w Gdansku
ul. Slowackiego 173
80-298 Gdansk
Sad Rejonowy Gdansk Polnoc w Gdansku,
VII Wydzial Gospodarczy Krajowego Rejestru Sadowego,
numer KRS 101882
NIP 957-07-52-316
Kapital zakladowy 200.000 zl
This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
reply other threads:[~2012-02-20 13:37 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1329705554-22225-1-git-send-email-andrew.zaborowski@intel.com \
--to=andrew.zaborowski@intel.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).