diff --git a/src/ast/ast.c b/src/ast/ast.c index a6b1f01d..0da8db86 100644 --- a/src/ast/ast.c +++ b/src/ast/ast.c @@ -8,7 +8,7 @@ #include "ast.h" -#include "../options/options.h" +#include "options/options.h" struct ast_node *ast_node_new(enum ast_type type) { @@ -92,7 +92,7 @@ char *ast_type_to_string(enum ast_type type) case AST_WORD_ASSIGNMENT: return "AST_WORD_ASSIGNMENT"; case AST_VARIABLE: - return "AST_VARIABLE"; + return "AST_VARIABLE"; default: return "UNKNOWN"; } @@ -105,11 +105,12 @@ void print_ast(struct ast_node *node, int depth, bool logger_enabled) for (int i = 0; i < depth; i++) printf(" "); printf("%s\n", ast_type_to_string(node->type)); - if (node->type == AST_WORD || node->type == AST_WORD_ASSIGNMENT || node->type == AST_VARIABLE) + if (node->type == AST_WORD || node->type == AST_WORD_ASSIGNMENT + || node->type == AST_VARIABLE) { printf("%s:\n", node->value); } - //logger(node->value, LOGGER_PARSER, logger_enabled); + // logger(node->value, LOGGER_PARSER, logger_enabled); for (int i = 0; i < node->children_count; i++) print_ast(node->children[i], depth + 1, logger_enabled); } diff --git a/src/execute/Makefile.am b/src/execute/Makefile.am index 9ea6a98c..996d98a8 100644 --- a/src/execute/Makefile.am +++ b/src/execute/Makefile.am @@ -6,4 +6,4 @@ libexecute_a_SOURCES = pipeline.c loop.c ast_eval.c ast_eval.h ../parser/parser. libexecute_a_CFLAGS = -Wall -Wextra -Werror -Wvla -pedantic -std=c99 -libexecute_a_CPPFLAGS =-I$(top_srcdir) +libexecute_a_CPPFLAGS =-I$(top_srcdir)/src diff --git a/src/execute/ast_eval.c b/src/execute/ast_eval.c index f21c7e54..801645dc 100644 --- a/src/execute/ast_eval.c +++ b/src/execute/ast_eval.c @@ -13,9 +13,8 @@ #include #include -#include "../options/options.h" -#include "../parser/parser.h" #include "builtin.h" +#include "parser/parser.h" // true = 0 // false = 1 @@ -44,7 +43,7 @@ int exec_cmd(struct ast_node *node, bool logger_enabled) for (int i = 0; i < node->children_count; i++) { args[i] = handle_word(node->children[i]); - //printf("%s ", args[i]); + // printf("%s ", args[i]); logger(args[i], LOGGER_EXEC, logger_enabled); } logger("\n", LOGGER_EXEC, logger_enabled); diff --git a/src/execute/ast_eval.h b/src/execute/ast_eval.h index 0c05ffdb..5688c088 100644 --- a/src/execute/ast_eval.h +++ b/src/execute/ast_eval.h @@ -11,8 +11,8 @@ #include -#include "../ast/ast.h" -#include "../options/options.h" +#include "ast/ast.h" +#include "options/options.h" /** * \brief Evaluates the given AST and returns the exit status of the last diff --git a/src/execute/ast_variable.c b/src/execute/ast_variable.c index 05256030..2ccbc001 100644 --- a/src/execute/ast_variable.c +++ b/src/execute/ast_variable.c @@ -1,6 +1,6 @@ #include "ast_eval.h" #include "hash_map/hash_map.h" -#include "../parser/parser.h" +#include "parser/parser.h" struct hash_map *variables = NULL; @@ -28,7 +28,7 @@ void set_variable(char *key, char *value) char *get_variable(char *key) { key++; - //gerer les variables envirovment + // gerer les variables envirovment init_variables(); if (variables == NULL) { @@ -63,7 +63,8 @@ int ast_eval_assignment(struct ast_node *node, bool logger_enabled) return 0; } -// Small function for handle variable (just check ast_node type and check the hash table) +// Small function for handle variable (just check ast_node type and check the +// hash table) char *handle_word(struct ast_node *node) { if (node->type == AST_WORD) @@ -74,7 +75,6 @@ char *handle_word(struct ast_node *node) { return get_variable(node->value); } - //IMPOSSIBLE + // IMPOSSIBLE return NULL; - } diff --git a/src/execute/builtin.c b/src/execute/builtin.c index bb86f5b8..a763e944 100644 --- a/src/execute/builtin.c +++ b/src/execute/builtin.c @@ -74,7 +74,8 @@ int echo_fun(struct ast_node *node) int j = 1; for (int i = 1; i < node->children_count; i++) { - if (strlen(handle_word(node->children[i])) >= 1 && handle_word(node->children[i])[0] == '-') + if (strlen(handle_word(node->children[i])) >= 1 + && handle_word(node->children[i])[0] == '-') { if (strspn(handle_word(node->children[i]), "-neE") != strlen(handle_word(node->children[i]))) diff --git a/src/execute/loop.c b/src/execute/loop.c index e2ed1294..191eb9d2 100644 --- a/src/execute/loop.c +++ b/src/execute/loop.c @@ -1,4 +1,4 @@ -#include "../ast/ast.h" +#include "ast/ast.h" #include "ast_eval.h" int while_loop(struct ast_node *node, bool logger_enabled) diff --git a/src/execute/pipeline.c b/src/execute/pipeline.c index ee5747eb..170ce841 100644 --- a/src/execute/pipeline.c +++ b/src/execute/pipeline.c @@ -3,7 +3,7 @@ #include #include -#include "../ast/ast.h" +#include "ast/ast.h" #include "ast_eval.h" int pipeline_eval(struct ast_node *node, bool logger_enabled) diff --git a/src/execute/redirections.c b/src/execute/redirections.c index e7ced60d..98941122 100644 --- a/src/execute/redirections.c +++ b/src/execute/redirections.c @@ -1,11 +1,11 @@ -#include "../ast/ast.h" -#include "ast_eval.h" - -#include #include -#include #include +#include #include +#include + +#include "ast/ast.h" +#include "ast_eval.h" int redir_output(struct ast_node *node, bool logger_enabled) { diff --git a/src/execute/tests/exec_tests.c b/src/execute/tests/exec_tests.c index bab27c87..02756a6d 100644 --- a/src/execute/tests/exec_tests.c +++ b/src/execute/tests/exec_tests.c @@ -10,12 +10,12 @@ #include #include -#include "../../io_backend/io_backend.h" -#include "../../lexer/lexer.h" -#include "../../parser/parser.h" -#include "../ast_eval.h" +#include "execute/ast_eval.h" +#include "io_backend/io_backend.h" +#include "lexer/lexer.h" +#include "parser/parser.h" -TestSuite(exec, .timeout = 1); +TestSuite(exec, .timeout = 10); Test(exec, test_exec_simple_command) { diff --git a/src/io_backend/Makefile.am b/src/io_backend/Makefile.am index e8ba22d4..17881106 100644 --- a/src/io_backend/Makefile.am +++ b/src/io_backend/Makefile.am @@ -2,4 +2,4 @@ lib_LIBRARIES = libio.a libio_a_SOURCES = io_backend.c io_backend.h libio_a_CFLAGS = -Wall -Wextra -Werror -Wvla -pedantic -std=c99 -libio_a_CPPFLAGS = -I$(top_srcdir) +libio_a_CPPFLAGS = -I$(top_srcdir)/src diff --git a/src/io_backend/tests/io_backend_tests.c b/src/io_backend/tests/io_backend_tests.c index 24630d53..76e9e126 100644 --- a/src/io_backend/tests/io_backend_tests.c +++ b/src/io_backend/tests/io_backend_tests.c @@ -10,9 +10,9 @@ #include #include -#include "../io_backend.h" +#include "io_backend/io_backend.h" -TestSuite(io_backend, .timeout = 1); +TestSuite(io_backend, .timeout = 10); Test(io_backend, io_backend_direct) { diff --git a/src/lexer/Makefile.am b/src/lexer/Makefile.am index cb0a3779..1b1fcc5c 100644 --- a/src/lexer/Makefile.am +++ b/src/lexer/Makefile.am @@ -2,4 +2,4 @@ lib_LIBRARIES = liblexer.a liblexer_a_SOURCES = lexer.c lexer_utils.c lexer.h token.h liblexer_a_CFLAGS = -Wall -Wextra -Werror -Wvla -pedantic -std=c99 -liblexer_a_CPPFLAGS = -I$(top_srcdir) +liblexer_a_CPPFLAGS = -I$(top_srcdir)/src diff --git a/src/lexer/lexer.c b/src/lexer/lexer.c index 5deee865..1d502b16 100644 --- a/src/lexer/lexer.c +++ b/src/lexer/lexer.c @@ -133,16 +133,18 @@ char *get_word(struct lexer *lexer, bool *is_diactivated) } // Handle the word assignement if it's contain '=' and it's not the // first character - + else if (lexer->data[lexer->index] == '=' && word_index > 0 && lexer->curr_tok.type != TOKEN_DOUBLE_QUOTE - && lexer->curr_tok.type != TOKEN_VARIABLE_VALUE && check_variable_assignement(word)) + && lexer->curr_tok.type != TOKEN_VARIABLE_VALUE + && check_variable_assignement(word)) { - lexer->curr_tok.type = TOKEN_WORD_ASSIGNMENT; + lexer->curr_tok.type = TOKEN_WORD_ASSIGNMENT; break; } - else if (lexer->data[lexer->index] == '=' && word_index == 0 && lexer->curr_tok.type == TOKEN_VARIABLE_VALUE) + else if (lexer->data[lexer->index] == '=' && word_index == 0 + && lexer->curr_tok.type == TOKEN_VARIABLE_VALUE) { lexer->index += 1; } @@ -203,8 +205,9 @@ char *get_word(struct lexer *lexer, bool *is_diactivated) word = realloc(word, sizeof(char) * (word_index + 1)); word[word_index] = '\0'; - if (is_number(word) && (lexer->data[lexer->index] == '>' - || lexer->data[lexer->index] == '<' )) + if (is_number(word) + && (lexer->data[lexer->index] == '>' + || lexer->data[lexer->index] == '<')) { lexer->curr_tok.type = TOKEN_IONUMBER; } diff --git a/src/lexer/lexer.h b/src/lexer/lexer.h index 9826143c..05dfc386 100644 --- a/src/lexer/lexer.h +++ b/src/lexer/lexer.h @@ -12,8 +12,8 @@ #include #include +#include "options/options.h" #include "token.h" -#include "../options/options.h" /** * \struct lexer diff --git a/src/lexer/lexer_utils.c b/src/lexer/lexer_utils.c index a065a3c6..dca5ead6 100644 --- a/src/lexer/lexer_utils.c +++ b/src/lexer/lexer_utils.c @@ -236,7 +236,7 @@ char *handle_double_quote(struct lexer *lexer, bool *is_diactivated, char *word, } else { - *word_index -= 1; + *word_index -= 1; } lexer->index += 1; } diff --git a/src/lexer/tests/lexer2_tests.c b/src/lexer/tests/lexer2_tests.c index a728cfb2..2422ef5f 100644 --- a/src/lexer/tests/lexer2_tests.c +++ b/src/lexer/tests/lexer2_tests.c @@ -11,9 +11,9 @@ #include #include -#include "../lexer.h" +#include "lexer/lexer.h" -TestSuite(lexer2, .timeout = 1); +TestSuite(lexer2, .timeout = 10); Test(lexer2, token_and) { @@ -287,7 +287,7 @@ Test(lexer2, token_redir_stick_left_alpha) cr_assert_eq(tok.type, TOKEN_WORD); cr_assert_str_eq(tok.data, "file"); token_free(tok); - + lexer_free(lexer); } @@ -313,7 +313,7 @@ Test(lexer2, token_redir_stick_left_alphanum) cr_assert_eq(tok.type, TOKEN_WORD); cr_assert_str_eq(tok.data, "file"); token_free(tok); - + lexer_free(lexer); } @@ -1038,7 +1038,7 @@ Test(lexer2, variable_distinction_access_all_deactivated2) tok = lexer_pop(lexer); } -Test (lexer2, personalized_variable) +Test(lexer2, personalized_variable) { struct lexer *lexer = lexer_new("echo a=4; echo $b"); struct token tok = lexer_pop(lexer); @@ -1046,7 +1046,7 @@ Test (lexer2, personalized_variable) cr_assert_str_eq(tok.data, "echo"); token_free(tok); - // has to be a word + // has to be a word tok = lexer_pop(lexer); cr_assert_eq(tok.type, TOKEN_WORD_ASSIGNMENT, "got %d", tok.type); cr_assert_str_eq(tok.data, "a"); @@ -1075,7 +1075,7 @@ Test (lexer2, personalized_variable) lexer_free(lexer); } -Test (lexer2, personalized_variable2) +Test(lexer2, personalized_variable2) { struct lexer *lexer = lexer_new("a=4; echo $a"); struct token tok = lexer_pop(lexer); @@ -1105,4 +1105,3 @@ Test (lexer2, personalized_variable2) lexer_free(lexer); } - diff --git a/src/lexer/tests/lexer_tests.c b/src/lexer/tests/lexer_tests.c index c4648e27..a91bf37d 100644 --- a/src/lexer/tests/lexer_tests.c +++ b/src/lexer/tests/lexer_tests.c @@ -10,9 +10,9 @@ #include #include -#include "../lexer.h" +#include "lexer/lexer.h" -TestSuite(lexer, .timeout = 1); +TestSuite(lexer, .timeout = 10); Test(lexer, lexer_new_and_free) { diff --git a/src/main.c b/src/main.c index 1bf003c4..199d945d 100644 --- a/src/main.c +++ b/src/main.c @@ -35,7 +35,7 @@ int main(int argc, char **argv) } logger(input, LOGGER_INPUT, logger_enabled); - //printf("Input: %s\n", input); + // printf("Input: %s\n", input); struct lexer *lexer = lexer_new(input); /*while (lexer_peek(lexer).type != TOKEN_EOF) { diff --git a/src/options/Makefile.am b/src/options/Makefile.am index 1297055f..7b8f4567 100644 --- a/src/options/Makefile.am +++ b/src/options/Makefile.am @@ -2,4 +2,4 @@ lib_LIBRARIES = liboptions.a liboptions_a_SOURCES = options.c options.h liboptions_a_CFLAGS = -Wall -Wextra -Werror -Wvla -pedantic -std=c99 -liboptions_a_CPPFLAGS = -I$(top_srcdir) +liboptions_a_CPPFLAGS = -I$(top_srcdir)/src diff --git a/src/options/options.c b/src/options/options.c index 3287260d..04d72d5e 100644 --- a/src/options/options.c +++ b/src/options/options.c @@ -15,8 +15,6 @@ #include #include -#include "../ast/ast.h" - int is_number(char *str) { int i = 0; diff --git a/src/options/options.h b/src/options/options.h index 7d76d8c4..20778a36 100644 --- a/src/options/options.h +++ b/src/options/options.h @@ -12,7 +12,7 @@ #include #include -#include "../ast/ast.h" +#include "ast/ast.h" /** * \brief Enum for the different logger steps. @@ -57,7 +57,7 @@ void pretty_print(struct ast_node *ast, bool pretty_print_enabled, int *depths); * \brief Check if the given string is a number. * \param str The string to check. * \return True if the string is a number, false otherwise. -*/ + */ int is_number(char *str); #endif /* ! OPTIONS_H */ diff --git a/src/options/tests/options_tests.c b/src/options/tests/options_tests.c index 00f38f68..284fcd12 100644 --- a/src/options/tests/options_tests.c +++ b/src/options/tests/options_tests.c @@ -10,9 +10,9 @@ #include #include -#include "../options.h" +#include "options/options.h" -TestSuite(options, .timeout = 1); +TestSuite(options, .timeout = 10); Test(options, last_arg_logger) { diff --git a/src/parser/Makefile.am b/src/parser/Makefile.am index b687f8b9..2ad0c1e2 100644 --- a/src/parser/Makefile.am +++ b/src/parser/Makefile.am @@ -6,4 +6,4 @@ libparser_a_SOURCES = parser.c parser.h \ ../lexer/lexer.c ../lexer/lexer.h parser_functionnal.c parser_variable.c libparser_a_CFLAGS = -Wall -Wextra -Werror -Wvla -pedantic -std=c99 -libparser_a_CPPFLAGS =-I$(top_srcdir) +libparser_a_CPPFLAGS =-I$(top_srcdir)/src diff --git a/src/parser/parser.c b/src/parser/parser.c index 9c4c730e..0c331a69 100644 --- a/src/parser/parser.c +++ b/src/parser/parser.c @@ -8,7 +8,7 @@ #include "parser.h" -#include "../execute/ast_eval.h" +#include "execute/ast_eval.h" /* input = diff --git a/src/parser/parser.h b/src/parser/parser.h index 7f70be6f..7322ee86 100644 --- a/src/parser/parser.h +++ b/src/parser/parser.h @@ -11,10 +11,10 @@ #include -#include "../ast/ast.h" -#include "../lexer/lexer.h" -#include "../lexer/token.h" -#include "../options/options.h" +#include "ast/ast.h" +#include "lexer/lexer.h" +#include "lexer/token.h" +#include "options/options.h" /** * \brief Parse loop the given lexer diff --git a/src/parser/parser_element.c b/src/parser/parser_element.c index 46351c2e..fa6aaf7a 100644 --- a/src/parser/parser_element.c +++ b/src/parser/parser_element.c @@ -196,9 +196,10 @@ struct ast_node *element(struct lexer *lexer) if (parser_peek(lexer) == TOKEN_WORD || parser_peek(lexer) == TOKEN_IF || parser_peek(lexer) == TOKEN_THEN || parser_peek(lexer) == TOKEN_ELSE || parser_peek(lexer) == TOKEN_ELIF || parser_peek(lexer) == TOKEN_FI - || parser_peek(lexer) == TOKEN_DONE || parser_peek(lexer) == TOKEN_WORD_ASSIGNMENT) + || parser_peek(lexer) == TOKEN_DONE + || parser_peek(lexer) == TOKEN_WORD_ASSIGNMENT) { - //printf("value=%s\n", lexer_peek(lexer).data); + // printf("value=%s\n", lexer_peek(lexer).data); struct ast_node *curr = ast_node_word(lexer_peek(lexer).data); parser_pop(lexer); return curr; diff --git a/src/parser/tests/parser_tests.c b/src/parser/tests/parser_tests.c index de6159a3..169d8764 100644 --- a/src/parser/tests/parser_tests.c +++ b/src/parser/tests/parser_tests.c @@ -10,10 +10,10 @@ #include #include -#include "../../ast/ast.h" -#include "../parser.h" +#include "ast/ast.h" +#include "parser/parser.h" -TestSuite(parser, .timeout = 1); +TestSuite(parser, .timeout = 10); Test(parser, empty_string) {