GVM User Suite
User tools for the GVM open source project.
Macros | Functions
cargs.c File Reference
#include <assert.h>
#include <cargs.h>
#include <memory.h>
#include <stdio.h>
#include <string.h>
Include dependency graph for cargs.c:

Go to the source code of this file.

Macros

#define CAG_OPTION_PRINT_DISTANCE   4
 
#define CAG_OPTION_PRINT_MIN_INDENTION   20
 

Functions

static void cag_option_print_value (const cag_option *option, size_t *accessor_length, FILE *destination)
 
static void cag_option_print_letters (const cag_option *option, bool *first, size_t *accessor_length, FILE *destination)
 
static void cag_option_print_name (const cag_option *option, bool *first, size_t *accessor_length, FILE *destination)
 
static size_t cag_option_get_print_indention (const cag_option *options, size_t option_count)
 
void cag_option_print (const cag_option *options, size_t option_count, FILE *destination)
 Prints all options to the terminal. More...
 
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...
 
static const cag_optioncag_option_find_by_name (cag_option_context *context, char *name, size_t name_size)
 
static const cag_optioncag_option_find_by_letter (cag_option_context *context, char letter)
 
static void cag_option_parse_value (cag_option_context *context, const cag_option *option, char **c)
 
static void cag_option_parse_access_name (cag_option_context *context, char **c)
 
static void cag_option_parse_access_letter (cag_option_context *context, char **c)
 
static void cag_option_shift (cag_option_context *context, int start, int option, int end)
 
static bool cag_option_is_argument_string (const char *c)
 
static int cag_option_find_next (cag_option_context *context)
 
bool cag_option_fetch (cag_option_context *context)
 Fetches an option from the argument list. More...
 
char cag_option_get (const cag_option_context *context)
 Gets the identifier of the option. More...
 
const char * cag_option_get_value (const cag_option_context *context)
 Gets the value from the option. More...
 
int cag_option_get_index (const cag_option_context *context)
 Gets the current index of the context. More...
 

Macro Definition Documentation

◆ CAG_OPTION_PRINT_DISTANCE

#define CAG_OPTION_PRINT_DISTANCE   4

Definition at line 30 of file cargs.c.

◆ CAG_OPTION_PRINT_MIN_INDENTION

#define CAG_OPTION_PRINT_MIN_INDENTION   20

Definition at line 31 of file cargs.c.

Function Documentation

◆ cag_option_fetch()

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.

Parameters
contextThe context from which we will fetch the option.
Returns
Returns true if there was another option or false if the end is reached.

Definition at line 389 of file cargs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cag_option_find_by_letter()

static const cag_option* cag_option_find_by_letter ( cag_option_context context,
char  letter 
)
static

Definition at line 175 of file cargs.c.

Here is the caller graph for this function:

◆ cag_option_find_by_name()

static const cag_option* cag_option_find_by_name ( cag_option_context context,
char *  name,
size_t  name_size 
)
static

Definition at line 147 of file cargs.c.

Here is the caller graph for this function:

◆ cag_option_find_next()

static int cag_option_find_next ( cag_option_context context)
static

Definition at line 356 of file cargs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cag_option_get()

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.

Parameters
contextThe context from which the option was fetched.
Returns
Returns the identifier of the option.

Definition at line 444 of file cargs.c.

Here is the caller graph for this function:

◆ cag_option_get_index()

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.

Parameters
contextThe context from which the option was fetched.
Returns
Returns the current index of the context.

Definition at line 456 of file cargs.c.

◆ cag_option_get_print_indention()

static size_t cag_option_get_print_indention ( const cag_option options,
size_t  option_count 
)
static

Definition at line 71 of file cargs.c.

Here is the caller graph for this function:

◆ cag_option_get_value()

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.

Parameters
contextThe context from which the option was fetched.
Returns
Returns a pointer to the value or NULL if there is no value.

Definition at line 450 of file cargs.c.

Here is the caller graph for this function:

◆ cag_option_is_argument_string()

static bool cag_option_is_argument_string ( const char *  c)
static

Definition at line 351 of file cargs.c.

Here is the caller graph for this function:

◆ cag_option_parse_access_letter()

static void cag_option_parse_access_letter ( cag_option_context context,
char **  c 
)
static

Definition at line 277 of file cargs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cag_option_parse_access_name()

static void cag_option_parse_access_name ( cag_option_context context,
char **  c 
)
static

Definition at line 235 of file cargs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cag_option_parse_value()

static void cag_option_parse_value ( cag_option_context context,
const cag_option option,
char **  c 
)
static

Definition at line 202 of file cargs.c.

Here is the caller graph for this function:

◆ cag_option_prepare()

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.

Parameters
contextThe context which will be initialized.
optionsThe registered options which are available for the program.
option_countThe amount of options which are available for the program.
argcThe amount of arguments the user supplied in the main function.
argvA pointer to the arguments of the main function.

Definition at line 134 of file cargs.c.

Here is the caller graph for this function:

◆ cag_option_print()

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.

Parameters
optionsThe options which will be printed.
option_countThe option count which will be printed.
destinationThe destination where the output will be printed.

Definition at line 103 of file cargs.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cag_option_print_letters()

static void cag_option_print_letters ( const cag_option option,
bool *  first,
size_t *  accessor_length,
FILE *  destination 
)
static

Definition at line 41 of file cargs.c.

Here is the caller graph for this function:

◆ cag_option_print_name()

static void cag_option_print_name ( const cag_option option,
bool *  first,
size_t *  accessor_length,
FILE *  destination 
)
static

Definition at line 59 of file cargs.c.

Here is the caller graph for this function:

◆ cag_option_print_value()

static void cag_option_print_value ( const cag_option option,
size_t *  accessor_length,
FILE *  destination 
)
static

Definition at line 33 of file cargs.c.

Here is the caller graph for this function:

◆ cag_option_shift()

static void cag_option_shift ( cag_option_context context,
int  start,
int  option,
int  end 
)
static

Definition at line 313 of file cargs.c.

Here is the caller graph for this function: