fixed export with multiple variable definitions and exit long long exit code overflows
This commit is contained in:
BIN
minishell_bonus
Executable file
BIN
minishell_bonus
Executable file
Binary file not shown.
13
srcs/exit.c
13
srcs/exit.c
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/07 16:04:11 by tomoron #+# #+# */
|
/* Created: 2024/02/07 16:04:11 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/04/25 13:51:19 by tomoron ### ########.fr */
|
/* Updated: 2024/04/25 18:08:21 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -20,12 +20,21 @@ void numeric_arg_err(char *arg, int *exit_code)
|
|||||||
*exit_code = 2;
|
*exit_code = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int is_too_big(char *num_str)
|
||||||
|
{
|
||||||
|
if ((strlen(num_str) == 19 && strcmp(num_str, "9223372036854775807") > 0)
|
||||||
|
|| (strlen(num_str) == 20 && num_str[0] == '-'
|
||||||
|
&& strcmp(num_str, "-9223372036854775808") > 0) || strlen(num_str) > 20)
|
||||||
|
return 1;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
void get_exit_bt_return_code(t_msh *msh, int *exit_code)
|
void get_exit_bt_return_code(t_msh *msh, int *exit_code)
|
||||||
{
|
{
|
||||||
t_token *cur_cmd;
|
t_token *cur_cmd;
|
||||||
|
|
||||||
cur_cmd = msh->tokens->next;
|
cur_cmd = msh->tokens->next;
|
||||||
if (cur_cmd && (!ft_strisnbr(cur_cmd->value) || ft_strlen(cur_cmd->value) > 18))
|
if (cur_cmd && (!ft_strisnbr(cur_cmd->value) || is_too_big(cur_cmd->value)))
|
||||||
numeric_arg_err(cur_cmd->value, exit_code);
|
numeric_arg_err(cur_cmd->value, exit_code);
|
||||||
else if (cur_cmd)
|
else if (cur_cmd)
|
||||||
*exit_code = (unsigned char)ft_atoi(cur_cmd->value);
|
*exit_code = (unsigned char)ft_atoi(cur_cmd->value);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/18 18:29:20 by marde-vr #+# #+# */
|
/* Created: 2024/02/18 18:29:20 by marde-vr #+# #+# */
|
||||||
/* Updated: 2024/04/24 14:41:01 by tomoron ### ########.fr */
|
/* Updated: 2024/04/25 18:19:39 by marde-vr ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -61,20 +61,16 @@ t_env *export_set_env(t_env *env, char *name, char *value, int append)
|
|||||||
return (set_env(env, name, value, append));
|
return (set_env(env, name, value, append));
|
||||||
}
|
}
|
||||||
|
|
||||||
int ft_export(t_msh *msh, t_token *cmd, t_env *env)
|
int export_var(t_token *cmd, t_env *env)
|
||||||
{
|
{
|
||||||
char *arg;
|
char *arg;
|
||||||
char *name;
|
char *name;
|
||||||
char *value;
|
char *value;
|
||||||
int len;
|
int len;
|
||||||
int append;
|
int append;
|
||||||
|
|
||||||
if (cmd && !cmd->next)
|
|
||||||
print_env_declare(msh, env);
|
|
||||||
if (cmd && cmd->next && !cmd->next->next)
|
|
||||||
{
|
|
||||||
arg = cmd->next->value;
|
|
||||||
len = 0;
|
len = 0;
|
||||||
|
|
||||||
|
arg = cmd->value;
|
||||||
while (arg[len] && arg[len] != '=' && arg[len] != '+')
|
while (arg[len] && arg[len] != '=' && arg[len] != '+')
|
||||||
len++;
|
len++;
|
||||||
name = ft_substr(arg, 0, len);
|
name = ft_substr(arg, 0, len);
|
||||||
@ -85,10 +81,28 @@ int ft_export(t_msh *msh, t_token *cmd, t_env *env)
|
|||||||
return (export_invalid_identifier(arg, name));
|
return (export_invalid_identifier(arg, name));
|
||||||
value = ft_strdup(arg + len);
|
value = ft_strdup(arg + len);
|
||||||
env = export_set_env(env, name, value, append);
|
env = export_set_env(env, name, value, append);
|
||||||
}
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ft_export(t_msh *msh, t_token *cmd, t_env *env)
|
||||||
|
{
|
||||||
|
int error;
|
||||||
|
|
||||||
|
if (cmd && !cmd->next)
|
||||||
|
print_env_declare(msh, env);
|
||||||
|
cmd = cmd->next;
|
||||||
|
while (cmd->next)
|
||||||
|
//if (cmd && cmd->next && !cmd->next->next)
|
||||||
|
{
|
||||||
|
if (export_var(cmd, env))
|
||||||
|
error = 1;
|
||||||
|
cmd = cmd->next;
|
||||||
|
}
|
||||||
|
if (export_var(cmd, env))
|
||||||
|
error = 1;
|
||||||
|
return (error);
|
||||||
|
}
|
||||||
|
|
||||||
int ft_unset(t_msh *msh)
|
int ft_unset(t_msh *msh)
|
||||||
{
|
{
|
||||||
t_token *cmd;
|
t_token *cmd;
|
||||||
|
21
todo_list
21
todo_list
@ -1,5 +1,26 @@
|
|||||||
|
exit with positive and negative 18/19 digits
|
||||||
|
check error codes
|
||||||
|
Export multiple variables
|
||||||
|
./tester os_specific
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Open file descriptor with cat << eof | ls open fd and infinte loop
|
||||||
|
Cat makefile | (echo yes && rev) leaks
|
||||||
|
echo yes && echo yes && car dhdgdgjsk || echo no leaks
|
||||||
|
echo abc && echo def | cat | rev && echo yes
|
||||||
|
(), ((())), (())
|
||||||
|
export leaks
|
||||||
|
|
||||||
|
fix broken tests from tester
|
||||||
|
|
||||||
|
|
||||||
To test:
|
To test:
|
||||||
|
|
||||||
|
|
||||||
|
ctrl backslash in middle of line
|
||||||
|
ctrl c on character we are ln with cursor, not end of line
|
||||||
|
|
||||||
test signals
|
test signals
|
||||||
test and verify all malocs
|
test and verify all malocs
|
||||||
verify forbidden functions
|
verify forbidden functions
|
||||||
|
Reference in New Issue
Block a user