DPDK  24.03.0
Data Structures | Typedefs | Enumerations | Functions
rte_argparse.h File Reference
#include <stdbool.h>
#include <stdint.h>
#include <rte_bitops.h>
#include <rte_compat.h>

Go to the source code of this file.

Data Structures

struct  rte_argparse_arg
 
struct  rte_argparse
 

Typedefs

typedef int(* rte_arg_parser_t) (uint32_t index, const char *value, void *opaque)
 

Enumerations

enum  rte_argparse_flag {
  RTE_ARGPARSE_ARG_NO_VALUE = RTE_SHIFT_VAL64(1, 0), RTE_ARGPARSE_ARG_REQUIRED_VALUE = RTE_SHIFT_VAL64(2, 0), RTE_ARGPARSE_ARG_OPTIONAL_VALUE = RTE_SHIFT_VAL64(3, 0), RTE_ARGPARSE_ARG_VALUE_INT = RTE_SHIFT_VAL64(1, 2),
  RTE_ARGPARSE_ARG_VALUE_U8 = RTE_SHIFT_VAL64(2, 2), RTE_ARGPARSE_ARG_VALUE_U16 = RTE_SHIFT_VAL64(3, 2), RTE_ARGPARSE_ARG_VALUE_U32 = RTE_SHIFT_VAL64(4, 2), RTE_ARGPARSE_ARG_VALUE_U64 = RTE_SHIFT_VAL64(5, 2),
  RTE_ARGPARSE_ARG_VALUE_MAX = RTE_SHIFT_VAL64(6, 2), RTE_ARGPARSE_ARG_SUPPORT_MULTI = RTE_BIT64(10), RTE_ARGPARSE_ARG_RESERVED_FIELD = RTE_GENMASK64(63, 48)
}
 

Functions

__rte_experimental int rte_argparse_parse (struct rte_argparse *obj, int argc, char **argv)
 
__rte_experimental int rte_argparse_parse_type (const char *str, uint64_t val_type, void *val)
 

Detailed Description

Argument parsing API.

The argument parsing API makes it easy to write user-friendly command-line program. The program defines what arguments it requires, and the API will parse those arguments from [argc, argv].

The API provides the following functions: 1) Support parsing optional argument (which could take with no-value, required-value and optional-value. 2) Support parsing positional argument (which must take with required-value). 3) Support automatic generate usage information. 4) Support issue errors when provided with invalid arguments.

There are two ways to parse arguments: 1) AutoSave: for which known value types, the way can be used. 2) Callback: will invoke user callback to parse.

Definition in file rte_argparse.h.

Typedef Documentation

◆ rte_arg_parser_t

typedef int(* rte_arg_parser_t) (uint32_t index, const char *value, void *opaque)

Callback prototype used by parsing specified arguments.

Parameters
indexThe argument's index, coming from argument's val_set field.
valueThe value corresponding to the argument, it may be NULL (e.g. the argument has no value, or the argument has optional value but doesn't provided value).
opaqueAn opaque pointer coming from the caller.
Returns
0 on success. Otherwise negative value is returned.

Definition at line 147 of file rte_argparse.h.

Enumeration Type Documentation

◆ rte_argparse_flag

Flag definition (in bitmask form) for an argument.

Enumerator
RTE_ARGPARSE_ARG_NO_VALUE 

The argument has no value.

RTE_ARGPARSE_ARG_REQUIRED_VALUE 

The argument must have a value.

RTE_ARGPARSE_ARG_OPTIONAL_VALUE 

The argument has optional value.

RTE_ARGPARSE_ARG_VALUE_INT 

The argument's value is int type.

RTE_ARGPARSE_ARG_VALUE_U8 

The argument's value is uint8 type.

RTE_ARGPARSE_ARG_VALUE_U16 

The argument's value is uint16 type.

RTE_ARGPARSE_ARG_VALUE_U32 

The argument's value is uint32 type.

RTE_ARGPARSE_ARG_VALUE_U64 

The argument's value is uint64 type.

RTE_ARGPARSE_ARG_VALUE_MAX 

Max value type.

RTE_ARGPARSE_ARG_SUPPORT_MULTI 

Bit 10: flag for that argument support occur multiple times. This flag can be set only when the argument is optional. When this flag is set, the callback type must be used for parsing.

RTE_ARGPARSE_ARG_RESERVED_FIELD 

Bits 48-63: reserved for this library implementation usage.

Definition at line 43 of file rte_argparse.h.

Function Documentation

◆ rte_argparse_parse()

__rte_experimental int rte_argparse_parse ( struct rte_argparse obj,
int  argc,
char **  argv 
)
Warning
EXPERIMENTAL: this API may change without prior notice.

Parse parameters.

Parameters
objParser object.
argcParameters count.
argvArray of parameters points.
Returns
0 on success. Otherwise negative value is returned.
Examples:
examples/dma/dmafwd.c.

◆ rte_argparse_parse_type()

__rte_experimental int rte_argparse_parse_type ( const char *  str,
uint64_t  val_type,
void *  val 
)
Warning
EXPERIMENTAL: this API may change without prior notice.

Parse the value from the input string based on the value type.

Parameters
strInput string.
val_typeThe value type,
See also
RTE_ARGPARSE_ARG_VALUE_INT or other type.
Parameters
valSaver for the value.
Returns
0 on success. Otherwise negative value is returned.