[FIX] export without arg
This commit is contained in:
parent
5b313a1f5c
commit
668bd06c17
4 changed files with 53 additions and 9 deletions
2
Makefile
2
Makefile
|
@ -5,7 +5,7 @@ SRCS = src/
|
||||||
# include directory
|
# include directory
|
||||||
INCLUDES = include/ libtf/ libft/
|
INCLUDES = include/ libtf/ libft/
|
||||||
# .c files in src/ without the extension
|
# .c files in src/ without the extension
|
||||||
CODE = main ask_command error path parse_command exec_command builtin builtin2\
|
CODE = main ask_command error path parse_command exec_command builtin builtin2 export_print\
|
||||||
signals cool_readline variables parse_command_utils \
|
signals cool_readline variables parse_command_utils \
|
||||||
parse_command_read_string parse_command_read_element variables_utils
|
parse_command_read_string parse_command_read_element variables_utils
|
||||||
# directories to 'make'
|
# directories to 'make'
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/23 14:15:12 by mcolonna #+# #+# */
|
/* Created: 2024/04/23 14:15:12 by mcolonna #+# #+# */
|
||||||
/* Updated: 2024/06/28 15:26:29 by mcolonna ### ########.fr */
|
/* Updated: 2024/07/03 18:59:22 by jschaft ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -27,6 +27,9 @@ int echo_builtin(t_env *env, t_call call);
|
||||||
// Execute cd builtin
|
// Execute cd builtin
|
||||||
int cd_builtin(t_env *env, t_call call);
|
int cd_builtin(t_env *env, t_call call);
|
||||||
|
|
||||||
|
//Execute builtin with no arguments
|
||||||
|
int export_print_builtin(char *const *envp);
|
||||||
|
|
||||||
// Execute export builtin
|
// Execute export builtin
|
||||||
int export_builtin(t_env *env, t_call call);
|
int export_builtin(t_env *env, t_call call);
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/06/03 12:02:45 by jschaft #+# #+# */
|
/* Created: 2024/06/03 12:02:45 by jschaft #+# #+# */
|
||||||
/* Updated: 2024/07/01 12:35:09 by jschaft ### ########.fr */
|
/* Updated: 2024/07/03 18:57:09 by jschaft ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -44,11 +44,7 @@ static int pwd_builtin(t_env *env, t_call call)
|
||||||
char *str;
|
char *str;
|
||||||
|
|
||||||
(void)env;
|
(void)env;
|
||||||
if (call.argv[1])
|
(void)call;
|
||||||
{
|
|
||||||
print_line(fatal_error, 2, "too many arguments");
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
str = getcwd(NULL, 0);
|
str = getcwd(NULL, 0);
|
||||||
printf("%s\n", str);
|
printf("%s\n", str);
|
||||||
free(str);
|
free(str);
|
||||||
|
@ -85,10 +81,13 @@ int exec_builtin(t_env *env, t_call call)
|
||||||
exit (cd_builtin(env, call));
|
exit (cd_builtin(env, call));
|
||||||
if (ft_strncmp(call.program, "exit", 5) == 0)
|
if (ft_strncmp(call.program, "exit", 5) == 0)
|
||||||
exit (exit_builtin(env, call));
|
exit (exit_builtin(env, call));
|
||||||
if (ft_strncmp(call.program, "export", 7) == 0)
|
if (ft_strncmp(call.program, "export", 7) == 0 && call.argc != 1)
|
||||||
exit (export_builtin(env, call));
|
exit (export_builtin(env, call));
|
||||||
if (ft_strncmp(call.program, "unset", 6) == 0)
|
if (ft_strncmp(call.program, "unset", 6) == 0)
|
||||||
exit (unset_builtin(env, call));
|
exit (unset_builtin(env, call));
|
||||||
|
if (ft_strncmp(call.program, "export", 6) == 0 && call.argc == 1)
|
||||||
|
exit (export_print_builtin(variables_envp(env->variables,
|
||||||
|
mem_subclass(fatal_error, env->mc_global))));
|
||||||
if (ft_strncmp(call.program, "pwd", 4) == 0)
|
if (ft_strncmp(call.program, "pwd", 4) == 0)
|
||||||
exit (pwd_builtin(env, call));
|
exit (pwd_builtin(env, call));
|
||||||
if (ft_strncmp(call.program, "echo", 5) == 0)
|
if (ft_strncmp(call.program, "echo", 5) == 0)
|
||||||
|
|
42
src/export_print.c
Normal file
42
src/export_print.c
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* export_print.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/07/03 18:57:19 by jschaft #+# #+# */
|
||||||
|
/* Updated: 2024/07/03 18:58:53 by jschaft ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "include.h"
|
||||||
|
|
||||||
|
int export_print_builtin(char *const *envp)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int i2;
|
||||||
|
|
||||||
|
i2 = 0;
|
||||||
|
i = 0;
|
||||||
|
while (envp[i])
|
||||||
|
{
|
||||||
|
printf("declare -x ");
|
||||||
|
while (envp[i][i2] != '=')
|
||||||
|
{
|
||||||
|
printf("%c", envp[i][i2]);
|
||||||
|
i2++;
|
||||||
|
}
|
||||||
|
printf("=\"");
|
||||||
|
i2++;
|
||||||
|
while (envp[i][i2])
|
||||||
|
{
|
||||||
|
printf("%c", envp[i][i2]);
|
||||||
|
i2++;
|
||||||
|
}
|
||||||
|
printf("\"\n");
|
||||||
|
i++;
|
||||||
|
i2++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue