diff mbox

[v2,3/6] opts: do not print separator before first item in qemu_opts_print

Message ID 06990ada8a0d0beb9bb942b5b9ddc1c19a9a4664.1434458391.git.DirtY.iCE.hu@gmail.com
State New
Headers show

Commit Message

=?UTF-8?B?Wm9sdMOhbiBLxZF2w6Fnw7M=?= June 16, 2015, 12:49 p.m. UTC
This allows to print options in a format that the user would actually write it
on the command line (foo=bar,baz=asd,etc=def), without prepending a spurious
comma at the beginning of the list.

Only block.c depended on the old behavior, but it was also updated.

Signed-off-by: Kővágó, Zoltán <DirtY.iCE.hu@gmail.com>
---
 block.c            | 2 +-
 util/qemu-option.c | 5 ++++-
 2 files changed, 5 insertions(+), 2 deletions(-)

Comments

Markus Armbruster June 17, 2015, 7:53 a.m. UTC | #1
"Kővágó, Zoltán" <dirty.ice.hu@gmail.com> writes:

> This allows to print options in a format that the user would actually write it
> on the command line (foo=bar,baz=asd,etc=def), without prepending a spurious
> comma at the beginning of the list.

Suggest: This will let us print...

> Only block.c depended on the old behavior, but it was also updated.

I'd drop this sentence.

>
> Signed-off-by: Kővágó, Zoltán <DirtY.iCE.hu@gmail.com>
> ---
>  block.c            | 2 +-
>  util/qemu-option.c | 5 ++++-
>  2 files changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/block.c b/block.c
> index dd4f58d..c5d456c 100644
> --- a/block.c
> +++ b/block.c
> @@ -3823,7 +3823,7 @@ void bdrv_img_create(const char *filename, const char *fmt,
>      }
>  
>      if (!quiet) {
> -        printf("Formatting '%s', fmt=%s", filename, fmt);
> +        printf("Formatting '%s', fmt=%s ", filename, fmt);
>          qemu_opts_print(opts, " ");
>          puts("");
>      }
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index 840f5f7..b347d92 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -728,14 +728,16 @@ void qemu_opts_del(QemuOpts *opts)
>      g_free(opts);
>  }
>  
> -void qemu_opts_print(QemuOpts *opts, const char *sep)
> +void qemu_opts_print(QemuOpts *opts, const char *d_sep)
>  {
>      QemuOpt *opt;
>      QemuOptDesc *desc = opts->list->desc;
> +    const char *sep = "";
>  
>      if (desc[0].name == NULL) {
>          QTAILQ_FOREACH(opt, &opts->head, next) {
>              printf("%s%s=\"%s\"", sep, opt->name, opt->str);
> +            sep = d_sep;
>          }
>          return;
>      }
> @@ -755,6 +757,7 @@ void qemu_opts_print(QemuOpts *opts, const char *sep)
>          } else {
>              printf("%s%s=%s", sep, desc->name, value);
>          }
> +        sep = d_sep;
>      }
>  }

No idea what d_ means.  Let's rename d_sep to separator.

With that rename:
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Kevin Wolf June 17, 2015, 9:02 a.m. UTC | #2
Am 16.06.2015 um 14:49 hat Kővágó, Zoltán geschrieben:
> This allows to print options in a format that the user would actually write it
> on the command line (foo=bar,baz=asd,etc=def), without prepending a spurious
> comma at the beginning of the list.

Note that if you really want to produce a valid command line, you would
have to escape any commas in option values. The quotes arounds strings
might not be wanted any more then either.

> Only block.c depended on the old behavior, but it was also updated.
> 
> Signed-off-by: Kővágó, Zoltán <DirtY.iCE.hu@gmail.com>

Seems that no behaviour changes from a block layer perspective, so:

Acked-by: Kevin Wolf <kwolf@redhat.com>
diff mbox

Patch

diff --git a/block.c b/block.c
index dd4f58d..c5d456c 100644
--- a/block.c
+++ b/block.c
@@ -3823,7 +3823,7 @@  void bdrv_img_create(const char *filename, const char *fmt,
     }
 
     if (!quiet) {
-        printf("Formatting '%s', fmt=%s", filename, fmt);
+        printf("Formatting '%s', fmt=%s ", filename, fmt);
         qemu_opts_print(opts, " ");
         puts("");
     }
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 840f5f7..b347d92 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -728,14 +728,16 @@  void qemu_opts_del(QemuOpts *opts)
     g_free(opts);
 }
 
-void qemu_opts_print(QemuOpts *opts, const char *sep)
+void qemu_opts_print(QemuOpts *opts, const char *d_sep)
 {
     QemuOpt *opt;
     QemuOptDesc *desc = opts->list->desc;
+    const char *sep = "";
 
     if (desc[0].name == NULL) {
         QTAILQ_FOREACH(opt, &opts->head, next) {
             printf("%s%s=\"%s\"", sep, opt->name, opt->str);
+            sep = d_sep;
         }
         return;
     }
@@ -755,6 +757,7 @@  void qemu_opts_print(QemuOpts *opts, const char *sep)
         } else {
             printf("%s%s=%s", sep, desc->name, value);
         }
+        sep = d_sep;
     }
 }