On 09/23/2013 06:09 AM, Max Reitz wrote: > Add a function for generically dumping the ImageInfoSpecific information > in a human-readable format to block/qapi.c. > > Use this function in bdrv_image_info_dump and qemu-io-cmds.c:info_f to > allow qemu-img info resp. qemu-io -c info to print that format specific > information. > > Signed-off-by: Max Reitz <[email protected]> > --- > block/qapi.c | 121 > +++++++++++++++++++++++++++++++++++++++++++++++++++ > include/block/qapi.h | 2 + > qemu-io-cmds.c | 9 ++++ > 3 files changed, 132 insertions(+) >
> +
> +static void dump_qdict(fprintf_function func_fprintf, void *f, int
> indentation,
> + QDict *dict)
> +{
> + const QDictEntry *entry;
> +
> + for (entry = qdict_first(dict); entry; entry = qdict_next(dict, entry)) {
> + qtype_code type = qobject_type(entry->value);
> + bool composite = (type == QTYPE_QDICT || type == QTYPE_QLIST);
> + const char *format = composite ? "%*s%s:\n" : "%*s%s: ";
> + char key[strlen(entry->key) + 1];
> + int i;
> +
> + /* replace dashes with spaces in key (variable) names */
> + for (i = 0; entry->key[i]; i++) {
> + key[i] = entry->key[i] == '-' ? ' ' : entry->key[i];
I wonder if this should replace underscores, too. For now, this
function is only being used on types that happen to use - in key names,
but it seems generic enough that we may want to use it on older types
that followed older conventions. But I won't force a respin for just
that (if someone DOES reuse this function in the future, they can tweak
underscores at that time, if you don't do it now).
Reviewed-by: Eric Blake <[email protected]>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
