🔨」 fix: if folder crash

This commit is contained in:
2024-07-14 15:39:28 +02:00
parent 4739d6b6f9
commit fe0285a5b2
17 changed files with 119 additions and 18 deletions

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/22 13:05:18 by adjoly #+# #+# */
/* Updated: 2024/07/13 16:10:38 by mmoussou ### ########.fr */
/* Updated: 2024/07/14 14:18:50 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -29,6 +29,8 @@ void ft_env(t_env *env);
void ft_unset(char *arg, t_env *env);
void ft_exit(char **argv, int ac);
char **env_get_list(t_env *env);
void add_to_env(char *name, char *content, t_env *env);
void ft_export(char **args, t_env *env);

View File

@ -43,5 +43,6 @@ t_env **get_env(t_env **env);
t_list **get_list(t_list **list);
t_list **get_list2(t_list **list);
int get_exit_code(int in);
size_t ft_arrlen(char **a);
#endif

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/25 12:20:26 by adjoly #+# #+# */
/* Updated: 2024/07/13 16:35:57 by adjoly ### ########.fr */
/* Updated: 2024/07/14 13:45:22 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */

33
src/builtins/ft_exit.c Normal file
View File

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_exit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/14 13:46:57 by adjoly #+# #+# */
/* Updated: 2024/07/14 14:24:47 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void ft_exit(char **argv, int ac)
{
char **tmp;
char *tmp_arg;
(void)tmp;
(void)tmp_arg;
(void)argv;
(void)ac;
exit(727);
// if (ac > 2)
// exit
// while (*tmp)
// {
//
// tmp++;
// }
}

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/01 14:55:06 by mmoussou #+# #+# */
/* Updated: 2024/07/10 14:11:59 by adjoly ### ########.fr */
/* Updated: 2024/07/14 14:44:18 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -35,7 +35,7 @@ void exec_cmd(char *cmd, char **argv, char **env, t_env *env_t)
if (i == 7)
ft_env(env_t);
if (i == 1)
exit(ft_atoi(argv[1]));
ft_exit(argv, ft_arrlen(argv));
}
else
execve(cmd, argv, env);
@ -73,7 +73,7 @@ int exec_single_cmd(t_cmd *cmd, char **env, t_env *env_t, int pipe_fd[2])
if (exec.status == -1 || !input || (access(cmd->cmd, X_OK) \
&& !is_in_builtins(cmd->cmd)))
{
printf("minishell : command not found: %s\n", input);
printf("minishell : command not found: %s$\n", input);
free(input);
return (-1);
}

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/03 10:50:52 by mmoussou #+# #+# */
/* Updated: 2024/07/13 13:19:34 by adjoly ### ########.fr */
/* Updated: 2024/07/14 14:19:30 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/24 11:18:04 by adjoly #+# #+# */
/* Updated: 2024/07/13 18:51:03 by adjoly ### ########.fr */
/* Updated: 2024/07/14 15:37:11 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,6 +20,7 @@ void sig_c(int code)
rl_on_new_line();
rl_replace_line("", 0);
rl_redisplay();
get_exit_code(0);
}
bool run_checks(char *rl)
@ -50,30 +51,34 @@ int main(int ac, char **av, char **env)
get_env(&env_l);
if (!env_l)
return (EXIT_FAILURE);
get_exit_code(12);
get_exit_code(727);
while (1)
{
signal(SIGINT, &sig_c);
signal(SIGQUIT, SIG_IGN);
prompt = get_prompt(env_l);
rl = readline(prompt);
free(prompt);
if (!rl)
{
get_exit_code(0);
break ;
}
if (run_checks(rl))
{
free(rl);
continue ;
}
add_history(rl);
rl = env_var_replace(rl, env_l);
piped = tokenizer(rl);
get_list(&piped);
if (check_argv(piped))
{
free(rl);
ft_lstclear(&piped, &free_token);
continue ;
}
add_history(rl);
cmd_list = get_cmd_list(piped);
free(rl);
ft_lstclear(&piped, &free_token);
@ -96,5 +101,5 @@ int main(int ac, char **av, char **env)
free(rl);
rl_clear_history();
ft_envclear(&env_l, free);
return (727);
return (get_exit_code(-1));
}

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/03 16:34:19 by adjoly #+# #+# */
/* Updated: 2024/07/03 19:07:23 by adjoly ### ########.fr */
/* Updated: 2024/07/14 15:34:16 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,6 +14,17 @@
#include "parsing.h"
#include "error_msg.h"
bool check_file_name(t_list *redir)
{
while (redir)
{
if (!((t_redirection *)redir->content)->file_name)
return (true);
redir = redir->next;
}
return (false);
}
bool check_argv(t_list *token)
{
t_list *tmp;
@ -23,6 +34,8 @@ bool check_argv(t_list *token)
{
if (!((t_token *)tmp->content)->argv)
return (send_error_parsing(ERROR_NO_CMD));
if (check_file_name(((t_token *)tmp->content)->redirection))
return (send_error_parsing(ERROR_NO_FILE));
tmp = tmp->next;
}
return (false);

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/05 21:14:04 by adjoly #+# #+# */
/* Updated: 2024/07/13 18:48:16 by adjoly ### ########.fr */
/* Updated: 2024/07/14 14:50:44 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,11 +16,29 @@
#include "minishell.h"
#include "env.h"
char *__rep_quote(char *dollar)
{
char *tmp;
tmp = dollar;
if (!tmp)
return (NULL);
while (*tmp)
{
if (*tmp == DOUBLE)
*tmp = -2;
else if (*tmp == SINGLE)
*tmp = -1;
tmp++;
}
return (dollar);
}
void __cpy_dollar(char *tmp, size_t dollar_size, t_env *env, char **rl_dlrd)
{
char *dollar;
dollar = env_getn_value(tmp, env, dollar_size - 1);
dollar = __rep_quote(env_getn_value(tmp, env, dollar_size - 2));
if (!dollar)
{
tmp += dollar_size;
@ -28,6 +46,7 @@ void __cpy_dollar(char *tmp, size_t dollar_size, t_env *env, char **rl_dlrd)
}
ft_strlcat(*rl_dlrd, dollar, \
ft_strlen(dollar) + ft_strlen(*rl_dlrd) + 1);
free(dollar);
}
size_t strlen_till_notalnum(char *s)

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/30 10:48:41 by adjoly #+# #+# */
/* Updated: 2024/07/13 14:05:27 by adjoly ### ########.fr */
/* Updated: 2024/07/14 15:11:26 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/30 15:56:53 by adjoly #+# #+# */
/* Updated: 2024/07/13 13:47:38 by adjoly ### ########.fr */
/* Updated: 2024/07/14 15:19:48 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */

View File

@ -6,12 +6,13 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/25 15:06:15 by adjoly #+# #+# */
/* Updated: 2024/07/10 00:21:08 by adjoly ### ########.fr */
/* Updated: 2024/07/14 15:20:08 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "tokenizer.h"
#include <stdio.h>
t_redirection *__to_redir(char *redir_s)
{
t_redirection *redir;
@ -27,6 +28,8 @@ t_redirection *__to_redir(char *redir_s)
while (*redir_s && *redir_s == ' ')
redir_s++;
tmp = redir_s;
if (*tmp == '/' || *tmp == '.')
return (redir);
if (!ft_isalnum(*tmp))
return (redir);
while (*tmp && ft_isalnum(*tmp))

23
src/utils/ft_arrlen.c Normal file
View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_arrlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/14 13:52:08 by adjoly #+# #+# */
/* Updated: 2024/07/14 14:25:27 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
size_t ft_arrlen(char **a)
{
char **tmp;
tmp = a;
while (*tmp)
tmp++;
return (tmp - a);
}

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/09 17:24:15 by adjoly #+# #+# */
/* Updated: 2024/07/13 14:09:08 by adjoly ### ########.fr */
/* Updated: 2024/07/14 13:59:14 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
@ -44,6 +44,8 @@ int get_exit_code(int in)
{
static int exit_code;
if (in == 727)
exit_code = 727;
if (in != -1)
exit_code = in % 256;
if (exit_code < 0)