From 96308b2965acf2970a74e491ac4f6c6e169df4ec Mon Sep 17 00:00:00 2001 From: Max Wash Date: Tue, 10 Dec 2024 22:26:12 +0000 Subject: [PATCH] cmd: implement b_arglist_get_* functions --- cmd/arglist.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/cmd/arglist.c b/cmd/arglist.c index bf7b598..413519b 100644 --- a/cmd/arglist.c +++ b/cmd/arglist.c @@ -757,6 +757,60 @@ void b_arglist_destroy(struct b_arglist *args) free(args); } +b_status b_arglist_get_string( + const b_arglist *args, unsigned int opt_id, unsigned int arg_id, + unsigned int index, const char **out) +{ + b_arglist_iterator it = {0}; + b_arglist_iterator_begin(args, opt_id, arg_id, &it); + while (b_arglist_iterator_is_valid(&it)) { + if (it.value && it.value->val_str) { + *out = it.value->val_str; + return B_SUCCESS; + } + + b_arglist_iterator_next(&it); + } + + return B_ERR_NO_ENTRY; +} + +b_status b_arglist_get_int( + const b_arglist *args, unsigned int opt_id, unsigned int arg_id, + unsigned int index, long long *out) +{ + b_arglist_iterator it = {0}; + b_arglist_iterator_begin(args, opt_id, arg_id, &it); + while (b_arglist_iterator_is_valid(&it)) { + if (it.value) { + *out = it.value->val_int; + return B_SUCCESS; + } + + b_arglist_iterator_next(&it); + } + + return B_ERR_NO_ENTRY; +} + +b_status b_arglist_get_uint( + const b_arglist *args, unsigned int opt_id, unsigned int arg_id, + unsigned int index, unsigned long long *out) +{ + b_arglist_iterator it = {0}; + b_arglist_iterator_begin(args, opt_id, arg_id, &it); + while (b_arglist_iterator_is_valid(&it)) { + if (it.value && it.value->val_uint) { + *out = it.value->val_uint; + return B_SUCCESS; + } + + b_arglist_iterator_next(&it); + } + + return B_ERR_NO_ENTRY; +} + size_t b_arglist_get_count( const b_arglist *args, unsigned int opt_id, unsigned int arg_id) {