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 <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "lexer/lexer.h"
|
#include "../lexer/lexer.h"
|
||||||
#include "utils/ast/ast.h"
|
#include "../utils/ast/ast.h"
|
||||||
|
|
||||||
// === Static functions
|
// === Static functions
|
||||||
|
|
||||||
|
|
@ -70,7 +70,7 @@ struct ast *parse_list(void)
|
||||||
current_node = parse_and_or();
|
current_node = parse_and_or();
|
||||||
if (current_node == NULL)
|
if (current_node == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
list_append(result_list, current_node);
|
result_list = list_append(result_list, current_node);
|
||||||
|
|
||||||
// Following and_or commands
|
// Following and_or commands
|
||||||
token = PEEK_TOKEN();
|
token = PEEK_TOKEN();
|
||||||
|
|
@ -86,7 +86,7 @@ struct ast *parse_list(void)
|
||||||
// There must be a function for that
|
// There must be a function for that
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
list_append(result_list, current_node);
|
result_list = list_append(result_list, current_node);
|
||||||
token = PEEK_TOKEN();
|
token = PEEK_TOKEN();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -135,17 +135,37 @@ struct ast *parse_simple_command(void)
|
||||||
|
|
||||||
while (token->type == TOKEN_WORD)
|
while (token->type == TOKEN_WORD)
|
||||||
{
|
{
|
||||||
token = POP_TOKEN();
|
token = pop_token();
|
||||||
|
if (token == NULL)
|
||||||
|
{
|
||||||
|
// TODO free
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
char *word = strdup(token->data);
|
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);
|
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);
|
struct ast *result = ast_create_command(command_elements);
|
||||||
|
if (result == NULL)
|
||||||
|
{
|
||||||
|
// TODO free
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO check compliance with the grammar
|
|
||||||
struct ast *parse_shell_command(void)
|
struct ast *parse_shell_command(void)
|
||||||
{
|
{
|
||||||
return parse_if_rule();
|
return parse_if_rule();
|
||||||
|
|
@ -267,7 +287,6 @@ struct ast *parse_compound_list(void)
|
||||||
token = POP_TOKEN();
|
token = POP_TOKEN();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct ast *result = ast_create_list(result_list);
|
struct ast *result = ast_create_list(result_list);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue