Move to kernel style SPDX license identifiers
[babeltrace.git] / src / string-format / format-plugin-comp-cls-name.c
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright EfficiOS, Inc.
5 */
6
7 #define BT_LOG_OUTPUT_LEVEL log_level
8 #define BT_LOG_TAG "COMMON/FORMAT-PLUGIN-COMP-CLS-NAME"
9 #include <logging/log.h>
10
11 #include "format-plugin-comp-cls-name.h"
12
13 #include <common/common.h>
14
15
16 static
17 const char *component_type_str(bt_component_class_type type)
18 {
19 switch (type) {
20 case BT_COMPONENT_CLASS_TYPE_SOURCE:
21 return "source";
22 case BT_COMPONENT_CLASS_TYPE_SINK:
23 return "sink";
24 case BT_COMPONENT_CLASS_TYPE_FILTER:
25 return "filter";
26 default:
27 return "(unknown)";
28 }
29 }
30
31 gchar *format_plugin_comp_cls_opt(const char *plugin_name,
32 const char *comp_cls_name, bt_component_class_type type,
33 enum bt_common_color_when use_colors)
34 {
35 GString *str;
36 GString *shell_plugin_name = NULL;
37 GString *shell_comp_cls_name = NULL;
38 gchar *ret;
39 struct bt_common_color_codes codes;
40
41 str = g_string_new(NULL);
42 if (!str) {
43 goto end;
44 }
45
46 if (plugin_name) {
47 shell_plugin_name = bt_common_shell_quote(plugin_name, false);
48 if (!shell_plugin_name) {
49 goto end;
50 }
51 }
52
53 shell_comp_cls_name = bt_common_shell_quote(comp_cls_name, false);
54 if (!shell_comp_cls_name) {
55 goto end;
56 }
57
58 bt_common_color_get_codes(&codes, use_colors);
59
60 g_string_append_printf(str, "'%s%s%s%s",
61 codes.bold,
62 codes.fg_bright_cyan,
63 component_type_str(type),
64 codes.fg_default);
65
66 if (shell_plugin_name) {
67 g_string_append_printf(str, ".%s%s%s",
68 codes.fg_blue,
69 shell_plugin_name->str,
70 codes.fg_default);
71 }
72
73 g_string_append_printf(str, ".%s%s%s'",
74 codes.fg_yellow,
75 shell_comp_cls_name->str,
76 codes.reset);
77
78 end:
79 if (shell_plugin_name) {
80 g_string_free(shell_plugin_name, TRUE);
81 }
82
83 if (shell_comp_cls_name) {
84 g_string_free(shell_comp_cls_name, TRUE);
85 }
86
87 if (str) {
88 ret = g_string_free(str, FALSE);
89 } else {
90 ret = NULL;
91 }
92
93 return ret;
94 }
This page took 0.030217 seconds and 4 git commands to generate.