[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH 2/9] libxl: disks: new xlu_disk_parse function



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.

Ian.

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.