Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added parser fill data #407

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions include/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
45 changes: 30 additions & 15 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -627,7 +642,7 @@ SCParserNewVar(

if(READONLY_SECTION)
{
item->name = VAR_NAME;
item->name = (char *)VAR_NAME;
item->allocated = 0;
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down