#include "common/dynamic-array.h"
#include "common/mi-lttng.h"
#include "common/string-utils/string-utils.h"
#include "common/dynamic-array.h"
#include "common/mi-lttng.h"
#include "common/string-utils/string-utils.h"
int consumed_args = -1;
struct lttng_kernel_probe_location *kernel_probe_location = NULL;
struct lttng_userspace_probe_location *userspace_probe_location = NULL;
int consumed_args = -1;
struct lttng_kernel_probe_location *kernel_probe_location = NULL;
struct lttng_userspace_probe_location *userspace_probe_location = NULL;
- state = argpar_state_create(*argc, *argv, event_rule_opt_descrs);
- if (!state) {
- ERR("Failed to allocate an argpar state.");
+ argpar_iter = argpar_iter_create(*argc, *argv, event_rule_opt_descrs);
+ if (!argpar_iter) {
+ ERR("Failed to allocate an argpar iter.");
- ARGPAR_ITEM_DESTROY_AND_RESET(item);
- status = argpar_state_parse_next(state, &item, &error);
- if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR) {
- ERR("%s", error);
+ status = parse_next_item(argpar_iter, &argpar_item, *argv,
+ false, NULL);
+ if (status == PARSE_NEXT_ITEM_STATUS_ERROR) {
- } else if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT) {
- /* Just stop parsing here. */
- break;
- } else if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_END) {
+ } else if (status == PARSE_NEXT_ITEM_STATUS_END) {
- if (item->type == ARGPAR_ITEM_TYPE_OPT) {
- const struct argpar_item_opt *item_opt =
- (const struct argpar_item_opt *) item;
+ if (argpar_item_type(argpar_item) == ARGPAR_ITEM_TYPE_OPT) {
+ const struct argpar_opt_descr *descr =
+ argpar_item_opt_descr(argpar_item);
+ const char *arg = argpar_item_opt_arg(argpar_item);
- if (!assign_string(&log_level_str,
- item_opt->arg, "--log-level/-l")) {
+ if (!assign_string(&log_level_str, arg,
+ "--log-level/-l")) {
struct lttng_action *handle_action_notify(int *argc, const char ***argv)
{
struct lttng_action *action = NULL;
struct lttng_action *handle_action_notify(int *argc, const char ***argv)
{
struct lttng_action *action = NULL;
- state = argpar_state_create(*argc, *argv, notify_action_opt_descrs);
- if (!state) {
- ERR("Failed to allocate an argpar state.");
+ argpar_iter = argpar_iter_create(*argc, *argv, notify_action_opt_descrs);
+ if (!argpar_iter) {
+ ERR("Failed to allocate an argpar iter.");
- ARGPAR_ITEM_DESTROY_AND_RESET(item);
- status = argpar_state_parse_next(state, &item, &error);
- if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR) {
- ERR("%s", error);
+ status = parse_next_item(argpar_iter, &argpar_item, *argv,
+ false, "While parsing `notify` action:");
+ if (status == PARSE_NEXT_ITEM_STATUS_ERROR) {
- } else if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT) {
- /* Just stop parsing here. */
- break;
- } else if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_END) {
+ } else if (status == PARSE_NEXT_ITEM_STATUS_END) {
- if (item->type == ARGPAR_ITEM_TYPE_OPT) {
- const struct argpar_item_opt *item_opt =
- (const struct argpar_item_opt *) item;
+ if (argpar_item_type(argpar_item) == ARGPAR_ITEM_TYPE_OPT) {
+ const struct argpar_opt_descr *descr =
+ argpar_item_opt_descr(argpar_item);
+ const char *arg = argpar_item_opt_arg(argpar_item);
- const struct argpar_item_non_opt *item_non_opt;
-
- LTTNG_ASSERT(item->type == ARGPAR_ITEM_TYPE_NON_OPT);
-
- item_non_opt = (const struct argpar_item_non_opt *) item;
+ const char *arg = argpar_item_non_opt_arg(argpar_item);
- *argc -= argpar_state_get_ingested_orig_args(state);
- *argv += argpar_state_get_ingested_orig_args(state);
+ *argc -= argpar_iter_ingested_orig_args(argpar_iter);
+ *argv += argpar_iter_ingested_orig_args(argpar_iter);
- state = argpar_state_create(*argc, *argv, rate_policy_opt_descrs);
- if (!state) {
- ERR("Failed to allocate an argpar state.");
+ argpar_iter = argpar_iter_create(*argc, *argv, rate_policy_opt_descrs);
+ if (!argpar_iter) {
+ ERR("Failed to allocate an argpar iter.");
- ARGPAR_ITEM_DESTROY_AND_RESET(item);
- status = argpar_state_parse_next(state, &item, &error);
- if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR) {
- ERR("%s", error);
+ status = parse_next_item(argpar_iter, &argpar_item, *argv,
+ false, "While parsing `%s` action:", action_name);
+ if (status == PARSE_NEXT_ITEM_STATUS_ERROR) {
- LTTNG_ASSERT(status == ARGPAR_STATE_PARSE_NEXT_STATUS_OK);
- if (item->type == ARGPAR_ITEM_TYPE_OPT) {
- const struct argpar_item_opt *item_opt =
- (const struct argpar_item_opt *) item;
+ LTTNG_ASSERT(status == PARSE_NEXT_ITEM_STATUS_OK);
+
+ if (argpar_item_type(argpar_item) == ARGPAR_ITEM_TYPE_OPT) {
+ const struct argpar_opt_descr *descr =
+ argpar_item_opt_descr(argpar_item);
+ const char *arg = argpar_item_opt_arg(argpar_item);
- const struct argpar_item_non_opt *item_non_opt;
- item_non_opt = (const struct argpar_item_non_opt *) item;
+ const char *arg = argpar_item_non_opt_arg(argpar_item);
+ unsigned int idx = argpar_item_non_opt_non_opt_index(argpar_item);
- *argc -= argpar_state_get_ingested_orig_args(state);
- *argv += argpar_state_get_ingested_orig_args(state);
+ *argc -= argpar_iter_ingested_orig_args(argpar_iter);
+ *argv += argpar_iter_ingested_orig_args(argpar_iter);
const char *session_name_arg = NULL;
char *snapshot_name_arg = NULL;
char *ctrl_url_arg = NULL;
const char *session_name_arg = NULL;
char *snapshot_name_arg = NULL;
char *ctrl_url_arg = NULL;
- state = argpar_state_create(*argc, *argv, snapshot_action_opt_descrs);
- if (!state) {
- ERR("Failed to allocate an argpar state.");
+ argpar_iter = argpar_iter_create(*argc, *argv, snapshot_action_opt_descrs);
+ if (!argpar_iter) {
+ ERR("Failed to allocate an argpar iter.");
- ARGPAR_ITEM_DESTROY_AND_RESET(item);
- status = argpar_state_parse_next(state, &item, &error);
- if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR) {
- ERR("%s", error);
+ status = parse_next_item(argpar_iter, &argpar_item, *argv,
+ false, "While parsing `snapshot` action:");
+ if (status == PARSE_NEXT_ITEM_STATUS_ERROR) {
- } else if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT) {
- /* Just stop parsing here. */
- break;
- } else if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_END) {
+ } else if (status == PARSE_NEXT_ITEM_STATUS_END) {
- if (item->type == ARGPAR_ITEM_TYPE_OPT) {
- const struct argpar_item_opt *item_opt =
- (const struct argpar_item_opt *) item;
+ if (argpar_item_type(argpar_item) == ARGPAR_ITEM_TYPE_OPT) {
+ const struct argpar_opt_descr *descr =
+ argpar_item_opt_descr(argpar_item);
+ const char *arg = argpar_item_opt_arg(argpar_item);
- const struct argpar_item_non_opt *item_non_opt;
-
- LTTNG_ASSERT(item->type == ARGPAR_ITEM_TYPE_NON_OPT);
-
- item_non_opt = (const struct argpar_item_non_opt *) item;
+ const char *arg = argpar_item_non_opt_arg(argpar_item);
+ const unsigned int idx = argpar_item_non_opt_non_opt_index(argpar_item);
- *argc -= argpar_state_get_ingested_orig_args(state);
- *argv += argpar_state_get_ingested_orig_args(state);
+ *argc -= argpar_iter_ingested_orig_args(argpar_iter);
+ *argv += argpar_iter_ingested_orig_args(argpar_iter);
const char **my_argv = argv + 1;
struct lttng_condition *condition = NULL;
struct lttng_dynamic_pointer_array actions;
const char **my_argv = argv + 1;
struct lttng_condition *condition = NULL;
struct lttng_dynamic_pointer_array actions;
struct lttng_action *action_list = NULL;
struct lttng_action *action = NULL;
struct lttng_trigger *trigger = NULL;
struct lttng_action *action_list = NULL;
struct lttng_action *action = NULL;
struct lttng_trigger *trigger = NULL;
- argpar_state_destroy(argpar_state);
- argpar_state = argpar_state_create(my_argc, my_argv,
+ argpar_iter_destroy(argpar_iter);
+ argpar_iter = argpar_iter_create(my_argc, my_argv,
- ARGPAR_ITEM_DESTROY_AND_RESET(argpar_item);
- status = argpar_state_parse_next(argpar_state, &argpar_item, &error);
- if (status == ARGPAR_STATE_PARSE_NEXT_STATUS_ERROR) {
- ERR("%s", error);
+ status = parse_next_item(argpar_iter, &argpar_item, my_argv,
+ true, NULL);
+ if (status == PARSE_NEXT_ITEM_STATUS_ERROR) {
- LTTNG_ASSERT(status == ARGPAR_STATE_PARSE_NEXT_STATUS_OK);
-
- if (argpar_item->type == ARGPAR_ITEM_TYPE_NON_OPT) {
- const struct argpar_item_non_opt *item_non_opt =
- (const struct argpar_item_non_opt *)
- argpar_item;
+ LTTNG_ASSERT(status == PARSE_NEXT_ITEM_STATUS_OK);
- ERR("Unexpected argument `%s`.", item_non_opt->arg);
+ if (argpar_item_type(argpar_item) == ARGPAR_ITEM_TYPE_NON_OPT) {
+ ERR("Unexpected argument `%s`.",
+ argpar_item_non_opt_arg(argpar_item));
argpar_item_destroy(argpar_item);
lttng_dynamic_pointer_array_reset(&actions);
lttng_condition_destroy(condition);
lttng_action_destroy(action_list);
lttng_action_destroy(action);
lttng_trigger_destroy(trigger);
argpar_item_destroy(argpar_item);
lttng_dynamic_pointer_array_reset(&actions);
lttng_condition_destroy(condition);
lttng_action_destroy(action_list);
lttng_action_destroy(action);
lttng_trigger_destroy(trigger);