+static char *escape_name_for_shell(const char *input)
+{
+ char *output = g_malloc0(strlen(input) * 5 + 1);
+ const char *in;
+ char *out = output;
+
+ if (!output) {
+ goto end;
+ }
+
+ for (in = input; *in != '\0'; in++) {
+ switch (*in) {
+ case '\\':
+ *out++ = '\\';
+ *out++ = '\\';
+ break;
+ case '\'':
+ *out++ = '\'';
+ *out++ = '"';
+ *out++ = '\'';
+ *out++ = '"';
+ *out++ = '\'';
+ break;
+ case '.':
+ *out++ = '\\';
+ *out++ = '.';
+ break;
+ default:
+ *out++ = *in;
+ break;
+ }
+ }
+
+end:
+ return output;
+}
+
+static
+const char *component_type_str(enum bt_component_class_type type)
+{
+ switch (type) {
+ case BT_COMPONENT_CLASS_TYPE_SOURCE:
+ return "source";
+ case BT_COMPONENT_CLASS_TYPE_SINK:
+ return "sink";
+ case BT_COMPONENT_CLASS_TYPE_FILTER:
+ return "filter";
+ case BT_COMPONENT_CLASS_TYPE_UNKNOWN:
+ default:
+ return "unknown";
+ }
+}
+
+static void print_plugin_comp_cls_opt(FILE *fh, const char *plugin_name,
+ const char *comp_cls_name, enum bt_component_class_type type)
+{
+ char *shell_plugin_name = NULL;
+ char *shell_comp_cls_name = NULL;
+
+ shell_plugin_name = escape_name_for_shell(plugin_name);
+ if (!shell_plugin_name) {
+ goto end;
+ }
+
+ shell_comp_cls_name = escape_name_for_shell(comp_cls_name);
+ if (!shell_comp_cls_name) {
+ goto end;
+ }
+
+ fprintf(fh, "%s%s--%s%s %s'%s%s%s%s.%s%s%s'",
+ bt_common_color_bold(),
+ bt_common_color_fg_cyan(),
+ component_type_str(type),
+ bt_common_color_reset(),
+ bt_common_color_fg_default(),
+ bt_common_color_bold(),
+ bt_common_color_fg_blue(),
+ shell_plugin_name,
+ bt_common_color_fg_default(),
+ bt_common_color_fg_yellow(),
+ shell_comp_cls_name,
+ bt_common_color_reset());
+
+end:
+ g_free(shell_plugin_name);
+ g_free(shell_comp_cls_name);
+}
+