From patchwork Wed May 7 22:41:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hani Benhabiles X-Patchwork-Id: 346833 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 B461A14011A for ; Thu, 8 May 2014 08:42:27 +1000 (EST) Received: from localhost ([::1]:43898 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WiAXh-00065q-CI for incoming@patchwork.ozlabs.org; Wed, 07 May 2014 18:42:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59866) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WiAX6-0005G7-Mf for qemu-devel@nongnu.org; Wed, 07 May 2014 18:41:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WiAX0-00032h-Hd for qemu-devel@nongnu.org; Wed, 07 May 2014 18:41:48 -0400 Received: from mail-wi0-x232.google.com ([2a00:1450:400c:c05::232]:61287) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WiAX0-00032O-Ae for qemu-devel@nongnu.org; Wed, 07 May 2014 18:41:42 -0400 Received: by mail-wi0-f178.google.com with SMTP id hm4so2157636wib.17 for ; Wed, 07 May 2014 15:41:41 -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=IwCzy1pE4asbImlXaxPwmgtaGhmdBx0qCIk6c3TOS0k=; b=XYus6+lH5TTN3hwT8vax8W9BHxA3vQTyU2vG3ggMZPVcOWQSQdsLdV9AkYtY5CvRj3 HksJXZA2cbG3GFQDrO7On0WpY18ukhe8lIj6014Nb1GxvHLdEq/J6rRQAyxULk6vsspf dgF0egVbSQzHawxuCB3a61DMHGu3B5eStWpraDttZ2FjZNMirdytG/bJPGGhZv+oBCGw xdinJL8BxzNk+/Rw174X6ffkvVL6rK+3FccpPU1p0ZN61zOIhP86OEvKEtrWRMLtsbf/ dgY8Y88mpNoIblJThH780e9y91Cae5oQ8tGJYJ5PXOZc4eLeIJOW+W954gKw4pmAX8zG Y3Zg== X-Received: by 10.194.189.116 with SMTP id gh20mr16058240wjc.41.1399502501495; Wed, 07 May 2014 15:41:41 -0700 (PDT) Received: from localhost.localdomain ([41.109.207.215]) by mx.google.com with ESMTPSA id f11sm196112wiv.1.2014.05.07.15.41.40 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 07 May 2014 15:41:40 -0700 (PDT) From: Hani Benhabiles To: qemu-devel@nongnu.org Date: Wed, 7 May 2014 23:41:27 +0100 Message-Id: <1399502492-6188-2-git-send-email-kroosec@gmail.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1399502492-6188-1-git-send-email-kroosec@gmail.com> References: <1399502492-6188-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:c05::232 Cc: kraxel@redhat.com, lcapitulino@redhat.com Subject: [Qemu-devel] [PATCH 1/6] 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 8971f1b..b4b23c8 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 2d3fb3f..7ef251c 100644 --- a/monitor.c +++ b/monitor.c @@ -4359,6 +4359,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, @@ -4427,15 +4449,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); }