fix: includes with relative path and memory leaks

This commit is contained in:
Gu://em_ 2026-01-20 19:25:55 +01:00
parent f38e828c0a
commit 603def1597

View file

@ -8,13 +8,13 @@
#include <stdio.h>
#include <string.h>
#include "lexer/lexer.h"
#include "utils/ast/ast.h"
#include "../lexer/lexer.h"
#include "../utils/ast/ast.h"
// === Static functions
/* Returns true if c is a command terminator, false otherwise
*/
*/
static bool isterminator(struct token *token)
{
if (token == NULL)
@ -70,7 +70,7 @@ struct ast *parse_list(void)
current_node = parse_and_or();
if (current_node == NULL)
return NULL;
list_append(result_list, current_node);
result_list = list_append(result_list, current_node);
// Following and_or commands
token = PEEK_TOKEN();
@ -82,11 +82,11 @@ struct ast *parse_list(void)
current_node = parse_and_or();
if (current_node == NULL)
{
//TODO free list
// TODO free list
// There must be a function for that
return NULL;
}
list_append(result_list, current_node);
result_list = list_append(result_list, current_node);
token = PEEK_TOKEN();
}
}
@ -135,17 +135,37 @@ struct ast *parse_simple_command(void)
while (token->type == TOKEN_WORD)
{
token = POP_TOKEN();
char* word = strdup(token->data);
token = pop_token();
if (token == NULL)
{
// TODO free
return NULL;
}
char *word = strdup(token->data);
if (word == NULL)
{
// TODO free
puts("Internal error: Couldn't copy token content (is memory full "
"?)");
return NULL;
}
command_elements = list_append(command_elements, word);
token = PEEK_TOKEN();
token = peek_token();
if (token == NULL)
{
// TODO free
return NULL;
}
}
struct ast *result = ast_create_command(command_elements);
if (result == NULL)
{
// TODO free
}
return result;
}
// TODO check compliance with the grammar
struct ast *parse_shell_command(void)
{
return parse_if_rule();
@ -267,7 +287,6 @@ struct ast *parse_compound_list(void)
token = POP_TOKEN();
}
struct ast *result = ast_create_list(result_list);
return result;
}