This commit is contained in:
mdev9
2024-04-26 10:54:32 +02:00
parent 40a5533c5f
commit c3a0786da1
10 changed files with 52 additions and 42 deletions

View File

@ -6,7 +6,7 @@
# By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ # # By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2023/07/28 00:35:01 by tomoron #+# #+# # # Created: 2023/07/28 00:35:01 by tomoron #+# #+# #
# Updated: 2024/04/24 14:58:52 by tomoron ### ########.fr # # Updated: 2024/04/26 10:52:53 by marde-vr ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -45,6 +45,7 @@ SRCS_RAW = main.c\
get_len_bonus.c\ get_len_bonus.c\
check_syntax.c\ check_syntax.c\
check_syntax_utils.c\ check_syntax_utils.c\
unset.c\
free.c free.c
OBJS_DIR = objs/ OBJS_DIR = objs/

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */ /* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */
/* Updated: 2024/04/26 10:34:15 by tomoron ### ########.fr */ /* Updated: 2024/04/26 10:53:49 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -73,7 +73,7 @@ int exec(t_msh *msh, char **cmd_args, int i, int cmd_count)
void exec_command(t_msh *msh, int i, int cmd_count) void exec_command(t_msh *msh, int i, int cmd_count)
{ {
g_return_code = 0; g_return_code = 0;
if(msh->out_fd != -1 && msh->in_fd != -1) if (msh->out_fd != -1 && msh->in_fd != -1)
{ {
msh->fds[i] = ft_calloc(2, sizeof(int *)); msh->fds[i] = ft_calloc(2, sizeof(int *));
if (!msh->fds[i]) if (!msh->fds[i])
@ -111,7 +111,6 @@ void end_execution(t_msh *msh, int cmd_count)
free(msh->fds); free(msh->fds);
signal(SIGINT, signal_handler_interactive); signal(SIGINT, signal_handler_interactive);
signal(SIGQUIT, signal_handler_interactive); signal(SIGQUIT, signal_handler_interactive);
//set_echoctl(0);
} }
void exec_commands(t_msh *msh) void exec_commands(t_msh *msh)

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 18:08:21 by marde-vr ### ########.fr */ /* Updated: 2024/04/26 10:49:17 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -23,9 +23,9 @@ void numeric_arg_err(char *arg, int *exit_code)
int is_too_big(char *num_str) int is_too_big(char *num_str)
{ {
if ((strlen(num_str) == 19 && strcmp(num_str, "9223372036854775807") > 0) if ((strlen(num_str) == 19 && strcmp(num_str, "9223372036854775807") > 0)
|| (strlen(num_str) == 20 && num_str[0] == '-' || (strlen(num_str) == 20 && num_str[0] == '-' && strcmp(num_str,
&& strcmp(num_str, "-9223372036854775808") > 0) || strlen(num_str) > 20) "-9223372036854775808") > 0) || strlen(num_str) > 20)
return 1; return (1);
return (0); return (0);
} }
@ -54,7 +54,6 @@ int exit_bt(t_msh *msh)
else else
{ {
get_exit_bt_return_code(msh, &exit_code); get_exit_bt_return_code(msh, &exit_code);
//set_echoctl(msh->echoctl);
free_msh(msh); free_msh(msh);
exit(exit_code); exit(exit_code);
} }

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/26 10:29:05 by tomoron ### ########.fr */ /* Updated: 2024/04/26 10:52:17 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -68,8 +68,8 @@ int export_var(t_token *cmd, t_env *env)
char *value; char *value;
int len; int len;
int append; int append;
len = 0;
len = 0;
arg = cmd->value; arg = cmd->value;
while (arg[len] && arg[len] != '=' && arg[len] != '+') while (arg[len] && arg[len] != '=' && arg[len] != '+')
len++; len++;
@ -105,18 +105,3 @@ int ft_export(t_msh *msh, t_token *cmd, t_env *env)
error = 1; error = 1;
return (error); return (error);
} }
int ft_unset(t_msh *msh)
{
t_token *cmd;
cmd = msh->tokens;
if (cmd)
cmd = cmd->next;
while (cmd)
{
delete_from_env(msh, cmd->value);
cmd = cmd->next;
}
return (0);
}

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */ /* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */
/* Updated: 2024/04/26 10:24:46 by tomoron ### ########.fr */ /* Updated: 2024/04/26 10:53:31 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -82,7 +82,7 @@ t_env *add_shlvl(t_env *env)
else else
nb = ft_atoi(tmp); nb = ft_atoi(tmp);
nb++; nb++;
if(nb < 0) if (nb < 0)
nb = 0; nb = 0;
env = export_set_env(env, ft_strdup("SHLVL"), ft_itoa(nb), 0); env = export_set_env(env, ft_strdup("SHLVL"), ft_itoa(nb), 0);
return (env); return (env);

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 18:17:25 by marde-vr #+# #+# */ /* Created: 2024/03/05 18:17:25 by marde-vr #+# #+# */
/* Updated: 2024/04/25 13:26:52 by tomoron ### ########.fr */ /* Updated: 2024/04/26 10:49:45 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -73,7 +73,6 @@ void execute_command(t_msh *msh, char **cmd_args)
env = env_to_char_tab(msh->env); env = env_to_char_tab(msh->env);
if (env) if (env)
{ {
//set_echoctl(msh->echoctl);
if (execve(msh->tokens->value, cmd_args, env)) if (execve(msh->tokens->value, cmd_args, env))
perror("execve"); perror("execve");
} }

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/22 14:31:13 by tomoron #+# #+# */ /* Created: 2024/03/22 14:31:13 by tomoron #+# #+# */
/* Updated: 2024/04/25 18:39:18 by tomoron ### ########.fr */ /* Updated: 2024/04/26 10:54:13 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -44,7 +44,7 @@ void signal_handler_here_doc(int signum)
msh = here_doc_variables(0, 0); msh = here_doc_variables(0, 0);
rl_on_new_line(); rl_on_new_line();
printf("\n"); printf("\n");
if(msh->in_fd > 2) if (msh->in_fd > 2)
close(msh->in_fd); close(msh->in_fd);
ft_exit(msh, 1); ft_exit(msh, 1);
} }
@ -52,11 +52,11 @@ void signal_handler_here_doc(int signum)
int set_echoctl(int value) int set_echoctl(int value)
{ {
printf("nope");
(void)value;
/*
struct termios t_p; struct termios t_p;
printf("nope");
(void)value;
/*
if (!isatty(1)) if (!isatty(1))
return (0); return (0);
if (tcgetattr(1, &t_p)) if (tcgetattr(1, &t_p))
@ -71,7 +71,7 @@ int set_echoctl(int value)
return (1); return (1);
return (0); return (0);
*/ */
return(0); return (0);
} }
void signal_handler_command(int signum) void signal_handler_command(int signum)

28
srcs/unset.c Normal file
View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* unset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/26 10:52:20 by marde-vr #+# #+# */
/* Updated: 2024/04/26 10:52:28 by marde-vr ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int ft_unset(t_msh *msh)
{
t_token *cmd;
cmd = msh->tokens;
if (cmd)
cmd = cmd->next;
while (cmd)
{
delete_from_env(msh, cmd->value);
cmd = cmd->next;
}
return (0);
}

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 18:19:26 by marde-vr #+# #+# */ /* Created: 2024/03/05 18:19:26 by marde-vr #+# #+# */
/* Updated: 2024/04/25 13:44:14 by tomoron ### ########.fr */ /* Updated: 2024/04/26 10:53:29 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,7 +14,6 @@
void ft_exit(t_msh *msh, int exit_code) void ft_exit(t_msh *msh, int exit_code)
{ {
//set_echoctl(msh->echoctl);
free_msh(msh); free_msh(msh);
exit(exit_code); exit(exit_code);
} }

View File

@ -6,7 +6,7 @@
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */ /* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/15 12:53:29 by tomoron #+# #+# */ /* Created: 2024/04/15 12:53:29 by tomoron #+# #+# */
/* Updated: 2024/04/25 10:35:48 by tomoron ### ########.fr */ /* Updated: 2024/04/26 10:49:36 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
@ -19,7 +19,7 @@ int filename_corresponds(char *wildcard, char *value)
{ {
if (*wildcard == '*') if (*wildcard == '*')
{ {
while(*wildcard == '*' && wildcard[1] == '*') while (*wildcard == '*' && wildcard[1] == '*')
wildcard++; wildcard++;
if (!wildcard[1]) if (!wildcard[1])
return (1); return (1);