babeltrace-cfg.c: do not infer text.text sink with -v
[babeltrace.git] / converter / babeltrace-cfg.c
index e005df2c528c28b9b1b84a887bf3d27a06f92464..706fbfd803402699b7bcf873f0059568821ad204 100644 (file)
@@ -187,7 +187,7 @@ bool text_legacy_opts_is_any_set(struct text_legacy_opts *opts)
                bt_value_array_size(opts->names) > 0 ||
                bt_value_array_size(opts->fields) > 0 ||
                opts->no_delta || opts->clock_cycles || opts->clock_seconds ||
-               opts->clock_date || opts->clock_gmt || opts->verbose ||
+               opts->clock_date || opts->clock_gmt ||
                opts->dbg_info_full_path;
 }
 
@@ -642,42 +642,74 @@ static
 void plugin_component_names_from_arg(const char *arg, char **plugin,
                char **component)
 {
-       const char *dot;
-       const char *end;
-       size_t plugin_len;
-       size_t component_len;
+       const char *arg_ch = arg;
+       char *ch;
+       bool in_component = false;
 
-       /* Initialize both return values to NULL: not found */
-       *plugin = NULL;
-       *component = NULL;
-
-       dot = strchr(arg, '.');
-       if (!dot) {
-               /* No dot */
-               goto end;
-       }
-
-       end = arg + strlen(arg);
-       plugin_len = dot - arg;
-       component_len = end - dot - 1;
-       if (plugin_len == 0 || component_len == 0) {
-               goto end;
-       }
-
-       *plugin = g_malloc0(plugin_len + 1);
+       /* Initialize both return values */
+       *plugin = g_malloc0(strlen(arg) + 1);
+       ch = *plugin;
        if (!*plugin) {
                print_err_oom();
-               goto end;
+               goto error;
        }
 
-       g_strlcpy(*plugin, arg, plugin_len + 1);
-       *component = g_malloc0(component_len + 1);
+       *component = g_malloc0(strlen(arg) + 1);
        if (!*component) {
                print_err_oom();
-               goto end;
+               goto error;
+       }
+
+       while (*arg_ch != '\0') {
+               switch (*arg_ch) {
+               case '\\':
+                       if (arg_ch[1] == '\0') {
+                               /* `\` at the end of the string */
+                               *ch = *arg_ch;
+                               ch++;
+                               arg_ch++;
+                       } else if (arg_ch[1] == '\\' || arg_ch[1] == '.') {
+                               /* Escaped `\` or `.` */
+                               *ch = arg_ch[1];
+                               ch++;
+                               arg_ch += 2;
+                       } else {
+                               /* Unknown escaped character (write `\` too) */
+                               ch[0] = arg_ch[0];
+                               ch[1] = arg_ch[1];
+                               ch += 2;
+                               arg_ch += 2;
+
+                       }
+                       continue;
+               case '.':
+                       if (in_component) {
+                               goto error;
+                       }
+
+                       in_component = true;
+                       ch = *component;
+                       arg_ch++;
+                       break;
+               default:
+                       *ch = *arg_ch;
+                       ch++;
+                       arg_ch++;
+                       break;
+               }
+       }
+
+       if (strlen(*plugin) == 0 || strlen(*component) == 0) {
+               goto error;
        }
 
-       g_strlcpy(*component, dot + 1, component_len + 1);
+       goto end;
+
+error:
+       g_free(*plugin);
+       *plugin = NULL;
+       g_free(*component);
+       *component = NULL;
 
 end:
        return;
@@ -2072,6 +2104,7 @@ static void set_offset_value(struct offset_opt *offset_opt, int64_t value)
 
 enum bt_config_component_dest {
        BT_CONFIG_COMPONENT_DEST_SOURCE,
+       BT_CONFIG_COMPONENT_DEST_FILTER,
        BT_CONFIG_COMPONENT_DEST_SINK,
 };
 
@@ -2083,10 +2116,18 @@ static void add_cfg_comp(struct bt_config *cfg,
                struct bt_config_component *cfg_comp,
                enum bt_config_component_dest dest)
 {
-       if (dest == BT_CONFIG_COMPONENT_DEST_SOURCE) {
+       switch (dest) {
+       case BT_CONFIG_COMPONENT_DEST_SOURCE:
                g_ptr_array_add(cfg->cmd_data.convert.sources, cfg_comp);
-       } else {
+               break;
+       case BT_CONFIG_COMPONENT_DEST_FILTER:
+               g_ptr_array_add(cfg->cmd_data.convert.filters, cfg_comp);
+               break;
+       case BT_CONFIG_COMPONENT_DEST_SINK:
                g_ptr_array_add(cfg->cmd_data.convert.sinks, cfg_comp);
+               break;
+       default:
+               assert(false);
        }
 }
 
@@ -3137,6 +3178,9 @@ void print_convert_usage(FILE *fp)
        fprintf(fp, "      --end=END                     Set the `end` parameter of the latest\n");
        fprintf(fp, "                                    source component instance to END\n");
        fprintf(fp, "                                    (see the suggested format of BEGIN below)\n");
+       fprintf(fp, "      --filter=PLUGIN.COMPCLS       Instantiate a filter component from plugin\n");
+       fprintf(fp, "                                    PLUGIN and component class COMPCLS (may be\n");
+       fprintf(fp, "                                    repeated)\n");
        fprintf(fp, "      --name=NAME                   Set the name of the latest component\n");
        fprintf(fp, "                                    instance to NAME (must be unique amongst\n");
        fprintf(fp, "                                    all the names of the component instances)\n");
@@ -3213,6 +3257,7 @@ static struct poptOption convert_long_options[] = {
        { "debug-info-target-prefix", 0, POPT_ARG_STRING, NULL, OPT_DEBUG_INFO_TARGET_PREFIX, NULL, NULL },
        { "end", '\0', POPT_ARG_STRING, NULL, OPT_END, NULL, NULL },
        { "fields", 'f', POPT_ARG_STRING, NULL, OPT_FIELDS, NULL, NULL },
+       { "filter", '\0', POPT_ARG_STRING, NULL, OPT_FILTER, NULL, NULL },
        { "help", 'h', POPT_ARG_NONE, NULL, OPT_HELP, NULL, NULL },
        { "input-format", 'i', POPT_ARG_STRING, NULL, OPT_INPUT_FORMAT, NULL, NULL },
        { "name", '\0', POPT_ARG_STRING, NULL, OPT_NAME, NULL, NULL },
@@ -3456,6 +3501,33 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                        cur_cfg_comp_dest = BT_CONFIG_COMPONENT_DEST_SOURCE;
                        break;
                }
+               case OPT_FILTER:
+               {
+                       if (cur_cfg_comp && !cur_is_implicit_source) {
+                               add_cfg_comp(cfg, cur_cfg_comp,
+                                       cur_cfg_comp_dest);
+                       }
+
+                       cur_cfg_comp = bt_config_component_from_arg(
+                               BT_COMPONENT_CLASS_TYPE_FILTER, arg);
+                       if (!cur_cfg_comp) {
+                               printf_err("Invalid format for --filter option's argument:\n    %s\n",
+                                       arg);
+                               goto error;
+                       }
+                       cur_is_implicit_source = false;
+
+                       assert(cur_base_params);
+                       bt_put(cur_cfg_comp->params);
+                       cur_cfg_comp->params = bt_value_copy(cur_base_params);
+                       if (!cur_cfg_comp->params) {
+                               print_err_oom();
+                               goto error;
+                       }
+
+                       cur_cfg_comp_dest = BT_CONFIG_COMPONENT_DEST_FILTER;
+                       break;
+               }
                case OPT_OUTPUT_FORMAT:
                case OPT_SINK:
                {
This page took 0.026134 seconds and 4 git commands to generate.