X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Fargpar-utils%2Fargpar-utils.h;fp=src%2Fcommon%2Fargpar-utils%2Fargpar-utils.h;h=b9ae510c9e138e4e9db9afa099399db99a966151;hb=d50d200af8d01f4b58a14e384cabd46b1afb4817;hp=0000000000000000000000000000000000000000;hpb=411b31544f22b773b4aad6cdb81faa81dc05e641;p=lttng-tools.git diff --git a/src/common/argpar-utils/argpar-utils.h b/src/common/argpar-utils/argpar-utils.h new file mode 100644 index 000000000..b9ae510c9 --- /dev/null +++ b/src/common/argpar-utils/argpar-utils.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2021 Simon Marchi + * + * SPDX-License-Identifier: GPL-2.0-only + * + */ + +#ifndef COMMON_ARGPAR_UTILS_H +#define COMMON_ARGPAR_UTILS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include +#include +#include + +enum parse_next_item_status +{ + PARSE_NEXT_ITEM_STATUS_OK = 0, + PARSE_NEXT_ITEM_STATUS_END = 1, + PARSE_NEXT_ITEM_STATUS_ERROR = -1, +}; + +/* + * Parse the next argpar item using `iter`. + * + * The item in `*item` is always freed and cleared on entry. + * + * If an item is parsed successfully, return the new item in `*item` and return + * PARSE_NEXT_ITEM_STATUS_OK. + * + * If the end of the argument list is reached, return + * PARSE_NEXT_ITEM_STATUS_END. + * + * On error, print a descriptive error message and return + * PARSE_NEXT_ITEM_STATUS_ERROR. If `context_fmt` is non-NULL, it is formatted + * using the following arguments and prepended to the error message. + * + * If `unknown_opt_is_error` is true, an unknown option is considered an error. + * Otherwise, it is considered as the end of the argument list. + */ +ATTR_FORMAT_PRINTF(5, 6) +enum parse_next_item_status parse_next_item(struct argpar_iter *iter, + const struct argpar_item **item, const char **argv, + bool unknown_opt_is_error, const char *context_fmt, ...); + +#ifdef __cplusplus +} +#endif +#endif