ocssw
V2022
|
#include <stdio.h>
#include <inttypes.h>
Go to the source code of this file.
Classes | |
struct | clo_option_t |
struct | clo_optionList_t |
struct | clo_programMetadata_t |
struct | clo_programMetadataList_t |
Macros | |
#define | CLO_CHUNK_SIZE 32 |
#define | CLO_ARRAY_DELIMITER " \t,:[]()\"" |
Typedefs | |
typedef void(* | clo_optionCallback_t) (struct clo_option_t *option) |
Enumerations | |
enum | clo_dataType_t { CLO_TYPE_BOOL, CLO_TYPE_INT, CLO_TYPE_INT64, CLO_TYPE_FLOAT, CLO_TYPE_DOUBLE, CLO_TYPE_STRING, CLO_TYPE_IFILE, CLO_TYPE_OFILE, CLO_TYPE_HELP, CLO_TYPE_POSITION } |
Detailed Description
Command Line Option (CLO) is a library for reading and documenting the command line options for a program. The library can also read parameter files.
First the program should set the version string using #clo_setVersionString() function. Then the option list is created using clo_createList(). The list is filled by defining options and assigning default values and descriptions using the clo_addOption() function.
Next the program should call clo_readArgs() which first reads the command line arguments into the options list and looks for pre-defined options like -help and -version.
The last occurrence of an option is the one used. Overwriting the previous option value.
Options on the command line are expressed as "key" or "key=val". Each option is separated by white space and multiple values are separated by commas, colons, or spaces.
progName key10 key=val key1=val1,val2,val3 key2="val1 val2 val3"
boolean
key=0,1,y,n,yes,no,on,off
int
key=1,2,548,9
key=[1,2,3,4]
key=(1,2,3,4)
key="[1,2,3,4]"
key=["1","2",3,4]
key=1:2
float
key=1,8.3,.6, 1.0 , 1
string
key=hello,dude
key="two words","other",what
key="val1,val2,val3"
key="val\,with comma, other"
There are a few key values that are inherently understood by the library. They are invoked when clo_readArgs() is called.
-version, –version will print out the version string
-h, -help, –help will print the usage
-dump_options will print out everything help does plus the current value of the option and where the value came from. -dump_options_paramfile will write a param file with all of the params and values -dump_options_xmlfile will write an xml file with all of the param information
Definition in file clo.h.
Macro Definition Documentation
◆ CLO_ARRAY_DELIMITER
#define CLO_ARRAY_DELIMITER " \t,:[]()\"" |
◆ CLO_CHUNK_SIZE
#define CLO_CHUNK_SIZE 32 |
Typedef Documentation
◆ clo_optionCallback_t
typedef void(* clo_optionCallback_t) (struct clo_option_t *option) |
Enumeration Type Documentation
◆ clo_dataType_t
enum clo_dataType_t |
Function Documentation
◆ clo_addAlias()
void clo_addAlias | ( | clo_optionList_t * | list, |
const char * | key, | ||
const char * | alias | ||
) |
◆ clo_addOption()
clo_option_t* clo_addOption | ( | clo_optionList_t * | list, |
const char * | key, | ||
enum clo_dataType_t | dataType, | ||
const char * | defaultVal, | ||
const char * | desc | ||
) |
◆ clo_addOptionAlias()
void clo_addOptionAlias | ( | clo_option_t * | option, |
const char * | alias | ||
) |
◆ clo_addXmlProgramMetadata()
◆ clo_clearXmlProgramMetadata()
void clo_clearXmlProgramMetadata | ( | ) |
◆ clo_copyList()
clo_optionList_t* clo_copyList | ( | clo_optionList_t * | list | ) |
◆ clo_copyOption()
clo_option_t* clo_copyOption | ( | clo_option_t * | option | ) |
◆ clo_createList()
clo_optionList_t* clo_createList | ( | ) |
◆ clo_createOption()
clo_option_t* clo_createOption | ( | const char * | key, |
enum clo_dataType_t | dataType, | ||
const char * | defaultVal, | ||
const char * | desc | ||
) |
◆ clo_deleteList()
void clo_deleteList | ( | clo_optionList_t * | list | ) |
◆ clo_deleteOption()
void clo_deleteOption | ( | clo_option_t * | option | ) |
◆ clo_dumpOption()
void clo_dumpOption | ( | clo_option_t * | option | ) |
◆ clo_dumpOptions()
void clo_dumpOptions | ( | clo_optionList_t * | list | ) |
◆ clo_findOption()
clo_option_t* clo_findOption | ( | clo_optionList_t * | list, |
const char * | key | ||
) |
◆ clo_getBool()
int clo_getBool | ( | clo_optionList_t * | list, |
const char * | key | ||
) |
Find the option "key" and return the first value. exit is called if "key" is not found. If the option has not been set the default value is returned.
- Parameters
-
list list of options to search key option name to search for
- Returns
- internal pointer to the first boolean value
◆ clo_getBools()
int* clo_getBools | ( | clo_optionList_t * | list, |
const char * | key, | ||
int * | count | ||
) |
Find the option "key" and return the count and boolean array. exit is called if "key" is not found. If the option has not been set the default value is returned. The pointer returned references internally allocated memory stored in the option structure, so it should be valid until the value of option is changed.
- Parameters
-
list list of options to search through key option name to search for count [out] number of items in the array
- Returns
- an array of booleans. This pointer is pointing to internal memory stored in the option structure.
◆ clo_getDouble()
double clo_getDouble | ( | clo_optionList_t * | list, |
const char * | key | ||
) |
Find the option "key" and return the first value. exit is called if "key" is not found. If the option has not been set the default value is returned.
- Parameters
-
list list of options to search key option name to search for
- Returns
- internal pointer to the first double value
◆ clo_getDoubles()
double* clo_getDoubles | ( | clo_optionList_t * | list, |
const char * | key, | ||
int * | count | ||
) |
Find the option "key" and return the count and float array. exit is called if "key" is not found. If the option has not been set the default value is returned. The pointer returned references internally allocated memory stored in the option structure, so it should be valid until the value of option is changed.
- Parameters
-
list list of options to search through key option name to search for count [out] number of items in the array
- Returns
- an array of doubles. This pointer is pointing to internal memory stored in the option structure.
◆ clo_getEnableDumpOptions()
int clo_getEnableDumpOptions | ( | ) |
◆ clo_getEnableExtraOptions()
int clo_getEnableExtraOptions | ( | ) |
◆ clo_getEnableParOption()
int clo_getEnableParOption | ( | ) |
◆ clo_getEnablePositionOptions()
int clo_getEnablePositionOptions | ( | ) |
◆ clo_getFloat()
float clo_getFloat | ( | clo_optionList_t * | list, |
const char * | key | ||
) |
Find the option "key" and return the first value. exit is called if "key" is not found. If the option has not been set the default value is returned.
- Parameters
-
list list of options to search key option name to search for
- Returns
- internal pointer to the first float value
◆ clo_getFloats()
float* clo_getFloats | ( | clo_optionList_t * | list, |
const char * | key, | ||
int * | count | ||
) |
Find the option "key" and return the count and float array. exit is called if "key" is not found. If the option has not been set the default value is returned. The pointer returned references internally allocated memory stored in the option structure, so it should be valid until the value of option is changed.
- Parameters
-
list list of options to search through key option name to search for count [out] number of items in the array
- Returns
- an array of floats. This pointer is pointing to internal memory stored in the option structure.
◆ clo_getHelpStr()
char* clo_getHelpStr | ( | ) |
◆ clo_getIgnoreKeyCase()
int clo_getIgnoreKeyCase | ( | ) |
◆ clo_getInt()
int clo_getInt | ( | clo_optionList_t * | list, |
const char * | key | ||
) |
Find the option "key" and return the first value. exit is called if "key" is not found. If the option has not been set the default value is returned.
- Parameters
-
list list of options to search key option name to search for
- Returns
- internal pointer to the first int value
◆ clo_getInts()
int* clo_getInts | ( | clo_optionList_t * | list, |
const char * | key, | ||
int * | count | ||
) |
Find the option "key" and return the count and int array. exit is called if "key" is not found. If the option has not been set the default value is returned. The pointer returned references internally allocated memory stored in the option structure, so it should be valid until the value of option is changed.
- Parameters
-
list list of options to search through key option name to search for count [out] number of items in the array
- Returns
- an array of ints. This pointer is pointing to internal memory stored in the option structure.
◆ clo_getNumOptions()
int clo_getNumOptions | ( | clo_optionList_t * | list | ) |
◆ clo_getOption()
clo_option_t* clo_getOption | ( | clo_optionList_t * | list, |
int | i | ||
) |
◆ clo_getOptionBool()
int clo_getOptionBool | ( | clo_option_t * | option | ) |
◆ clo_getOptionBools()
int* clo_getOptionBools | ( | clo_option_t * | option, |
int * | count | ||
) |
Return the count and boolean array from the given option. If the option has not been set the default value is returned. The pointer returned references internally allocated memory stored in the option structure, so it should be valid until the value of option is changed.
- Parameters
-
option option to get the information from count [out] pointer where number of booleans in array is written
- Returns
- array of booleans
◆ clo_getOptionDouble()
double clo_getOptionDouble | ( | clo_option_t * | option | ) |
◆ clo_getOptionDoubles()
double* clo_getOptionDoubles | ( | clo_option_t * | option, |
int * | count | ||
) |
Return the count and double array from the given option. If the option has not been set the default value is returned. The pointer returned references internally allocated memory stored in the option structure, so it should be valid until the value of option is changed.
- Parameters
-
option option to get the information from count [out] pointer where number of doubles in array is written
- Returns
- array of doubles
◆ clo_getOptionFloat()
float clo_getOptionFloat | ( | clo_option_t * | option | ) |
◆ clo_getOptionFloats()
float* clo_getOptionFloats | ( | clo_option_t * | option, |
int * | count | ||
) |
Return the count and float array from the given option. If the option has not been set the default value is returned. The pointer returned references internally allocated memory stored in the option structure, so it should be valid until the value of option is changed.
- Parameters
-
option option to get the information from count pointer where number of floats in array is written
- Returns
- array of floats
◆ clo_getOptionInt()
int clo_getOptionInt | ( | clo_option_t * | option | ) |
◆ clo_getOptionInt64()
int64_t clo_getOptionInt64 | ( | clo_option_t * | option | ) |
◆ clo_getOptionInts()
int* clo_getOptionInts | ( | clo_option_t * | option, |
int * | count | ||
) |
Return the count and int array from the given option. If the option has not been set the default value is returned. The pointer returned references internally allocated memory stored in the option structure, so it should be valid until the value of option is changed.
- Parameters
-
option option to get the information from count [out] pointer where number of ints in array is written
- Returns
- array of ints
◆ clo_getOptionRawString()
char* clo_getOptionRawString | ( | clo_option_t * | option | ) |
◆ clo_getOptionString()
char* clo_getOptionString | ( | clo_option_t * | option | ) |
◆ clo_getOptionStrings()
char** clo_getOptionStrings | ( | clo_option_t * | option, |
int * | count | ||
) |
Return the count and string array from the given option. If the option has not been set the default value is returned. The pointer returned references internally allocated memory stored in the option structure, so it should be valid until the value of option is changed.
- Parameters
-
option option to get the information from count [out] pointer where number of strings in array is written
- Returns
- array of strings
◆ clo_getPositionNumOptions()
int clo_getPositionNumOptions | ( | clo_optionList_t * | list | ) |
◆ clo_getPositionOption()
clo_option_t* clo_getPositionOption | ( | clo_optionList_t * | list, |
int | i | ||
) |
◆ clo_getPositionString()
char* clo_getPositionString | ( | clo_optionList_t * | list, |
int | pos | ||
) |
◆ clo_getRawString()
char* clo_getRawString | ( | clo_optionList_t * | list, |
const char * | key | ||
) |
Find the option "key" and return the raw string value. Exit is called if "key" is not found. If the option has not been set the default value is returned. Exit is called if the option has not been set and the default value is NULL.
- Parameters
-
list list to search through key option key to find
- Returns
- internal pointer to the raw string value
◆ clo_getSelectOptionKeys()
char** clo_getSelectOptionKeys | ( | ) |
◆ clo_getString()
char* clo_getString | ( | clo_optionList_t * | list, |
const char * | key | ||
) |
Find the option "key" and return the first value. exit is called if "key" is not found. If the option has not been set the default value is returned.
- Parameters
-
list list of options to search key option name to search for
- Returns
- internal pointer to the first string value
◆ clo_getStrings()
char** clo_getStrings | ( | clo_optionList_t * | list, |
const char * | key, | ||
int * | count | ||
) |
Find the option "key" and return the count and string array. exit is called if "key" is not found. If the option has not been set the default value is returned. The pointer returned references internally allocated memory stored in the option structure, so it should be valid until the value of option is changed.
- Parameters
-
list list of options to search through key option name to search for count [out] number of items in the array
- Returns
- an array of strings. This pointer is pointing to internal memory stored in the option structure.
◆ clo_getVersion()
char* clo_getVersion | ( | ) |
◆ clo_insertOption()
void clo_insertOption | ( | clo_optionList_t * | list, |
clo_option_t * | option | ||
) |
◆ clo_isOptionSet()
int clo_isOptionSet | ( | clo_option_t * | option | ) |
◆ clo_isSet()
int clo_isSet | ( | clo_optionList_t * | list, |
const char * | key | ||
) |
◆ clo_printHelpString()
◆ clo_printOption()
void clo_printOption | ( | clo_option_t * | option | ) |
◆ clo_printOptions()
void clo_printOptions | ( | clo_optionList_t * | list | ) |
◆ clo_printOptionVal()
void clo_printOptionVal | ( | clo_option_t * | option | ) |
◆ clo_printUsage()
void clo_printUsage | ( | clo_optionList_t * | list | ) |
◆ clo_printVals()
void clo_printVals | ( | clo_optionList_t * | list | ) |
◆ clo_printVersion()
◆ clo_readArgs()
void clo_readArgs | ( | clo_optionList_t * | list, |
int | argc, | ||
char * | argv[] | ||
) |
Read command line arguments handling function. First call to readArgsPar with file descending enabled, then disabled to allow Command Line options override
- Parameters
-
list option list to search argc number of elements in argv argv array of command line argument strings
◆ clo_readArgsPar()
void clo_readArgsPar | ( | clo_optionList_t * | list, |
int | argc, | ||
char * | argv[], | ||
int | enableFileDescending | ||
) |
◆ clo_readFile()
void clo_readFile | ( | clo_optionList_t * | list, |
const char * | fileName | ||
) |
◆ clo_readOptions()
void clo_readOptions | ( | clo_optionList_t * | list, |
clo_optionList_t * | readList | ||
) |
◆ clo_readString()
void clo_readString | ( | clo_optionList_t * | list, |
const char * | str, | ||
const char * | source | ||
) |
◆ clo_setEnableDumpOptions()
void clo_setEnableDumpOptions | ( | int | val | ) |
◆ clo_setEnableExtraOptions()
void clo_setEnableExtraOptions | ( | int | val | ) |
◆ clo_setEnableParOption()
void clo_setEnableParOption | ( | int | val | ) |
set whether or not the library will add the par file option this must be set before calling clo_createList()
- Parameters
-
val 1 = enable processing, 0 = disable
◆ clo_setEnablePositionOptions()
void clo_setEnablePositionOptions | ( | int | val | ) |
◆ clo_setHelpStr()
void clo_setHelpStr | ( | const char * | str | ) |
◆ clo_setIgnoreKeyCase()
void clo_setIgnoreKeyCase | ( | int | val | ) |
◆ clo_setOptionString()
int clo_setOptionString | ( | clo_option_t * | option, |
const char * | val, | ||
const char * | source | ||
) |
◆ clo_setSelectOptionKeys()
void clo_setSelectOptionKeys | ( | char * | keys[] | ) |
◆ clo_setString()
int clo_setString | ( | clo_optionList_t * | list, |
const char * | key, | ||
const char * | val, | ||
const char * | source | ||
) |
◆ clo_setVersion()
void clo_setVersion | ( | const char * | str | ) |
◆ clo_setVersion2()
◆ clo_trimDashes()
void clo_trimDashes | ( | char * | str | ) |
◆ clo_trimDashesDup()
char* clo_trimDashesDup | ( | const char * | str | ) |
◆ clo_writeParameterFile()
int clo_writeParameterFile | ( | clo_optionList_t * | list, |
const char * | filename | ||
) |
◆ clo_writeXmlEndTag()
void clo_writeXmlEndTag | ( | FILE * | fout, |
int | level, | ||
const char * | tag | ||
) |
◆ clo_writeXmlFile()
int clo_writeXmlFile | ( | clo_optionList_t * | list, |
const char * | filename | ||
) |
◆ clo_writeXmlStartTag()
void clo_writeXmlStartTag | ( | FILE * | fout, |
int | level, | ||
const char * | tag | ||
) |