This commit is contained in:
mcolonna 2024-06-27 15:55:32 +02:00
commit 7c92b7fe56
5 changed files with 50 additions and 6 deletions

View file

@ -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

View file

@ -6,7 +6,7 @@
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -6,7 +6,7 @@
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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
);
}
@ -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);

37
src/echo_builtin.c Normal file
View file

@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* echo_builtin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -6,7 +6,7 @@
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);