|
Guardtime Parameter and Task Handling SDK libparamset
|
Go to the source code of this file.
Macros | |
| #define | PARAM_SET_ERROR_BASE 0x30001 |
Typedefs | |
| typedef struct PARAM_SET_st | PARAM_SET |
Functions | |
| const char * | PST_getVersion (void) |
| int | PARAM_SET_new (const char *names, PARAM_SET **set) |
| void | PARAM_SET_free (PARAM_SET *set) |
| int | PARAM_SET_addControl (PARAM_SET *set, const char *names, int(*controlFormat)(const char *), int(*controlContent)(const char *), int(*convert)(const char *, char *, unsigned), int(*extractObject)(void **, const char *, void **)) |
| int | PARAM_SET_setPrintName (PARAM_SET *set, const char *names, const char *constv, const char *(*getPrintName)(PARAM *param, char *buf, unsigned buf_len)) |
| int | PARAM_SET_setPrintNameAlias (PARAM_SET *set, const char *names, const char *constv, const char *(*getPrintName)(PARAM *param, char *buf, unsigned buf_len)) |
| int | PARAM_SET_setHelpText (PARAM_SET *set, const char *names, const char *txt) |
| char * | PARAM_SET_helpToString (const PARAM_SET *set, const char *names, int indent, int header, int rowWidth, char *buf, size_t buf_len) |
| int | PARAM_SET_add (PARAM_SET *set, const char *name, const char *value, const char *source, int priority) |
| int | PARAM_SET_getStr (PARAM_SET *set, const char *name, const char *source, int priority, int at, char **value) |
| int | PARAM_SET_getObj (PARAM_SET *set, const char *name, const char *source, int priority, int at, void **obj) |
| int | PARAM_SET_getObjExtended (PARAM_SET *set, const char *name, const char *source, int priority, int at, void *ctx, void **obj) |
| int | PARAM_SET_getAtr (PARAM_SET *set, const char *name, const char *source, int priority, int at, PARAM_ATR *atr) |
| int | PARAM_SET_getPrintName (PARAM_SET *set, const char *name, const char **print_name) |
| int | PARAM_SET_getPrintNameAlias (PARAM_SET *set, const char *name, const char **print_name) |
| int | PARAM_SET_clearParameter (PARAM_SET *set, const char *names) |
| int | PARAM_SET_clearValue (PARAM_SET *set, const char *names, const char *source, int priority, int at) |
| int | PARAM_SET_getValueCount (PARAM_SET *set, const char *names, const char *source, int priority, int *count) |
| int | PARAM_SET_isSetByName (const PARAM_SET *set, const char *names) |
| int | PARAM_SET_isOneOfSetByName (const PARAM_SET *set, const char *names) |
| int | PARAM_SET_isFormatOK (const PARAM_SET *set) |
| int | PARAM_SET_isConstraintViolation (const PARAM_SET *set) |
| int | PARAM_SET_isTypoFailure (const PARAM_SET *set) |
| int | PARAM_SET_isSyntaxError (const PARAM_SET *set) |
| int | PARAM_SET_isUnknown (const PARAM_SET *set) |
| int | PARAM_SET_readFromFile (PARAM_SET *set, const char *fname, const char *source, int priority) |
| int | PARAM_SET_readFromCMD (PARAM_SET *set, int argc, char **argv, const char *source, int priority) |
| int | PARAM_SET_parseCMD (PARAM_SET *set, int argc, char **argv, const char *source, int priority) |
| int | PARAM_SET_setParseOptions (PARAM_SET *set, const char *names, int options) |
| int | PARAM_SET_IncludeSet (PARAM_SET *target, PARAM_SET *src) |
| char * | PARAM_SET_toString (PARAM_SET *set, char *buf, size_t buf_len) |
| char * | PARAM_SET_typosToString (PARAM_SET *set, const char *prefix, char *buf, size_t buf_len) |
| char * | PARAM_SET_unknownsToString (const PARAM_SET *set, const char *prefix, char *buf, size_t buf_len) |
| char * | PARAM_SET_invalidParametersToString (const PARAM_SET *set, const char *prefix, const char *(*getErrString)(int), char *buf, size_t buf_len) |
| char * | PARAM_SET_constraintErrorToString (const PARAM_SET *set, const char *prefix, char *buf, size_t buf_len) |
| const char * | PARAM_SET_errorToString (int err) |
| char * | PARAM_SET_syntaxErrorsToString (const PARAM_SET *set, const char *prefix, char *buf, size_t buf_len) |
| const char * | extract_next_name (const char *name_string, int(*isValidNameChar)(int), char *buf, short len, int *flags) |
| int | parse_key_value_pair (const char *line, char *key, char *value, size_t buf_len) |
| int | read_line (FILE *file, char *buf, size_t len, size_t *row_pointer, size_t *read_count) |
| int | PARAM_SET_setWildcardExpander (PARAM_SET *set, const char *names, const char *charList, void *ctx, void(*ctx_free)(void *), int(*expand_wildcard)(PARAM_VAL *param_value, void *ctx, int *value_shift)) |
| #define PARAM_SET_ERROR_BASE 0x30001 |
| typedef struct PARAM_SET_st PARAM_SET |
Parameter set object. Holds multiple parameters, performs parsing and access to the parameter values.
| enum PARAM_SET_ERR_enum |
List of error codes returned by the functions.
| Enumerator | |
|---|---|
| PST_OK | Everything is OK! |
| PST_INVALID_ARGUMENT | Function parameters are invalid, check for |
| PST_INVALID_FORMAT | Input content or syntax is wrong (e.g. parsing command line or configuration file). |
| PST_INDEX_OVF | Index out of boundaries. |
| PST_PARAMETER_NOT_FOUND | Parameter with the given name does not exist in the given set. |
| PST_PARAMETER_VALUE_NOT_FOUND | Parameter value with the given constraints does not exist. |
| PST_PARAMETER_EMPTY | The parameter value count is zero. |
| PST_PARAMETER_IS_TYPO | Parameter added to the set is possibly a typo. |
| PST_PARAMETER_IS_UNKNOWN | Parameter added to the set is unknown. |
| PST_PARAMETER_UNIMPLEMENTED_OBJ | Object extractor function is not implemented. |
| PST_PARAMETER_UNIMPLEMENTED_WILDCARD | The function for extracting wildcard is not implemented. |
| PST_OUT_OF_MEMORY | PST out of memory. |
| PST_IO_ERROR | PST IO error (e.g. when reading configuration file). |
| PST_PRIORITY_NEGATIVE | Priority value is negative. |
| PST_PRIORITY_TOO_LARGE | Priority value is too large. |
| PST_PARAMETER_INVALID_FORMAT | The format of the parameter is invalid. |
| PST_TASK_ZERO_CONSISTENT_TASKS | It was not possible to extract a consistent task from the task set. |
| PST_TASK_MULTIPLE_CONSISTENT_TASKS | There are two consistent tasks while only one is expected. |
| PST_TASK_SET_HAS_NO_DEFINITIONS | Task set is empty. |
| PST_TASK_SET_NOT_ANALYZED | Task set is not analyzed with PARAM_SET object. |
| PST_TASK_UNABLE_TO_ANALYZE_PARAM_SET_CHANGED | Task set is reanalyzed with different PARAM_SET object. |
| PST_WILDCARD_ERROR | Wildcard processor error occurred. |
| PST_UNDEFINED_BEHAVIOUR | Undefined behaviour occurred (e.g. a bug, unrecognised memory error). |
| PST_PRSCMD_INVALID_COMBINATION | Unable to set the combination of command-line parser options. |
| PST_PARAM_CONVERT_NOT_PERFORMED | Parameter conversion is not performed, original input must be used. (See PARAM_addControl and PARAM_SET_addControl). |
| PST_ALIAS_NOT_SPECIFIED | Parameter alias is not specified and it is not possible to work with it. |
| PST_UNKNOWN_ERROR | Unknown error. |
| const char* extract_next_name | ( | const char * | name_string, |
| int(*)(int) | isValidNameChar, | ||
| char * | buf, | ||
| short | len, | ||
| int * | flags | ||
| ) |
Separates names from a string. A function isValidNameChar must be defined to separate valid name characters from the separators.
| name_string | A string full of names that are separated from each other. |
| isValidNameChar | Function that defines valid name characters. |
| buf | Buffer for storing extracted name. |
| len | Buffer size. |
| flags | Can be NULL. |
name_string that points to next character after name extracted or NULL if end of string reached or no name can be extracted. | int PARAM_SET_add | ( | PARAM_SET * | set, |
| const char * | name, | ||
| const char * | value, | ||
| const char * | source, | ||
| int | priority | ||
| ) |
Appends value to the set. Invalid value format or content is not handled as error, but the state is saved. Internal format, content or count errors can be detected - see PARAM_SET_isFormatOK. If parameter name dose not exist, function will fail. When parameter is not found it is examined as a typo or unknown (see PARAM_SET_isTypoFailure and PARAM_SET_isUnknown).
| set | PARAM_SET object. |
| name | Parameter name. |
| value | Parameter value as c-string. Can be NULL. |
| source | Source description as c-string. Can be NULL. |
| priority | Priority that can be PST_PRIORITY_VALID_BASE (0) or higher. |
| int PARAM_SET_addControl | ( | PARAM_SET * | set, |
| const char * | names, | ||
| int(*)(const char *) | controlFormat, | ||
| int(*)(const char *) | controlContent, | ||
| int(*)(const char *, char *, unsigned) | convert, | ||
| int(*)(void **, const char *, void **) | extractObject | ||
| ) |
Adds several optional functions to a set of parameters. Each function takes one parameter as C-string value (must not fail if is NULL). All the functions except extractObject are applied when adding the value to the PARAM_SET object. Function extractObject is applied when calling PARAM_SET_getObj or PARAM_SET_getObjExtended.
Function controlFormat is to check the format. Return 0 if format is ok, error code otherwise.
int (*controlFormat)(const char *str)
Function controlContent is to check the content. Return 0 if content is ok, error code otherwise.
int (*controlContent)(const char *str)
Function convert is used to repair/convert the C-string value before any content or format check is performed. Takes two extra parameters for buffer and its size. Return PST_OK if conversion is successful or PST_PARAM_CONVERT_NOT_PERFORMED to skip conversion. Any other error code will break adding the value.
int (*convert)(const char *value, char *buf, unsigned *buf_len)
Function extractObject is used to extract an object from the parameter value. Function extractObject affects PARAM_SET_getObj and PARAM_SET_getObjExtended behavior. If not specified, the default function is used that extracts the C-string value. Parameter extra is void** pointer to array with 2 elements, str is parameter value and obj is pointer to receiving pointer. Calling PARAM_SET_getObj both array elements in extra are pointing to PARAM_SET itself (void **extra = {set, set}), when calling PARAM_SET_getObjExtended, the second value is determined by the function call and extra parameter given (void **extra = {set, extra}). If extracting of the object is successful, PST_OK is returned, error code otherwise.
int (*extractObject)(void **extra, const char *str, void **obj)
| set | PARAM_SET object. |
| names | List of names to add the functions for. |
| controlFormat | Function for format checking. |
| controlContent | Function for content checking. |
| convert | Function for value conversion. |
| extractObject | Function for object extraction. |
controlFormat and controlContent may return any error code but convert function should return PST_OK and PST_PARAM_CONVERT_NOT_PERFORMED as any other error code will break adding the simple value, parsing configuration file or command line. controlFormat and controlContent, see PARAM_SET_isFormatOK and PARAM_SET_invalidParametersToString. | int PARAM_SET_clearParameter | ( | PARAM_SET * | set, |
| const char * | names | ||
| ) |
| int PARAM_SET_clearValue | ( | PARAM_SET * | set, |
| const char * | names, | ||
| const char * | source, | ||
| int | priority, | ||
| int | at | ||
| ) |
Removes a value specified by the constraints from the specified parameter list. Parameter list is defined as 'p1,p2,p3 ...'.
| set | PARAM_SET object. |
| names | Parameter name list. |
| source | Constraint for the source, can be NULL. |
| priority | Priority that can be PST_PRIORITY_VALID_BASE (0) or higher. |
| at | Parameter index in the matching set composed with the constraints. |
| char* PARAM_SET_constraintErrorToString | ( | const PARAM_SET * | set, |
| const char * | prefix, | ||
| char * | buf, | ||
| size_t | buf_len | ||
| ) |
Generates constraint error report. See PARAM_CONSTRAINTS and PARAM_SET_new.
| set | PARAM_SET object. |
| prefix | Prefix for each constraint error string. Can be NULL. |
| buf | Receiving buffer. |
| buf_len | Receiving buffer size. |
buf if successful, NULL otherwise. | const char* PARAM_SET_errorToString | ( | int | err | ) |
Converts PST_* error codes to string.
| err | Error code from PARAM_SET_ERR_enum. |
| int PARAM_SET_getAtr | ( | PARAM_SET * | set, |
| const char * | name, | ||
| const char * | source, | ||
| int | priority, | ||
| int | at, | ||
| PARAM_ATR * | atr | ||
| ) |
Extract attributes with the given constraints.
| set | PARAM_SET object. |
| name | Parameter name. |
| source | Constraint for the source, can be NULL. |
| priority | Priority that can be PST_PRIORITY_VALID_BASE (0) or higher. |
| at | Parameter index in the matching set composed with the constraints. |
| atr | Output parameter filled with attributes. |
| int PARAM_SET_getObj | ( | PARAM_SET * | set, |
| const char * | name, | ||
| const char * | source, | ||
| int | priority, | ||
| int | at, | ||
| void ** | obj | ||
| ) |
Extracts object from the PARAM_SET. If no object extractor (see PARAM_SET_addControl) is set, a string (see PARAM_SET_getStr instead) value is returned. By default the user must not free the returned object. If a custom object extractor function is used, object must be freed if implementation requires it.
Values are filtered by constraints. If multiple names (e.g. name1,name2,name3) are specified, process is started with the first name and at is used to index over all specified values. If some parameters in the name list do not contain any values matching the constraints, the next name is selected without an error (if there exists a next value). If all parameters are empty PST_PARAMETER_EMPTY is returned, if some values are found and the end of the list is reached PST_PARAMETER_VALUE_NOT_FOUND is returned.
| set | PARAM_SET object. |
| name | Parameter name. |
| source | Constraint for the source, can be NULL. |
| priority | Priority that can be PST_PRIORITY_VALID_BASE (0) or higher. |
| at | Parameter index in the matching set composed with the constraints. |
| obj | Pointer to receiving pointer to object returned. |
| int PARAM_SET_getObjExtended | ( | PARAM_SET * | set, |
| const char * | name, | ||
| const char * | source, | ||
| int | priority, | ||
| int | at, | ||
| void * | ctx, | ||
| void ** | obj | ||
| ) |
Same as PARAM_SET_getObj, but the ctx fed to object extractor contains two pointers void **extra = {set, ctx}.
| set | PARAM_SET object. |
| name | Parameter name. |
| source | Constraint for the source, can be NULL. |
| priority | Priority that can be PST_PRIORITY_VALID_BASE (0) or higher. |
| at | Parameter index in the matching set composed with the constraints. |
| ctx | Pointer to extra context. |
| obj | Pointer to receiving pointer to object returned. |
| int PARAM_SET_getPrintName | ( | PARAM_SET * | set, |
| const char * | name, | ||
| const char ** | print_name | ||
| ) |
Extracts parameter's print name that is also displayed in (error) messages and help text.
| set | PARAM_SET object. |
| name | Parameter name. |
| print_name | Pointer to receiving pointer. |
| int PARAM_SET_getPrintNameAlias | ( | PARAM_SET * | set, |
| const char * | name, | ||
| const char ** | print_name | ||
| ) |
Same as PARAM_SET_getPrintName but works with alias.
| set | PARAM_SET object. |
| name | Parameters alias name. |
| print_name | Pointer to receiving pointer. |
| int PARAM_SET_getStr | ( | PARAM_SET * | set, |
| const char * | name, | ||
| const char * | source, | ||
| int | priority, | ||
| int | at, | ||
| char ** | value | ||
| ) |
Extracts strings from the PARAM_SET (see PARAM_SET_add). If object extractor is set, a string value is always extracted. The user MUST NOT free the returned string.
Values are filtered by constraints. If multiple names (e.g. name1,name2,name3) are specified, process is started with the first name and at is used to index over all specified values. If some parameters in the name list do not contain any values matching the constraints, the next name is selected without an error (if there exists a next value). If all parameters are empty PST_PARAMETER_EMPTY is returned, if some values are found and the end of the list is reached PST_PARAMETER_VALUE_NOT_FOUND is returned.
| set | PARAM_SET object. |
| name | Parameter name. |
| source | Constraint for the source, can be NULL. |
| priority | Priority that can be PST_PRIORITY_VALID_BASE (0) or higher. |
| at | Parameter index in the matching set composed with the constraints. |
| value | Pointer to receiving pointer to string returned. |
| int PARAM_SET_getValueCount | ( | PARAM_SET * | set, |
| const char * | names, | ||
| const char * | source, | ||
| int | priority, | ||
| int * | count | ||
| ) |
Counts all the existing parameter values in the list composed by the parameter list and constraints specified. Parameter list is defined as 'p1,p2,p3 ...'.
| set | PARAM_SET object. |
| names | Parameter name list. |
| source | Constraint for the source, can be NULL. |
| priority | Priority that can be PST_PRIORITY_VALID_BASE (0) or higher. |
| count | Pointer to integer for storing the value count. |
| char* PARAM_SET_helpToString | ( | const PARAM_SET * | set, |
| const char * | names, | ||
| int | indent, | ||
| int | header, | ||
| int | rowWidth, | ||
| char * | buf, | ||
| size_t | buf_len | ||
| ) |
Generates help text for parameters. Before any help text can be generated it must be configured for all the parameters with function PARAM_SET_setHelpText. The way the parameter is represented can be modified with PARAM_SET_setPrintName function.
| set | PARAM_SET object. |
| names | List of names to generate help for. |
| indent | Help text indention. |
| header | The size of the header (all the text and space before 'parameter' in ' -a - parameter A.'). |
| rowWidth | The size of the row. |
| buf | Buffer. |
| buf_len | The size of buf. |
buf if successful, NULL otherwise. Extracts all parameters from src known to target and appends all the values to the target PARAM_SET. Values are added via PARAM_SET_add and all check and extract functions that are used are from the target set. After successful operation both sets must be freed separately and operations applied to each set fo not affect the other one.
| char* PARAM_SET_invalidParametersToString | ( | const PARAM_SET * | set, |
| const char * | prefix, | ||
| const char *(*)(int) | getErrString, | ||
| char * | buf, | ||
| size_t | buf_len | ||
| ) |
Generates a string from invalid parameter list (see PARAM_SET_addControl). By default error strings generated contain only error code. To make the messages more human-readable define function getErrString that takes error code as input and returns const string describing the failure.
| set | PARAM_SET object. |
| prefix | Prefix for each failure string. Can be NULL. |
| getErrString | Function pointer to make error codes to string. Can be NULL. |
| buf | Receiving buffer. |
| buf_len | Receiving buffer size. |
buf if successful, NULL otherwise. | int PARAM_SET_isConstraintViolation | ( | const PARAM_SET * | set | ) |
Controls if the the constraints are violated.
| set | PARAM_SET object. |
-1 if an error occurred. | int PARAM_SET_isFormatOK | ( | const PARAM_SET * | set | ) |
Controls if the format and content of the parameters are OK.
| set | PARAM_SET object. |
| int PARAM_SET_isOneOfSetByName | ( | const PARAM_SET * | set, |
| const char * | names | ||
| ) |
Searches for a parameter defined in the list by name and checks if at least one of the parameters have at least on values set. Even if the value format or content is invalid, true is returned. Parameter list is defined as 'p1,p2,p3 ...'.
| set | PARAM_SET object. |
| names | Parameter name list. |
| int PARAM_SET_isSetByName | ( | const PARAM_SET * | set, |
| const char * | names | ||
| ) |
Searches for a parameter defined in the list by name and checks if all the parameters have at least one values set. Even if the value format or content is invalid, true is returned. Parameter list is defined as 'p1,p2,p3 ...'.
| set | PARAM_SET object. |
| names | Parameter name list. |
| int PARAM_SET_isSyntaxError | ( | const PARAM_SET * | set | ) |
Controls if there are some syntax errors after reading configuration file.
| set | PARAM_SET object. |
| int PARAM_SET_isTypoFailure | ( | const PARAM_SET * | set | ) |
Controls if there are some undefined parameters read from command line or file, similar to the defined ones - possible typos. Typos are detected using the difference value calculated as specified below:
The difference value with the unknown token is calculated for every known parameter in the set and the smallest value is saved as smdiff. An unknown token is interpreted as typo if there exists at least one parameter so that:
| set | PARAM_SET object. |
| int PARAM_SET_isUnknown | ( | const PARAM_SET * | set | ) |
Controls if there are some undefined parameters read from command line or file.
| set | PARAM_SET object. |
| int PARAM_SET_new | ( | const char * | names, |
| PARAM_SET ** | set | ||
| ) |
Creates new PARAM_SET object using parameter names. Parameter names are defined using string '{name|alias}*{name|alias}*...' where
name - parameter name,
alias - alias for the name (optional),
* - indicates the possibility of multiple values (optional), for usage instructions, see PARAM_SET_isConstraintViolation and PARAM_SET_constraintErrorToString.
Example: {h|help}{file}*{o}*{n}
| names | Pointer to parameter names. |
| set | Pointer to receiving pointer to PARAM_SET object. |
| int PARAM_SET_parseCMD | ( | PARAM_SET * | set, |
| int | argc, | ||
| char ** | argv, | ||
| const char * | source, | ||
| int | priority | ||
| ) |
Parses command-line parameters. It is similar to PARAM_SET_readFromCMD but extends its functionality. For example it is possible to have a parameter that always interprets the next token as its value, even if it is identical to some command-line parameter. To redirect all tokens after '--' to specified parameter, or process some parameters with configured wildcard expander see PARAM_SET_setParseOptions.
To specify parse option for each command line parameter:
| set | PARAM_SET object. |
| argc | Count of command line strings. |
| argv | Array of command line strings. |
| source | Source description as c-string. Can be NULL. |
| priority | Priority that can be PST_PRIORITY_VALID_BASE (0) or higher. |
| int PARAM_SET_readFromCMD | ( | PARAM_SET * | set, |
| int | argc, | ||
| char ** | argv, | ||
| const char * | source, | ||
| int | priority | ||
| ) |
Reads parameter values from command line into predefined PARAM_SET. Parameters are stored in internal data structures where one parameter can have multiple values. If configured, all values read are checked against checking functions (see PARAM_SET_addControl). See PARAM_SET_isSetByName, PARAM_SET_getStr and PARAM_SET_getObj to get command-line parameter values. If there are some misspelled and/or unknown parameters, it is detected and it is possible to get error reports. See PARAM_SET_isTypoFailure and PARAM_SET_isUnknown to check for errors. See PARAM_SET_unknownsToString and PARAM_SET_typosToString to get error reports.
Command-line format:
| set | PARAM_SET object. |
| argc | Count of command line strings. |
| argv | Array of command line strings. |
| source | Source description as c-string. Can be NULL. |
| priority | Priority that can be PST_PRIORITY_VALID_BASE (0) or higher. |
| int PARAM_SET_readFromFile | ( | PARAM_SET * | set, |
| const char * | fname, | ||
| const char * | source, | ||
| int | priority | ||
| ) |
Reads parameter values from file into predefined PARAM_SET. File must be formatted one parameter (and its possible value) per line. To add a comment '#' must be inserted at the beginning of the line. To learn how the key-value pairs are precisely extracted see parse_key_value_pair and read_line. Format of parameters:
| set | PARAM_SET object. |
| fname | File path. |
| source | Source description as c-string. Can be NULL. |
| priority | Priority that can be PST_PRIORITY_VALID_BASE (0) or higher. |
| int PARAM_SET_setHelpText | ( | PARAM_SET * | set, |
| const char * | names, | ||
| const char * | txt | ||
| ) |
Specify help text for a parameter.
| set | PARAM_SET object. |
| names | List of names to add the help text for. |
| txt | Help text for a parameter. Value is copied. Must NOT be NULL. |
| int PARAM_SET_setParseOptions | ( | PARAM_SET * | set, |
| const char * | names, | ||
| int | options | ||
| ) |
Specifies the parsing options (PARAM_PARSE_OPTIONS) used by PARAM_SET_parseCMD.
| set | PARAM_SET object. |
| names | Parameter name list. |
| options | Parsing options. |
| int PARAM_SET_setPrintName | ( | PARAM_SET * | set, |
| const char * | names, | ||
| const char * | constv, | ||
| const char *(*)(PARAM *param, char *buf, unsigned buf_len) | getPrintName | ||
| ) |
Alters the way the parameter is represented in (error) messages, help text and returned by PARAM_getPrintName.
If constv is not NULL, a user specified constant value is used. If constv is NULL, an abstract function getPrintName must be specified that formats the string. Default print format for long and short parameters are '--long' and '-a'.
const char* (*getPrintName)(PARAM *param, char *buf, unsigned buf_len)
param - this PARAM object. buf - Internal buffer with constant size. May be left unused. buf_len - The size of the internal buffer. | set | PARAM_SET object. |
| names | List of names to add the functions for. |
| constv | Constant string representation of the parameter, may be NULL. |
| getPrintName | Abstract function implementation. Has effect only when constv is NULL. May be NULL. |
| int PARAM_SET_setPrintNameAlias | ( | PARAM_SET * | set, |
| const char * | names, | ||
| const char * | constv, | ||
| const char *(*)(PARAM *param, char *buf, unsigned buf_len) | getPrintName | ||
| ) |
Same as PARAM_SET_setPrintName but works with alias.
| set | PARAM_SET object. |
| names | List of names to add the functions for. |
| constv | Constant string representation of the parameter alias. Can be NULL. |
| getPrintName | Abstract function implementation. Has effect only when constv is NULL. Can be NULL. |
| int PARAM_SET_setWildcardExpander | ( | PARAM_SET * | set, |
| const char * | names, | ||
| const char * | charList, | ||
| void * | ctx, | ||
| void(*)(void *) | ctx_free, | ||
| int(*)(PARAM_VAL *param_value, void *ctx, int *value_shift) | expand_wildcard | ||
| ) |
Specifies a function to expand tokens that contain wildcard character (WC) to array of new values. By default characters '?' and '*' are WC. Values containing WC are removed and replaced with the expanded values. To use default WC set charList as NULL.
int (*expand_wildcard)(PARAM_VAL *param_value, void *ctx, int *value_shift)
param_value - The value of the current parameter that contains WC. ctx - Additional data structure (same object as PARAM_SET_setWildcardExpander input parameter ctx). value_shift - Output parameter for the count of values expanded. | set | PARAM_SET object. |
| names | List of names to add the functionality. |
| charList | List of wildcard characters used. When set to NULL, '*?' is used. |
| ctx | Data structure used by Wildcard expander, can be NULL. |
| ctx_free | Data structure release function, can be NULL. |
| expand_wildcard | Function pointer to Wildcard Expander function. |
| char* PARAM_SET_syntaxErrorsToString | ( | const PARAM_SET * | set, |
| const char * | prefix, | ||
| char * | buf, | ||
| size_t | buf_len | ||
| ) |
Generates syntax error report.
| set | PARAM_SET object. |
| prefix | Prefix for each constraint error string. Can be NULL. |
| buf | Receiving buffer. |
| buf_len | Receiving buffer size. |
buf if successful, NULL otherwise. | char* PARAM_SET_toString | ( | PARAM_SET * | set, |
| char * | buf, | ||
| size_t | buf_len | ||
| ) |
| char* PARAM_SET_typosToString | ( | PARAM_SET * | set, |
| const char * | prefix, | ||
| char * | buf, | ||
| size_t | buf_len | ||
| ) |
Generates typo failure report.
| set | PARAM_SET object. |
| prefix | Prefix to each typo failure string. Can be NULL. |
| buf | Receiving buffer. |
| buf_len | Receiving buffer size. |
buf if successful, NULL otherwise. | char* PARAM_SET_unknownsToString | ( | const PARAM_SET * | set, |
| const char * | prefix, | ||
| char * | buf, | ||
| size_t | buf_len | ||
| ) |
Generates unknown parameter report.
| set | PARAM_SET object. |
| prefix | Prefix to each unknown failure string. Can be NULL. |
| buf | Receiving buffer. |
| buf_len | Receiving buffer size. |
buf if successful, NULL otherwise. | int parse_key_value_pair | ( | const char * | line, |
| char * | key, | ||
| char * | value, | ||
| size_t | buf_len | ||
| ) |
Extracts a key value pair from the line. Value part can be wrapped inside double quote marks (") to include whitespace characters. Use back slash (\) as escape character for itself and for double quotes. Some examples:
| line | Input line. |
| key | Pointer to receiving key. |
| value | Pointer to receiving value. |
| buf_len | Maximum size of both key and value buffer. |
| const char* PST_getVersion | ( | void | ) |
| int read_line | ( | FILE * | file, |
| char * | buf, | ||
| size_t | len, | ||
| size_t * | row_pointer, | ||
| size_t * | read_count | ||
| ) |
Reads a line from a file (opened with fopen in mode r) and tracks the lines. Supported line endings:
| file | A file pointer that is us used for reading from. |
| buf | A buffer to store the line. |
| len | Size of the buffer. |
| row_pointer | Pointer to the row counting value. Initial value pointed to must be 0. If not used can be NULL. |
| read_count | Pointer to character counting value. If not used can be NULL. |
EOF if end of file.
1.8.13