working on the functions...
This commit is contained in:
parent
f672ae724f
commit
2e3e00836d
|
@ -16,22 +16,34 @@ void CmdOptions_Init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int CmdOptions_Create(char* name) {
|
CONode* CmdOptions_Create(char* name) {
|
||||||
if (CmdOptions_NodeGet(name) == 0) {
|
CONode* node = CmdOptions_NodeGet(name);
|
||||||
CONode* newnode = 0;
|
if (node == 0) {
|
||||||
newnode = malloc(sizeof(CONode));
|
node = malloc(sizeof(CONode));
|
||||||
if (cmdoptions.options == 0) {
|
if (cmdoptions.options == 0) {
|
||||||
cmdoptions.options = newnode;
|
cmdoptions.options = node;
|
||||||
} else {
|
} else {
|
||||||
CONode* last = cmdoptions.options;
|
CONode* last = cmdoptions.options;
|
||||||
while (last->next != 0)
|
while (last->next != 0)
|
||||||
last = last->next;
|
last = last->next;
|
||||||
last->next = newnode;
|
last->next = node;
|
||||||
}
|
}
|
||||||
newnode->next = 0;
|
node->next = 0;
|
||||||
newnode->option = malloc(sizeof(Option));
|
node->option = malloc(sizeof(Option));
|
||||||
newnode->option->name = name;
|
node->option->name = name;
|
||||||
|
// init the option parts
|
||||||
|
node->option->defaultparametercount = 0;
|
||||||
|
node->option->defaultparameters = 0;
|
||||||
|
node->option->description = 0;
|
||||||
|
node->option->options = 0;
|
||||||
|
node->option->optionscount = 0;
|
||||||
|
node->option->possibleparametercount = 0;
|
||||||
|
node->option->possibleparameters = 0;
|
||||||
|
node->option->set = 0;
|
||||||
|
node->option->values = 0;
|
||||||
|
node->option->valuecount = 0;
|
||||||
}
|
}
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
CONode* CmdOptions_NodeGet(char* name) {
|
CONode* CmdOptions_NodeGet(char* name) {
|
||||||
|
@ -51,42 +63,72 @@ int CmdOptions_Parse(int argc, char** argv) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int CmdOptions_Add(char* name, char* option) {
|
void CmdOptions_Add(char* name, char* option) {
|
||||||
|
CONode* node = CmdOptions_Create(name);
|
||||||
|
CmdOptions_AddElement(node->option->options, &(node->option->optionscount),
|
||||||
|
option);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CmdOptions_AddDefaultParameter(char* name, char* defaultparameter) {
|
void CmdOptions_AddDefaultParameter(char* name, char* defaultparameter) {
|
||||||
|
CONode* node = CmdOptions_Create(name);
|
||||||
|
CmdOptions_AddElement(node->option->defaultparameters,
|
||||||
|
&(node->option->defaultparametercount), defaultparameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CmdOptions_AddPossibleParameter(char* name, char* possibleParameter) {
|
void CmdOptions_AddPossibleParameter(char* name, char* possibleParameter) {
|
||||||
|
CONode* node = CmdOptions_Create(name);
|
||||||
|
CmdOptions_AddElement(node->option->possibleparameters,
|
||||||
|
&(node->option->possibleparametercount), possibleParameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CmdOptions_AddDescription(char* name, char* description) {
|
void CmdOptions_AddDescription(char* name, char* description) {
|
||||||
|
CONode* node = CmdOptions_Create(name);
|
||||||
|
node->option->description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CmdOptions_IsSet(char* name) {
|
int CmdOptions_IsSet(char* name) {
|
||||||
|
CONode* node = CmdOptions_Create(name);
|
||||||
|
return node->option->set;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* CmdOptions_Get(char* name) {
|
char* CmdOptions_Get(char* name) {
|
||||||
|
CONode* node = CmdOptions_Create(name);
|
||||||
|
if (CmdOptions_IsSet(name) && node->option->valuecount > 0)
|
||||||
|
return node->option->values[0];
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CmdOptions_GetInt(char* name) {
|
int CmdOptions_GetInt(char* name) {
|
||||||
|
return atoi(CmdOptions_Get(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
long CmdOptions_GetLong(char* name) {
|
long CmdOptions_GetLong(char* name) {
|
||||||
|
return atol(CmdOptions_Get(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
double CmdOptions_GetDouble(char* name) {
|
double CmdOptions_GetDouble(char* name) {
|
||||||
|
return atod(CmdOptions_Get(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
int CmdOptions_GetAll(char* name, char** values, unsigned int* count) {
|
int CmdOptions_GetAll(char* name, char** values, unsigned int* count) {
|
||||||
|
CONode* node = CmdOptions_Create(name);
|
||||||
|
if(node == 0)
|
||||||
|
return 1;
|
||||||
|
values = node->option->values;
|
||||||
|
*count = node->option->valuecount;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CmdOptions_AddElement(char** target, int* counter, char* element) {
|
||||||
|
int cnt = *counter;
|
||||||
|
char** old = 0;
|
||||||
|
if (target != 0)
|
||||||
|
old = target;
|
||||||
|
target = malloc((cnt + 1) * sizeof(char*));
|
||||||
|
if (old != 0)
|
||||||
|
memcpy(target, old, (cnt) * sizeof(char*));
|
||||||
|
target[cnt] = element;
|
||||||
|
if (old != 0)
|
||||||
|
free(old);
|
||||||
|
*counter = cnt + 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,5 +88,6 @@ int CmdOptions_GetAll(char* name, char** values, unsigned int* count);
|
||||||
|
|
||||||
int CmdOptions_Create(char* name);
|
int CmdOptions_Create(char* name);
|
||||||
CONode* CmdOptions_NodeGet(char* name);
|
CONode* CmdOptions_NodeGet(char* name);
|
||||||
|
void CmdOptions_AddElement(char** target, char* element);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue