argpar: sync with upstream - adjust to iterator API
[lttng-tools.git] / src / common / argpar-utils / argpar-utils.h
CommitLineData
ea76a8bb
SM
1/*
2 * Copyright (C) 2021 Simon Marchi <simon.marchi@efficios.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8#ifndef COMMON_ARGPAR_UTILS_H
9#define COMMON_ARGPAR_UTILS_H
10
11#include <stdarg.h>
12
13#include <common/macros.h>
14#include <common/argpar/argpar.h>
15#include <common/string-utils/format.h>
16
17enum parse_next_item_status
18{
19 PARSE_NEXT_ITEM_STATUS_OK = 0,
20 PARSE_NEXT_ITEM_STATUS_END = 1,
21 PARSE_NEXT_ITEM_STATUS_ERROR = -1,
22};
23
24/*
25 * Parse the next argpar item using `iter`.
26 *
27 * The item in `*item` is always freed and cleared on entry.
28 *
29 * If an item is parsed successfully, return the new item in `*item` and return
30 * PARSE_NEXT_ITEM_STATUS_OK.
31 *
32 * If the end of the argument list is reached, return
33 * PARSE_NEXT_ITEM_STATUS_END.
34 *
35 * On error, print a descriptive error message and return
36 * PARSE_NEXT_ITEM_STATUS_ERROR. If `context_fmt` is non-NULL, it is formatted
37 * using the following arguments and prepended to the error message.
38 *
39 * If `unknown_opt_is_error` is true, an unknown option is considered an error.
40 * Otherwise, it is considered as the end of the argument list.
41 */
42LTTNG_HIDDEN ATTR_FORMAT_PRINTF(5, 6)
43enum parse_next_item_status parse_next_item(struct argpar_iter *iter,
44 const struct argpar_item **item, const char **argv,
45 bool unknown_opt_is_error, const char *context_fmt, ...);
46
47#endif
This page took 0.024204 seconds and 4 git commands to generate.