cmd: remove internal usage of legacy iterator interface
This commit is contained in:
53
cmd/option.c
53
cmd/option.c
@@ -26,18 +26,17 @@ void b_command_option_destroy(struct b_command_option *opt)
|
||||
free(opt->opt_description);
|
||||
}
|
||||
|
||||
b_queue_iterator it = {0};
|
||||
struct b_queue_entry *entry = b_queue_first(&opt->opt_args);
|
||||
|
||||
b_queue_iterator_begin(&opt->opt_args, &it);
|
||||
while (b_queue_iterator_is_valid(&it)) {
|
||||
while (entry) {
|
||||
struct b_command_arg *arg
|
||||
= b_unbox(struct b_command_arg, it.entry, arg_entry);
|
||||
if (!arg) {
|
||||
break;
|
||||
}
|
||||
= b_unbox(struct b_command_arg, entry, arg_entry);
|
||||
|
||||
struct b_queue_entry *next = b_queue_next(entry);
|
||||
b_queue_delete(&opt->opt_args, entry);
|
||||
|
||||
b_queue_iterator_erase(&it);
|
||||
b_command_arg_destroy(arg);
|
||||
entry = next;
|
||||
}
|
||||
|
||||
free(opt);
|
||||
@@ -107,15 +106,16 @@ void z__b_get_option_description(struct b_command_option *opt, b_string *out)
|
||||
size_t nr_args = b_queue_length(&opt->opt_args);
|
||||
bool close_bracket = false;
|
||||
|
||||
b_queue_iterator it;
|
||||
b_queue_foreach (&it, &opt->opt_args) {
|
||||
size_t i = 0;
|
||||
struct b_queue_entry *entry = b_queue_first(&opt->opt_args);
|
||||
while (entry) {
|
||||
struct b_command_arg *arg
|
||||
= b_unbox(struct b_command_arg, it.entry, arg_entry);
|
||||
= b_unbox(struct b_command_arg, entry, arg_entry);
|
||||
if (!arg || !arg->arg_allowed_values) {
|
||||
continue;
|
||||
goto skip;
|
||||
}
|
||||
|
||||
if (it.i > 0) {
|
||||
if (i > 0) {
|
||||
b_string_append_cstr(out, "; ");
|
||||
} else {
|
||||
b_string_append_cstr(out, " [[");
|
||||
@@ -138,6 +138,10 @@ void z__b_get_option_description(struct b_command_option *opt, b_string *out)
|
||||
out, " " F_GREEN "%s" F_RESET,
|
||||
arg->arg_allowed_values[i]);
|
||||
}
|
||||
|
||||
skip:
|
||||
i++;
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
|
||||
if (close_bracket) {
|
||||
@@ -175,12 +179,12 @@ void z__b_get_option_usage_string(
|
||||
b_string_append_cstr(out, "}");
|
||||
}
|
||||
|
||||
b_queue_iterator it;
|
||||
b_queue_foreach (&it, &opt->opt_args) {
|
||||
struct b_queue_entry *entry = b_queue_first(&opt->opt_args);
|
||||
while (entry) {
|
||||
struct b_command_arg *arg
|
||||
= b_unbox(struct b_command_arg, it.entry, arg_entry);
|
||||
= b_unbox(struct b_command_arg, entry, arg_entry);
|
||||
if (!arg) {
|
||||
continue;
|
||||
goto skip;
|
||||
}
|
||||
|
||||
bool optional = false, multi = false;
|
||||
@@ -228,23 +232,26 @@ void z__b_get_option_usage_string(
|
||||
if (flags & CMD_STR_COLOUR) {
|
||||
b_string_append_cstr(out, F_RESET);
|
||||
}
|
||||
|
||||
skip:
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
}
|
||||
|
||||
struct b_command_arg *b_command_option_get_arg_with_id(
|
||||
struct b_command_option *opt, unsigned int id)
|
||||
{
|
||||
b_queue_iterator it;
|
||||
b_queue_foreach (&it, &opt->opt_args) {
|
||||
struct b_queue_entry *entry = b_queue_first(&opt->opt_args);
|
||||
|
||||
while (entry) {
|
||||
struct b_command_arg *arg
|
||||
= b_unbox(struct b_command_arg, it.entry, arg_entry);
|
||||
if (!arg) {
|
||||
continue;
|
||||
}
|
||||
= b_unbox(struct b_command_arg, entry, arg_entry);
|
||||
|
||||
if (arg->arg_id == id) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
Reference in New Issue
Block a user