GVM User Suite
User tools for the GVM open source project.
Data Structures | Macros | Typedefs | Functions
cargs.h File Reference
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
Include dependency graph for cargs.h:
This graph shows which files directly or indirectly include this file:

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

Macro Definition Documentation

◆ CAG_ARRAY_SIZE

#define CAG_ARRAY_SIZE (   arr)    (sizeof(arr) / sizeof((arr)[0]))

This is just a small macro which calculates the size of an array.

Definition at line 97 of file cargs.h.

◆ CAG_EXPORT

#define CAG_EXPORT

Definition at line 46 of file cargs.h.

◆ CAG_IMPORT

#define CAG_IMPORT

Definition at line 47 of file cargs.h.

◆ CAG_LIBRARY_H

#define CAG_LIBRARY_H

This is a simple alternative cross-platform implementation of getopt, which is used to parse argument strings submitted to the executable (argc and argv which are received in the main function).

Definition at line 33 of file cargs.h.

◆ CAG_PUBLIC

#define CAG_PUBLIC

Definition at line 57 of file cargs.h.

Typedef Documentation

◆ cag_option

typedef struct cag_option cag_option

An option is used to describe a flag/argument option submitted when the program is run.

◆ cag_option_context

A context is used to iterate over all options provided. It stores the parsing state.

Function Documentation

◆ cag_option_fetch()

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.

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_get()

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.

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()

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.

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_value()

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.

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_prepare()

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.

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()

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.

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: