diff --git a/c/cmdlineoptions.c b/c/cmdlineoptions.c index dbc09d3..3755243 100644 --- a/c/cmdlineoptions.c +++ b/c/cmdlineoptions.c @@ -260,3 +260,40 @@ void CmdLO_AddElement(char*** target, unsigned int* counter, char* element) { free(old); *counter = cnt + 1; } + +void CmdLO_Destroy() { + // free everything inside the structures and then the whole tree + CONode * node = cmdoptions.options; + int i = 0; + while (node != 0) { + if (node->option->optionscount > 0) { + i = 0; + for (; i < node->option->optionscount; ++i) + free(node->option->options[i]); + free(node->option->options); + } + if (node->option->defaultparametercount > 0) { + i = 0; + for (; i < node->option->defaultparametercount; ++i) + free(node->option->defaultparameters[i]); + free(node->option->defaultparameters); + } + if (node->option->possibleparametercount > 0) { + i = 0; + for (; i < node->option->possibleparametercount; ++i) + free(node->option->possibleparametercount[i]); + free(node->option->possibleparametercount); + } + if (node->option->valuecount > 0) { + i = 0; + for (; i < node->option->valuecount; ++i) + free(node->option->values[i]); + free(node->option->values); + } + free(node->option); + CONode* old = node; + node = node->next; + free(old); + } + cmdoptions.options = 0; +} diff --git a/c/cmdlineoptions.h b/c/cmdlineoptions.h index 98c9d83..f4fa812 100644 --- a/c/cmdlineoptions.h +++ b/c/cmdlineoptions.h @@ -88,9 +88,23 @@ double CmdLO_GetDouble(char* name); * 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