[Mesa-dev] [PATCH 2/2] intel/aubinator_error_decode: Avoid exit when using a pager

Jordan Justen jordan.l.justen at intel.com
Thu Apr 6 20:37:55 UTC 2017


I have an error state which includes an ascii85 section that fails to
decode. If we exit early when using a pager, it confuses the terminal.

Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
---
 src/intel/tools/aubinator_error_decode.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/intel/tools/aubinator_error_decode.c b/src/intel/tools/aubinator_error_decode.c
index 21386fef8a9..5ce6932f2ba 100644
--- a/src/intel/tools/aubinator_error_decode.c
+++ b/src/intel/tools/aubinator_error_decode.c
@@ -52,6 +52,7 @@ static bool option_full_decode = true;
 static bool option_print_offsets = true;
 static enum { COLOR_AUTO, COLOR_ALWAYS, COLOR_NEVER } option_color;
 static char *xml_path = NULL;
+static bool pager = false;
 
 static uint32_t
 print_head(unsigned int reg)
@@ -427,8 +428,12 @@ read_data_file(FILE *file)
       if (ascii85_start) {
          count = ascii85_decode(line+1, &data, line[0] == ':');
          if (count == 0) {
-            fprintf(stderr, "ASCII85 decode failed.\n");
-            exit(1);
+            fprintf(pager ? stdout : stderr,
+                    "ascii85 decode failed on line %d\n", line_number);
+            if (pager)
+               continue;
+            else
+               exit(1);
          }
          decode(spec,
                 buffer_name, ring_name,
@@ -608,7 +613,7 @@ main(int argc, char *argv[])
    const char *path;
    struct stat st;
    int c, i, error;
-   bool help = false, pager = true;
+   bool help = false;
    const struct option aubinator_opts[] = {
       { "help",       no_argument,       (int *) &help,                 true },
       { "no-pager",   no_argument,       (int *) &pager,                false },
@@ -619,6 +624,7 @@ main(int argc, char *argv[])
       { NULL,         0,                 NULL,                          0 }
    };
 
+   pager = true;
    i = 0;
    while ((c = getopt_long(argc, argv, "", aubinator_opts, &i)) != -1) {
       switch (c) {
@@ -682,7 +688,9 @@ main(int argc, char *argv[])
    if (option_color == COLOR_AUTO)
       option_color = isatty(1) ? COLOR_ALWAYS : COLOR_NEVER;
 
-   if (isatty(1) && pager)
+   if (!isatty(1))
+      pager = false;
+   if (pager)
       setup_pager();
 
    if (S_ISDIR(st.st_mode)) {
-- 
2.11.0



More information about the mesa-dev mailing list