fix: includes with relative path and memory leaks
This commit is contained in:
parent
f38e828c0a
commit
603def1597
1 changed files with 38 additions and 19 deletions
|
|
@ -8,8 +8,8 @@
|
|||
#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
|
||||
|
||||
|
|
@ -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();
|
||||
|
|
@ -86,7 +86,7 @@ struct ast *parse_list(void)
|
|||
// 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();
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue