GVM User Suite
User tools for the GVM open source project.
|
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
Go to the source code of this file.
Data Structures | |
struct | cag_option |
struct | cag_option_context |
Macros | |
#define | CAG_LIBRARY_H |
#define | CAG_EXPORT |
#define | CAG_IMPORT |
#define | CAG_PUBLIC |
#define | CAG_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) |
Typedefs | |
typedef struct cag_option | cag_option |
typedef struct cag_option_context | cag_option_context |
Functions | |
CAG_PUBLIC void | cag_option_print (const cag_option *options, size_t option_count, FILE *destination) |
Prints all options to the terminal. More... | |
CAG_PUBLIC void | cag_option_prepare (cag_option_context *context, const cag_option *options, size_t option_count, int argc, char **argv) |
Prepare argument options context for parsing. More... | |
CAG_PUBLIC bool | cag_option_fetch (cag_option_context *context) |
Fetches an option from the argument list. More... | |
CAG_PUBLIC char | cag_option_get (const cag_option_context *context) |
Gets the identifier of the option. More... | |
CAG_PUBLIC const char * | cag_option_get_value (const cag_option_context *context) |
Gets the value from the option. More... | |
CAG_PUBLIC int | cag_option_get_index (const cag_option_context *context) |
Gets the current index of the context. More... | |
#define CAG_ARRAY_SIZE | ( | arr | ) | (sizeof(arr) / sizeof((arr)[0])) |
#define CAG_LIBRARY_H |
typedef struct cag_option cag_option |
An option is used to describe a flag/argument option submitted when the program is run.
typedef struct cag_option_context cag_option_context |
A context is used to iterate over all options provided. It stores the parsing state.
CAG_PUBLIC bool cag_option_fetch | ( | cag_option_context * | context | ) |
Fetches an option from the argument list.
This function fetches a single option from the argument list. The context will be moved to that item. Information can be extracted from the context after the item has been fetched. The arguments will be re-ordered, which means that non-option arguments will be moved to the end of the argument list. After all options have been fetched, all non-option arguments will be positioned after the index of the context.
context | The context from which we will fetch the option. |
Definition at line 389 of file cargs.c.
CAG_PUBLIC char cag_option_get | ( | const cag_option_context * | context | ) |
Gets the identifier of the option.
This function gets the identifier of the option, which should be unique to this option and can be used to determine what kind of option this is.
context | The context from which the option was fetched. |
Definition at line 444 of file cargs.c.
CAG_PUBLIC int cag_option_get_index | ( | const cag_option_context * | context | ) |
Gets the current index of the context.
This function gets the index within the argv arguments of the context. The context always points to the next item which it will inspect. This is particularly useful to inspect the original argument array, or to get non-option arguments after option fetching has finished.
context | The context from which the option was fetched. |
CAG_PUBLIC const char* cag_option_get_value | ( | const cag_option_context * | context | ) |
Gets the value from the option.
This function gets the value from the option, if any. If the option does not contain a value, this function will return NULL.
context | The context from which the option was fetched. |
Definition at line 450 of file cargs.c.
CAG_PUBLIC void cag_option_prepare | ( | cag_option_context * | context, |
const cag_option * | options, | ||
size_t | option_count, | ||
int | argc, | ||
char ** | argv | ||
) |
Prepare argument options context for parsing.
This function prepares the context for iteration and initializes the context with the supplied options and arguments. After the context has been prepared, it can be used to fetch arguments from it.
context | The context which will be initialized. |
options | The registered options which are available for the program. |
option_count | The amount of options which are available for the program. |
argc | The amount of arguments the user supplied in the main function. |
argv | A pointer to the arguments of the main function. |
Definition at line 134 of file cargs.c.
CAG_PUBLIC void cag_option_print | ( | const cag_option * | options, |
size_t | option_count, | ||
FILE * | destination | ||
) |
Prints all options to the terminal.
This function prints all options to the terminal. This can be used to generate the output for a "--help" option.
options | The options which will be printed. |
option_count | The option count which will be printed. |
destination | The destination where the output will be printed. |
Definition at line 103 of file cargs.c.