Skip to content

Commit

Permalink
Merge pull request #64 from ErwannLesech/fix_imports
Browse files Browse the repository at this point in the history
Fix imports relative to src dependent + increase timeout in unit tests + clang
  • Loading branch information
ErwannLesech authored Jan 18, 2024
2 parents 7fd4f09 + bf585ea commit 4963915
Show file tree
Hide file tree
Showing 28 changed files with 71 additions and 69 deletions.
9 changes: 5 additions & 4 deletions src/ast/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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";
}
Expand All @@ -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);
}
2 changes: 1 addition & 1 deletion src/execute/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 2 additions & 3 deletions src/execute/ast_eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
#include <sys/wait.h>
#include <unistd.h>

#include "../options/options.h"
#include "../parser/parser.h"
#include "builtin.h"
#include "parser/parser.h"

// true = 0
// false = 1
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/execute/ast_eval.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

#include <stdbool.h>

#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
Expand Down
10 changes: 5 additions & 5 deletions src/execute/ast_variable.c
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand All @@ -74,7 +75,6 @@ char *handle_word(struct ast_node *node)
{
return get_variable(node->value);
}
//IMPOSSIBLE
// IMPOSSIBLE
return NULL;

}
3 changes: 2 additions & 1 deletion src/execute/builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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])))
Expand Down
2 changes: 1 addition & 1 deletion src/execute/loop.c
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/execute/pipeline.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <sys/wait.h>
#include <unistd.h>

#include "../ast/ast.h"
#include "ast/ast.h"
#include "ast_eval.h"

int pipeline_eval(struct ast_node *node, bool logger_enabled)
Expand Down
10 changes: 5 additions & 5 deletions src/execute/redirections.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "../ast/ast.h"
#include "ast_eval.h"

#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>

#include "ast/ast.h"
#include "ast_eval.h"

int redir_output(struct ast_node *node, bool logger_enabled)
{
Expand Down
10 changes: 5 additions & 5 deletions src/execute/tests/exec_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
#include <criterion/redirect.h>
#include <string.h>

#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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/io_backend/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/io_backend/tests/io_backend_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#include <criterion/redirect.h>
#include <string.h>

#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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/lexer/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 9 additions & 6 deletions src/lexer/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lexer/lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include <stdbool.h>
#include <stddef.h>

#include "options/options.h"
#include "token.h"
#include "../options/options.h"

/**
* \struct lexer
Expand Down
2 changes: 1 addition & 1 deletion src/lexer/lexer_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
15 changes: 7 additions & 8 deletions src/lexer/tests/lexer2_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#include <fnmatch.h>
#include <string.h>

#include "../lexer.h"
#include "lexer/lexer.h"

TestSuite(lexer2, .timeout = 1);
TestSuite(lexer2, .timeout = 10);

Test(lexer2, token_and)
{
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -1038,15 +1038,15 @@ 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);
cr_assert_eq(tok.type, TOKEN_WORD);
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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1105,4 +1105,3 @@ Test (lexer2, personalized_variable2)

lexer_free(lexer);
}

4 changes: 2 additions & 2 deletions src/lexer/tests/lexer_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#include <criterion/redirect.h>
#include <string.h>

#include "../lexer.h"
#include "lexer/lexer.h"

TestSuite(lexer, .timeout = 1);
TestSuite(lexer, .timeout = 10);

Test(lexer, lexer_new_and_free)
{
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/options/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions src/options/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
#include <string.h>
#include <unistd.h>

#include "../ast/ast.h"

int is_number(char *str)
{
int i = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/options/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <stdbool.h>
#include <stdio.h>

#include "../ast/ast.h"
#include "ast/ast.h"

/**
* \brief Enum for the different logger steps.
Expand Down Expand Up @@ -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 */
4 changes: 2 additions & 2 deletions src/options/tests/options_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#include <criterion/redirect.h>
#include <string.h>

#include "../options.h"
#include "options/options.h"

TestSuite(options, .timeout = 1);
TestSuite(options, .timeout = 10);

Test(options, last_arg_logger)
{
Expand Down
2 changes: 1 addition & 1 deletion src/parser/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/parser/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "parser.h"

#include "../execute/ast_eval.h"
#include "execute/ast_eval.h"

/*
input =
Expand Down
Loading

0 comments on commit 4963915

Please sign in to comment.