babeltrace-cfg.c: do not infer text.text sink with -v
[babeltrace.git] / converter / babeltrace-cfg.c
index f3625c3bdfc3ac77e135bc33386000aa83663700..706fbfd803402699b7bcf873f0059568821ad204 100644 (file)
@@ -130,6 +130,7 @@ struct text_legacy_opts {
        bool clock_date;
        bool clock_gmt;
        bool dbg_info_full_path;
+       bool verbose;
 };
 
 /* Legacy input format format */
@@ -641,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;
        }
 
-       g_strlcpy(*component, dot + 1, component_len + 1);
+       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;
+       }
+
+       goto end;
+
+error:
+       g_free(*plugin);
+       *plugin = NULL;
+       g_free(*component);
+       *component = NULL;
 
 end:
        return;
@@ -854,12 +887,12 @@ void bt_config_destroy(struct bt_object *obj)
                BT_PUT(cfg->cmd_data.help.plugin_paths);
                BT_PUT(cfg->cmd_data.help.cfg_component);
                break;
-       case BT_CONFIG_COMMAND_QUERY_INFO:
-               BT_PUT(cfg->cmd_data.query_info.plugin_paths);
-               BT_PUT(cfg->cmd_data.query_info.cfg_component);
+       case BT_CONFIG_COMMAND_QUERY:
+               BT_PUT(cfg->cmd_data.query.plugin_paths);
+               BT_PUT(cfg->cmd_data.query.cfg_component);
 
-               if (cfg->cmd_data.query_info.action) {
-                       g_string_free(cfg->cmd_data.query_info.action, TRUE);
+               if (cfg->cmd_data.query.object) {
+                       g_string_free(cfg->cmd_data.query.object, TRUE);
                }
                break;
        default:
@@ -1325,6 +1358,12 @@ struct bt_value *params_from_text_legacy_opts(
                goto error;
        }
 
+       if (bt_value_map_insert_bool(params, "verbose",
+                       text_legacy_opts->verbose)) {
+               print_err_oom();
+               goto error;
+       }
+
        if (insert_flat_names_fields_from_array(params,
                        text_legacy_opts->names, "name")) {
                goto error;
@@ -1755,6 +1794,8 @@ void print_output_legacy_to_sinks(
                        text_legacy_opts->clock_date);
                g_string_append_bool_param(str, "clock-gmt",
                        text_legacy_opts->clock_gmt);
+               g_string_append_bool_param(str, "verbose",
+                       text_legacy_opts->verbose);
                ret = append_prefixed_flag_params(str, text_legacy_opts->names,
                        "name");
                if (ret) {
@@ -2063,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,
 };
 
@@ -2074,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);
        }
 }
 
@@ -2353,32 +2403,32 @@ end:
        return cfg;
 }
 
-static struct bt_config *bt_config_query_info_create(
+static struct bt_config *bt_config_query_create(
                struct bt_value *initial_plugin_paths)
 {
        struct bt_config *cfg;
 
        /* Create config */
-       cfg = bt_config_base_create(BT_CONFIG_COMMAND_QUERY_INFO);
+       cfg = bt_config_base_create(BT_CONFIG_COMMAND_QUERY);
        if (!cfg) {
                print_err_oom();
                goto error;
        }
 
        if (initial_plugin_paths) {
-               cfg->cmd_data.query_info.plugin_paths =
+               cfg->cmd_data.query.plugin_paths =
                        bt_get(initial_plugin_paths);
        } else {
-               cfg->cmd_data.query_info.plugin_paths =
+               cfg->cmd_data.query.plugin_paths =
                        bt_value_array_create();
-               if (!cfg->cmd_data.query_info.plugin_paths) {
+               if (!cfg->cmd_data.query.plugin_paths) {
                        print_err_oom();
                        goto error;
                }
        }
 
-       cfg->cmd_data.query_info.action = g_string_new(NULL);
-       if (!cfg->cmd_data.query_info.action) {
+       cfg->cmd_data.query.object = g_string_new(NULL);
+       if (!cfg->cmd_data.query.object) {
                print_err_oom();
                goto error;
        }
@@ -2660,16 +2710,16 @@ end:
  * Prints the help command usage.
  */
 static
-void print_query_info_usage(FILE *fp)
+void print_query_usage(FILE *fp)
 {
-       fprintf(fp, "Usage: babeltrace [GEN OPTS] query-info [OPTS] ACTION --source=PLUGIN.COMPCLS\n");
-       fprintf(fp, "       babeltrace [GEN OPTS] query-info [OPTS] ACTION --filter=PLUGIN.COMPCLS\n");
-       fprintf(fp, "       babeltrace [GEN OPTS] query-info [OPTS] ACTION --sink=PLUGIN.COMPCLS\n");
+       fprintf(fp, "Usage: babeltrace [GEN OPTS] query [OPTS] OBJECT --source=PLUGIN.COMPCLS\n");
+       fprintf(fp, "       babeltrace [GEN OPTS] query [OPTS] OBJECT --filter=PLUGIN.COMPCLS\n");
+       fprintf(fp, "       babeltrace [GEN OPTS] query [OPTS] OBJECT --sink=PLUGIN.COMPCLS\n");
        fprintf(fp, "\n");
        fprintf(fp, "Options:\n");
        fprintf(fp, "\n");
-       fprintf(fp, "      --filter=PLUGIN.COMPCLS       Query info from the filter component class\n");
-       fprintf(fp, "                                    COMPCLS found in the plugin PLUGIN\n");
+       fprintf(fp, "      --filter=PLUGIN.COMPCLS       Query object from the filter component\n");
+       fprintf(fp, "                                    class COMPCLS found in the plugin PLUGIN\n");
        fprintf(fp, "      --omit-home-plugin-path       Omit home plugins from plugin search path\n");
        fprintf(fp, "                                    (~/.local/lib/babeltrace/plugins)\n");
        fprintf(fp, "      --omit-system-plugin-path     Omit system plugins from plugin search path\n");
@@ -2677,16 +2727,16 @@ void print_query_info_usage(FILE *fp)
        fprintf(fp, "                                    (see the expected format of PARAMS below)\n");
        fprintf(fp, "      --plugin-path=PATH[:PATH]...  Add PATH to the list of paths from which\n");
        fprintf(fp, "                                    dynamic plugins can be loaded\n");
-       fprintf(fp, "      --sink=PLUGIN.COMPCLS         Query info from the sink component class\n");
-       fprintf(fp, "                                    COMPCLS found in the plugin PLUGIN\n");
-       fprintf(fp, "      --source=PLUGIN.COMPCLS       Query info from the source component class\n");
+       fprintf(fp, "      --sink=PLUGIN.COMPCLS         Query object from the sink component class\n");
        fprintf(fp, "                                    COMPCLS found in the plugin PLUGIN\n");
+       fprintf(fp, "      --source=PLUGIN.COMPCLS       Query object from the source component\n");
+       fprintf(fp, "                                    class COMPCLS found in the plugin PLUGIN\n");
        fprintf(fp, "  -h  --help                        Show this help and quit\n");
        fprintf(fp, "\n\n");
        print_expected_params_format(fp);
 }
 
-static struct poptOption query_info_long_options[] = {
+static struct poptOption query_long_options[] = {
        /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
        { "filter", '\0', POPT_ARG_STRING, NULL, OPT_FILTER, NULL, NULL },
        { "help", 'h', POPT_ARG_NONE, NULL, OPT_HELP, NULL, NULL },
@@ -2700,12 +2750,12 @@ static struct poptOption query_info_long_options[] = {
 };
 
 /*
- * Creates a Babeltrace config object from the arguments of a query-info
+ * Creates a Babeltrace config object from the arguments of a query
  * command.
  *
  * *retcode is set to the appropriate exit code to use.
  */
-struct bt_config *bt_config_query_info_from_args(int argc, const char *argv[],
+struct bt_config *bt_config_query_from_args(int argc, const char *argv[],
                int *retcode, bool omit_system_plugin_path,
                bool omit_home_plugin_path,
                struct bt_value *initial_plugin_paths)
@@ -2719,16 +2769,16 @@ struct bt_config *bt_config_query_info_from_args(int argc, const char *argv[],
        struct bt_value *params = bt_value_null;
 
        *retcode = 0;
-       cfg = bt_config_query_info_create(initial_plugin_paths);
+       cfg = bt_config_query_create(initial_plugin_paths);
        if (!cfg) {
                print_err_oom();
                goto error;
        }
 
-       cfg->cmd_data.query_info.omit_system_plugin_path =
+       cfg->cmd_data.query.omit_system_plugin_path =
                omit_system_plugin_path;
-       cfg->cmd_data.query_info.omit_home_plugin_path = omit_home_plugin_path;
-       ret = append_env_var_plugin_paths(cfg->cmd_data.query_info.plugin_paths);
+       cfg->cmd_data.query.omit_home_plugin_path = omit_home_plugin_path;
+       ret = append_env_var_plugin_paths(cfg->cmd_data.query.plugin_paths);
        if (ret) {
                printf_err("Cannot append plugin paths from BABELTRACE_PLUGIN_PATH\n");
                goto error;
@@ -2736,7 +2786,7 @@ struct bt_config *bt_config_query_info_from_args(int argc, const char *argv[],
 
        /* Parse options */
        pc = poptGetContext(NULL, argc, (const char **) argv,
-               query_info_long_options, 0);
+               query_long_options, 0);
        if (!pc) {
                printf_err("Cannot get popt context\n");
                goto error;
@@ -2753,7 +2803,7 @@ struct bt_config *bt_config_query_info_from_args(int argc, const char *argv[],
                                printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
                        } else {
                                if (bt_config_append_plugin_paths(
-                                               cfg->cmd_data.query_info.plugin_paths,
+                                               cfg->cmd_data.query.plugin_paths,
                                                arg)) {
                                        printf_err("Invalid --plugin-path option's argument:\n    %s\n",
                                                arg);
@@ -2762,10 +2812,10 @@ struct bt_config *bt_config_query_info_from_args(int argc, const char *argv[],
                        }
                        break;
                case OPT_OMIT_SYSTEM_PLUGIN_PATH:
-                       cfg->cmd_data.query_info.omit_system_plugin_path = true;
+                       cfg->cmd_data.query.omit_system_plugin_path = true;
                        break;
                case OPT_OMIT_HOME_PLUGIN_PATH:
-                       cfg->cmd_data.query_info.omit_home_plugin_path = true;
+                       cfg->cmd_data.query.omit_home_plugin_path = true;
                        break;
                case OPT_SOURCE:
                case OPT_FILTER:
@@ -2773,7 +2823,7 @@ struct bt_config *bt_config_query_info_from_args(int argc, const char *argv[],
                {
                        enum bt_component_class_type type;
 
-                       if (cfg->cmd_data.query_info.cfg_component) {
+                       if (cfg->cmd_data.query.cfg_component) {
                                printf_err("Cannot specify more than one plugin and component class:\n    %s\n",
                                        arg);
                                goto error;
@@ -2793,17 +2843,17 @@ struct bt_config *bt_config_query_info_from_args(int argc, const char *argv[],
                                assert(false);
                        }
 
-                       cfg->cmd_data.query_info.cfg_component =
+                       cfg->cmd_data.query.cfg_component =
                                bt_config_component_from_arg(type, arg);
-                       if (!cfg->cmd_data.query_info.cfg_component) {
+                       if (!cfg->cmd_data.query.cfg_component) {
                                printf_err("Invalid format for --source/--filter/--sink option's argument:\n    %s\n",
                                        arg);
                                goto error;
                        }
 
                        /* Default parameters: null */
-                       bt_put(cfg->cmd_data.query_info.cfg_component->params);
-                       cfg->cmd_data.query_info.cfg_component->params =
+                       bt_put(cfg->cmd_data.query.cfg_component->params);
+                       cfg->cmd_data.query.cfg_component->params =
                                bt_value_null;
                        break;
                }
@@ -2818,7 +2868,7 @@ struct bt_config *bt_config_query_info_from_args(int argc, const char *argv[],
                        break;
                }
                case OPT_HELP:
-                       print_query_info_usage(stdout);
+                       print_query_usage(stdout);
                        *retcode = -1;
                        BT_PUT(cfg);
                        goto end;
@@ -2832,13 +2882,13 @@ struct bt_config *bt_config_query_info_from_args(int argc, const char *argv[],
                arg = NULL;
        }
 
-       if (!cfg->cmd_data.query_info.cfg_component) {
+       if (!cfg->cmd_data.query.cfg_component) {
                printf_err("No target component class specified with --source/--filter/--sink option\n");
                goto error;
        }
 
        assert(params);
-       BT_MOVE(cfg->cmd_data.query_info.cfg_component->params, params);
+       BT_MOVE(cfg->cmd_data.query.cfg_component->params, params);
 
        /* Check for option parsing error */
        if (opt < -1) {
@@ -2849,18 +2899,18 @@ struct bt_config *bt_config_query_info_from_args(int argc, const char *argv[],
 
        /*
         * We need exactly one leftover argument which is the
-        * mandatory action.
+        * mandatory object.
         */
        leftover = poptGetArg(pc);
        if (leftover) {
                if (strlen(leftover) == 0) {
-                       printf_err("Invalid empty action\n");
+                       printf_err("Invalid empty object\n");
                        goto error;
                }
 
-               g_string_assign(cfg->cmd_data.query_info.action, leftover);
+               g_string_assign(cfg->cmd_data.query.object, leftover);
        } else {
-               print_query_info_usage(stdout);
+               print_query_usage(stdout);
                *retcode = -1;
                BT_PUT(cfg);
                goto end;
@@ -2873,9 +2923,9 @@ struct bt_config *bt_config_query_info_from_args(int argc, const char *argv[],
        }
 
        if (append_home_and_system_plugin_paths(
-                       cfg->cmd_data.query_info.plugin_paths,
-                       cfg->cmd_data.query_info.omit_system_plugin_path,
-                       cfg->cmd_data.query_info.omit_home_plugin_path)) {
+                       cfg->cmd_data.query.plugin_paths,
+                       cfg->cmd_data.query.omit_system_plugin_path,
+                       cfg->cmd_data.query.omit_home_plugin_path)) {
                printf_err("Cannot append home and system plugin paths\n");
                goto error;
        }
@@ -3128,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");
@@ -3204,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 },
@@ -3447,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:
                {
@@ -3754,6 +3835,7 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                        BT_PUT(cfg);
                        goto end;
                case OPT_VERBOSE:
+                       text_legacy_opts.verbose = true;
                        cfg->verbose = true;
                        break;
                case OPT_DEBUG:
@@ -3944,7 +4026,7 @@ void print_gen_usage(FILE *fp)
        fprintf(fp, "    convert       Build a trace conversion graph and run it (default)\n");
        fprintf(fp, "    help          Get help for a plugin or a component class\n");
        fprintf(fp, "    list-plugins  List available plugins and their content\n");
-       fprintf(fp, "    query-info    Query information from a component class\n");
+       fprintf(fp, "    query         Query objects from a component class\n");
        fprintf(fp, "\n");
        fprintf(fp, "Use `babeltrace COMMAND --help` to show the help of COMMAND.\n");
 }
@@ -4003,8 +4085,8 @@ struct bt_config *bt_config_from_args(int argc, const char *argv[],
                                command = BT_CONFIG_COMMAND_LIST_PLUGINS;
                        } else if (strcmp(cur_arg, "help") == 0) {
                                command = BT_CONFIG_COMMAND_HELP;
-                       } else if (strcmp(cur_arg, "query-info") == 0) {
-                               command = BT_CONFIG_COMMAND_QUERY_INFO;
+                       } else if (strcmp(cur_arg, "query") == 0) {
+                               command = BT_CONFIG_COMMAND_QUERY;
                        } else {
                                /*
                                 * Unknown argument, but not a known
@@ -4057,8 +4139,8 @@ struct bt_config *bt_config_from_args(int argc, const char *argv[],
                        command_argv, retcode, omit_system_plugin_path,
                        omit_home_plugin_path, initial_plugin_paths);
                break;
-       case BT_CONFIG_COMMAND_QUERY_INFO:
-               config = bt_config_query_info_from_args(command_argc,
+       case BT_CONFIG_COMMAND_QUERY:
+               config = bt_config_query_from_args(command_argc,
                        command_argv, retcode, omit_system_plugin_path,
                        omit_home_plugin_path, initial_plugin_paths);
                break;
This page took 0.033213 seconds and 4 git commands to generate.