Clean-up: normed out files

This commit is contained in:
Tanguy MAZE 2019-10-17 11:04:04 +02:00
parent d22bc173f1
commit 85af14cd9f
7 changed files with 29 additions and 31 deletions

View File

@ -6,13 +6,13 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/20 14:42:42 by tmaze #+# #+# */ /* Created: 2019/09/20 14:42:42 by tmaze #+# #+# */
/* Updated: 2019/09/26 15:26:44 by tmaze ### ########.fr */ /* Updated: 2019/10/17 10:59:38 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
int cmd_cd(char** argv, t_env** env) int cmd_cd(char **argv, t_env **env)
{ {
(void)argv; (void)argv;
(void)env; (void)env;

View File

@ -6,13 +6,13 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/20 14:42:30 by tmaze #+# #+# */ /* Created: 2019/09/20 14:42:30 by tmaze #+# #+# */
/* Updated: 2019/09/26 15:26:53 by tmaze ### ########.fr */ /* Updated: 2019/10/17 10:58:52 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
int cmd_echo(char** argv, t_env** env) int cmd_echo(char **argv, t_env **env)
{ {
(void)argv; (void)argv;
(void)env; (void)env;

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/20 14:33:48 by tmaze #+# #+# */ /* Created: 2019/09/20 14:33:48 by tmaze #+# #+# */
/* Updated: 2019/10/10 13:49:33 by tmaze ### ########.fr */ /* Updated: 2019/10/17 10:07:21 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -39,7 +39,7 @@ t_env *envcpy(t_env *env)
return (cpy); return (cpy);
} }
int cmd_env(char** argv, t_env** env) int cmd_env(char **argv, t_env **env)
{ {
int i; int i;
t_env *it; t_env *it;
@ -48,7 +48,7 @@ int cmd_env(char** argv, t_env** env)
i = 1; i = 1;
env_cp = NULL; env_cp = NULL;
if (!ft_strequ(argv[i] , "-i") && (env != NULL)) if (!ft_strequ(argv[i], "-i") && (env != NULL))
{ {
it = *env; it = *env;
while (it) while (it)
@ -63,7 +63,7 @@ int cmd_env(char** argv, t_env** env)
it = it->next; it = it->next;
} }
} }
if (ft_strequ(argv[i] , "-i")) if (ft_strequ(argv[i], "-i"))
i++; i++;
if (argv[i]) if (argv[i])
exec_cmd(argv + i, &env_cp); exec_cmd(argv + i, &env_cp);

View File

@ -6,13 +6,13 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/20 14:41:08 by tmaze #+# #+# */ /* Created: 2019/09/20 14:41:08 by tmaze #+# #+# */
/* Updated: 2019/10/10 14:31:47 by tmaze ### ########.fr */ /* Updated: 2019/10/17 09:59:40 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
int cmd_setenv(char** argv, t_env** env) int cmd_setenv(char **argv, t_env **env)
{ {
t_env *new; t_env *new;
@ -20,10 +20,14 @@ int cmd_setenv(char** argv, t_env** env)
{ {
lstaddend(env, new); lstaddend(env, new);
return (0); return (0);
} else if (argv[1]) { }
else if (argv[1])
{
ft_printf("minishell: setenv: memory error\n"); ft_printf("minishell: setenv: memory error\n");
return (2); return (2);
} else { }
else
{
printf("usage: setenv [KEY]=[value]\n"); printf("usage: setenv [KEY]=[value]\n");
return (1); return (1);
} }

View File

@ -6,13 +6,13 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/20 14:42:01 by tmaze #+# #+# */ /* Created: 2019/09/20 14:42:01 by tmaze #+# #+# */
/* Updated: 2019/10/10 16:05:56 by tmaze ### ########.fr */ /* Updated: 2019/10/17 10:58:23 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
int cmd_unsetenv(char** argv, t_env** env) int cmd_unsetenv(char **argv, t_env **env)
{ {
t_env **it; t_env **it;
t_env *tmp; t_env *tmp;

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/20 11:43:53 by tmaze #+# #+# */ /* Created: 2019/09/20 11:43:53 by tmaze #+# #+# */
/* Updated: 2019/09/27 16:21:14 by tmaze ### ########.fr */ /* Updated: 2019/10/17 11:02:54 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/26 16:25:00 by tmaze #+# #+# */ /* Created: 2019/09/26 16:25:00 by tmaze #+# #+# */
/* Updated: 2019/10/10 14:05:31 by tmaze ### ########.fr */ /* Updated: 2019/10/17 11:01:38 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -96,19 +96,9 @@ char *check_path(char *exec, t_env *env)
if (exec) if (exec)
{ {
if (ft_isin(exec, '/') != -1 && ft_isin(exec, '.') == -1) if (ft_isin(exec, '/') != -1 && ft_isin(exec, '.') == -1)
{ return (check_path_slash(exec));
if ((ret = check_path_slash(exec)) != NULL)
return (ret);
else
return (NULL);
}
if (exec[0] == '.') if (exec[0] == '.')
{ return (check_path_dot(exec, env));
if ((ret = check_path_dot(exec, env)) != NULL)
return (ret);
else
return (NULL);
}
if ((path = lstgetelem("PATH", env)) == NULL if ((path = lstgetelem("PATH", env)) == NULL
|| path->val == NULL || path->val == NULL
|| (path_elems = ft_strsplit(path->val, ':')) == NULL) || (path_elems = ft_strsplit(path->val, ':')) == NULL)
@ -135,6 +125,9 @@ char *check_path(char *exec, t_env *env)
if (access(ret, X_OK) == 0) if (access(ret, X_OK) == 0)
break ; break ;
put_error(exec, "permission denied"); put_error(exec, "permission denied");
ft_strdel(&ret);
ft_del_words_tables(&path_elems);
return (NULL);
} }
ft_strdel(&ret); ft_strdel(&ret);
i++; i++;
@ -156,6 +149,7 @@ int exec_cmd(char **argv, t_env **env)
return (-1); return (-1);
if ((path = check_path(argv[0], *env)) == NULL) if ((path = check_path(argv[0], *env)) == NULL)
ft_del_words_tables(&env_tab); ft_del_words_tables(&env_tab);
ft_printf("path after resolve: %s\n", path);
if (path == NULL) if (path == NULL)
return (-1); return (-1);
if ((ret = fork()) == 0) if ((ret = fork()) == 0)