From patchwork Sun Apr 27 16:00:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hani Benhabiles X-Patchwork-Id: 343162 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 218A71400A3 for ; Mon, 28 Apr 2014 02:01:25 +1000 (EST) Received: from localhost ([::1]:39747 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WeRW6-0002i2-MZ for incoming@patchwork.ozlabs.org; Sun, 27 Apr 2014 12:01:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45173) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WeRVC-0001YO-8e for qemu-devel@nongnu.org; Sun, 27 Apr 2014 12:00:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WeRV6-0001Nz-4m for qemu-devel@nongnu.org; Sun, 27 Apr 2014 12:00:26 -0400 Received: from mail-wg0-x234.google.com ([2a00:1450:400c:c00::234]:50835) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WeRV5-0001Nm-SZ for qemu-devel@nongnu.org; Sun, 27 Apr 2014 12:00:20 -0400 Received: by mail-wg0-f52.google.com with SMTP id b13so4161455wgh.11 for ; Sun, 27 Apr 2014 09:00:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=R8wgNXupH2pVIphAZCsMgcKKPFBZjmQ8T79y4EIl7Wk=; b=m/o3mV37qjW2PxsUskRvpsDX+B9DID+HHgbwE92mERhysvZQqwkO4x6sbYc4x/Uz84 0uEXLh4+MzXsrXf9sjypFIAOM96xrEp7RMpsqp70p/67tEbhTJp1Rz0JvlecCk9GdCh8 tcS910k+A2K2CFpd0lWjJg2MJNJx7sl7vFfzZGvAGwTDWvmHLGA4ka5qXOHu3cBsq4B4 +7GTAYzXTZXhMV9eCPYZAA6XCdJufLx40eC+u8jVXbrylqTk/oM94izGzIT6QbBrOmR8 NTYp7h1USU2xnFsjDR0e/GXethgV57dlseokMPodeRgcOQ5OCNlmlA9bLcELZsb17TdK i33A== X-Received: by 10.180.90.132 with SMTP id bw4mr1959462wib.26.1398614418944; Sun, 27 Apr 2014 09:00:18 -0700 (PDT) Received: from localhost.localdomain ([41.104.79.200]) by mx.google.com with ESMTPSA id lh6sm21576414wjb.27.2014.04.27.09.00.17 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 27 Apr 2014 09:00:18 -0700 (PDT) From: Hani Benhabiles To: qemu-devel@nongnu.org Date: Sun, 27 Apr 2014 17:00:02 +0100 Message-Id: <1398614409-30792-2-git-send-email-kroosec@gmail.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1398614409-30792-1-git-send-email-kroosec@gmail.com> References: <1398614409-30792-1-git-send-email-kroosec@gmail.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c00::234 Cc: stefanha@redhat.com, lcapitulino@redhat.com Subject: [Qemu-devel] [PATCH 1/7] monitor: Convert sendkey to use command_completion. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Hani Benhabiles --- hmp-commands.hx | 1 + hmp.h | 1 + monitor.c | 32 +++++++++++++++++++++++--------- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/hmp-commands.hx b/hmp-commands.hx index 4c4d261..b3f45d6 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -556,6 +556,7 @@ ETEXI .params = "keys [hold_ms]", .help = "send keys to the VM (e.g. 'sendkey ctrl-alt-f1', default hold time=100 ms)", .mhandler.cmd = hmp_send_key, + .command_completion = sendkey_completion, }, STEXI diff --git a/hmp.h b/hmp.h index 20ef454..12e21e7 100644 --- a/hmp.h +++ b/hmp.h @@ -97,5 +97,6 @@ void object_add_completion(ReadLineState *rs, int nb_args, const char *str); void object_del_completion(ReadLineState *rs, int nb_args, const char *str); void device_add_completion(ReadLineState *rs, int nb_args, const char *str); void device_del_completion(ReadLineState *rs, int nb_args, const char *str); +void sendkey_completion(ReadLineState *rs, int nb_args, const char *str); #endif diff --git a/monitor.c b/monitor.c index 17738f8..7edfcee 100644 --- a/monitor.c +++ b/monitor.c @@ -4385,6 +4385,28 @@ void object_del_completion(ReadLineState *rs, int nb_args, const char *str) qapi_free_ObjectPropertyInfoList(start); } +void sendkey_completion(ReadLineState *rs, int nb_args, const char *str) +{ + int i; + char *sep; + size_t len; + + if (nb_args != 2) { + return; + } + sep = strrchr(str, '-'); + if (sep) { + str = sep + 1; + } + len = strlen(str); + readline_set_completion_index(rs, len); + for (i = 0; i < Q_KEY_CODE_MAX; i++) { + if (!strncmp(str, QKeyCode_lookup[i], len)) { + readline_add_completion(rs, QKeyCode_lookup[i]); + } + } +} + static void monitor_find_completion_by_table(Monitor *mon, const mon_cmd_t *cmd_table, char **args, @@ -4453,15 +4475,7 @@ static void monitor_find_completion_by_table(Monitor *mon, break; case 's': case 'S': - if (!strcmp(cmd->name, "sendkey")) { - char *sep = strrchr(str, '-'); - if (sep) - str = sep + 1; - readline_set_completion_index(mon->rs, strlen(str)); - for (i = 0; i < Q_KEY_CODE_MAX; i++) { - cmd_completion(mon, str, QKeyCode_lookup[i]); - } - } else if (!strcmp(cmd->name, "help|?")) { + if (!strcmp(cmd->name, "help|?")) { monitor_find_completion_by_table(mon, cmd_table, &args[1], nb_args - 1); }