From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36284) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YOO6k-0005W1-RF for qemu-devel@nongnu.org; Thu, 19 Feb 2015 05:13:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YOO6f-0002gD-O8 for qemu-devel@nongnu.org; Thu, 19 Feb 2015 05:13:22 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45095) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YOO6f-0002fz-FJ for qemu-devel@nongnu.org; Thu, 19 Feb 2015 05:13:17 -0500 Date: Thu, 19 Feb 2015 11:13:10 +0100 From: "Michael S. Tsirkin" Message-ID: <1424340754-24444-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] [PATCH] qapi-types: add C99 index names to arrays List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Markus Armbruster , Wenchao Xia , Luiz Capitulino It's not easy to figure out how monitor translates strings: most QEMU code deals with translated indexes, these are translated using _lookup arrays, so you need to find the array name, and find the appropriate offset. This patch adds C99 indexes to lookup arrays, which makes it possible to find the correct key using simple grep, and see that the matching is correct at a glance. Example: Before: const char *MigrationCapability_lookup[] = { "xbzrle", "rdma-pin-all", "auto-converge", "zero-blocks", NULL, }; After: const char *MigrationCapability_lookup[] = { [MIGRATION_CAPABILITY_XBZRLE] = "xbzrle", [MIGRATION_CAPABILITY_RDMA_PIN_ALL] = "rdma-pin-all", [MIGRATION_CAPABILITY_AUTO_CONVERGE] = "auto-converge", [MIGRATION_CAPABILITY_ZERO_BLOCKS] = "zero-blocks", [MIGRATION_CAPABILITY_MAX] = NULL, }; Signed-off-by: Michael S. Tsirkin --- scripts/qapi-types.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index 1eb272d..db87218 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -123,16 +123,19 @@ const char *%(name)s_lookup[] = { name=name) i = 0 for value in values: + index = generate_enum_full_value(name, value) ret += mcgen(''' - "%(value)s", + [%(index)s] = "%(value)s", ''', - value=value) + index = index, value = value) + max_index = generate_enum_full_value(name, 'MAX') ret += mcgen(''' - NULL, + [%(max_index)s] = NULL, }; -''') +''', + max_index=max_index) return ret def generate_enum(name, values): -- MST