---
name: "rte_argparse.h"
section: "3"
platform: "linux"
package: "dpdk-doc"
version: "24.11.4-0+deb13u1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/rte_argparse.h"
---

# rte\_argparse.h(3)

## NAME

rte\_argparse.h

## SYNOPSIS

`#include <stdbool.h>`\
 `#include <stdint.h>`\
 `#include <rte_bitops.h>`\
 `#include <rte_compat.h>`\

### Data Structures

struct **rte\_argparse\_arg**\
 struct **rte\_argparse**\

### Macros

\#define **RTE\_ARGPARSE\_HAS\_VAL\_BITMASK**   **RTE\_GENMASK64**(1, 0)\
 \#define **RTE\_ARGPARSE\_VAL\_TYPE\_BITMASK**   **RTE\_GENMASK64**(9, 2)\

**Flag definition (in bitmask form) for an argument**\

**Note**

Bits\[0~1\] represent the argument whether has value, bits\[2~9\] represent the value type which used when autosave.

**See also**

struct **rte\_argparse\_arg::flags**

\#define **RTE\_ARGPARSE\_ARG\_NO\_VALUE**   **RTE\_SHIFT\_VAL64**(1, 0)\
 \#define **RTE\_ARGPARSE\_ARG\_REQUIRED\_VALUE**   **RTE\_SHIFT\_VAL64**(2, 0)\
 \#define **RTE\_ARGPARSE\_ARG\_OPTIONAL\_VALUE**   **RTE\_SHIFT\_VAL64**(3, 0)\
 \#define **RTE\_ARGPARSE\_ARG\_VALUE\_INT**   **RTE\_SHIFT\_VAL64**(1, 2)\
 \#define **RTE\_ARGPARSE\_ARG\_VALUE\_U8**   **RTE\_SHIFT\_VAL64**(2, 2)\
 \#define **RTE\_ARGPARSE\_ARG\_VALUE\_U16**   **RTE\_SHIFT\_VAL64**(3, 2)\
 \#define **RTE\_ARGPARSE\_ARG\_VALUE\_U32**   **RTE\_SHIFT\_VAL64**(4, 2)\
 \#define **RTE\_ARGPARSE\_ARG\_VALUE\_U64**   **RTE\_SHIFT\_VAL64**(5, 2)\
 \#define **RTE\_ARGPARSE\_ARG\_VALUE\_MAX**   **RTE\_SHIFT\_VAL64**(6, 2)\
 \#define **RTE\_ARGPARSE\_ARG\_SUPPORT\_MULTI**   **RTE\_BIT64**(10)\
 \#define **RTE\_ARGPARSE\_ARG\_RESERVED\_FIELD**   **RTE\_GENMASK64**(63, 48)\

### Typedefs

**typedef** int(\* **rte\_arg\_parser\_t**) (uint32\_t index, const char \*value, void \*opaque)\

### 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**.

## Macro Definition Documentation

### #define RTE\_ARGPARSE\_ARG\_NO\_VALUE RTE\_SHIFT\_VAL64(1, 0)

The argument has no value.

Definition at line **48** of file **rte\_argparse.h**.

### #define RTE\_ARGPARSE\_ARG\_REQUIRED\_VALUE RTE\_SHIFT\_VAL64(2, 0)

The argument must have a value.

Definition at line **50** of file **rte\_argparse.h**.

### #define RTE\_ARGPARSE\_ARG\_OPTIONAL\_VALUE RTE\_SHIFT\_VAL64(3, 0)

The argument has optional value.

Definition at line **52** of file **rte\_argparse.h**.

### #define RTE\_ARGPARSE\_ARG\_VALUE\_INT RTE\_SHIFT\_VAL64(1, 2)

The argument's value is int type.

Definition at line **54** of file **rte\_argparse.h**.

### #define RTE\_ARGPARSE\_ARG\_VALUE\_U8 RTE\_SHIFT\_VAL64(2, 2)

The argument's value is uint8 type.

Definition at line **56** of file **rte\_argparse.h**.

### #define RTE\_ARGPARSE\_ARG\_VALUE\_U16 RTE\_SHIFT\_VAL64(3, 2)

The argument's value is uint16 type.

Definition at line **58** of file **rte\_argparse.h**.

### #define RTE\_ARGPARSE\_ARG\_VALUE\_U32 RTE\_SHIFT\_VAL64(4, 2)

The argument's value is uint32 type.

Definition at line **60** of file **rte\_argparse.h**.

### #define RTE\_ARGPARSE\_ARG\_VALUE\_U64 RTE\_SHIFT\_VAL64(5, 2)

The argument's value is uint64 type.

Definition at line **62** of file **rte\_argparse.h**.

### #define RTE\_ARGPARSE\_ARG\_VALUE\_MAX RTE\_SHIFT\_VAL64(6, 2)

Max value type.

Definition at line **64** of file **rte\_argparse.h**.

### #define RTE\_ARGPARSE\_ARG\_SUPPORT\_MULTI RTE\_BIT64(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.

Definition at line **70** of file **rte\_argparse.h**.

### #define RTE\_ARGPARSE\_ARG\_RESERVED\_FIELD RTE\_GENMASK64(63, 48)

Reserved for this library implementation usage.

Definition at line **72** of file **rte\_argparse.h**.

### #define RTE\_ARGPARSE\_HAS\_VAL\_BITMASK RTE\_GENMASK64(1, 0)

Bitmask used to get the argument whether has value.

Definition at line **76** of file **rte\_argparse.h**.

### #define RTE\_ARGPARSE\_VAL\_TYPE\_BITMASK RTE\_GENMASK64(9, 2)

Bitmask used to get the argument's value type.

Definition at line **78** of file **rte\_argparse.h**.

## Typedef Documentation

### typedef int(\* rte\_arg\_parser\_t) (uint32\_t index, const char \*value, void \*opaque)

Callback prototype used by parsing specified arguments.

**Parameters**

*index* The argument's index, coming from argument's val\_set field. \
 *value* The 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). \
 *opaque* An opaque pointer coming from the caller.

**Returns**

0 on success. Otherwise negative value is returned.

Definition at line **140** of file **rte\_argparse.h**.

## Function Documentation

### \_\_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**

*obj* Parser object. \
 *argc* Parameters count. \
 *argv* Array of parameters points.

**Returns**

0 on success. Otherwise negative value is returned.

### \_\_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**

*str* Input string. \
 *val\_type* The value type,

**See also**

**RTE\_ARGPARSE\_ARG\_VALUE\_INT** or other type.

**Parameters**

*val* Saver for the value.

**Returns**

0 on success. Otherwise negative value is returned.

## Author

Generated automatically by Doxygen for DPDK from the source code.
