sink.text.pretty: use bt_common_g_string_append_printf
[babeltrace.git] / src / plugins / text / pretty / print.c
index 9645827e15bd6b7d912e5bcdb98d57cae52db3ae..5803d4fcfb1d86405b30aa118ac4edbc10ca29d0 100644 (file)
@@ -60,10 +60,10 @@ static
 void print_name_equal(struct pretty_component *pretty, const char *name)
 {
        if (pretty->use_colors) {
-               g_string_append_printf(pretty->string, "%s%s%s = ", COLOR_NAME,
+               bt_common_g_string_append_printf(pretty->string, "%s%s%s = ", COLOR_NAME,
                        name, COLOR_RST);
        } else {
-               g_string_append_printf(pretty->string, "%s = ", name);
+               bt_common_g_string_append_printf(pretty->string, "%s = ", name);
        }
 }
 
@@ -71,10 +71,10 @@ static
 void print_field_name_equal(struct pretty_component *pretty, const char *name)
 {
        if (pretty->use_colors) {
-               g_string_append_printf(pretty->string, "%s%s%s = ",
+               bt_common_g_string_append_printf(pretty->string, "%s%s%s = ",
                        COLOR_FIELD_NAME, name, COLOR_RST);
        } else {
-               g_string_append_printf(pretty->string, "%s = ", name);
+               bt_common_g_string_append_printf(pretty->string, "%s = ", name);
        }
 }
 
@@ -85,7 +85,7 @@ void print_timestamp_cycles(struct pretty_component *pretty,
        uint64_t cycles;
 
        cycles = bt_clock_snapshot_get_value(clock_snapshot);
-       g_string_append_printf(pretty->string, "%020" PRIu64, cycles);
+       bt_common_g_string_append_printf(pretty->string, "%020" PRIu64, cycles);
 
        if (update_last) {
                if (pretty->last_cycles_timestamp != -1ULL) {
@@ -202,13 +202,13 @@ void print_timestamp_wall(struct pretty_component *pretty,
                }
 
                /* Print time in HH:MM:SS.ns */
-               g_string_append_printf(pretty->string,
+               bt_common_g_string_append_printf(pretty->string,
                        "%02d:%02d:%02d.%09" PRIu64, tm.tm_hour, tm.tm_min,
                        tm.tm_sec, ts_nsec_abs);
                goto end;
        }
 seconds:
-       g_string_append_printf(pretty->string, "%s%" PRId64 ".%09" PRIu64,
+       bt_common_g_string_append_printf(pretty->string, "%s%" PRId64 ".%09" PRIu64,
                is_negative ? "-" : "", ts_sec_abs, ts_nsec_abs);
 end:
        return;
@@ -262,7 +262,7 @@ int print_event_timestamp(struct pretty_component *pretty,
                                g_string_append(pretty->string,
                                        "+??????????\?\?"); /* Not a trigraph. */
                        } else {
-                               g_string_append_printf(pretty->string,
+                               bt_common_g_string_append_printf(pretty->string,
                                        "+%012" PRIu64, pretty->delta_cycles);
                        }
                } else {
@@ -272,7 +272,7 @@ int print_event_timestamp(struct pretty_component *pretty,
                                delta = pretty->delta_real_timestamp;
                                delta_sec = delta / NSEC_PER_SEC;
                                delta_nsec = delta % NSEC_PER_SEC;
-                               g_string_append_printf(pretty->string,
+                               bt_common_g_string_append_printf(pretty->string,
                                        "+%" PRIu64 ".%09" PRIu64,
                                        delta_sec, delta_nsec);
                        } else {
@@ -296,7 +296,6 @@ int print_event_header(struct pretty_component *pretty,
        bool print_names = pretty->options.print_header_field_names;
        int ret = 0;
        const bt_event_class *event_class = NULL;
-       const bt_packet *packet = NULL;
        const bt_stream *stream = NULL;
        const bt_trace *trace = NULL;
        const bt_event *event = bt_message_event_borrow_event_const(event_msg);
@@ -305,8 +304,7 @@ int print_event_header(struct pretty_component *pretty,
        bt_property_availability prop_avail;
 
        event_class = bt_event_borrow_class_const(event);
-       packet = bt_event_borrow_packet_const(event);
-       stream = bt_packet_borrow_stream_const(packet);
+       stream = bt_event_borrow_stream_const(event);
        trace = bt_stream_borrow_trace_const(stream);
        ret = print_event_timestamp(pretty, event_msg, &pretty->start_line);
        if (ret) {
@@ -408,8 +406,8 @@ int print_event_header(struct pretty_component *pretty,
                        } else if (dom_print) {
                                g_string_append(pretty->string, ":");
                        }
-                       value = bt_value_signed_integer_get(vpid_value);
-                       g_string_append_printf(pretty->string,
+                       value = bt_value_integer_signed_get(vpid_value);
+                       bt_common_g_string_append_printf(pretty->string,
                                "(%" PRId64 ")", value);
                        dom_print = 1;
                }
@@ -451,7 +449,7 @@ int print_event_header(struct pretty_component *pretty,
                        }
 
                        g_string_append(pretty->string, log_level_str);
-                       g_string_append_printf(
+                       bt_common_g_string_append_printf(
                                pretty->string, " (%d)", (int) log_level);
                        dom_print = 1;
                }
@@ -529,9 +527,9 @@ int print_integer(struct pretty_component *pretty,
        ft_type = bt_field_get_class_type(field);
        if (ft_type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER ||
                        ft_type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION) {
-               v.u = bt_field_unsigned_integer_get_value(field);
+               v.u = bt_field_integer_unsigned_get_value(field);
        } else {
-               v.s = bt_field_signed_integer_get_value(field);
+               v.s = bt_field_integer_signed_get_value(field);
        }
 
        if (pretty->use_colors) {
@@ -549,7 +547,7 @@ int print_integer(struct pretty_component *pretty,
                g_string_append(pretty->string, "0b");
                _bt_safe_lshift(v.u, 64 - len);
                for (bitnr = 0; bitnr < len; bitnr++) {
-                       g_string_append_printf(pretty->string, "%u", (v.u & (1ULL << 63)) ? 1 : 0);
+                       bt_common_g_string_append_printf(pretty->string, "%u", (v.u & (1ULL << 63)) ? 1 : 0);
                        _bt_safe_lshift(v.u, 1);
                }
                break;
@@ -572,15 +570,15 @@ int print_integer(struct pretty_component *pretty,
                        }
                }
 
-               g_string_append_printf(pretty->string, "0%" PRIo64, v.u);
+               bt_common_g_string_append_printf(pretty->string, "0%" PRIo64, v.u);
                break;
        }
        case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL:
                if (ft_type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER ||
                                ft_type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION) {
-                       g_string_append_printf(pretty->string, "%" PRIu64, v.u);
+                       bt_common_g_string_append_printf(pretty->string, "%" PRIu64, v.u);
                } else {
-                       g_string_append_printf(pretty->string, "%" PRId64, v.s);
+                       bt_common_g_string_append_printf(pretty->string, "%" PRId64, v.s);
                }
                break;
        case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL:
@@ -595,7 +593,7 @@ int print_integer(struct pretty_component *pretty,
                        v.u &= ((uint64_t) 1 << rounded_len) - 1;
                }
 
-               g_string_append_printf(pretty->string, "0x%" PRIX64, v.u);
+               bt_common_g_string_append_printf(pretty->string, "0x%" PRIX64, v.u);
                break;
        }
        default:
@@ -669,7 +667,7 @@ void print_escape_string(struct pretty_component *pretty, const char *str)
                        break;
                default:
                        /* Unhandled control-sequence, print as hex. */
-                       g_string_append_printf(pretty->string, "\\x%02x", str[i]);
+                       bt_common_g_string_append_printf(pretty->string, "\\x%02x", str[i]);
                        break;
                }
        }
@@ -695,11 +693,11 @@ int print_enum(struct pretty_component *pretty,
 
        switch (bt_field_get_class_type(field)) {
        case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION:
-               ret = bt_field_unsigned_enumeration_get_mapping_labels(field,
+               ret = bt_field_enumeration_unsigned_get_mapping_labels(field,
                        &label_array, &label_count);
                break;
        case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION:
-               ret = bt_field_signed_enumeration_get_mapping_labels(field,
+               ret = bt_field_enumeration_signed_get_mapping_labels(field,
                        &label_array, &label_count);
                break;
        default:
@@ -856,7 +854,7 @@ int print_array_field(struct pretty_component *pretty,
                g_string_append(pretty->string, " ");
        }
        if (print_names) {
-               g_string_append_printf(pretty->string, "[%" PRIu64 "] = ", i);
+               bt_common_g_string_append_printf(pretty->string, "[%" PRIu64 "] = ", i);
        }
 
        field = bt_field_array_borrow_element_field_by_index_const(array, i);
@@ -906,7 +904,7 @@ int print_sequence_field(struct pretty_component *pretty,
                g_string_append(pretty->string, " ");
        }
        if (print_names) {
-               g_string_append_printf(pretty->string, "[%" PRIu64 "] = ", i);
+               bt_common_g_string_append_printf(pretty->string, "[%" PRIu64 "] = ", i);
        }
 
        field = bt_field_array_borrow_element_field_by_index_const(seq, i);
@@ -985,7 +983,7 @@ int print_field(struct pretty_component *pretty,
                if (pretty->use_colors) {
                        g_string_append(pretty->string, COLOR_NUMBER_VALUE);
                }
-               g_string_append_printf(pretty->string, "%g", v);
+               bt_common_g_string_append_printf(pretty->string, "%g", v);
                if (pretty->use_colors) {
                        g_string_append(pretty->string, COLOR_RST);
                }
@@ -1015,7 +1013,9 @@ int print_field(struct pretty_component *pretty,
        case BT_FIELD_CLASS_TYPE_STRUCTURE:
                return print_struct(pretty, field, print_names, filter_fields,
                                filter_array_len);
-       case BT_FIELD_CLASS_TYPE_VARIANT:
+       case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR:
+       case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR:
+       case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR:
                return print_variant(pretty, field, print_names);
        case BT_FIELD_CLASS_TYPE_STATIC_ARRAY:
                return print_array(pretty, field, print_names);
@@ -1038,7 +1038,6 @@ int print_stream_packet_context(struct pretty_component *pretty,
 
        packet = bt_event_borrow_packet_const(event);
        if (!packet) {
-               ret = -1;
                goto end;
        }
        main_field = bt_packet_borrow_context_field_const(packet);
@@ -1250,7 +1249,7 @@ int print_discarded_elements_msg(struct pretty_component *pretty,
                init_msg = "Tracer discarded";
        }
 
-       g_string_append_printf(pretty->string,
+       bt_common_g_string_append_printf(pretty->string,
                "%s%sWARNING%s%s: %s ",
                bt_common_color_fg_yellow(),
                bt_common_color_bold(),
@@ -1258,9 +1257,9 @@ int print_discarded_elements_msg(struct pretty_component *pretty,
                bt_common_color_fg_yellow(), init_msg);
 
        if (count == UINT64_C(-1)) {
-               g_string_append_printf(pretty->string, "%ss", elem_type);
+               bt_common_g_string_append_printf(pretty->string, "%ss", elem_type);
        } else {
-               g_string_append_printf(pretty->string,
+               bt_common_g_string_append_printf(pretty->string,
                        "%" PRIu64 " %s%s", count, elem_type,
                        count == 1 ? "" : "s");
        }
@@ -1277,28 +1276,28 @@ int print_discarded_elements_msg(struct pretty_component *pretty,
                g_string_append(pretty->string, "(unknown time range)");
        }
 
-       g_string_append_printf(pretty->string, " in trace \"%s\" ", trace_name);
+       bt_common_g_string_append_printf(pretty->string, " in trace \"%s\" ", trace_name);
 
        if (trace_uuid) {
-               g_string_append_printf(pretty->string,
+               bt_common_g_string_append_printf(pretty->string,
                        "(UUID: " BT_UUID_FMT ") ",
                        BT_UUID_FMT_VALUES(trace_uuid));
        } else {
                g_string_append(pretty->string, "(no UUID) ");
        }
 
-       g_string_append_printf(pretty->string,
+       bt_common_g_string_append_printf(pretty->string,
                "within stream \"%s\" (stream class ID: %" PRIu64 ", ",
                stream_name, stream_class_id);
 
        if (stream_id >= 0) {
-               g_string_append_printf(pretty->string,
+               bt_common_g_string_append_printf(pretty->string,
                        "stream ID: %" PRIu64, stream_id);
        } else {
                g_string_append(pretty->string, "no stream ID");
        }
 
-       g_string_append_printf(pretty->string, ").%s\n",
+       bt_common_g_string_append_printf(pretty->string, ").%s\n",
                bt_common_color_reset());
 
        /*
This page took 0.027765 seconds and 4 git commands to generate.