[Mesa-dev] [PATCH 2/2] aubinator: print_help swap "FILE *file" with "bool critical"

Emil Velikov emil.l.velikov at gmail.com
Mon Sep 12 11:59:12 UTC 2016


From: Emil Velikov <emil.velikov at collabora.com>

Derive file locally and exit() accordingly based on the bool.
Allows us to save a couple lines of code.

Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
---
s/print_help/print_help_and_exit/ and/or too bike sheddy ?
---
 src/intel/tools/aubinator.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/src/intel/tools/aubinator.c b/src/intel/tools/aubinator.c
index 9d29b68..e48ab3e 100644
--- a/src/intel/tools/aubinator.c
+++ b/src/intel/tools/aubinator.c
@@ -1011,8 +1011,10 @@ setup_pager(void)
 }
 
 static void
-print_help(const char *progname, FILE *file)
+print_help(const char *progname, bool critical)
 {
+   FILE *file = critical ? stderr : stdout;
+
    fprintf(file,
            "Usage: %s [OPTION]... FILE\n"
            "Decode aub file contents.\n\n"
@@ -1025,6 +1027,7 @@ print_help(const char *progname, FILE *file)
            "      --no-pager      don't launch pager\n"
            "      --no-offsets    don't print instruction offsets\n",
            progname);
+   exit(critical ? EXIT_FAILURE : EXIT_SUCCESS);
 }
 
 static bool
@@ -1054,10 +1057,8 @@ int main(int argc, char *argv[])
    const char *value;
    char gen_file[256], gen_val[24];
 
-   if (argc == 1) {
-      print_help(argv[0], stderr);
-      exit(EXIT_FAILURE);
-   }
+   if (argc == 1)
+      print_help(argv[0], true);
 
    for (i = 1; i < argc; ++i) {
       if (strcmp(argv[i], "--no-pager") == 0) {
@@ -1087,8 +1088,7 @@ int main(int argc, char *argv[])
             exit(EXIT_FAILURE);
          }
       } else if (strcmp(argv[i], "--help") == 0) {
-         print_help(argv[0], stdout);
-         exit(EXIT_SUCCESS);
+         print_help(argv[0], false);
       } else {
          if (argv[i][0] == '-') {
             fprintf(stderr, "unknown option %s\n", argv[i]);
@@ -1166,12 +1166,10 @@ int main(int argc, char *argv[])
    spec = gen_spec_load(gen_file);
    disasm = gen_disasm_create(pci_id);
 
-   if (argv[i] == NULL) {
-       print_help(argv[0], stderr);
-       exit(EXIT_FAILURE);
-   } else {
+   if (argv[i] == NULL)
+       print_help(argv[0], true);
+   else
        file = aub_file_open(argv[i]);
-   }
 
    while (aub_file_more_stuff(file))
       aub_file_decode_batch(file, spec);
-- 
2.9.3



More information about the mesa-dev mailing list