Compare commits
6 Commits
4a534c8156
...
dev
Author | SHA1 | Date | |
---|---|---|---|
|
9a44444070 | ||
|
cd72d29c63 | ||
|
de2a6e77d7 | ||
|
64bd25ae09 | ||
|
ce15b661f3 | ||
|
25c4b28f4c |
5
Makefile
5
Makefile
@@ -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/30 12:00:42 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)
|
||||
|
||||
|
@@ -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,7 @@ 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);
|
||||
int put_error_cd2(char *file, char *msg);
|
||||
|
||||
#endif
|
||||
|
@@ -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);
|
||||
|
16
norm.txt
16
norm.txt
@@ -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
|
@@ -6,30 +6,12 @@
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
void *put_error_cd(char *file, char *msg)
|
||||
{
|
||||
ft_putstr("cd: ");
|
||||
ft_putstr(file);
|
||||
ft_putstr(": ");
|
||||
ft_putendl(msg);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
int put_error_cd2(char *file, char *msg)
|
||||
{
|
||||
ft_putstr("cd: ");
|
||||
ft_putstr(file);
|
||||
ft_putstr(": ");
|
||||
ft_putendl(msg);
|
||||
return (1);
|
||||
}
|
||||
|
||||
char *check_path_slash_cd(char *exec)
|
||||
{
|
||||
int i;
|
||||
|
@@ -6,7 +6,7 @@
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/09/20 14:33:48 by tmaze #+# #+# */
|
||||
/* Updated: 2019/12/09 09:59:58 by tmaze ### ########.fr */
|
||||
/* Updated: 2020/01/30 15:41:08 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -47,6 +47,24 @@ int env_cleanup(t_env *env_cp, int code)
|
||||
return (code);
|
||||
}
|
||||
|
||||
t_env *inline_env(char **argv, int *i, t_env **env_cp)
|
||||
{
|
||||
t_env *new;
|
||||
|
||||
while (ft_strchr(argv[*i], '='))
|
||||
{
|
||||
if ((new = ft_envnew(argv[*i])) == NULL)
|
||||
{
|
||||
ft_printf("env: memory error\n");
|
||||
ft_envdel(env_cp);
|
||||
break ;
|
||||
}
|
||||
ft_envaddend(env_cp, new);
|
||||
(*i)++;
|
||||
}
|
||||
return (*env_cp);
|
||||
}
|
||||
|
||||
int cmd_env(char **argv, t_env **env)
|
||||
{
|
||||
int i;
|
||||
@@ -55,8 +73,7 @@ int cmd_env(char **argv, t_env **env)
|
||||
t_env *env_cp;
|
||||
|
||||
i = 1;
|
||||
env_cp = NULL;
|
||||
if (!ft_strequ(argv[i], "-i") && (env != NULL))
|
||||
if (!(env_cp = NULL) && !ft_strequ(argv[i], "-i") && (env != NULL))
|
||||
{
|
||||
it = *env;
|
||||
while (it)
|
||||
@@ -67,8 +84,9 @@ int cmd_env(char **argv, t_env **env)
|
||||
it = it->next;
|
||||
}
|
||||
}
|
||||
if (ft_strequ(argv[i], "-i"))
|
||||
else if (ft_strequ(argv[i], "-i"))
|
||||
i++;
|
||||
inline_env(argv, &i, &env_cp);
|
||||
if (argv[i])
|
||||
exec_cmd(argv + i, &env_cp);
|
||||
else
|
||||
|
47
srcs/main.c
47
srcs/main.c
@@ -6,12 +6,51 @@
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/09/19 17:08:46 by tmaze #+# #+# */
|
||||
/* Updated: 2020/01/25 16:23:50 by tmaze ### ########.fr */
|
||||
/* Updated: 2020/01/30 13:47:35 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
char *inc_shlvl(char **shlvl)
|
||||
{
|
||||
char *ret;
|
||||
|
||||
if ((ret = ft_itoa(ft_atoi(*shlvl) + 1)) != NULL)
|
||||
{
|
||||
ft_strdel(shlvl);
|
||||
*shlvl = ret;
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
t_env *env2lst(char **env)
|
||||
{
|
||||
t_env *ret;
|
||||
@@ -23,7 +62,11 @@ t_env *env2lst(char **env)
|
||||
while (env[i])
|
||||
{
|
||||
if ((new = ft_envnew(env[i])) != NULL)
|
||||
{
|
||||
if (ft_strequ(new->key, "SHLVL") && ft_str_is_numeric(new->val))
|
||||
inc_shlvl(&new->val);
|
||||
ft_envaddend(&ret, new);
|
||||
}
|
||||
else
|
||||
{
|
||||
ft_envdelelem(&new);
|
||||
@@ -32,6 +75,8 @@ t_env *env2lst(char **env)
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (i == 0 && ret == NULL && (ret = def_env()) == NULL)
|
||||
ft_printf("Env: Memory Error\n");
|
||||
return (ret);
|
||||
}
|
||||
|
||||
|
@@ -6,7 +6,7 @@
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/09/26 16:25:00 by tmaze #+# #+# */
|
||||
/* Updated: 2020/01/25 16:46:29 by tmaze ### ########.fr */
|
||||
/* Updated: 2020/01/30 11:48:25 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -95,6 +95,7 @@ char *check_path_elems(char **path_elems, char *exec)
|
||||
char *ret;
|
||||
|
||||
i = -1;
|
||||
ret = NULL;
|
||||
while (path_elems[++i])
|
||||
{
|
||||
if ((tmp = ft_strjoin(path_elems[i], "/")) == NULL
|
||||
@@ -136,9 +137,10 @@ char *check_path(char *exec, t_env *env)
|
||||
return (put_error(exec, "could not resolve path"));
|
||||
i = 0;
|
||||
if ((ret = check_path_elems(path_elems, exec)) == NULL)
|
||||
return (NULL);
|
||||
if (path_elems[i] == NULL)
|
||||
put_error(exec, "command not found");
|
||||
{
|
||||
ft_del_words_tables(&path_elems);
|
||||
return (put_error(exec, "command not found"));
|
||||
}
|
||||
ft_del_words_tables(&path_elems);
|
||||
}
|
||||
return (ret);
|
||||
@@ -157,9 +159,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);
|
||||
|
@@ -6,7 +6,7 @@
|
||||
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/10/25 18:21:47 by tmaze #+# #+# */
|
||||
/* Updated: 2020/01/25 16:53:59 by tmaze ### ########.fr */
|
||||
/* Updated: 2020/01/30 15:42:17 by tmaze ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -57,9 +57,10 @@ char *replace_env(char *src, t_env *elem, int key_size, int i)
|
||||
int res_len;
|
||||
|
||||
res_len = ft_strlen(src) - key_size + ft_strlen(elem->val);
|
||||
ft_printf("size replace: %d\n", res_len);
|
||||
if ((ret = ft_strnew(res_len)) != NULL)
|
||||
{
|
||||
ft_strlcpy(ret, src, i + 1);
|
||||
ft_strncpy(ret, src, i);
|
||||
ft_strlcat(ret, elem->val, res_len + 1);
|
||||
ft_strlcat(ret, src + key_size, res_len + 1);
|
||||
}
|
||||
@@ -104,6 +105,9 @@ char **res_ext(char **av, t_env *env)
|
||||
else if (av[i[0]][i[1]] == '~' && (tmp = ft_envgetelem("HOME", env))
|
||||
!= NULL && (ret = replace_env(av[i[0]], tmp, 1, i[1])) != NULL)
|
||||
ft_strreplace(&av[i[0]], ret, &i[1], tmp);
|
||||
else if (av[i[0]][i[1]] == '~' && (tmp = ft_envgetelem("HOME", env))
|
||||
== NULL)
|
||||
return (return_null("Entry HOME not found\n"));
|
||||
else if (av[i[0]][i[1]] == '$'
|
||||
&& resolve_complete_key(&av[i[0]], &i[1], env) == NULL)
|
||||
return (NULL);
|
||||
|
31
srcs/put_error_cd.c
Normal file
31
srcs/put_error_cd.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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);
|
||||
}
|
||||
|
||||
int put_error_cd2(char *file, char *msg)
|
||||
{
|
||||
ft_putstr("cd: ");
|
||||
ft_putstr(file);
|
||||
ft_putstr(": ");
|
||||
ft_putendl(msg);
|
||||
return (1);
|
||||
}
|
Reference in New Issue
Block a user