diff mbox

[2/6] qemu-log: Abstract out "print usage message about valid log categories"

Message ID 1360600885-6917-3-git-send-email-peter.maydell@linaro.org
State Accepted
Commit 59a6fa6e67d2335d867c66c59d992847e5b62879
Headers show

Commit Message

Peter Maydell Feb. 11, 2013, 4:41 p.m. UTC
Abstract out the "print a human readable list of all the
valid log categories" functionality which is currently duplicated
in three separate places. (We leave the monitor.c help_cmd()
implementation as-is since it wants to send the message to
the monitor and add its own information.)

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 bsd-user/main.c    |    6 +-----
 cpus.c             |    6 +-----
 include/qemu/log.h |    5 +++++
 linux-user/main.c  |    6 +-----
 qemu-log.c         |    9 +++++++++
 5 files changed, 17 insertions(+), 15 deletions(-)

Comments

Andreas Färber Feb. 11, 2013, 7:23 p.m. UTC | #1
Am 11.02.2013 17:41, schrieb Peter Maydell:
> Abstract out the "print a human readable list of all the
> valid log categories" functionality which is currently duplicated
> in three separate places. (We leave the monitor.c help_cmd()
> implementation as-is since it wants to send the message to
> the monitor and add its own information.)
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  bsd-user/main.c    |    6 +-----
>  cpus.c             |    6 +-----
>  include/qemu/log.h |    5 +++++
>  linux-user/main.c  |    6 +-----
>  qemu-log.c         |    9 +++++++++
>  5 files changed, 17 insertions(+), 15 deletions(-)
> 
> diff --git a/bsd-user/main.c b/bsd-user/main.c
> index 76ab359..26604b4 100644
> --- a/bsd-user/main.c
> +++ b/bsd-user/main.c
> @@ -864,14 +864,10 @@ int main(int argc, char **argv)
>      qemu_set_log_filename(log_file);
>      if (log_mask) {
>          int mask;
> -        const CPULogItem *item;
>  
>          mask = cpu_str_to_log_mask(log_mask);
>          if (!mask) {
> -            printf("Log items (comma separated):\n");
> -            for (item = cpu_log_items; item->mask != 0; item++) {
> -                printf("%-10s %s\n", item->name, item->help);
> -            }
> +            qemu_print_log_usage(stdout);
>              exit(1);
>          }
>          cpu_set_log(mask);
> diff --git a/cpus.c b/cpus.c
> index 2155441..0fdc48c 100644
> --- a/cpus.c
> +++ b/cpus.c
> @@ -1178,14 +1178,10 @@ void set_numa_modes(void)
>  void set_cpu_log(const char *optarg)
>  {
>      int mask;
> -    const CPULogItem *item;
>  
>      mask = cpu_str_to_log_mask(optarg);
>      if (!mask) {
> -        printf("Log items (comma separated):\n");
> -        for (item = cpu_log_items; item->mask != 0; item++) {
> -            printf("%-10s %s\n", item->name, item->help);
> -        }
> +        qemu_print_log_usage(stdout);
>          exit(1);
>      }
>      cpu_set_log(mask);
> diff --git a/include/qemu/log.h b/include/qemu/log.h
> index 4760e04..59511a3 100644
> --- a/include/qemu/log.h
> +++ b/include/qemu/log.h
> @@ -157,4 +157,9 @@ static inline void cpu_set_log(int log_flags)
>  void qemu_set_log_filename(const char *filename);
>  int cpu_str_to_log_mask(const char *str);
>  
> +/* Print a usage message listing all the valid logging categories
> + * to the specified FILE*.
> + */
> +void qemu_print_log_usage(FILE *f);
> +
>  #endif
> diff --git a/linux-user/main.c b/linux-user/main.c
> index 99219ef..81eb126 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -3098,14 +3098,10 @@ static void handle_arg_help(const char *arg)
>  static void handle_arg_log(const char *arg)
>  {
>      int mask;
> -    const CPULogItem *item;
>  
>      mask = cpu_str_to_log_mask(arg);
>      if (!mask) {
> -        printf("Log items (comma separated):\n");
> -        for (item = cpu_log_items; item->mask != 0; item++) {
> -            printf("%-10s %s\n", item->name, item->help);
> -        }
> +        qemu_print_log_usage(stdout);
>          exit(1);
>      }
>      cpu_set_log(mask);
> diff --git a/qemu-log.c b/qemu-log.c
> index 9a7e567..786d335 100644
> --- a/qemu-log.c
> +++ b/qemu-log.c
> @@ -170,3 +170,12 @@ int cpu_str_to_log_mask(const char *str)
>      }
>      return mask;
>  }
> +
> +void qemu_print_log_usage(FILE *f)
> +{
> +    const CPULogItem *item;

If this gets resubmitted or included in a PULL, a while line here would
match our usual separate-variables-from-statements convention.

> +    fprintf(f, "Log items (comma separated):\n");
> +    for (item = cpu_log_items; item->mask != 0; item++) {
> +        fprintf(f, "%-10s %s\n", item->name, item->help);
> +    }
> +}

Other than that, a nice cleanup,

Reviewed-by: Andreas Färber <afaerber@suse.de>

Andreas
Peter Maydell Feb. 11, 2013, 9:09 p.m. UTC | #2
On 11 February 2013 19:23, Andreas Färber <afaerber@suse.de> wrote:
> Am 11.02.2013 17:41, schrieb Peter Maydell:
>> +void qemu_print_log_usage(FILE *f)
>> +{
>> +    const CPULogItem *item;
>
> If this gets resubmitted or included in a PULL, a while line here would
> match our usual separate-variables-from-statements convention.

You mean a blank line? Sure, I can add one.

>> +    fprintf(f, "Log items (comma separated):\n");
>> +    for (item = cpu_log_items; item->mask != 0; item++) {
>> +        fprintf(f, "%-10s %s\n", item->name, item->help);
>> +    }
>> +}

-- PMM
diff mbox

Patch

diff --git a/bsd-user/main.c b/bsd-user/main.c
index 76ab359..26604b4 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -864,14 +864,10 @@  int main(int argc, char **argv)
     qemu_set_log_filename(log_file);
     if (log_mask) {
         int mask;
-        const CPULogItem *item;
 
         mask = cpu_str_to_log_mask(log_mask);
         if (!mask) {
-            printf("Log items (comma separated):\n");
-            for (item = cpu_log_items; item->mask != 0; item++) {
-                printf("%-10s %s\n", item->name, item->help);
-            }
+            qemu_print_log_usage(stdout);
             exit(1);
         }
         cpu_set_log(mask);
diff --git a/cpus.c b/cpus.c
index 2155441..0fdc48c 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1178,14 +1178,10 @@  void set_numa_modes(void)
 void set_cpu_log(const char *optarg)
 {
     int mask;
-    const CPULogItem *item;
 
     mask = cpu_str_to_log_mask(optarg);
     if (!mask) {
-        printf("Log items (comma separated):\n");
-        for (item = cpu_log_items; item->mask != 0; item++) {
-            printf("%-10s %s\n", item->name, item->help);
-        }
+        qemu_print_log_usage(stdout);
         exit(1);
     }
     cpu_set_log(mask);
diff --git a/include/qemu/log.h b/include/qemu/log.h
index 4760e04..59511a3 100644
--- a/include/qemu/log.h
+++ b/include/qemu/log.h
@@ -157,4 +157,9 @@  static inline void cpu_set_log(int log_flags)
 void qemu_set_log_filename(const char *filename);
 int cpu_str_to_log_mask(const char *str);
 
+/* Print a usage message listing all the valid logging categories
+ * to the specified FILE*.
+ */
+void qemu_print_log_usage(FILE *f);
+
 #endif
diff --git a/linux-user/main.c b/linux-user/main.c
index 99219ef..81eb126 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -3098,14 +3098,10 @@  static void handle_arg_help(const char *arg)
 static void handle_arg_log(const char *arg)
 {
     int mask;
-    const CPULogItem *item;
 
     mask = cpu_str_to_log_mask(arg);
     if (!mask) {
-        printf("Log items (comma separated):\n");
-        for (item = cpu_log_items; item->mask != 0; item++) {
-            printf("%-10s %s\n", item->name, item->help);
-        }
+        qemu_print_log_usage(stdout);
         exit(1);
     }
     cpu_set_log(mask);
diff --git a/qemu-log.c b/qemu-log.c
index 9a7e567..786d335 100644
--- a/qemu-log.c
+++ b/qemu-log.c
@@ -170,3 +170,12 @@  int cpu_str_to_log_mask(const char *str)
     }
     return mask;
 }
+
+void qemu_print_log_usage(FILE *f)
+{
+    const CPULogItem *item;
+    fprintf(f, "Log items (comma separated):\n");
+    for (item = cpu_log_items; item->mask != 0; item++) {
+        fprintf(f, "%-10s %s\n", item->name, item->help);
+    }
+}