HAZE
haze is a drop-in replacement to process water vapor to be used with FORCE
Loading...
Searching...
No Matches
CLI Arguments Parsing and Program Setup

Functions

void printHelp (void)
 Print a help string for haze to stdout.
option_tparseOptions (int argc, char *argv[])
 Parse command line options for haze.
int parseRange (int *arr, size_t capacity, size_t *elements, const char *argString)
 Parse positive integer from string representation to numeric reprentation.
int parseList (int *arr, size_t capacity, size_t *elements, char *argString)
 Parse a comma-separated list of integers to an list of integers.
int parseSingle (int *arr, size_t *elements, const char *argString)
 Convert the string representation of an integer to an integer.
bool validateArray (int *arr, const size_t elements, const int min, const int max)
 Test if all elements in an array are within range and initialized.
int getAuthentication (char **authenticationToken, const char *filePath)
 Get CDS API authentication token from various sources.
int getAuthenticationFromEnvironment (char **authenticationToken)
 Get CDS API authentication token from environment.
int getAuthenticationFromFile (char **authenticationToken, const char *filePath)
 Get CDS API authentication token from a file.
char * extractKey (const char *cdsapirc)
 Parse cdsapirc file and extract the key value.
void forceNoTrailingSlash (const option_t *options)
 Enforce file system path doesn't end with a slash.
void printOptions (const option_t *options)
 Print fields of options struct to stdout.

Detailed Description

Function Documentation

◆ extractKey()

char * extractKey ( const char * cdsapirc)
nodiscard

Parse cdsapirc file and extract the key value.

Note
Assumes no padding for value to extract.
After the function returns, the caller owns the returned object and must free it after use.
Parameters
cdsapircFile path to .cdsapirc.
Returns
char* Reference to key, NULL on error.

◆ forceNoTrailingSlash()

void forceNoTrailingSlash ( const option_t * options)

Enforce file system path doesn't end with a slash.

Parameters
CLI Arguments Parsing and Program SetupReference to parsed options.

◆ getAuthentication()

int getAuthentication ( char ** authenticationToken,
const char * filePath )

Get CDS API authentication token from various sources.

Query both the environment variables of the running process, possibly a specified file path and $HOME/.cdsapirc in that order. Returns after the first successfull token extraction.

Parameters
authenticationTokenPointer to char * where token should be stored
filePathFile storing CDS API credentials, possibly NULL.
Returns
int 0 on success, 1 on failure.

◆ getAuthenticationFromEnvironment()

int getAuthenticationFromEnvironment ( char ** authenticationToken)

Get CDS API authentication token from environment.

Query the environment of the calling process for a variable called ADSAUTH. If found, the corresponding value is used for authentication.

Note
After the function returns successfully, the caller owns *authenticationToken and must free it after use.
Parameters
authenticationTokenIndirect reference to object storing the access token/key.
Returns
int 0 on success, 1 on failure.

◆ getAuthenticationFromFile()

int getAuthenticationFromFile ( char ** authenticationToken,
const char * filePath )

Get CDS API authentication token from a file.

Get the authentication token from a specified file. In case filePath is set to NULL, try to access the file $HOME/.cdsapirc and extract the authentication token from there.

Note
After the function returns successfully, the caller owns *authenticationToken and must free it after use.
Parameters
authenticationTokenIndirect reference to object storing the access token/key.
filePathFile storing CDS API credentials, possibly NULL.
Returns
int 0 on success, 1 on failure.

◆ parseList()

int parseList ( int * arr,
size_t capacity,
size_t * elements,
char * argString )

Parse a comma-separated list of integers to an list of integers.

Note
The argString argument is modified by replacing all occurences of a comma with NULL.
If no comma-separated list was passed, an error is returned.
Parameters
arrArray to store converted values in.
capacityMaximum capacity of array.
elementsReference to number of elements in array.
argStringString representation of comma-separated intger values.
Returns
int 0 on success, 1 on failure.

◆ parseOptions()

option_t * parseOptions ( int argc,
char * argv[] )
nodiscard

Parse command line options for haze.

Parse command line options specified by user, validate numeric inputs, read authentication token and force trailing slash on directory paths.

Remarks
The returned object is owned by the caller and must be freed after use.
Parameters
argcArgument count
argvArgument values
Returns
option_t* Reference to parsed options, NULL on error.

◆ parseRange()

int parseRange ( int * arr,
size_t capacity,
size_t * elements,
const char * argString )

Parse positive integer from string representation to numeric reprentation.

This function is a thin wrapper around strtol. In comparison with `parseSingle, it directly returns a value instead of storing the converted number in an array.

Parameters
stringString representation of integer.
Returns
int Parsed integer, -1 on error. */ int convertPositiveIntegerSafely(const char *string);

/**

Parse a range of integers denoted by min:max to list of intgers with closed interval bounds

Note
If max < min or the range exceeds the list's capacity, an error is returned.
Parameters
arrArray to store converted values in.
capacityMaximum capacity of array.
elementsReference to number of elements in array.
argStringString representation of integer range.
Returns
int 0 on success, 1 on failure.

◆ parseSingle()

int parseSingle ( int * arr,
size_t * elements,
const char * argString )

Convert the string representation of an integer to an integer.

Parameters
arrArray to store converted value in.
elementsReference to number of elements in array.
argStringString representation of integer.
Returns
int 0 on success, 1 on failure.

◆ printHelp()

void printHelp ( void )

Print a help string for haze to stdout.

◆ printOptions()

void printOptions ( const option_t * options)

Print fields of options struct to stdout.

Parameters
CLI Arguments Parsing and Program SetupObject whose fields to print.

◆ validateArray()

bool validateArray ( int * arr,
const size_t elements,
const int min,
const int max )

Test if all elements in an array are within range and initialized.

Test if all elements in arr are in the closed interval [min, max].

Parameters
arrArray to check.
elementsNumber of elements in array.
minMinimum value, all stored values must be greater or equal than this value.
maxMaximum value, all stored values must be smaller or equal than this value.
Returns
true Return true, iff all values in arr are in [min, max], all values are unique and arr has at least one element.
false Return false, otherwise.