diff --git a/include/minishell.h b/include/minishell.h index 3871d2b..2b73e61 100644 --- a/include/minishell.h +++ b/include/minishell.h @@ -6,7 +6,11 @@ /* By: mmoussou >>>>>> e1ba625 (「🏗️」 wip: testing things, might broke.) /* */ /* ************************************************************************** */ @@ -26,5 +30,6 @@ char set_env(char **env, const char *name, char *content); char *get_hostname(void); char *get_prompt(void); char *get_pwd(void); +bool is_str(char *src, char *dst); #endif diff --git a/include/minishell.h.orig b/include/minishell.h.orig new file mode 100644 index 0000000..2b73e61 --- /dev/null +++ b/include/minishell.h.orig @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* minishell.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: mmoussou >>>>>> e1ba625 (「🏗️」 wip: testing things, might broke.) +/* */ +/* ************************************************************************** */ + +#ifndef MINISHELL_H +# define MINISHELL_H + +# include +# include +# include +# include +# include "libft.h" + +# include "parsing.h" +# include "execution.h" + +char set_env(char **env, const char *name, char *content); +char *get_hostname(void); +char *get_prompt(void); +char *get_pwd(void); +bool is_str(char *src, char *dst); + +#endif diff --git a/include/parsing.h b/include/parsing.h index 0768c87..327d8cc 100644 --- a/include/parsing.h +++ b/include/parsing.h @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/25 12:20:26 by adjoly #+# #+# */ -/* Updated: 2024/04/25 14:30:50 by adjoly ### ########.fr */ +/* Updated: 2024/05/04 13:54:02 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,4 +19,11 @@ typedef struct s_cmd char **argv; } t_cmd; +typedef struct s_parsing +{ + +} t_parsing; + +t_cmd split_cmd(char *cmd_av); + #endif diff --git a/src/is_str.c b/src/is_str.c new file mode 100644 index 0000000..109ec70 --- /dev/null +++ b/src/is_str.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* is_str.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/03 10:23:40 by adjoly #+# #+# */ +/* Updated: 2024/05/03 10:23:55 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +bool is_str(char *src, char *dst) +{ + while (*src && *dst && *src == *dst) + { + src++; + dst++; + } + if (*dst) + return (false); + return (true); +} diff --git a/src/main.c b/src/main.c index eda7de3..5ba8dd4 100644 --- a/src/main.c +++ b/src/main.c @@ -6,28 +6,25 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/24 11:18:04 by adjoly #+# #+# */ -/* Updated: 2024/05/02 15:53:21 by adjoly ### ########.fr */ +/* Updated: 2024/05/04 15:33:54 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #include #include -#include #include #include #include #include "minishell.h" -bool is_str(char *src, char *dst) +void print_cmd(t_cmd cmd) { - while (*src && *dst && *src == *dst) + ft_putendl_fd(cmd.cmd, 1); + while (*(cmd.argv)) { - src++; - dst++; + ft_putendl_fd(*(cmd.argv), 1); + (cmd.argv)++; } - if (*dst) - return (false); - return (true); } int main(int ac, char **av, char **env) @@ -35,6 +32,7 @@ int main(int ac, char **av, char **env) char *test; char **lll; char *prompt; + t_cmd *cmd; (void)ac; (void)av; @@ -50,7 +48,11 @@ int main(int ac, char **av, char **env) continue; if (is_str(test, "exit")) break; + cmd = ft_calloc(sizeof(t_cmd), 1); + *cmd = split_cmd(test); + print_cmd(*cmd); + ft_free("a", &lll); } - //ft_free("a", &lll); + ft_free("a", &lll); return (0); } diff --git a/src/parsing/split_cmd.c b/src/parsing/split_cmd.c new file mode 100644 index 0000000..b88eb69 --- /dev/null +++ b/src/parsing/split_cmd.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* split_cmd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/04 15:00:32 by adjoly #+# #+# */ +/* Updated: 2024/05/04 15:20:29 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "parsing.h" +#include "libft.h" + +t_cmd split_cmd(char *cmd_av) +{ + char **split; + char **tmp_split; + t_cmd cmd; + + split = ft_split(cmd_av, 32); + tmp_split = split; + cmd.cmd = ft_strdup(*tmp_split); + cmd.argv = tmp_split; + return (cmd); +} diff --git a/src/prompt/get_hostname.c b/src/prompt/get_hostname.c index dd70044..6ed0e70 100644 --- a/src/prompt/get_hostname.c +++ b/src/prompt/get_hostname.c @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/02 10:36:31 by adjoly #+# #+# */ -/* Updated: 2024/05/02 13:42:24 by adjoly ### ########.fr */ +/* Updated: 2024/05/03 10:32:07 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,7 +29,7 @@ char *get_hostname(void) free(buf); return (buf); } - hostname = ft_calloc(delimiter - buf, sizeof(char)); + hostname = ft_calloc(delimiter - buf + 1, sizeof(char)); ft_strlcpy(hostname, buf, delimiter - buf + 1); free(buf); return (hostname);