diff --git a/Minishell.mk b/Minishell.mk index 597a0e09..2fce1588 100644 --- a/Minishell.mk +++ b/Minishell.mk @@ -6,7 +6,7 @@ # By: maiboyer +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2024/04/28 17:28:30 by maiboyer #+# #+# # -# Updated: 2024/05/01 10:34:21 by maiboyer ### ########.fr # +# Updated: 2024/05/02 15:14:11 by maiboyer ### ########.fr # # # # **************************************************************************** # @@ -55,7 +55,7 @@ END = \033[0m all: @$(MAKE) -C ./stdme/ LIB_NAME="$(shell realpath ./stdme)/" "BUILD_DIR=$(shell realpath ./$(OBJDIRNAME))" CC=$(CC) libme.a - @$(MAKE) -C ./parser/ LIB_NAME="$(shell realpath ./parser)/" "BUILD_DIR=$(shell realpath ./$(OBJDIRNAME))" libgmr.a + @$(MAKE) -C ./parser/ LIB_NAME="$(shell realpath ./parser)/" -j "BUILD_DIR=$(shell realpath ./$(OBJDIRNAME))" libgmr.a @$(MAKE) -f./Minishell.mk $(NAME) # Bonus (make bonus) diff --git a/includes/app/node/handle_concat.h b/includes/app/node/handle_concat.h new file mode 100644 index 00000000..174ed05c --- /dev/null +++ b/includes/app/node/handle_concat.h @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* handle_concat.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: maiboyer +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/02 15:49:12 by maiboyer #+# #+# */ +/* Updated: 2024/05/02 15:52:16 by maiboyer ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef HANDLE_CONCAT_H +#define HANDLE_CONCAT_H + +#include "app/state.h" +#include "app/node.h" +#include "me/types.h" + +t_error handle_concat(t_node *self, t_utils *shcat, t_str *ret); + +#endif /* HANDLE_CONCAT_H */ diff --git a/includes/app/node/handle_raw_word.h b/includes/app/node/handle_raw_word.h new file mode 100644 index 00000000..5ece8af0 --- /dev/null +++ b/includes/app/node/handle_raw_word.h @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* handle_raw_word.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: maiboyer +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/02 15:58:01 by maiboyer #+# #+# */ +/* Updated: 2024/05/02 15:58:48 by maiboyer ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef HANDLE_RAW_WORD_H +#define HANDLE_RAW_WORD_H + +#include "app/node.h" +#include "app/state.h" + +t_error handle_raw_string(t_node *self, t_utils *shcat, t_str *ret); + +#endif /* HANDLE_RAW_WORD_H */ diff --git a/includes/app/node/handle_word.h b/includes/app/node/handle_word.h new file mode 100644 index 00000000..7b418966 --- /dev/null +++ b/includes/app/node/handle_word.h @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* handle_word.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: maiboyer +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/02 16:00:11 by maiboyer #+# #+# */ +/* Updated: 2024/05/02 16:00:40 by maiboyer ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef HANDLE_WORD_H +#define HANDLE_WORD_H + +#include "app/state.h" +#include "app/node.h" +#include "me/types.h" + +t_error handle_word(t_node *self, t_utils *shcat, t_str *ret); + +#endif /* HANDLE_WORD_H */ diff --git a/includes/app/state.h b/includes/app/state.h new file mode 100644 index 00000000..96e465bb --- /dev/null +++ b/includes/app/state.h @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* state.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: maiboyer +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/02 15:49:56 by maiboyer #+# #+# */ +/* Updated: 2024/05/02 15:51:38 by maiboyer ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef STATE_H +#define STATE_H + +#include "app/node.h" +#include "me/types.h" + +typedef struct s_parser +{ + t_first_parser *parser; +} t_parser; + +typedef struct s_utils +{ + t_str name_shell; + t_str str_input; + t_str *strs_input; + t_str *path; + t_str *envp; + t_parser parser; + t_node current_node; +} t_utils; + +#endif /* STATE_H */ diff --git a/includes/minishell.h b/includes/minishell.h index 9238fda0..aa22bae0 100644 --- a/includes/minishell.h +++ b/includes/minishell.h @@ -6,57 +6,41 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/28 14:41:15 by rparodi #+# #+# */ -/* Updated: 2024/04/30 16:41:57 by maiboyer ### ########.fr */ +/* Updated: 2024/05/02 15:51:57 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef MINISHELL_H #define MINISHELL_H -# include "me/types.h" -# include "app/node.h" +#include "app/node.h" +#include "app/state.h" +#include "me/types.h" -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -# define PATH_FILES "/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games" - -typedef struct s_parser -{ - t_first_parser *parser; -} t_parser; - -typedef struct s_utils -{ - t_str name_shell; - t_str str_input; - t_str *strs_input; - t_str *path; - t_str *envp; - t_parser parser; - t_node current_node; -} t_utils; +#define PATH_FILES "/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games" t_i32 main(t_i32 argc, t_str argv[], t_str arge[]); void ft_other_cmd(t_utils *shcat, t_usize i, t_usize prev_i); t_i32 ft_strcmp(const char *s1, const char *s2); t_i32 ft_check_type_operators(t_str operators); -t_str *ft_split(t_const_str s, t_i8 c); +t_str *ft_split(t_const_str s, t_i8 c); t_str ft_strdup(t_const_str s); -char *ft_strjoin(char const *s1, char const *s2); -void *ft_calloc(t_usize nmemb, t_usize size); +char *ft_strjoin(char const *s1, char const *s2); +void *ft_calloc(t_usize nmemb, t_usize size); size_t ft_strlen(t_const_str s); -t_usize ft_strlcpy(t_str dst, t_const_str src, t_usize size); -void *ft_memset(void *s, t_i32 c, t_usize n); +t_usize ft_strlcpy(t_str dst, t_const_str src, t_usize size); +void *ft_memset(void *s, t_i32 c, t_usize n); void ft_bzero(void *s, t_usize n); void ft_free_strs(t_str *strs); void ft_pwd(void); diff --git a/sources/exec/handle_concat.c b/sources/exec/handle_concat.c new file mode 100644 index 00000000..ce4d5f1b --- /dev/null +++ b/sources/exec/handle_concat.c @@ -0,0 +1,52 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* handle_concat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: maiboyer +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/02 15:05:06 by maiboyer #+# #+# */ +/* Updated: 2024/05/02 16:01:52 by maiboyer ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "app/node/handle_concat.h" +#include "app/node.h" +#include "app/node/handle_raw_word.h" +#include "app/node/handle_word.h" +#include "app/state.h" +#include "gmr/symbols.h" +#include "me/buffered_str/buf_str.h" +#include "me/types.h" + +t_error node_get_string(t_node *self, t_utils *shcat, t_str *ret) +{ + if (self->kind == sym_word) + return (handle_word(self, shcat, ret)); + if (self->kind == sym_raw_string) + return (handle_raw_string(self, shcat, ret)); + return (ERROR); +} + +t_error handle_concat(t_node *self, t_utils *shcat, t_str *ret) +{ + t_buffer_str out; + t_usize i; + t_str tmp; + + (void)(shcat); + if (self == NULL || ret == NULL || self->kind != sym_concatenation) + return (ERROR); + out = alloc_new_buffer(16); + i = 0; + while (i < self->childs_count) + { + if (node_get_string(&self->childs[i], shcat, &tmp)) + return (str_free(out), ERROR); + push_str_buffer(&out, tmp); + free(tmp); + i++; + } + *ret = out.buf; + return (NO_ERROR); +} diff --git a/sources/exec/handle_raw_word.c b/sources/exec/handle_raw_word.c new file mode 100644 index 00000000..ad93ca50 --- /dev/null +++ b/sources/exec/handle_raw_word.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* handle_raw_word.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: maiboyer +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/02 15:57:33 by maiboyer #+# #+# */ +/* Updated: 2024/05/02 16:03:09 by maiboyer ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "app/node/handle_raw_word.h" +#include "app/node.h" +#include "app/state.h" +#include "gmr/symbols.h" +#include "me/string/str_len.h" +#include "me/string/str_substring.h" +#include "me/types.h" + +t_error handle_raw_string(t_node *self, t_utils *shcat, t_str *ret) +{ + t_str tmp; + t_usize i; + + (void)(shcat); + if (self == NULL || ret == NULL || self->kind != sym_raw_string) + return (ERROR); + tmp = node_getstr(self); + i = str_len(tmp); + *ret = str_substring(tmp, 1, i - 2); + return (NO_ERROR); +} diff --git a/sources/exec/handle_word.c b/sources/exec/handle_word.c new file mode 100644 index 00000000..2b8f2c6b --- /dev/null +++ b/sources/exec/handle_word.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* handle_word.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: maiboyer +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/02 15:59:04 by maiboyer #+# #+# */ +/* Updated: 2024/05/02 16:00:00 by maiboyer ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "app/node/handle_word.h" +#include "app/state.h" +#include "gmr/symbols.h" +#include "me/string/str_clone.h" +#include "me/types.h" + +t_error handle_word(t_node *self, t_utils *shcat, t_str *ret) +{ + (void)(shcat); + if (self == NULL || ret == NULL || self->kind != sym_word) + return (ERROR); + *ret = str_clone(node_getstr(self)); + return (NO_ERROR); +} diff --git a/sources/main.c b/sources/main.c index f2b8df4d..33740396 100644 --- a/sources/main.c +++ b/sources/main.c @@ -6,13 +6,14 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */ -/* Updated: 2024/05/02 14:18:02 by maiboyer ### ########.fr */ +/* Updated: 2024/05/02 15:26:55 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #include "../includes/minishell.h" #include "app/node.h" #include "app/signal_handler.h" +#include "gmr/symbols.h" #include "me/string/str_len.h" #include "parser/api.h" @@ -74,9 +75,30 @@ void ft_check(t_utils *shcat, char **input) } } +t_error handle_concat(t_node *self, t_utils* shcat, t_str *ret); + +void print_node_concat(t_node *self) +{ + if (self->kind != sym_concatenation) + { + t_usize i = 0; + while (i < self->childs_count) + print_node_concat(&self->childs[i++]); + } + else + { + t_str ret; + if (handle_concat(self, NULL, &ret)) + return ((void)printf("ERROR\n")); + printf("concat value = '%s'\n", ret); + free(ret); + } +} + void exec_shcat(t_utils *shcat) { print_node_data(&shcat->current_node, 0); + print_node_concat(&shcat->current_node); free_node(shcat->current_node); } diff --git a/src.list b/src.list index f0e11998..41fb1256 100644 --- a/src.list +++ b/src.list @@ -1,3 +1,6 @@ +exec/handle_concat.c +exec/handle_raw_word.c +exec/handle_word.c ft_cmd.c ft_echo.c ft_exit.c diff --git a/symbol_list b/symbol_list new file mode 100644 index 00000000..40c9c6bc --- /dev/null +++ b/symbol_list @@ -0,0 +1,110 @@ + sym_word = 1, + sym__special_character = 102, + sym_string_content = 104, + sym_raw_string = 105, + sym_ansi_c_string = 106, + sym_comment = 146, + sym__comment_word = 147, + sym_heredoc_start = 153, + sym_simple_heredoc_body = 154, + sym__heredoc_body_beginning = 155, + sym_heredoc_content = 156, + sym_heredoc_end = 157, + sym_file_descriptor = 158, + sym__empty_value = 159, + sym__concat = 160, + sym_variable_name = 161, + sym_test_operator = 162, + sym_regex = 163, + sym__regex_no_slash = 164, + sym__regex_no_space = 165, + sym__expansion_word = 166, + sym_extglob_pattern = 167, + sym__bare_dollar = 168, + sym__brace_start = 169, + sym__immediate_double_hash = 170, + sym__external_expansion_sym_hash = 171, + sym__external_expansion_sym_bang = 172, + sym__external_expansion_sym_equal = 173, + sym___error_recovery = 174, + sym_program = 175, + sym__statements = 176, + sym__statement_not_pipeline = 178, + sym_redirected_statement = 179, + sym_for_statement = 180, + sym_c_style_for_statement = 181, + sym__for_body = 182, + sym__c_expression = 183, + sym__c_expression_not_assignment = 184, + sym__c_variable_assignment = 185, + sym__c_unary_expression = 186, + sym__c_binary_expression = 187, + sym__c_postfix_expression = 188, + sym__c_parenthesized_expression = 189, + sym_while_statement = 190, + sym_do_group = 191, + sym_if_statement = 192, + sym_elif_clause = 193, + sym_else_clause = 194, + sym_case_statement = 195, + sym_case_item = 196, + sym_last_case_item = 197, + sym_function_definition = 198, + sym_compound_statement = 199, + sym_subshell = 200, + sym_pipeline = 201, + sym_list = 202, + sym_negated_command = 203, + sym_test_command = 204, + sym__test_command_binary_expression = 205, + sym_declaration_command = 206, + sym_unset_command = 207, + sym_command = 208, + sym_command_name = 209, + sym_variable_assignment = 210, + sym_variable_assignments = 211, + sym_subscript = 212, + sym_file_redirect = 213, + sym_heredoc_redirect = 214, + sym__heredoc_pipeline = 215, + sym__heredoc_expression = 216, + sym__heredoc_body = 218, + sym_heredoc_body = 219, + sym__simple_heredoc_body = 220, + sym_herestring_redirect = 221, + sym__expression = 222, + sym_binary_expression = 223, + sym_ternary_expression = 224, + sym_unary_expression = 225, + sym_postfix_expression = 226, + sym_parenthesized_expression = 227, + sym_arithmetic_expansion = 228, + sym_brace_expression = 229, + sym__arithmetic_expression = 230, + sym__arithmetic_literal = 231, + sym__arithmetic_binary_expression = 232, + sym__arithmetic_ternary_expression = 233, + sym__arithmetic_unary_expression = 234, + sym__arithmetic_postfix_expression = 235, + sym__arithmetic_parenthesized_expression = 236, + sym_concatenation = 237, + sym_string = 238, + sym_translated_string = 239, + sym_array = 240, + sym_number = 241, + sym_simple_expansion = 242, + sym_expansion = 243, + sym__expansion_body = 244, + sym__expansion_expression = 245, + sym__expansion_regex = 246, + sym__expansion_regex_replacement = 247, + sym__expansion_regex_removal = 248, + sym__expansion_max_length = 249, + sym__expansion_max_length_expression = 250, + sym__expansion_max_length_binary_expression = 251, + sym__expansion_operator = 252, + sym__concatenation_in_expansion = 253, + sym_command_substitution = 254, + sym_process_substitution = 255, + sym__extglob_blob = 256, + sym__c_terminator = 257,