[RFC 4/4] util/error-report: Use LogOutput in vreport

Richard Henderson posted 4 patches 3 weeks, 5 days ago
[RFC 4/4] util/error-report: Use LogOutput in vreport
Posted by Richard Henderson 3 weeks, 5 days ago
Merge print_loc.  Use the LogOutput callbacks instead of
error_printf and error_vprintf.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 util/error-report.c | 72 +++++++++++++++++++++------------------------
 1 file changed, 34 insertions(+), 38 deletions(-)

diff --git a/util/error-report.c b/util/error-report.c
index 6ef556af5f..db5b2c1608 100644
--- a/util/error-report.c
+++ b/util/error-report.c
@@ -132,36 +132,6 @@ void loc_set_file(const char *fname, int lno)
     }
 }
 
-/*
- * Print current location to current monitor if we have one, else to stderr.
- */
-static void print_loc(void)
-{
-    const char *sep = "";
-    int i;
-    const char *const *argp;
-
-    switch (cur_loc->kind) {
-    case LOC_CMDLINE:
-        argp = cur_loc->ptr;
-        for (i = 0; i < cur_loc->num; i++) {
-            error_printf("%s%s", sep, argp[i]);
-            sep = " ";
-        }
-        error_printf(": ");
-        break;
-    case LOC_FILE:
-        error_printf("%s:", (const char *)cur_loc->ptr);
-        if (cur_loc->num) {
-            error_printf("%d:", cur_loc->num);
-        }
-        error_printf(" ");
-        break;
-    default:
-        error_printf("%s", sep);
-    }
-}
-
 /*
  * Print a message to current monitor if we have one, else to stderr.
  * @report_type is the type of message: error, warning or informational.
@@ -172,28 +142,54 @@ static void print_loc(void)
 G_GNUC_PRINTF(2, 0)
 static void vreport(report_type type, const char *fmt, va_list ap)
 {
-    if (!monitor_cur()) {
-        void *opaque;
-        const LogOutput *l = error_log_output(&opaque);
+    void *opaque;
+    const LogOutput *l = error_log_output(&opaque);
 
+    if (!monitor_cur()) {
         qmessage_context(l, opaque);
     }
 
-    print_loc();
+    switch (cur_loc->kind) {
+    case LOC_CMDLINE:
+        {
+            const char *const *argp = cur_loc->ptr;
+            const char *sep = "";
+
+            for (int i = 0; i < cur_loc->num; i++) {
+                l->print(opaque, "%s%s", sep, argp[i]);
+                sep = " ";
+            }
+            l->print(opaque, ": ");
+        }
+        break;
+    case LOC_FILE:
+        {
+            const char *file = cur_loc->ptr;
+
+            if (cur_loc->num) {
+                error_printf("%s:%d: ", file, cur_loc->num);
+            } else {
+                error_printf("%s: ", file);
+            }
+        }
+        break;
+    case LOC_NONE:
+        break;
+    }
 
     switch (type) {
     case REPORT_TYPE_ERROR:
         break;
     case REPORT_TYPE_WARNING:
-        error_printf("warning: ");
+        l->print(opaque, "warning: ");
         break;
     case REPORT_TYPE_INFO:
-        error_printf("info: ");
+        l->print(opaque, "info: ");
         break;
     }
 
-    error_vprintf(fmt, ap);
-    error_printf("\n");
+    l->vprint(opaque, fmt, ap);
+    l->print(opaque, "\n");
 }
 
 /*
-- 
2.43.0