Etk
Main Page Object Hierarchy Data Structures Related Pages
Etk

Argument parser


Detailed Description

A couple of functions to parse the arguments of a program.

You can use those two functions to parse the arguments given to your program.
Two kinds of arguments are supported:

  • Short arguments: "-c", "-c value" or "-cvalue"
  • Long arguments: "--argument", "--agument value" or "--argument=value"

To check whether an argument that takes no value is present, use etk_argument_is_set().
To get the value of an argument, use etk_argument_value_get()


Functions

Etk_Bool etk_argument_is_set (int *argc, char ***argv, const char *long_name, char short_name, Etk_Bool remove)
 Checks whether the argument has been passed to the program.
Etk_Bool etk_argument_value_get (int *argc, char ***argv, const char *long_name, char short_name, Etk_Bool remove, char **value)
 Gets the value of an argument passed to the program.


Function Documentation

Etk_Bool etk_argument_is_set ( int *  argc,
char ***  argv,
const char *  long_name,
char  short_name,
Etk_Bool  remove 
)

Checks whether the argument has been passed to the program.

Parameters:
argc the location of the "argc" parameter passed to main()
argv the location of the "argv" parameter passed to main()
long_name the complete name of the argument to find. If '--long_name' is found in argv, this function will return ETK_TRUE. You can set this param to NULL to ignore it
short_name a shortcut for the argument to find. If '-short_name' is found in argv, this function will return ETK_TRUE. You can set this param to NULL to ignore it
remove if remove is ETK_TRUE, the argument will be removed from argv if it is found
Returns:
Returns ETK_TRUE if the argument has been found, ETK_FALSE otherwise

Etk_Bool etk_argument_value_get ( int *  argc,
char ***  argv,
const char *  long_name,
char  short_name,
Etk_Bool  remove,
char **  value 
)

Gets the value of an argument passed to the program.

Parameters:
argc the location of the "argc" parameter passed to main()
argv the location of the "argv" parameter passed to main()
long_name the complete name of the argument to find. If --long_name is found in argv and is followed by a value, this function will return ETK_TRUE. You can set this param to NULL to ignore it
short_name a shortcut for the argument to find. If -short_name is found in argv and is followed by a value, this function will return ETK_TRUE. You can set this param to NULL to ignore it
remove if remove is ETK_TRUE, the argument and its value will be removed from argv if they are found
value the location where to store the value of the argument. You'll have to free it when you no longer need it. This parameter should not be NULL, otherwise the function will return ETK_FALSE
Returns:
Returns ETK_TRUE if the argument has been found and was followed by a value, ETK_FALSE otherwise