From: Ian Campbell Subject: Re: [PATCH 2/9] libxl: disks: new xlu_disk_parse function Date: Fri, 3 Jun 2011 13:03:40 +0100 Message-ID: <1307102620.775.373.camel@zakaz.uk.xensource.com> References: <1307037346-31251-1-git-send-email-ian.jackson@eu.citrix.com> <1307037346-31251-2-git-send-email-ian.jackson@eu.citrix.com> <1307037346-31251-3-git-send-email-ian.jackson@eu.citrix.com> <1307095702.775.343.camel@zakaz.uk.xensource.com> <19944.49437.818111.279525@mariner.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <19944.49437.818111.279525@mariner.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Ian Jackson Cc: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org On Fri, 2011-06-03 at 12:10 +0100, Ian Jackson wrote: > Ian Campbell writes ("Re: [Xen-devel] [PATCH 2/9] libxl: disks: new xlu_disk_parse function"): > > On Thu, 2011-06-02 at 18:55 +0100, Ian Jackson wrote: > > > +/* Sets ->format from the string. IDL should provide something for this. */ > > > > (please imagine a thunderclap and cloud of smoke here...) > > :-). > > > I'm not sure if we need to be more flexible, e.g. allow output in both > > upper and lower case, accept - where the name has _ etc. > > Those would all be nice to have :-). But I don't think they're that > important. > > > +def libxl_C_enum_from_string(ty, str, e, indent = " "): > > + s = "" > > + s += "static struct { const char *s; %s v; } lookup[] = {\n" % ty.typename > > + for v in ty.values: > > + s += " { \"%s\", %s },\n" % (v.valuename.lower(), v.name) > > + s += "};\n" > > + s += "int i;\n" > > + s += "\n" > > + s += "for (i=0; i<(sizeof(lookup)/sizeof(lookup[0])); i++) {\n" > > + s += " if (!strcasecmp(lookup[i].s, %s)) {\n" % (str) > > + s += " %s = lookup[i].v;\n" % (e) > > + s += " return 0;\n" > > + s += " }\n" > > + s += "}\n" > > + s += "return -1;\n" > > This is a bit mad, isn't it ? I mean, we could have a > non-autogenerated "lookup string from table" function and only > autogenerate the tables. I think that's a nicer interface for > callers, too - for example, they can print a list of options if they > want to, etc. Yes, I agree. Ian.