Command line parsing API
Collaboration diagram for Command line parsing API:

Data Structures

struct  RDM_CMDLINE_OPT
 Generic usage function option record. More...
 
struct  RDM_CMDLINE
 The buffer used by the command line parser to hold state information. More...
 

Functions

RDM_RETCODE rdm_cmdlineInit (RDM_CMDLINE *cmd, int32_t argc, const char *const argv[], const char *description, const RDM_CMDLINE_OPT *opts)
 Initialize an RDM_CMDLINE buffer and validate the command line. More...
 
const char * rdm_cmdlineNextLongOption (RDM_CMDLINE *cmd, const char **arg)
 Get next option or argument. More...
 
char rdm_cmdlineNextShortOption (RDM_CMDLINE *cmd, const char **arg)
 Get next option or argument. More...
 

Detailed Description

The RDM command line API. The functions here are located in RDM Base Functionality. Linker option:

    -lrdmbase

Function Documentation

◆ rdm_cmdlineInit()

RDM_RETCODE rdm_cmdlineInit ( RDM_CMDLINE cmd,
int32_t  argc,
const char *const  argv[],
const char *  description,
const RDM_CMDLINE_OPT opts 
)

#include <rdmcmdlineapi.h>

Initialize an RDM_CMDLINE buffer and validate the command line.

This function initializeds an RDM_CMDLINE buffer and parses the command line given. This function must be called before any of the other rdm_cmd* functions are called.

If sOKAY is returned call rdm_cmdlineNextShortOption() or rdm_cmdlineNextLongOption() to get all the option and arguments.

If any error or status other that sOKAY are returned no handle is allocated and you are done parsing the command line and should not continue with normal execution.

Return values
sOKAYSuccess
sCMD_USAGEUsage information was printed and normal execution should not proceed
sCMD_VERSIONThe version number was printed and normal execution should not proceed
eBASE_COMMANDCommand line error and normal execution should not proceed
See also
rdm_cmdlineNextShortOption
rdm_cmdlineNextLongOption
Parameters
[in]cmdA pointer to an RDM_CMDLINE buffer for the command line parser
[in]argcThe number of arguments in argv not counting argv[0]
[in]argvThe command and following options and arguments that are to be parsed
[in]descriptionDescription
[in]optsThe option and argument description for the command line parser
Examples
c-core/02_core/core02Example_main.c, c-core/03_core/core03Example_main.c, c-core/04_core/core04Example_main.c, c-core/05_core/core05Example_main.c, c-core/06_core/core06Example_main.c, c-core/07_core/core07Example_main.c, c-core/08_core/core08Example_main.c, c-core/09_core/core09Example_main.c, c-core/10_core/core10Example_main.c, c-core/11_core/core11Example_main.c, c-core/12_core/core12Example_main.c, c-core/13_core/core13Example_main.c, c-core/20_core/core20Example_main.c, c-core/21_core/core21Example_main.c, c-core/22_core/core22Example_main.c, c-core/23_core/core23Example_main.c, c-core/24_core/core24Example_main.c, c-core/25_core/core25Example_main.c, c-core/28_core/core28Example_main.c, c-core/29_core/core29Example_main.c, and c-core/30_core/core30Example_main.c.

◆ rdm_cmdlineNextLongOption()

const char* rdm_cmdlineNextLongOption ( RDM_CMDLINE cmd,
const char **  arg 
)

#include <rdmcmdlineapi.h>

Get next option or argument.

This function returns the next option or argument as a string as specified in the long option of the matching RDM_CMDLINE_OPT provided to rdm_cmdAllocCmd(). If the long option is specified as NULL the short option is returned instead.

Returns
The matching option
See also
rdm_cmdlineInit
rdm_cmdlineNextShortOption
Parameters
[in]cmdThe RDM_CMDLINE handle for the command line parser initialized by rdm_cmdlineInit()
[out]argA pointer to a string pointer where any argument will be returned. NULL means there were no argument. The returned string should not be freed by the application

◆ rdm_cmdlineNextShortOption()

char rdm_cmdlineNextShortOption ( RDM_CMDLINE cmd,
const char **  arg 
)

#include <rdmcmdlineapi.h>

Get next option or argument.

This function returns the next option or argument as a single character as specified in the short option of the matching RDM_CMDLINE_OPT provided to rdm_cmdAllocCmd().

This function should not be used in the case where some short options are specified with the empty string. Use rdm_cmdlineNextLongOption() instead.

Returns
The next short option character.
See also
rdm_cmdlineInit
rdm_cmdlineNextLongOption
Parameters
[in]cmdThe RDM_CMDLINE handle for the command line parser initialized by rdm_cmdlineInit()
[out]argA pointer to a string pointer where any argument will be returned. NULL means there were no argument. The returned string should not be freed by the application