cmdlineoptions/c/cmdlineoptions.h

111 lines
2.9 KiB
C
Raw Normal View History

#ifndef CMDLINEOPTIONS_H
#define CMDLINEOPTIONS_H
2013-12-27 11:53:29 +01:00
typedef struct _Option {
2013-12-24 18:05:27 +01:00
char* name; // the name of this option
char** options; //dashed option name and alternatives
unsigned int optionscount; // count of option alternatives
char** possibleparameters; // possible parameters for this options
unsigned int possibleparametercount; // count of possible parameters
char* description; // description of this parameter
char** defaultparameters; // default parameters
unsigned int defaultparametercount; // count of default parameters
2013-12-24 18:05:27 +01:00
char** values; // values
unsigned int valuecount; // size of the values, if more than one...
char set; // boolean if this option has been set
} Option;
2013-12-24 18:05:27 +01:00
typedef struct _CONode {
//CONode* prev;
struct _CONode* next;
2013-12-25 13:29:54 +01:00
Option* option;
} CONode;
2013-12-25 13:29:54 +01:00
2013-12-27 11:53:29 +01:00
typedef struct _CmdOptions {
char init;
2013-12-25 13:29:54 +01:00
CONode* options;
2013-12-27 19:59:33 +01:00
char cmdchar;
} CmdOptions;
2013-12-24 18:05:27 +01:00
2013-12-27 19:59:33 +01:00
/**
2013-12-25 13:29:54 +01:00
* Main structure
*/
extern CmdOptions cmdoptions;
2013-12-27 19:59:33 +01:00
/** Init function.
2013-12-24 18:05:27 +01:00
*/
void CmdLO_InitCmd(char addhelp, char cmdchar);
void CmdLO_Init(char addhelp);
2013-12-24 18:05:27 +01:00
/**
* The heart of this whole thing, the parsing of all options...
*/
int CmdLO_Parse(int argc, char** argv);
CONode* CmdLO_SearchNode(char* cmdlineargument);
2013-12-24 18:05:27 +01:00
/**
* Add a new option with a new name, or a new option alternative to an existing one.
*/
void CmdLO_Add(char* name, char* option);
2013-12-24 18:05:27 +01:00
/**
* Add a defaultparameter to an existing option, specified by name.
*/
void CmdLO_AddDefaultParameter(char* name, char* defaultparameter);
2013-12-24 18:05:27 +01:00
/**
* Add a possible parameter to an existing option, specified by name.
* Keep in mind that you LIMIT that option to all possible parameters (?)
*/
void CmdLO_AddPossibleParameter(char* name, char* possibleParameter);
2013-12-24 18:05:27 +01:00
/**
* Add a description to an existing option, specified by name.
*/
void CmdLO_AddDescription(char* name, char* description);
2013-12-24 18:05:27 +01:00
/**
* Check if the option specified by name is set.
*/
int CmdLO_IsSet(char* name);
2013-12-24 18:05:27 +01:00
/**
* Get first parameter of the option specified by name.
*/
char* CmdLO_Get(char* name);
2013-12-24 18:05:27 +01:00
/**
* Get the first parameter of the option specified by name as integer.
*/
int CmdLO_GetInt(char* name);
2013-12-24 18:05:27 +01:00
/**
* Get the first parameter of the option specified by name as long.
*/
long CmdLO_GetLong(char* name);
2013-12-24 18:05:27 +01:00
/**
* Get the first parameter of the option specified by name as double.
*/
double CmdLO_GetDouble(char* name);
2013-12-24 18:05:27 +01:00
/**
* Get all parameters of the given option name as string array.
* This is the 'Do It Yourself' retrieve function.
*/
int CmdLO_GetAll(char* name, char** values, unsigned int* count);
/**
* Get the node with the given name or create a new one with that name.
*/
CONode* CmdLO_Create(char* name);
/**
* Just get the node with the given name.
*/
CONode* CmdLO_NodeGet(char* name);
/**
* Convenience function to add a string to a string array.
*/
void CmdLO_AddElement(char*** target,unsigned int* counter, char* element);
/**
* Clean up everything, like nothing ever happened...
*/
void CmdLO_Destroy();
#endif