Received: from [140.186.70.92] (port=38121 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OSPFh-0007Uo-CF for qemu-devel@nongnu.org; Sat, 26 Jun 2010 02:52:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OSPFg-00049p-Ao for qemu-devel@nongnu.org; Sat, 26 Jun 2010 02:52:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45021) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OSPFg-00049i-2X for qemu-devel@nongnu.org; Sat, 26 Jun 2010 02:52:32 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5Q6qUUx008542 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sat, 26 Jun 2010 02:52:31 -0400 From: Markus Armbruster Subject: Re: [Qemu-devel] [PATCH 03/19] Add enum handlers for easy & efficient string <-> int conversion References: <1275921752-29420-1-git-send-email-berrange@redhat.com> <1275921752-29420-4-git-send-email-berrange@redhat.com> Date: Sat, 26 Jun 2010 08:52:28 +0200 In-Reply-To: <1275921752-29420-4-git-send-email-berrange@redhat.com> (Daniel P. Berrange's message of "Mon, 7 Jun 2010 15:42:16 +0100") Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" Cc: qemu-devel@nongnu.org "Daniel P. Berrange" writes: > There is quite alot of code using an enumeration of possible > values, which also needs todo conversions to/from a string > representation of enum values. These string <-> int conversions > have been repeated in an adhoc manner throughout the code. > > This makes it hard to report on the list of valid strings, > eg in help output, or todo proper validation in the qemu > config/option parsing routines. Correct. > This addresses the first problem by introducing a standard > set of routines for performing string <-> int conversions > for enums. There are two restrictions on using these helpers, > the first enum value must be 0, and there must be a sentinal > in the enum to provide the max value. > > For each enumeration, three functions will be made available > > - string to int convertor: > > int XXXX_from_string(const char *value); > > Returns -1 if the value was not an allowed string for the > enumeration. Returns >= 0 for a valid value > > - int to string convertor > > const char * XXXX_to_string(int value); > > Returns NULL if the value was not a member of the > enumeration. Returns a non-NULL sstring for valid value > > - string list generator > > char * XXXX_to_string_list(void); > > Returns a malloc'd string containing all valid values, > separated by commas. Caller must free the string. Make the separator an argument? Return a malloc'ed char **, NULL terminated? > The general usage pattern is as follows. [...]