Compare commits

...

4 Commits

Author SHA1 Message Date
tvdu29
de2a6e77d7 Delete norm.txt 2020-01-29 13:26:49 +01:00
tvdu29
64bd25ae09 Merge pull request #1 from tvdu29/dev2
corrected env -i crash & SHLVL
2020-01-28 13:42:43 +01:00
tvdu29
ce15b661f3 Merge branch 'dev' into dev2 2020-01-28 13:42:03 +01:00
Tanguy Maze
25c4b28f4c corrected env -i crash & SHLVL 2020-01-28 13:38:25 +01:00
8 changed files with 70 additions and 28 deletions

View File

@@ -6,7 +6,7 @@
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/03/27 16:51:02 by tmaze #+# #+# #
# Updated: 2020/01/25 18:03:28 by tmaze ### ########.fr #
# Updated: 2020/01/26 22:21:26 by tmaze ### ########.fr #
# #
#******************************************************************************#
@@ -43,7 +43,8 @@ SRC = main.c \
cmd_cd.c \
cmd_echo.c \
ms_exec.c \
ms_ext.c
ms_ext.c \
put_error_cd.c
OBJ = $(SRC:.c=.o)

View File

@@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/18 13:12:34 by tmaze #+# #+# */
/* Updated: 2020/01/25 15:06:00 by tmaze ### ########.fr */
/* Updated: 2020/01/26 22:19:25 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
@@ -36,4 +36,6 @@ char **res_ext(char **argv, t_env *env);
int exec_cmd(char **argv, t_env **env);
void *ft_strdel_null(char **s);
void *put_error_cd(char *file, char *msg);
#endif

View File

@@ -17,7 +17,7 @@ char *ft_envtochar(t_env *env)
int size;
char *ret;
size = ft_strlen(env->key) + ft_strlen(env->val) + 1;
size = ft_strlen(env->key) + ft_strlen(env->val) + 2;
if ((ret = ft_strnew(size)) != NULL)
{
ft_strlcpy(ret, env->key, size);

View File

@@ -1,16 +0,0 @@
Norme: ./srcs/main.c
Error (line 38): function main has 49 lines
Error (line 38, col 0): main has 6 variables
--
Norme: ./srcs/cmd_cd.c
Error: 7 functions in the file
Error (line 120): function cmd_cd has 33 lines
--
Norme: ./srcs/ms_exec.c
Error: 6 functions in the file
Error (line 59): function check_path_dot has 26 lines
Error (line 89): function check_path has 51 lines
Error (line 144): function exec_cmd has 30 lines
--
Norme: ./srcs/ms_ext.c
Error: 6 functions in the file

View File

@@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/07 16:44:40 by tmaze #+# #+# */
/* Updated: 2020/01/25 17:00:23 by tmaze ### ########.fr */
/* Updated: 2020/01/26 22:17:48 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */

View File

@@ -12,6 +12,33 @@
#include "minishell.h"
t_env *def_env(void)
{
t_env *ret;
t_env *n;
char p[PATH_MAX];
n = ft_memalloc(sizeof(t_env));
if (n != NULL && ((n->key = ft_strnew(3)) == NULL || !getcwd(p, PATH_MAX)))
ft_envdelelem(&n);
if (n != NULL)
ft_strcpy(n->key, "PWD");
if (n != NULL && (n->val = ft_strdup(p)) == NULL)
ft_envdelelem(&n);
if (n != NULL)
ft_envaddend(&ret, n);
n = ft_memalloc(sizeof(t_env));
if (n != NULL && (n->key = ft_strnew(5)) == NULL)
ft_envdelelem(&n);
if (n != NULL)
ft_strcpy(n->key, "SHLVL");
if (n != NULL && (n->val = ft_strdup("1")) == NULL)
ft_envdelelem(&n);
if (n != NULL)
ft_envaddend(&ret, n);
return (ret);
}
t_env *env2lst(char **env)
{
t_env *ret;
@@ -23,15 +50,21 @@ t_env *env2lst(char **env)
while (env[i])
{
if ((new = ft_envnew(env[i])) != NULL)
ft_envaddend(&ret, new);
{
if (ft_strequ(new->key, "SHLVL") && ft_str_is_numeric(new->val))
new->val = ft_itoa(ft_atoi(new->val) + 1);
ft_envaddend(&ret, new);
}
else
{
ft_envdelelem(&new);
ft_envdel(&ret);
return (NULL);
ft_envdelelem(&new);
ft_envdel(&ret);
return (NULL);
}
i++;
}
if (i == 0 && ret == NULL && (ret = def_env()) == NULL)
ft_printf("Env: Memory Error\n");
return (ret);
}

View File

@@ -157,9 +157,9 @@ void exec_cmd_child(char *path, char **argv, char **env_tab, t_env **env)
int exec_cmd(char **argv, t_env **env)
{
int ret;
char **env_tab;
char *path;
int ret;
char **env_tab;
char *path;
if ((env_tab = ft_envtotab(*env)) == NULL)
return (-1);

22
srcs/put_error_cd.c Normal file
View File

@@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* put_error_cd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/01/26 22:18:09 by tmaze #+# #+# */
/* Updated: 2020/01/26 22:18:24 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void *put_error_cd(char *file, char *msg)
{
ft_putstr("cd: ");
ft_putstr(file);
ft_putstr(": ");
ft_putendl(msg);
return (NULL);
}