From 59ce849e26a10df00800dce9b76fbc7c243b3916 Mon Sep 17 00:00:00 2001 From: tomoron Date: Wed, 24 Apr 2024 16:29:00 +0200 Subject: [PATCH 1/4] swp --- srcs/.lst_token.c.swp | Bin 12288 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 srcs/.lst_token.c.swp diff --git a/srcs/.lst_token.c.swp b/srcs/.lst_token.c.swp deleted file mode 100644 index bbfb795e564e737d36bb4bf3e39a4fb7297ff6b8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2KWG#|6vm&iaidX5AcfT=2l4(Sw|AF|#*GG15fucRSXg*$?&i#yz1^_87ZZb| zP&;c23wyP&6vSE-1i`}ELc~I`5Ul-ncV=@Z!30gCya~U|?97{Q-uw2h2$}iP7&qVd%ovJE5B`(Ge?WnitS$WI*x41V$soA9$uZ$2=p0#n4+a+by>hEJ(*O1HT@aP7u~YZ&A9%`sTVk%MP#uTR6}On-kLm zG+8OfU-iuBh!`52+hP+hvjgk^JHQUG1MC1hzz(nj?7;uzK)AGv)=^NODr#EwyMF1_ zBX{foJHQUG1MC1hzz(nj>;OB!4zL6406XvxI$$@5KJOv=Xdrp~|6l+8|MURSRWJZv z>?c|ThrsIrq7`r$yx&K37u*4D;DDoG3XFjvFbIC^CHf9Nf_LC8cmy7Td*BAR4z7T6 zpbUlqfp7gpU%?mf3cLi*!87mx+z0F6I%t9m;4H|4VK4}GgCD5xJNN{mT0aAB>;OB! z4zL6406V}A{I3q&BEy$q$9F}xl$#*~&qjQqQk)PaJR7)@DYNlRv>dM|0TZ*XTnTkp z9G6_hOrn$Jc+VR4wVEQC7h_{0mQw-0XfE4MNA`$nxp?KbdPxKsI4?aeM{A_6h#L8* z7M)|#i+oZVQI`>Ewe^ngOE*j_^<@xwpr(;!PXLx~EVLXcvOUu|>e>)XM;h96NJce9 z`HrYmuog_rY9r#ldqx()SW%;Y#+fYQFN?i+f s-45Tbq*btzP&G(8Ex28ko;b_Wk{Cq|tA8cfqpltj!5#ae;7e!HPf}y8ng9R* From 52174b8737b7a4b3bb5f06e8661d048a759530ab Mon Sep 17 00:00:00 2001 From: tomoron Date: Wed, 24 Apr 2024 18:11:37 +0200 Subject: [PATCH 2/4] Fuck it, YOLO! --- srcs/lst_token.c | 6 +++--- srcs/minishell.h | 8 ++++---- srcs/parsing.c | 28 +++++++++++++++------------- srcs/parsing_var.c | 5 +++-- srcs/path.c | 9 ++++++--- srcs/wildcards.c | 18 +++++++++--------- todo_list | 2 ++ 7 files changed, 42 insertions(+), 34 deletions(-) diff --git a/srcs/lst_token.c b/srcs/lst_token.c index 0cbc6ff..0f76319 100755 --- a/srcs/lst_token.c +++ b/srcs/lst_token.c @@ -6,18 +6,18 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/06 20:46:19 by tomoron #+# #+# */ -/* Updated: 2024/04/24 15:36:12 by tomoron ### ########.fr */ +/* Updated: 2024/04/24 18:04:15 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -t_token *token_add_back(t_token *token, char *value) +t_token *token_add_back(t_token *token, char *value, int is_var) { t_token *res; t_token *current; - if (/*value && !*value*/0) + if (value && !*value && is_var) { free(value); return (token); diff --git a/srcs/minishell.h b/srcs/minishell.h index 440a861..e009638 100755 --- a/srcs/minishell.h +++ b/srcs/minishell.h @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */ -/* Updated: 2024/04/24 15:17:35 by tomoron ### ########.fr */ +/* Updated: 2024/04/24 18:08:01 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -81,15 +81,15 @@ extern int g_return_code; t_cmd *cmd_add_back(t_cmd *res, char *cmd, t_cmd_type type); t_env *export_set_env(t_env *env, char *name, char *value, int append); void *here_doc_variables(int write, void *data); -int add_var_to_str(char *res, char **command, t_env *env); +int add_var_to_str(char *res, char **command, t_env *env, int *is_var); void find_cmd_path(t_msh *msh, char **paths, int *found); t_env *env_add_back(t_env *env, char *name, char *value); t_token *parse_cmds_to_token(t_cmd *command, t_env *env); void exec_command_bonus(t_msh *msh, char *cmd_str); t_token *add_token_back(t_token *res, t_token *next); -t_token *expand_wildcards(t_token *res, char *value); +t_token *expand_wildcards(t_token *res, char *value, int is_var); int cmd_is_builtin(t_msh *msh, char *cmd_token); -t_token *token_add_back(t_token *res, char *token); +t_token *token_add_back(t_token *res, char *token, int is_var); void child(t_msh *msh, char **cmd_args, int i); t_token *parse_tokens(char *command, t_env *env); void parent(t_msh *msh, int i, int cmd_count, char **cmd_args); diff --git a/srcs/parsing.c b/srcs/parsing.c index 9d5f43b..ff7d70d 100755 --- a/srcs/parsing.c +++ b/srcs/parsing.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/09 15:26:01 by tomoron #+# #+# */ -/* Updated: 2024/04/23 13:32:17 by tomoron ### ########.fr */ +/* Updated: 2024/04/24 18:08:42 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" @@ -31,7 +31,7 @@ int add_home_to_str(char *res) return (i); } -char *get_token(char **cmd, int *in_quote, int *in_dquote, t_env *env) +char *get_token(char **cmd, int *quotes[2], t_env *env, int *is_var) { char *res; int i; @@ -40,17 +40,17 @@ char *get_token(char **cmd, int *in_quote, int *in_dquote, t_env *env) while (ft_isspace(**cmd)) (*cmd)++; res = ft_calloc(get_token_len(*cmd, env) + 1, 1); - while (res && **cmd && (is_cmd_char(**cmd) || *in_quote || *in_dquote)) + while (res && **cmd && (is_cmd_char(**cmd) || *(quotes[0]) || *(quotes[1]))) { - if (**cmd == '"' && !*in_quote) - *in_dquote = !*in_dquote; - if (**cmd == '\'' && !*in_dquote) - *in_quote = !*in_quote; - if (**cmd == '$' && !*in_quote) - i += add_var_to_str(res + i, cmd, env); - else if (**cmd == '~' && !*in_quote && !*in_dquote) + if (**cmd == '"' && !*(quotes[0])) + *(quotes[1]) = !*(quotes[1]); + if (**cmd == '\'' && !*(quotes[1])) + *(quotes[0]) = !*(quotes[0]); + if (**cmd == '$' && !*(quotes[0])) + i += add_var_to_str(res + i, cmd, env, is_var); + else if (**cmd == '~' && !*(quotes[0]) && !*(quotes[1])) i += add_home_to_str(res + i); - else if (((**cmd == '\'' && *in_dquote) || (**cmd == '"' && *in_quote)) + else if (((**cmd == '\'' && *(quotes[1])) || (**cmd == '"' && *(quotes[0]))) || (**cmd != '\'' && **cmd != '"')) res[i++] = **cmd; (*cmd)++; @@ -64,16 +64,18 @@ t_token *parse_tokens(char *command, t_env *env) int in_dquote; t_token *res; char *value; + int is_var; in_quote = 0; in_dquote = 0; res = 0; + is_var = 0; while (command && *command) { - value = get_token(&command, &in_quote, &in_dquote, env); + value = get_token(&command, (int *[2]){&in_quote, &in_dquote}, env, &is_var); if (!value) return (free_token(res)); - res = expand_wildcards(res, value); + res = expand_wildcards(res, value, is_var); while (ft_isspace(*command)) command++; } diff --git a/srcs/parsing_var.c b/srcs/parsing_var.c index 736ef5e..386ef5e 100755 --- a/srcs/parsing_var.c +++ b/srcs/parsing_var.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/09 15:24:36 by tomoron #+# #+# */ -/* Updated: 2024/04/22 19:28:28 by marde-vr ### ########.fr */ +/* Updated: 2024/04/24 17:59:47 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -79,7 +79,7 @@ int invalid_variable_char(char *res, char c) return (2); } -int add_var_to_str(char *res, char **command, t_env *env) +int add_var_to_str(char *res, char **command, t_env *env, int *is_var) { char *var_name; char *var; @@ -87,6 +87,7 @@ int add_var_to_str(char *res, char **command, t_env *env) i = 0; (*command)++; + *is_var = 1; if (**command == '\'' || **command == '"' || !**command) { *res = '$'; diff --git a/srcs/path.c b/srcs/path.c index f65070a..90f1c4c 100755 --- a/srcs/path.c +++ b/srcs/path.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/21 21:47:15 by marde-vr #+# #+# */ -/* Updated: 2024/04/23 16:41:42 by tomoron ### ########.fr */ +/* Updated: 2024/04/24 17:48:14 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -60,7 +60,7 @@ void get_path(t_msh *msh, int *found) char **paths; paths = split_paths_from_env(msh->env); - if (!paths) + if (!paths || !*(msh->tokens->value)) { free_paths(paths); return ; @@ -94,7 +94,10 @@ void get_cmd_path(t_msh *msh) get_path(msh, &found); if (!found) { - ft_printf_fd(2, "%s: command not found\n", msh->tokens->value); + if(!*(msh->tokens->value)) + ft_printf_fd(2, "'': command not found\n"); + else + ft_printf_fd(2, "%s: command not found\n", msh->tokens->value); free(msh->tokens->value); msh->tokens->value = 0; g_return_code = 127; diff --git a/srcs/wildcards.c b/srcs/wildcards.c index d8c1df3..d884fc9 100644 --- a/srcs/wildcards.c +++ b/srcs/wildcards.c @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/15 12:53:29 by tomoron #+# #+# */ -/* Updated: 2024/04/22 19:28:13 by marde-vr ### ########.fr */ +/* Updated: 2024/04/24 18:02:49 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" @@ -33,7 +33,7 @@ int filename_corresponds(char *wildcard, char *value) return (!*wildcard && !*value); } -t_token *get_all_files(DIR *dir, char *wildcard) +t_token *get_all_files(DIR *dir, char *wildcard, int is_var) { struct dirent *content; t_token *res; @@ -43,7 +43,7 @@ t_token *get_all_files(DIR *dir, char *wildcard) while (content) { if (filename_corresponds(wildcard, content->d_name)) - res = token_add_back(res, ft_strdup(content->d_name)); + res = token_add_back(res, ft_strdup(content->d_name), is_var); content = readdir(dir); } return (res); @@ -62,25 +62,25 @@ t_token *add_token_back(t_token *res, t_token *next) return (start); } -t_token *expand_wildcards(t_token *res, char *value) +t_token *expand_wildcards(t_token *res, char *value, int is_var) { DIR *dir; char *cwd; t_token *new; if (!ft_strchr(value, '*')) - return (token_add_back(res, value)); + return (token_add_back(res, value, is_var)); cwd = getcwd(NULL, 100000); if (!cwd) - return (token_add_back(res, value)); + return (token_add_back(res, value, is_var)); dir = opendir(cwd); free(cwd); if (!dir) - return (token_add_back(res, value)); - new = get_all_files(dir, value); + return (token_add_back(res, value, is_var)); + new = get_all_files(dir, value, is_var); closedir(dir); if (!new) - return (token_add_back(res, value)); + return (token_add_back(res, value, is_var)); free(value); sort_wildcards_token(new); res = add_token_back(res, new); diff --git a/todo_list b/todo_list index 6bccdce..029c8cd 100644 --- a/todo_list +++ b/todo_list @@ -18,3 +18,5 @@ test signals test and verify all malocs verify forbidden functions check for any hidden or useless files + +return code 0 quand liste token est a 0 From 93e4d43283f5d5a899f61b1210f366525602dc92 Mon Sep 17 00:00:00 2001 From: mdev9 Date: Wed, 24 Apr 2024 18:42:59 +0200 Subject: [PATCH 3/4] fixed echo and updated todo_list --- srcs/echo.c | 4 ++-- todo_list | 9 --------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/srcs/echo.c b/srcs/echo.c index ad4c7b2..1aa8a3f 100755 --- a/srcs/echo.c +++ b/srcs/echo.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/07 15:30:37 by tomoron #+# #+# */ -/* Updated: 2024/04/18 20:48:52 by marde-vr ### ########.fr */ +/* Updated: 2024/04/24 14:52:21 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,7 +39,7 @@ int echo(t_token *args) { while (args->value[i] == 'n') i++; - if (!args->value[i]) + if (!args->value[i] && i > 1) put_nl = 0; else ft_printf("%s ", args->value); diff --git a/todo_list b/todo_list index 029c8cd..9495302 100644 --- a/todo_list +++ b/todo_list @@ -1,17 +1,8 @@ -cat Date: Wed, 24 Apr 2024 19:07:28 +0200 Subject: [PATCH 4/4] updated todo_list --- srcs/check_syntax_utils.c | 4 ++-- srcs/exec_bonus.c | 5 ++++- srcs/utils_bonus.c | 4 ++-- todo_list | 7 ------- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/srcs/check_syntax_utils.c b/srcs/check_syntax_utils.c index 8c6fd38..32cf586 100644 --- a/srcs/check_syntax_utils.c +++ b/srcs/check_syntax_utils.c @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/24 14:54:53 by tomoron #+# #+# */ -/* Updated: 2024/04/24 14:55:56 by tomoron ### ########.fr */ +/* Updated: 2024/04/24 18:57:48 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,7 +38,7 @@ int check_tokens_syntax(t_cmd *cmd, t_cmd *last, t_env *env) return (0); } token = parse_cmds_to_token(cmd, env); - if (!token) + if (token == (void *)1) return (0); free_token(token); return (1); diff --git a/srcs/exec_bonus.c b/srcs/exec_bonus.c index 4d83a4b..24e0c80 100755 --- a/srcs/exec_bonus.c +++ b/srcs/exec_bonus.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */ -/* Updated: 2024/04/24 15:22:20 by tomoron ### ########.fr */ +/* Updated: 2024/04/24 18:55:58 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -116,7 +116,10 @@ void exec_commands(t_msh *msh) int i; if (!msh->tokens && !is_parenthesis(msh->cmds)) + { + g_return_code = 0; return ; + } cmd_count = get_cmd_count(msh->cmds); msh->fds = ft_calloc(cmd_count + 1, sizeof(int **)); msh->pids = ft_calloc(cmd_count, sizeof(int *)); diff --git a/srcs/utils_bonus.c b/srcs/utils_bonus.c index 34a3e5e..73e8101 100755 --- a/srcs/utils_bonus.c +++ b/srcs/utils_bonus.c @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/27 17:19:27 by tomoron #+# #+# */ -/* Updated: 2024/04/18 20:49:00 by marde-vr ### ########.fr */ +/* Updated: 2024/04/24 18:59:26 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,7 @@ t_token *parsing_syntax_error(t_token *res) { free_token(res); ft_putstr_fd("minishell: syntax error\n", 2); - return (0); + return ((void *)1); } int is_input_type(t_cmd *cmd) diff --git a/todo_list b/todo_list index 9495302..9d6f4ef 100644 --- a/todo_list +++ b/todo_list @@ -1,13 +1,6 @@ -#invalid command, followed by empty variable, should clear the exit code -doesntexist -$EMPTY -echo $? - To test: test signals test and verify all malocs verify forbidden functions check for any hidden or useless files - -return code 0 quand liste token est a 0