Merge branch 'bonus' of github.com:mdev9/minishell into bonus

This commit is contained in:
2024-04-25 18:41:09 +02:00
4 changed files with 63 additions and 18 deletions

1
.gitignore vendored
View File

@ -4,6 +4,7 @@
minishell minishell
minishell_bonus
.minishellrc .minishellrc
objs/ objs/
.tmp* .tmp*

View File

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

View File

@ -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,32 +61,46 @@ 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;
len = 0;
arg = cmd->value;
while (arg[len] && arg[len] != '=' && arg[len] != '+')
len++;
name = ft_substr(arg, 0, len);
append = arg[len] == '+';
if (arg[len] == '=' || (arg[len] == '+' && arg[len + 1] == '='))
len += 1 + (arg[len] == '+');
if (!name || !check_var_name(name) || arg[len] == '+')
return (export_invalid_identifier(arg, name));
value = ft_strdup(arg + len);
env = export_set_env(env, name, value, append);
return (0);
}
int ft_export(t_msh *msh, t_token *cmd, t_env *env)
{
int error;
if (cmd && !cmd->next) if (cmd && !cmd->next)
print_env_declare(msh, env); print_env_declare(msh, env);
if (cmd && cmd->next && !cmd->next->next) cmd = cmd->next;
while (cmd->next)
//if (cmd && cmd->next && !cmd->next->next)
{ {
arg = cmd->next->value; if (export_var(cmd, env))
len = 0; error = 1;
while (arg[len] && arg[len] != '=' && arg[len] != '+') cmd = cmd->next;
len++;
name = ft_substr(arg, 0, len);
append = arg[len] == '+';
if (arg[len] == '=' || (arg[len] == '+' && arg[len + 1] == '='))
len += 1 + (arg[len] == '+');
if (!name || !check_var_name(name) || arg[len] == '+')
return (export_invalid_identifier(arg, name));
value = ft_strdup(arg + len);
env = export_set_env(env, name, value, append);
} }
return (0); if (export_var(cmd, env))
error = 1;
return (error);
} }
int ft_unset(t_msh *msh) int ft_unset(t_msh *msh)

View File

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