From a4befa5fa60f450e83e06475af4513e0e033e949 Mon Sep 17 00:00:00 2001 From: Etienne Rey-bethbeder Date: Wed, 22 Feb 2023 13:24:35 +0100 Subject: [PATCH 1/3] Finito Echo --- builtins/echo.c | 80 ++++++++++++++----------------------------------- env3.c | 23 +++++++++++++- minishell.h | 3 +- 3 files changed, 46 insertions(+), 60 deletions(-) diff --git a/builtins/echo.c b/builtins/echo.c index 2c3bff4..641313d 100644 --- a/builtins/echo.c +++ b/builtins/echo.c @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/02/17 13:09:08 by erey-bet #+# #+# */ -/* Updated: 2023/02/21 23:31:04 by cchauvet ### ########.fr */ +/* Updated: 2023/02/22 13:23:16 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,80 +18,44 @@ int is_space(char c) || c == '\r' || c == '\n'); } -int check_argument(char *str, int *check, int i) +int check_argument(char *str, int *check) { - int y; - - y = 0; - if (str[i] == '-') - { - while (!is_space(str[i]) || (str[i + 1] == '-' )) - { - i++; - if (is_space(str[i])) - { - y = i; - *check = 1; - } - else if (str[i] == '-' && str[i - 1] != '-') - ; - else if (str[i] != 'n') - break ; - } - i = y; - while (is_space(str[i])) - i++; - } - return (i); -} - -char *conca(char **strs) -{ - int len; - char *str; - char *p; - int i; + int i; i = -1; - len = 0; - while (strs[++i] != NULL) - len += ft_strlen(strs[i]) + 2; - str = (char *) ft_calloc(len + 1, sizeof(char)); - if (str == NULL) - return NULL; - i = -1; - while (strs[++i] != NULL) - { - ft_strlcat(str, strs[i], ft_strlen(str) + ft_strlen(strs[i]) + 2); - if (strs[i + 1] != NULL) - str[ft_strlen(str)] = ' '; - } - str[ft_strlen(str)] = '\0'; - return (str); + while (str[++i]) + if (str[i] != '-' && str[i] != 'n') + return (1); + if (ft_strnstr(str, "n", ft_strlen(str))) + *check = 1; + return (0); } int echo(int fd, char **strs) { int check; int i; - char *str; - str = conca(strs); check = 0; - i = 0; - while (is_space(str[i])) - i++; - i = check_argument(str, &check, i); - while (str[i]) - ft_putchar_fd(str[i++], fd); + i = -1; + while (strs[++i]) + { + while (is_space(*strs[i])) + strs[i]++; + if (check == 1 || check_argument(strs[i], &check)) + { + ft_putstr_fd(strs[i], fd); + if (strs[i + 1] != NULL) + write(fd, " ", 1); + } + } if (!check) write(fd, "\n", 1); - free(str); return (0); } /*int main(int argc, char *argv[]) { - echo(1, argv); + echo(1, argv + 1); return (0); }*/ diff --git a/env3.c b/env3.c index 3c69c62..42b357e 100644 --- a/env3.c +++ b/env3.c @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/02/17 17:25:09 by erey-bet #+# #+# */ -/* Updated: 2023/02/21 14:09:42 by cchauvet ### ########.fr */ +/* Updated: 2023/02/22 01:41:04 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -61,3 +61,24 @@ int create_value_by_key_dup(char *key, char *value, t_list **env) return (1); return (0); } + +int delete_by_key(char *key, t_list **head) +{ + t_list *last; + t_list *current; + + current = *head; + while (current->next != NULL) + { + if (ft_strcmp(((t_env *)current->content)->key, key) == 0) + { + if (last->next != NULL) + last->next = current->next; + else + *head = current->next; + } + last = current; + current = current->next; + } + return (1); +} diff --git a/minishell.h b/minishell.h index 2485e11..416b30c 100644 --- a/minishell.h +++ b/minishell.h @@ -6,7 +6,7 @@ /* By: cchauvet Date: Wed, 22 Feb 2023 14:00:09 +0100 Subject: [PATCH 2/3] Bozo3 avance --- builtins/unset.c | 18 ++++++++++++++++++ env3.c | 5 +++-- 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 builtins/unset.c diff --git a/builtins/unset.c b/builtins/unset.c new file mode 100644 index 0000000..1de43be --- /dev/null +++ b/builtins/unset.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* unset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/22 13:28:27 by erey-bet #+# #+# */ +/* Updated: 2023/02/22 13:37:27 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int unset(t_list **env, char **args, int fd) +{ + while (args++) + delete_by_key(*args, env); + return (0); +} diff --git a/env3.c b/env3.c index 42b357e..bca6060 100644 --- a/env3.c +++ b/env3.c @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/02/17 17:25:09 by erey-bet #+# #+# */ -/* Updated: 2023/02/22 01:41:04 by erey-bet ### ########.fr */ +/* Updated: 2023/02/22 13:28:51 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -76,9 +76,10 @@ int delete_by_key(char *key, t_list **head) last->next = current->next; else *head = current->next; + return (1); } last = current; current = current->next; } - return (1); + return (0); } From 0661f2fbd12fc3a4f7fffd522bbaef127841080c Mon Sep 17 00:00:00 2001 From: Etienne Rey-bethbeder Date: Thu, 23 Feb 2023 13:36:26 +0100 Subject: [PATCH 3/3] =?UTF-8?q?Je=20suis=20tout=20dur=20fa=C3=A7e=20a=20Sa?= =?UTF-8?q?mantha?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- builtins/env.c | 11 ++++++++++- env.c | 15 +++++++++++++-- minishell.h | 4 ++-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/builtins/env.c b/builtins/env.c index 87a2b34..0ba0787 100644 --- a/builtins/env.c +++ b/builtins/env.c @@ -6,7 +6,7 @@ /* By: cchauvet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/02/02 14:39:56 by erey-bet #+# #+# */ -/* Updated: 2023/02/17 17:11:03 by erey-bet ### ########.fr */ +/* Updated: 2023/02/23 13:34:41 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,7 @@ void add_sort(t_list **head, t_env *var) current = *head; while (current->next != NULL - && ft_strcmp(var->key, ((t_env *)(current->content))->key) != 0) + && ft_strcmp(var->key, ((t_env *)(current->content))->key) > 0) current = current->next; if (current->content == NULL) current->content = var; @@ -108,3 +108,14 @@ t_list **init_env(char **env) } return (head); } + +/*int main(int argc, char *argv[], char **env) +{ + t_list **n_env; + + n_env = init_env(env); + delete_by_key("SSH_AUTH_SOCK", n_env); + print_env(n_env, 1); + + return (0); +}*/ diff --git a/minishell.h b/minishell.h index 416b30c..967a912 100644 --- a/minishell.h +++ b/minishell.h @@ -6,7 +6,7 @@ /* By: cchauvet