diff --git a/Makefile b/Makefile index fd2d6ee..3043eb3 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ INCLUDES = include/ libtf/ libft/ # .c files in src/ without the extension CODE = main ask_command error path parse_command exec_command builtin \ signals cool_readline variables parse_command_utils \ - parse_command_read_string parse_command_read_element + parse_command_read_string parse_command_read_element echo_builtin # directories to 'make' LIBRARIES = libtf libft # .a files to include diff --git a/include/builtins.h b/include/builtins.h index e73e5d2..afb69ad 100644 --- a/include/builtins.h +++ b/include/builtins.h @@ -6,7 +6,7 @@ /* By: jschaft +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/23 14:15:12 by mcolonna #+# #+# */ -/* Updated: 2024/06/25 13:28:18 by mcolonna ### ########.fr */ +/* Updated: 2024/06/27 15:54:05 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,4 +21,8 @@ bool is_builtin(const char *str); // Execute the builtin command int exec_builtin(t_call call, t_env *env); +// Execute echo builtin +int echo_builtin(const char **argv); + + #endif diff --git a/src/builtin.c b/src/builtin.c index a07b947..46676a4 100644 --- a/src/builtin.c +++ b/src/builtin.c @@ -6,7 +6,7 @@ /* By: jschaft +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/03 12:02:45 by jschaft #+# #+# */ -/* Updated: 2024/06/25 13:37:36 by mcolonna ### ########.fr */ +/* Updated: 2024/06/27 15:54:44 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ bool is_builtin(const char *str) // || ft_strncmp(str, "export", 7) == 0 || ft_strncmp(str, "env", 4) == 0 || ft_strncmp(str, "pwd", 4) == 0 -// || ft_strncmp(str, "echo", 5) == 0 + || ft_strncmp(str, "echo", 5) == 0 // || ft_strncmp(str, "unset", 6) == 0 ); } @@ -42,7 +42,7 @@ static int cd_builtin(const char *path) return (0); } -//Execute the builtin pwd for the current directory. +// Execute the builtin pwd for the current directory. // Return 0 for the sake of returning something for exec_builtin static int pwd_builtin(void) { @@ -83,6 +83,8 @@ int exec_builtin(t_call call, t_env *env) return (unset_builtin());*/ if (ft_strncmp(call.program, "pwd", 4) == 0) return (pwd_builtin()); + if (ft_strncmp(call.program, "echo", 5) == 0) + return (echo_builtin((const char **)call.argv)); if (ft_strncmp(call.program, "env", 4) == 0) return (env_builtin(env->envp)); return (1); diff --git a/src/echo_builtin.c b/src/echo_builtin.c new file mode 100644 index 0000000..f50d704 --- /dev/null +++ b/src/echo_builtin.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* echo_builtin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jschaft +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/06/25 13:28:29 by jschaft #+# #+# */ +/* Updated: 2024/06/27 15:51:09 by mcolonna ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "include.h" + +int echo_builtin(const char **argv) +{ + int i; + bool newline; + + i = 1; + newline = true; + if (argv[1] && str_eq(argv[1], "-n")) + { + newline = false; + i++; + } + while (argv[i] != NULL) + { + printf("%s", argv[i]); + if (argv[i + 1] != NULL) + printf(" "); + i++; + } + if (newline) + printf("\n"); + return (0); +} diff --git a/src/main.c b/src/main.c index 59e6700..e15e320 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: jschaft +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/23 14:33:45 by mcolonna #+# #+# */ -/* Updated: 2024/06/27 13:15:27 by mcolonna ### ########.fr */ +/* Updated: 2024/06/27 15:55:02 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ @@ -50,6 +50,7 @@ static int do_command(t_env *env, const char *str) static void start(t_env *env) { env->mc_command = mem_subclass(fatal_error, env->mc_global); + do_command(env, "clear"); do_command(env, "cat ./header"); do_command(env, "echo"); mem_freeall(env->mc_command);