X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fplugins%2Ftext%2Fpretty%2Fprint.c;h=e908d75db9f074f635192136281857cbf950c5bf;hb=1ccca665267b4bae923e6435496ed380bd080db5;hp=c2f202ae5872b2ffa3d29117eb8bd630c1b3900e;hpb=498e7994d60bd0e9f63c3d5c0fd00eec77ba7c34;p=babeltrace.git diff --git a/src/plugins/text/pretty/print.c b/src/plugins/text/pretty/print.c index c2f202ae..e908d75d 100644 --- a/src/plugins/text/pretty/print.c +++ b/src/plugins/text/pretty/print.c @@ -37,15 +37,15 @@ #define NSEC_PER_SEC 1000000000LL -#define COLOR_NAME BT_COMMON_COLOR_BOLD -#define COLOR_FIELD_NAME BT_COMMON_COLOR_FG_CYAN -#define COLOR_RST BT_COMMON_COLOR_RESET -#define COLOR_STRING_VALUE BT_COMMON_COLOR_BOLD -#define COLOR_NUMBER_VALUE BT_COMMON_COLOR_BOLD -#define COLOR_ENUM_MAPPING_NAME BT_COMMON_COLOR_BOLD -#define COLOR_UNKNOWN BT_COMMON_COLOR_BOLD BT_COMMON_COLOR_FG_RED -#define COLOR_EVENT_NAME BT_COMMON_COLOR_BOLD BT_COMMON_COLOR_FG_MAGENTA -#define COLOR_TIMESTAMP BT_COMMON_COLOR_BOLD BT_COMMON_COLOR_FG_YELLOW +static char color_name[32]; +static char color_field_name[32]; +static char color_rst[32]; +static char color_string_value[32]; +static char color_number_value[32]; +static char color_enum_mapping_name[32]; +static char color_unknown[32]; +static char color_event_name[32]; +static char color_timestamp[32]; struct timestamp { int64_t real_timestamp; /* Relative to UNIX epoch. */ @@ -60,9 +60,9 @@ static void print_name_equal(struct pretty_component *pretty, const char *name) { if (pretty->use_colors) { - bt_common_g_string_append(pretty->string, COLOR_NAME); + bt_common_g_string_append(pretty->string, color_name); bt_common_g_string_append(pretty->string, name); - bt_common_g_string_append(pretty->string, COLOR_RST); + bt_common_g_string_append(pretty->string, color_rst); } else { bt_common_g_string_append(pretty->string, name); } @@ -73,9 +73,9 @@ static void print_field_name_equal(struct pretty_component *pretty, const char *name) { if (pretty->use_colors) { - bt_common_g_string_append(pretty->string, COLOR_FIELD_NAME); + bt_common_g_string_append(pretty->string, color_field_name); bt_common_g_string_append(pretty->string, name); - bt_common_g_string_append(pretty->string, COLOR_RST); + bt_common_g_string_append(pretty->string, color_rst); } else { bt_common_g_string_append(pretty->string, name); } @@ -240,7 +240,7 @@ int print_event_timestamp(struct pretty_component *pretty, bt_common_g_string_append(pretty->string, "["); } if (pretty->use_colors) { - bt_common_g_string_append(pretty->string, COLOR_TIMESTAMP); + bt_common_g_string_append(pretty->string, color_timestamp); } if (pretty->options.print_timestamp_cycles) { print_timestamp_cycles(pretty, clock_snapshot, true); @@ -248,7 +248,7 @@ int print_event_timestamp(struct pretty_component *pretty, print_timestamp_wall(pretty, clock_snapshot, true); } if (pretty->use_colors) { - bt_common_g_string_append(pretty->string, COLOR_RST); + bt_common_g_string_append(pretty->string, color_rst); } if (!print_names) @@ -490,10 +490,10 @@ int print_event_header(struct pretty_component *pretty, if (pretty->use_colors) { if (ev_name) { bt_common_g_string_append(pretty->string, - COLOR_EVENT_NAME); + color_event_name); } else { bt_common_g_string_append(pretty->string, - COLOR_UNKNOWN); + color_unknown); } } if (ev_name) { @@ -502,7 +502,7 @@ int print_event_header(struct pretty_component *pretty, bt_common_g_string_append(pretty->string, ""); } if (pretty->use_colors) { - bt_common_g_string_append(pretty->string, COLOR_RST); + bt_common_g_string_append(pretty->string, color_rst); } if (!print_names) { bt_common_g_string_append(pretty->string, ": "); @@ -539,7 +539,7 @@ int print_integer(struct pretty_component *pretty, } if (pretty->use_colors) { - bt_common_g_string_append(pretty->string, COLOR_NUMBER_VALUE); + bt_common_g_string_append(pretty->string, color_number_value); rst_color = true; } @@ -609,7 +609,7 @@ int print_integer(struct pretty_component *pretty, } end: if (rst_color) { - bt_common_g_string_append(pretty->string, COLOR_RST); + bt_common_g_string_append(pretty->string, color_rst); } return ret; } @@ -687,17 +687,10 @@ int print_enum(struct pretty_component *pretty, const bt_field *field) { int ret = 0; - const bt_field_class *enumeration_field_class = NULL; bt_field_class_enumeration_mapping_label_array label_array; uint64_t label_count; uint64_t i; - enumeration_field_class = bt_field_borrow_class_const(field); - if (!enumeration_field_class) { - ret = -1; - goto end; - } - switch (bt_field_get_class_type(field)) { case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: ret = bt_field_enumeration_unsigned_get_mapping_labels(field, @@ -719,11 +712,11 @@ int print_enum(struct pretty_component *pretty, bt_common_g_string_append(pretty->string, "( "); if (label_count == 0) { if (pretty->use_colors) { - bt_common_g_string_append(pretty->string, COLOR_UNKNOWN); + bt_common_g_string_append(pretty->string, color_unknown); } bt_common_g_string_append(pretty->string, ""); if (pretty->use_colors) { - bt_common_g_string_append(pretty->string, COLOR_RST); + bt_common_g_string_append(pretty->string, color_rst); } goto skip_loop; } @@ -734,11 +727,11 @@ int print_enum(struct pretty_component *pretty, bt_common_g_string_append(pretty->string, ", "); } if (pretty->use_colors) { - bt_common_g_string_append(pretty->string, COLOR_ENUM_MAPPING_NAME); + bt_common_g_string_append(pretty->string, color_enum_mapping_name); } print_escape_string(pretty, mapping_name); if (pretty->use_colors) { - bt_common_g_string_append(pretty->string, COLOR_RST); + bt_common_g_string_append(pretty->string, color_rst); } } skip_loop: @@ -797,11 +790,6 @@ int print_struct(struct pretty_component *pretty, uint64_t nr_fields, i, nr_printed_fields; struct_class = bt_field_borrow_class_const(_struct); - if (!struct_class) { - ret = -1; - goto end; - } - nr_fields = bt_field_class_structure_get_member_count(struct_class); bt_common_g_string_append(pretty->string, "{"); @@ -846,15 +834,9 @@ int print_array(struct pretty_component *pretty, const bt_field *array, bool print_names) { int ret = 0; - const bt_field_class *array_class = NULL; uint64_t len; uint64_t i; - array_class = bt_field_borrow_class_const(array); - if (!array_class) { - ret = -1; - goto end; - } len = bt_field_array_get_length(array); bt_common_g_string_append(pretty->string, "["); pretty->depth++; @@ -984,7 +966,7 @@ int print_field(struct pretty_component *pretty, v = bt_field_bool_get_value(field); if (pretty->use_colors) { - bt_common_g_string_append(pretty->string, COLOR_NUMBER_VALUE); + bt_common_g_string_append(pretty->string, color_number_value); } if (v) { text = "true"; @@ -993,7 +975,7 @@ int print_field(struct pretty_component *pretty, } bt_common_g_string_append(pretty->string, text); if (pretty->use_colors) { - bt_common_g_string_append(pretty->string, COLOR_RST); + bt_common_g_string_append(pretty->string, color_rst); } return 0; } else if (class_id == BT_FIELD_CLASS_TYPE_BIT_ARRAY) { @@ -1001,12 +983,12 @@ int print_field(struct pretty_component *pretty, if (pretty->use_colors) { bt_common_g_string_append(pretty->string, - COLOR_NUMBER_VALUE); + color_number_value); } bt_common_g_string_append_printf(pretty->string, "0x%" PRIX64, v); if (pretty->use_colors) { - bt_common_g_string_append(pretty->string, COLOR_RST); + bt_common_g_string_append(pretty->string, color_rst); } return 0; } else if (bt_field_class_type_is(class_id, @@ -1026,11 +1008,11 @@ int print_field(struct pretty_component *pretty, } if (pretty->use_colors) { - bt_common_g_string_append(pretty->string, COLOR_NUMBER_VALUE); + bt_common_g_string_append(pretty->string, color_number_value); } bt_common_g_string_append_printf(pretty->string, "%g", v); if (pretty->use_colors) { - bt_common_g_string_append(pretty->string, COLOR_RST); + bt_common_g_string_append(pretty->string, color_rst); } return 0; } else if (class_id == BT_FIELD_CLASS_TYPE_STRING) { @@ -1042,11 +1024,11 @@ int print_field(struct pretty_component *pretty, } if (pretty->use_colors) { - bt_common_g_string_append(pretty->string, COLOR_STRING_VALUE); + bt_common_g_string_append(pretty->string, color_string_value); } print_escape_string(pretty, str); if (pretty->use_colors) { - bt_common_g_string_append(pretty->string, COLOR_RST); + bt_common_g_string_append(pretty->string, color_rst); } return 0; } else if (class_id == BT_FIELD_CLASS_TYPE_STRUCTURE) { @@ -1418,3 +1400,20 @@ int pretty_print_discarded_items(struct pretty_component *pretty, count, elem_type); return 0; } + +BT_HIDDEN +void pretty_print_init(void) +{ + strcpy(color_name, bt_common_color_bold()); + strcpy(color_field_name, bt_common_color_fg_cyan()); + strcpy(color_rst, bt_common_color_reset()); + strcpy(color_string_value, bt_common_color_bold()); + strcpy(color_number_value, bt_common_color_bold()); + strcpy(color_enum_mapping_name, bt_common_color_bold()); + strcpy(color_unknown, bt_common_color_bold()); + strcat(color_unknown, bt_common_color_fg_bright_red()); + strcpy(color_event_name, bt_common_color_bold()); + strcat(color_event_name, bt_common_color_fg_bright_magenta()); + strcpy(color_timestamp, bt_common_color_bold()); + strcat(color_timestamp, bt_common_color_fg_bright_yellow()); +}