DPDK 25.03.0-rc0
rte_argparse.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2024 HiSilicon Limited
3 */
4
5#ifndef RTE_ARGPARSE_H
6#define RTE_ARGPARSE_H
7
30#include <stdbool.h>
31#include <stdint.h>
32
33#include <rte_bitops.h>
34#include <rte_compat.h>
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
48#define RTE_ARGPARSE_ARG_NO_VALUE RTE_SHIFT_VAL64(1, 0)
50#define RTE_ARGPARSE_ARG_REQUIRED_VALUE RTE_SHIFT_VAL64(2, 0)
52#define RTE_ARGPARSE_ARG_OPTIONAL_VALUE RTE_SHIFT_VAL64(3, 0)
54#define RTE_ARGPARSE_ARG_VALUE_INT RTE_SHIFT_VAL64(1, 2)
56#define RTE_ARGPARSE_ARG_VALUE_U8 RTE_SHIFT_VAL64(2, 2)
58#define RTE_ARGPARSE_ARG_VALUE_U16 RTE_SHIFT_VAL64(3, 2)
60#define RTE_ARGPARSE_ARG_VALUE_U32 RTE_SHIFT_VAL64(4, 2)
62#define RTE_ARGPARSE_ARG_VALUE_U64 RTE_SHIFT_VAL64(5, 2)
64#define RTE_ARGPARSE_ARG_VALUE_MAX RTE_SHIFT_VAL64(6, 2)
70#define RTE_ARGPARSE_ARG_SUPPORT_MULTI RTE_BIT64(10)
72#define RTE_ARGPARSE_ARG_RESERVED_FIELD RTE_GENMASK64(63, 48)
76#define RTE_ARGPARSE_HAS_VAL_BITMASK RTE_GENMASK64(1, 0)
78#define RTE_ARGPARSE_VAL_TYPE_BITMASK RTE_GENMASK64(9, 2)
79
90 const char *name_long;
97 const char *name_short;
98
100 const char *help;
101
120 void *val_set;
121
123 uint64_t flags;
124};
125
140typedef int (*rte_arg_parser_t)(uint32_t index, const char *value, void *opaque);
141
147 const char *prog_name;
149 const char *usage;
151 const char *descriptor;
153 const char *epilog;
159 void *opaque;
161 void *reserved[16];
164};
165
166#define ARGPARSE_ARG_END() { NULL }
167
184__rte_experimental
185int rte_argparse_parse(struct rte_argparse *obj, int argc, char **argv);
186
203__rte_experimental
204int rte_argparse_parse_type(const char *str, uint64_t val_type, void *val);
205
206#ifdef __cplusplus
207}
208#endif
209
210#endif /* RTE_ARGPARSE_H */
__rte_experimental int rte_argparse_parse_type(const char *str, uint64_t val_type, void *val)
__rte_experimental int rte_argparse_parse(struct rte_argparse *obj, int argc, char **argv)
int(* rte_arg_parser_t)(uint32_t index, const char *value, void *opaque)
Definition: rte_argparse.h:140
const char * name_long
Definition: rte_argparse.h:90
const char * help
Definition: rte_argparse.h:100
const char * name_short
Definition: rte_argparse.h:97
const char * epilog
Definition: rte_argparse.h:153
void * reserved[16]
Definition: rte_argparse.h:161
rte_arg_parser_t callback
Definition: rte_argparse.h:157
const char * prog_name
Definition: rte_argparse.h:147
const char * descriptor
Definition: rte_argparse.h:151
struct rte_argparse_arg args[]
Definition: rte_argparse.h:163
const char * usage
Definition: rte_argparse.h:149
bool exit_on_error
Definition: rte_argparse.h:155