Compare commits

27 Commits
master ... dev

Author SHA1 Message Date
Tanguy MAZE
9a44444070 added inline environment 2020-01-30 15:45:47 +01:00
Tanguy Maze
cd72d29c63 added put_error_cd2 in put_error_cd.c 2020-01-30 11:03:30 +01:00
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
Tanguy MAZE
4a534c8156 removed -fsanitize from Makefile 2020-01-25 18:06:03 +01:00
Tanguy MAZE
fdd37da7d0 Normed out funtions
sorting out needed
2020-01-25 17:27:02 +01:00
Tanguy MAZE
f094553b79 Normed out functions in cmd_cd 2020-01-25 14:30:26 +01:00
Tanguy MAZE
79e2ca6f1b Normedout cmd_cd.c 2020-01-24 18:59:26 +01:00
Tanguy Maze
40718a99ac Resolved infinite loop in extension revolving
WIP norming in cd
2020-01-24 00:33:56 +01:00
Tanguy Maze
4f7e1a56ef fixed out-of-memory access in extension 2020-01-23 00:25:58 +01:00
Tanguy Maze
8a421600f4 moved env functions to libft 2019-12-25 11:45:05 +01:00
Tanguy Maze
2362474fd6 Simple norm-out 2019-11-24 11:25:50 +01:00
Tanguy Maze
4123c5dca3 feature: add cd built-in 2019-11-10 21:45:56 +01:00
Tanguy Maze
e89ccb64b2 feature: added echo cmd
changed printf ref to ft_printf
2019-11-03 00:45:38 +01:00
Tanguy Maze
e6304a9f40 fix leak on ext need test 2019-11-02 00:36:21 +01:00
Tanguy Maze
aa5f198c46 feature: added completion for ~ and ${}
WIP leaks detected on ${} completion
2019-10-31 14:59:47 +01:00
Tanguy Maze
e32efb9312 Merge branch 'dev' of github.com:tvdu29/minishell into dev 2019-10-18 14:22:39 +02:00
Tanguy Maze
cfd4a67957 Changed comportment on error for check_path functions 2019-10-18 14:17:34 +02:00
Tanguy MAZE
85af14cd9f Clean-up: normed out files 2019-10-17 11:04:04 +02:00
Tanguy Maze
d22bc173f1 feature: added env, setenv & unsetenv builtins
added -i option & command execution to env
added setenv & unsetenv builtins
2019-10-10 16:56:40 +02:00
Tanguy MAZE
58459bc0c1 feature: added execution of commands from path 2019-09-27 17:00:03 +02:00
Tanguy MAZE
aa8e971688 feature: switched env from ft_list to specific list 2019-09-26 16:54:52 +02:00
Tanguy MAZE
05d8424f75 Feat(WIP): Added possibility to cmd_env to execute commands with
altered env.

Added dummy function for cd, echo, setenv & unsetenv
Started work on env copy feature
2019-09-20 15:49:38 +02:00
Tanguy MAZE
cf62dae53b norm: splitted functions in main into appropriate file
Moved lstdelenvelem & env2lst to ms_env.c
Normed out files
2019-09-20 12:06:44 +02:00
Tanguy MAZE
852248636f Restart from scratch
branched out on dev
removed all previous source files
started test on new env2lst function
2019-09-19 18:00:54 +02:00
16 changed files with 156 additions and 219 deletions

4
.ccls Normal file
View File

@@ -0,0 +1,4 @@
clang
-Iincludes
-Ilibft/includes
%c %h -Wall -Wextra -Werror -g-Wall -Wextra -Werror -g

View File

@@ -6,7 +6,7 @@
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ # # By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2019/03/27 16:51:02 by tmaze #+# #+# # # Created: 2019/03/27 16:51:02 by tmaze #+# #+# #
# Updated: 2020/02/14 11:56:31 by tmaze ### ########.fr # # Updated: 2020/01/30 12:00:42 by tmaze ### ########.fr #
# # # #
#******************************************************************************# #******************************************************************************#
@@ -38,17 +38,13 @@ INCDIR = includes libft/includes
# Source files # Source files
SRC = main.c \ SRC = main.c \
cmd_env.c \ cmd_env.c \
cmd_setenv.c \ cmd_setenv.c \
cmd_unsetenv.c \ cmd_unsetenv.c \
cmd_cd.c \ cmd_cd.c \
cmd_cd_utils.c \
cmd_echo.c \ cmd_echo.c \
ms_exec.c \ ms_exec.c \
ms_ext.c \ ms_ext.c \
put_error_cd.c \ put_error_cd.c
ms_exec_utils.c \
def_env.c \
check_path_slash_cd.c
OBJ = $(SRC:.c=.o) OBJ = $(SRC:.c=.o)

33
README.org Normal file
View File

@@ -0,0 +1,33 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# README.org :+: :+: :+: #
# +:+ +:+ +:+ #
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2018/10/26 13:33:24 by tmaze #+# #+# #
# Updated: 2018/11/18 16:57:11 by tmaze ### ########.fr #
# #
# **************************************************************************** #
#+AUTHOR: tmaze
#+TITLE: 42Minishell
/Minishell project from Ecole 42/
* Todo list
** TODO étudier les différents man du sujet [5/10]
- [X] access
- [X] open, close, read, write
- [X] getcwd, chdir
- [X] stat, lstat, fstat
- [X] fork, execve
- [ ] wait, waitpid, wait3, wait4
- [ ] signal, kill
- [ ] exit
- [ ] environ
- [ ] builtin
** TODO réaliser un shell qui accepte les commandes
- [ ] lanceur de binaires
- [ ] gestion de l'environement
** TODO réaliser les builtins

View File

@@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/18 13:12:34 by tmaze #+# #+# */ /* Created: 2018/11/18 13:12:34 by tmaze #+# #+# */
/* Updated: 2020/02/01 15:57:09 by tmaze ### ########.fr */ /* Updated: 2020/01/26 22:19:25 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -39,17 +39,4 @@ void *ft_strdel_null(char **s);
void *put_error_cd(char *file, char *msg); void *put_error_cd(char *file, char *msg);
int put_error_cd2(char *file, char *msg); int put_error_cd2(char *file, char *msg);
char *check_path_slash_cd(char *exec);
void exec_cmd_child(char *path, char **argv, char **env_tab,
t_env **env);
int ft_isin(char *str, char c);
void *put_error(char *file, char *msg);
t_env *def_env(void);
void *return_null(char *msg);
t_env *cd_updateenv(char *key, char *val, t_env **env);
#endif #endif

View File

@@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/08 00:12:36 by tmaze #+# #+# */ /* Created: 2018/04/08 00:12:36 by tmaze #+# #+# */
/* Updated: 2020/02/14 12:28:38 by tmaze ### ########.fr */ /* Updated: 2019/12/06 09:57:17 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -374,7 +374,6 @@ int ft_putendl_fd2(char const *s, int fd);
void ft_envdelelem(t_env **elem); void ft_envdelelem(t_env **elem);
void ft_envdel(t_env **env); void ft_envdel(t_env **env);
t_env *ft_envnew(char *env); t_env *ft_envnew(char *env);
t_env *ft_envnewinit(char *key, char *val);
t_env *ft_envaddend(t_env **alst, t_env *new); t_env *ft_envaddend(t_env **alst, t_env *new);
t_env *ft_envgetelem(char *key, t_env *env); t_env *ft_envgetelem(char *key, t_env *env);
char *ft_envtochar(t_env *env); char *ft_envtochar(t_env *env);

View File

@@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/12/05 14:54:55 by tmaze #+# #+# */ /* Created: 2019/12/05 14:54:55 by tmaze #+# #+# */
/* Updated: 2020/02/14 12:28:20 by tmaze ### ########.fr */ /* Updated: 2019/12/05 17:12:59 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -27,18 +27,3 @@ t_env *ft_envnew(char *env)
ft_envdelelem(&ret); ft_envdelelem(&ret);
return (ret); return (ret);
} }
t_env *ft_envnewinit(char *key, char *val)
{
t_env *ret;
int i;
i = 0;
ret = NULL;
if ((ret = (t_env*)ft_memalloc(sizeof(t_env))) != NULL)
if ((ret->key = ft_strdup(key)) != NULL)
if ((ret->val = ft_strdup(val)) != NULL)
return (ret);
ft_envdelelem(&ret);
return (ret);
}

View File

@@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/12/05 19:10:38 by tmaze #+# #+# */ /* Created: 2019/12/05 19:10:38 by tmaze #+# #+# */
/* Updated: 2020/02/07 15:26:10 by tmaze ### ########.fr */ /* Updated: 2019/12/05 19:10:52 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@@ -1,36 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_path_slach_cd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/01 15:29:57 by tmaze #+# #+# */
/* Updated: 2020/02/01 15:31:19 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
char *check_path_slash_cd(char *exec)
{
int i;
struct stat info;
struct stat info2;
if (exec[0] == '/')
{
if ((i = access(exec, F_OK)) != 0)
return (put_error_cd(exec, "no such file or directory"));
if ((i = lstat(exec, &info)) != 0)
return (put_error_cd(exec, "can't determine info"));
if ((S_ISLNK(info.st_mode)
&& ((i = stat(exec, &info2)) != 0 || !S_ISDIR(info2.st_mode)))
&& !S_ISDIR(info.st_mode))
return (put_error_cd(exec, "not a directory"));
if ((i = access(exec, X_OK)) != 0)
return (put_error_cd(exec, "permission denied"));
return (exec);
}
return (NULL);
}

View File

@@ -6,12 +6,35 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/01/07 16:44:40 by tmaze #+# #+# */ /* Created: 2019/01/07 16:44:40 by tmaze #+# #+# */
/* Updated: 2020/02/01 15:32:59 by tmaze ### ########.fr */ /* Updated: 2020/01/26 22:17:48 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
char *check_path_slash_cd(char *exec)
{
int i;
struct stat info;
struct stat info2;
if (exec[0] == '/')
{
if ((i = access(exec, F_OK)) != 0)
return (put_error_cd(exec, "no such file or directory"));
if ((i = lstat(exec, &info)) != 0)
return (put_error_cd(exec, "can't determine info"));
if ((S_ISLNK(info.st_mode)
&& ((i = stat(exec, &info2)) != 0 || !S_ISDIR(info2.st_mode)))
&& !S_ISDIR(info.st_mode))
return (put_error_cd(exec, "not a directory"));
if ((i = access(exec, X_OK)) != 0)
return (put_error_cd(exec, "permission denied"));
return (exec);
}
return (NULL);
}
int cmd_cd_update_env(char *path, t_env **env, char opt) int cmd_cd_update_env(char *path, t_env **env, char opt)
{ {
t_env *pwd; t_env *pwd;
@@ -25,8 +48,8 @@ int cmd_cd_update_env(char *path, t_env **env, char opt)
if (getcwd(p_path, 4096) == NULL || (oldpwd = ft_strdup(pwd->val)) == NULL if (getcwd(p_path, 4096) == NULL || (oldpwd = ft_strdup(pwd->val)) == NULL
|| ft_realpath(path, &c_path) == NULL) || ft_realpath(path, &c_path) == NULL)
return (put_error_cd2(path, "error")); return (put_error_cd2(path, "error"));
if (cd_updateenv("PWD", ((opt == 'P') ? p_path : c_path), env) == NULL if (ft_envupdate("PWD", *env, ((opt == 'P') ? p_path : c_path)) == NULL
|| cd_updateenv("OLDPWD", oldpwd, env) == NULL) || ft_envupdate("OLDPWD", *env, oldpwd) == NULL)
{ {
ft_strdel(&oldpwd); ft_strdel(&oldpwd);
ft_strdel(&c_path); ft_strdel(&c_path);

View File

@@ -1,31 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cmd_cd_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/14 11:55:54 by tmaze #+# #+# */
/* Updated: 2020/02/14 11:56:53 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_env *cd_updateenv(char *key, char *val, t_env **env)
{
t_env *tmp;
if ((tmp = ft_envgetelem(key, *env)) != NULL)
ft_envupdate(key, *env, val);
else if ((tmp = (t_env*)ft_memalloc(sizeof(t_env))) != NULL)
{
if ((tmp->key = ft_strdup(key)) == NULL)
ft_envdelelem(&tmp);
if (tmp && (tmp->val = ft_strdup(val)) == NULL)
ft_envdelelem(&tmp);
if (tmp)
ft_envaddend(env, tmp);
}
return (tmp);
}

View File

@@ -6,7 +6,7 @@
/* 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: 2020/02/07 15:56:06 by tmaze ### ########.fr */ /* Updated: 2019/11/10 21:38:30 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -21,11 +21,14 @@ int cmd_setenv(char **argv, t_env **env)
{ {
if (argv[1] && (tmp = ft_envgetelem(new->key, *env)) != NULL) if (argv[1] && (tmp = ft_envgetelem(new->key, *env)) != NULL)
{ {
ft_envupdate(new->key, *env, new->val); ft_strdel(&(tmp->val));
ft_envdelelem(&new); tmp->val = new->val;
ft_strdel(&(new->key));
ft_memdel((void**)&new);
} }
else else
ft_envaddend(env, new); ft_envaddend(env, new);
ft_envclean(env);
return (0); return (0);
} }
else if (argv[1] && argv[1][0] != '=' && !ft_strchr(argv[1], '=')) else if (argv[1] && argv[1][0] != '=' && !ft_strchr(argv[1], '='))

View File

@@ -1,40 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* def_env.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/01 15:53:22 by tmaze #+# #+# */
/* Updated: 2020/02/01 15:53:34 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);
}

View File

@@ -6,12 +6,39 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/19 17:08:46 by tmaze #+# #+# */ /* Created: 2019/09/19 17:08:46 by tmaze #+# #+# */
/* Updated: 2020/02/07 15:11:58 by tmaze ### ########.fr */ /* Updated: 2020/01/30 13:47:35 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #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 *inc_shlvl(char **shlvl)
{ {
char *ret; char *ret;
@@ -32,7 +59,7 @@ t_env *env2lst(char **env)
i = 0; i = 0;
ret = NULL; ret = NULL;
while (env && env[i]) while (env[i])
{ {
if ((new = ft_envnew(env[i])) != NULL) if ((new = ft_envnew(env[i])) != NULL)
{ {
@@ -78,15 +105,14 @@ int cleanup(char **argv, t_env *env)
return (0); return (0);
} }
int main(int ac , char **av, char **envp) int main(void)
{ {
extern char **environ;
char **argv; char **argv;
t_env *env; t_env *env;
char *cmd; char *cmd;
(void)ac; if ((env = env2lst(environ)) == NULL)
(void)av;
if ((env = env2lst(envp)) == NULL)
return (2); return (2);
while (1) while (1)
{ {

View File

@@ -6,12 +6,32 @@
/* 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: 2020/02/01 15:47:08 by tmaze ### ########.fr */ /* Updated: 2020/01/30 11:48:25 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
int ft_isin(char *str, char c)
{
int i;
i = 0;
while (str && str[i])
if (str[i++] == c)
return (i - 1);
return (-1);
}
void *put_error(char *file, char *msg)
{
ft_putstr("minishell: ");
ft_putstr(file);
ft_putstr(": ");
ft_putendl(msg);
return (NULL);
}
char *check_path_slash(char *exec) char *check_path_slash(char *exec)
{ {
int i; int i;
@@ -62,6 +82,12 @@ char *check_path_dot(char *exec, t_env *env)
return (put_error(exec, "no such file or directory")); return (put_error(exec, "no such file or directory"));
} }
void *ft_strdel_null(char **s)
{
ft_strdel(s);
return (NULL);
}
char *check_path_elems(char **path_elems, char *exec) char *check_path_elems(char **path_elems, char *exec)
{ {
int i; int i;
@@ -120,6 +146,17 @@ char *check_path(char *exec, t_env *env)
return (ret); return (ret);
} }
void exec_cmd_child(char *path, char **argv, char **env_tab, t_env **env)
{
execve(path, argv, env_tab);
ft_putendl_fd("minishell: error", 1);
if (ft_strcmp(path, argv[0]) != 0)
ft_strdel(&path);
ft_del_words_tables(&env_tab);
ft_envdel(env);
exit(-1);
}
int exec_cmd(char **argv, t_env **env) int exec_cmd(char **argv, t_env **env)
{ {
int ret; int ret;

View File

@@ -1,56 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ms_exec_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/01 15:43:41 by tmaze #+# #+# */
/* Updated: 2020/02/01 15:56:49 by tmaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void exec_cmd_child(char *path, char **argv, char **env_tab, t_env **env)
{
execve(path, argv, env_tab);
ft_putendl_fd("minishell: error", 1);
if (ft_strcmp(path, argv[0]) != 0)
ft_strdel(&path);
ft_del_words_tables(&env_tab);
ft_envdel(env);
exit(-1);
}
void *ft_strdel_null(char **s)
{
ft_strdel(s);
return (NULL);
}
int ft_isin(char *str, char c)
{
int i;
i = 0;
while (str && str[i])
if (str[i++] == c)
return (i - 1);
return (-1);
}
void *put_error(char *file, char *msg)
{
ft_putstr("minishell: ");
ft_putstr(file);
ft_putstr(": ");
ft_putendl(msg);
return (NULL);
}
void *return_null(char *msg)
{
ft_printf("%s\n", msg);
return (NULL);
}

View File

@@ -6,12 +6,18 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/25 18:21:47 by tmaze #+# #+# */ /* Created: 2019/10/25 18:21:47 by tmaze #+# #+# */
/* Updated: 2020/02/07 15:55:59 by tmaze ### ########.fr */ /* Updated: 2020/01/30 15:42:17 by tmaze ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
void *return_null(char *msg)
{
ft_printf("%s\n", msg);
return (NULL);
}
void ft_strreplace(char **dst, char *src, int *index, t_env *elem) void ft_strreplace(char **dst, char *src, int *index, t_env *elem)
{ {
if (*dst != NULL) if (*dst != NULL)
@@ -51,11 +57,12 @@ char *replace_env(char *src, t_env *elem, int key_size, int i)
int res_len; int res_len;
res_len = ft_strlen(src) - key_size + ft_strlen(elem->val); 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) if ((ret = ft_strnew(res_len)) != NULL)
{ {
ft_strncpy(ret, src, i); ft_strncpy(ret, src, i);
ft_strlcat(ret, elem->val, res_len + 1); ft_strlcat(ret, elem->val, res_len + 1);
ft_strlcat(ret, &src[i] + key_size, res_len + 1); ft_strlcat(ret, src + key_size, res_len + 1);
} }
else else
ft_printf("minishell: memory error\n"); ft_printf("minishell: memory error\n");