diff --git a/include/parser.h b/include/parser.h index 3a52f48..5416925 100644 --- a/include/parser.h +++ b/include/parser.h @@ -116,12 +116,26 @@ SCParserWrite( * RETURN: NULL on Failure. */ SCParser * -SCPParserCreate( +SCParserCreate( const uint32_t BASE_VAR_COUNT ); +/* + * + * RETURN: EXIT_SUCCESS on Success. + * RETURN: EXIT_FAILURE on Failure. + */ +int +SCParserCreateFilled( + SCParser *parser_return, + const uint32_t BASE_VAR_COUNT + ); + /* - * Frees parser data, and itself, any references should be terminated. + * Frees parser data, any references should be terminated. + * + * NOTE: Parser is not freed user must free "parser" if allocated. + * */ void SCParserDestroy( diff --git a/src/parser.c b/src/parser.c index 3518dab..a246fb8 100644 --- a/src/parser.c +++ b/src/parser.c @@ -446,33 +446,48 @@ SCParserWrite( } SCParser * -SCPParserCreate( +SCParserCreate( const uint32_t BASE_VAR_COUNT ) { SCParser *p = malloc(sizeof(SCParser)); if(p) { - p->strtable = kh_init(__STR__TABLE__); - - if(!p->strtable) + const int status = SCParserCreateFilled(p, BASE_VAR_COUNT); + if(status == EXIT_FAILURE) { free(p); - return NULL; - } - p->items = malloc(BASE_VAR_COUNT * sizeof(SCItem)); - if(!p->items) - { - kh_destroy(__STR__TABLE__, p->strtable); - free(p); - return NULL; + p = NULL; } - p->item_len = BASE_VAR_COUNT; - p->index = 0; } return p; } +int +SCParserCreateFilled( + SCParser *parser_return, + const uint32_t BASE_VAR_COUNT + ) +{ + if(!parser_return) + { return EXIT_FAILURE; + } + parser_return->strtable = kh_init(__STR__TABLE__); + + if(!parser_return->strtable) + { return EXIT_FAILURE; + } + parser_return->items = malloc(BASE_VAR_COUNT * sizeof(SCItem)); + if(!parser_return->items) + { + kh_destroy(__STR__TABLE__, parser_return->strtable); + return EXIT_FAILURE; + } + parser_return->item_len = BASE_VAR_COUNT; + parser_return->index = 0; + return EXIT_SUCCESS; +} + void SCParserDestroy( SCParser *parser @@ -627,7 +642,7 @@ SCParserNewVar( if(READONLY_SECTION) { - item->name = VAR_NAME; + item->name = (char *)VAR_NAME; item->allocated = 0; } else diff --git a/src/settings.c b/src/settings.c index 4612bd8..c49ea2c 100644 --- a/src/settings.c +++ b/src/settings.c @@ -315,7 +315,7 @@ USInit( return; } memset(settings_init, 0, sizeof(UserSettings)); - settings_init->cfg = SCPParserCreate(UserSettingsLAST); + settings_init->cfg = SCParserCreate(UserSettingsLAST); if(settings_init->cfg) { USSetupCFGVars(settings_init);