add builtin

This commit is contained in:
kinou-p 2022-04-05 19:39:36 +02:00
parent d78384b4e9
commit 01d80ba1cd
12 changed files with 856 additions and 15 deletions

View File

@ -6,7 +6,7 @@
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2022/03/06 12:50:24 by apommier #+# #+# #
# Updated: 2022/03/11 16:35:32 by apommier ### ########.fr #
# Updated: 2022/04/05 04:11:33 by apommier ### ########.fr #
# #
# **************************************************************************** #
@ -17,10 +17,18 @@ SRCS = srcs/main.c\
srcs/set_cmd/free_cmd.c\
srcs/set_cmd/set_cmd.c\
srcs/set_redirection/redirection.c\
srcs/set_redirection/utils.c
srcs/set_redirection/utils.c\
srcs/built_in/unset.c\
srcs/built_in/cd.c\
srcs/built_in/echo.c\
srcs/built_in/export.c\
srcs/built_in/utils_builtin.c\
srcs/built_in/init_builtin.c\
srcs/built_in/export2.c\
srcs/built_in/choose_builtin.c
OBJS = ${SRCS:.c=.o}
CC = clang
CFLAGS = -Wall -Wextra
CFLAGS = -Wall -Wextra -g
LIB = -lreadline
#CFLAGS = -Wall -Wextra -Werror
RM = rm -rf
@ -30,7 +38,7 @@ ${NAME}: ${OBJS}
@make bonus -C ${LIBFT}
@${CC} ${LIB} ${OBJS} ${LIBFT}/libft.a -o ${NAME}
all: ${NAME} bonus
all: ${NAME}
clean:
@${RM} ${OBJS}
@ -42,6 +50,6 @@ fclean: clean
re: fclean all
.PHONY: all clean fclean re bonus
.PHONY: all clean fclean re
-include ./valgrind.mk

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/09 22:33:49 by apommier #+# #+# */
/* Updated: 2022/04/03 19:22:42 by apommier ### ########.fr */
/* Updated: 2022/04/05 18:22:48 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -26,11 +26,13 @@
# include <stdio.h>
# include <errno.h>
# include <signal.h>
# include <dirent.h>
// Command Data Structure
// Describes a simple command and arguments
typedef struct s_simple {
char **env;
int fd[2];
int pipe[2];
int last;
@ -85,4 +87,23 @@ int double_size(char **tab);
void print_double_fd(char **tab, int fd);
void free_double(char **tab);
//builtins utils
void register_env(t_s_cmd *cmd, char *variable);
void ft_env(t_s_cmd *cmd, char **env);
int find_pwd(t_s_cmd *cmd);
void init_s_cmd(t_s_cmd *cmd, char **env);
int tab_len(char **tab);
int find_len(char *input, int i, char c);
//real builtin
void ft_env(t_s_cmd *cmd, char **env);
void ft_exit(t_s_cmd *cmd);
void ft_export(t_s_cmd *cmd);
void ft_unset(t_s_cmd *cmd);
void ft_echo(t_s_cmd *cmd);
void ft_pwd(t_s_cmd *cmd);
void open_directory(t_s_cmd *cmd);//cd
//parse builtin
int is_builtin(char *cmd);
void call_builtin(t_cmd *cmd, char **env);
#endif

155
srcs/built_in/cd.c Normal file
View File

@ -0,0 +1,155 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/21 18:30:26 by sadjigui #+# #+# */
/* Updated: 2022/04/05 18:30:30 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/minishell.h"
void ft_ls(char *input)
{
int i;
DIR *dir;
struct dirent *sd;
i = ft_strlen("ls");
// if (input[i] == ' ')
// {
printf("ici\n");
while (input[i] && input[i] != ' ')
i++;
// }
// printf("[%c]\n", input[i]);
// printf("[%c]\n", input[i+1]);
dir = opendir(".");
if (dir == NULL)
{
printf("stop\n");
return ;
}
// printf("dir --> %s\n", dir[0]);
while ((sd=readdir(dir)) != NULL)
{
printf(" >> %s\n", sd->d_name);
}
closedir(dir);
}
void del_one(t_s_cmd *cmd)
{
int i;
char *r;
i = ft_strlen(cmd->env[find_pwd(cmd)]);
// printf("%s\n", cmd->args[6]);
// while (cmd->env[find_pwd(cmd)][i])
// i++;
while (cmd->env[find_pwd(cmd)][i] != '/')
i--;
r = ft_substr(cmd->env[find_pwd(cmd)], 0, i);
free(cmd->env[find_pwd(cmd)]);
cmd->env[find_pwd(cmd)] = ft_strdup(r);
free(r);
}
void add_one(t_s_cmd *cmd, char *str)
{
char *r;
r = ft_strjoin(cmd->env[find_pwd(cmd)], "/");
r = ft_strjoin(r, str);
//free(cmd->env[find_pwd(cmd)]);
cmd->env[find_pwd(cmd)] = ft_strdup(r);
free(r);
}
void change_path(t_s_cmd *cmd)
{
char **tab;
int i;
i = 0;
tab = ft_split(cmd->args[1], '/');
while (cmd->env[i])
{
if (ft_strncmp(cmd->env[i], "OLDPWD=", 7) == 0)
break ;
i++;
}
printf("%d\n", i);
/*if (cmd->env[i])
free(cmd->env[i]);*/
cmd->env[i] = ft_strjoin("OLD", cmd->env[find_pwd(cmd)]);
i = 0;
while (tab[i])
{
if (ft_strcmp(tab[i], "..") == 0)
del_one(cmd);
else
add_one(cmd, tab[i]);
i++;
}
}
void reboot_pwd(t_s_cmd *cmd, int i)
{
char *str;
while (i > 3)
{
if (chdir("..") == 0)
del_one(cmd);
i--;
}
str = ft_substr(cmd->args[1], 2, ft_strlen(cmd->args[1]));
cmd->args[1] = ft_strdup(str);
free(str);
}
void open_directory(t_s_cmd *cmd)
{
char **str;
int j;
str = ft_split(cmd->env[find_pwd(cmd)], '/');
j = tab_len(str);
if (!cmd->args[1])
{
while (j-- > 3)
if (chdir("..") == 0)
del_one(cmd);
}
if (tab_len(cmd->args) == 2)
{
if (cmd->args[1][0] == '~')
reboot_pwd(cmd, j);
if (chdir(cmd->args[1]) == 0)
change_path(cmd);
}
}
void ft_pwd(t_s_cmd *cmd)
{
int i;
int j;
j = 0;
i = 0;
while (cmd->env[find_pwd(cmd)][j] != '=')
j++;
j += 1;
while (cmd->env[find_pwd(cmd)][j])
{
write (1, &cmd->env[find_pwd(cmd)][j], 1);
j++;
}
write(1, "\n", 1);
}

View File

@ -0,0 +1,46 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* choose_builtin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/28 17:12:52 by sadjigui #+# #+# */
/* Updated: 2022/04/05 18:22:08 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/minishell.h"
int is_builtin(char *cmd)
{
if (!ft_strcmp(cmd, "env"))
return (1);
if (!ft_strcmp(cmd, "export"))
return (1);
if (!ft_strcmp(cmd, "unset"))
return (1);
if (!ft_strcmp(cmd, "echo"))
return (1);
if (!ft_strcmp(cmd, "cd"))
return (1);
if (!ft_strcmp(cmd, "pwd"))
return (1);
return (0);
}
void call_builtin(t_cmd *cmd, char **env)
{
if (!ft_strcmp(cmd->current_s_cmd->cmd, "env"))
print_double_fd(env, 0);
if (!ft_strcmp(cmd->current_s_cmd->cmd, "export"))
ft_export(cmd->current_s_cmd);
if (!ft_strcmp(cmd->current_s_cmd->cmd, "unset"))
ft_unset(cmd->current_s_cmd);
if (!ft_strcmp(cmd->current_s_cmd->cmd, "echo"))
ft_echo(cmd->current_s_cmd);
if (!ft_strcmp(cmd->current_s_cmd->cmd, "cd"))
open_directory(cmd->current_s_cmd);
if (!ft_strcmp(cmd->current_s_cmd->cmd, "pwd"))
ft_pwd(cmd->current_s_cmd);
}

163
srcs/built_in/echo.c Normal file
View File

@ -0,0 +1,163 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* echo.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/11 20:52:56 by sadjigui #+# #+# */
/* Updated: 2022/04/05 17:30:24 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/minishell.h"
int jump_space(char *str, int i)
{
int j;
j = i;
while (str[j] == ' ')
j++;
return (j);
}
void print_value(char *str, char *input)
{
(void)input;
int i;
i = 0;
while (str[i] && str[i] != '=')
i++;
i++;
ft_putstr_fd(str + i, 0);
/*while (str[i])
{
ft_putchar(str[i]);
i++;
}*/
}
// void print_rest(char *input, char *str, int j)
// {
// int i;
//
// i = 0;
// j -= 1;
// while (input[j++])
// printf("%c", input[j]);
// printf("\n");
// while (input[j] && input[j] == str[i])
// {
// i++;
// j++;
// }
// printf("str == %s\n", str);
// if (input[j] != '\0')
// {
// j = jump_space(input, j);
// if (input[j] != '\0')
// while(input[j])
// {
// ft_putchar(input[j]);
// j++;
// }
// else
// return;
// }
// else
// return ;
// }
void find_for_print(t_s_cmd *cmd, char *input)
{
char *str;
// char *tmp;
int i;
int x;
i = 0;
// j = j + 1;
// tmp = ft_substr(input, j, find_len(input, j, 32));
// printf("%c\n", input[j]);
str = ft_strjoin(input, "=");
x = ft_strlen(str);
// printf("%d\n", x);
while (cmd->env[i])
{
if (ft_strncmp(cmd->env[i], str, x) == 0)
{
// printf("%s\n", cmd->env[i]);
break ;
}
i++;
}
if (cmd->env[i] != NULL)
{
print_value(cmd->env[i], input);
// print_rest(input, tmp, j);
}
}
int dollar_or_not(char *str)
{
int i;
i = 0;
while (str[i])
{
if (str[i] == '$')
return (1);
i++;
}
return (0);
}
void find_value(t_s_cmd *cmd, char *str)
{
// int i;
//
// i = 0;
while (*str)
{
if (*str == '$')
break ;
printf("%c", *str);
str++;
}
str++;
find_for_print(cmd, str);
}
void ft_echo(t_s_cmd *d)
{
int i;
int j;
int is_option;
j = 0;
i = 1;
is_option = 0;
if (d->args[i] && ft_strcmp(d->args[i], "-n") == 0)
{
is_option = 1;
i++;
}
if (d->args[i])
while (d->args[i])
{
if (dollar_or_not(d->args[i]) == 1)
find_value(d, d->args[i]);
else
printf("%s", d->args[i]);
if (d->args[i + 1] != NULL)
printf("\n");
i++;
}
// else
// my_putstr(input, i);
if (is_option == 0)
printf("\n");
}

112
srcs/built_in/export.c Normal file
View File

@ -0,0 +1,112 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* export.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/28 23:26:59 by sadjigui #+# #+# */
/* Updated: 2022/04/05 03:54:10 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/minishell.h"
int check_variable(char *variable)
{
int i;
i = 0;
if (!ft_isalpha(variable[i]))
return(0);
i++;
while(variable[i] != '=')
{
if(!ft_isalnum(variable[i]))
return(0);
i++;
}
return(1);
}
// char *define_double_quotes(char *value)
// {
// int i;
// char *dest;
//
// i = find_len(value, 0, '=') + 2;
// if (value[i] == '"')
// dest = ft_substr()
// }
char *check_value(char *value)
{
int i;
char *dest;
i = find_len(value, 0, '=') + 1;
if (value[i] == '"')
{
printf("wait\n");
dest = ft_strdup(" ");
// dest = define_double_quotes(value);
}
else{
dest = ft_substr(value, 0, find_len(value, 0, ' '));
// printf("brrrrrrr------\n");
}
return (dest);
}
void ft_export_variable(t_s_cmd *cmd, char *variable)
{
char *dest;
char *unset;
int i;
i = 0;
if (check_variable(variable) == 0)
{
printf("Voir bash\n");
return ;
}
// printf("jojo\n");
dest = check_value(variable);
unset = ft_substr(dest, 0, find_len(dest, 0, '='));
while (cmd->env[i] != NULL)
{
if (ft_strncmp(unset, cmd->env[i], ft_strlen(unset)) == 0)
{
find_variable(unset, cmd);
break ;
}
i++;
}
register_env(cmd, dest);
if (dest)
free(dest);
// if (unset)
// free(unset);
// if (check_variable(v_v[0]) == 1)
// {
// tmp = ft_strdup(v_v[1]);
// free(v_v[1]);
// v_v[1] = check_value(tmp);
// }
}
void ft_export(t_s_cmd *cmd)
{
int i;
i = 1;
if (!cmd->args[i])
lone_export(cmd);
else if (cmd->args[i])
while (cmd->args[i])
{
ft_export_variable(cmd, cmd->args[i]);
i++;
}
}

77
srcs/built_in/export2.c Normal file
View File

@ -0,0 +1,77 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* export2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/07 17:58:25 by sadjigui #+# #+# */
/* Updated: 2022/04/05 03:47:53 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/minishell.h"
void ft_swap(char **a, char **b)
{
char *tmp;
tmp = *a;
*a = *b;
*b = tmp;
}
void sort_tab(char **av)
{
int i;
int x;
i = 0;
// if (ac > 1)
// {
while (av[i])
{
x = i;
while (av[x])
{
if (ft_strcmp(av[i], av[x]) > 0)
ft_swap(&av[i], &av[x]);
x++;
}
i++;
}
// }
// return (av);
}
void print_export(char *tmp)
{
char *str1;
char *str2;
int i;
i = 0;
str1 = ft_substr(tmp, 0, find_len(tmp, i, '='));
i = find_len(tmp, 0, '=') + 1;
str2 = ft_substr(tmp, i, find_len(tmp, i, '\0'));
printf("declare -x %s=\"%s\"\n", str1, str2);
free(str1);
free(str2);
}
void lone_export(t_s_cmd *cmd)
{
char **tmp;
int i;
i = 0;
tmp = cmd->env;
sort_tab(tmp);
while (tmp[i])
{
print_export(tmp[i]);
i++;
}
}

View File

@ -0,0 +1,134 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* init_builtin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/28 17:17:01 by sadjigui #+# #+# */
/* Updated: 2022/04/05 17:16:17 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/minishell.h"
// void join_variable(t_s_cmd *cmd, char **v_v, int size, char **tab)
// {
// char *str;
// char *tmp;
//
// while (tab[size])
// {
// cmd->env[size] = ft_strdup(tab[size]);
// // printf("tmp----%s\n", tmp[size]);
// // printf("envy---%s\n", cmd->env[size]);
// size++;
// }
// str = ft_strjoin(v_v[0], "=");
// tmp = ft_strdup(str);
// free(str);
// str = ft_strjoin(tmp,v_v[1]);
// cmd->env[size] = ft_strdup(str);
// printf("ici\n");
// free(str);
// free(tmp);
// cmd->env[size + 1] = NULL;
// }
void register_env(t_s_cmd *cmd, char *variable)
{
char **tmp = NULL;
int i;
i = 0;
// tmp = NULL;
// printf("TABLEN %d", tab_len(cmd->env));
tmp = (char **)malloc(sizeof(char *) * (tab_len(cmd->env) + 2));
if(!tmp)
printf("no tmp\n");
while (cmd->env[i])
{
tmp[i] = ft_strdup(cmd->env[i]);
// printf("ici\n");
// printf("%s\n", "let me in");
i++;
}
// printf("i: %d %s\n",i,tmp[i]);
// printf("%s\n", "brrrrrrr");
tmp[i] = ft_strdup(variable);
tmp[i + 1] = NULL;
// printf("debut %p\n", tmp[2]);
// printf("1--------------------\n");
free_double(cmd->env);
// printf("1--------------------\n");
cmd->env = (char **)malloc(sizeof(char *) * (tab_len(tmp) + 1));
if (!cmd->env)
printf("no env\n");
i = 0;
while (tmp[i])
{
cmd->env[i] = ft_strdup(tmp[i]);
// if (tmp[size])
// free(tmp[size]);
// printf("tmp----%s\n", tmp[size]);
// printf("envy---%s\n", cmd->env[size]);
i++;
}
cmd->env[i] = NULL;
// printf("2--------------------\n");
if (tmp)
free_double(tmp);
// printf("2--------------------\n");
// int i = 0;
// while (tmp[i])
// {
// printf("nano");
// free(tmp[i]);
// i++;
// }
// if(tmp)
// free(tmp);
// join_variable(cmd, variable, size, tmp);
}
void ft_env(t_s_cmd *cmd, char **env)
{
int i;
i = 0;
while (env[i])
i++;
cmd->env = ft_calloc(sizeof(char *), i + 1);
i = 0;
while (env[i])
{
cmd->env[i] = ft_strdup(env[i]);
i++;
}
cmd->env[i] = NULL;
}
int find_pwd(t_s_cmd *cmd)
{
int i;
i = 0;
while (cmd->env[i] && ft_strncmp(cmd->env[i], "PWD=", 4) != 0)
i++;
return (i);
}
void init_s_cmd(t_s_cmd *cmd, char **env)
{
ft_env(cmd, env);
}
int tab_len(char **tab)
{
int i;
i = 0;
while (tab[i])
i++;
return (i);
}

90
srcs/built_in/unset.c Normal file
View File

@ -0,0 +1,90 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* unset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/11 18:26:29 by sadjigui #+# #+# */
/* Updated: 2022/04/05 03:54:57 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/minishell.h"
void unset_variable(t_s_cmd *cmd, int i)
{
int a;
int b;
char **tmp;
a = 0;
b = 0;
tmp = malloc(sizeof(char *) * tab_len(cmd->env));
if (!tmp)
printf("no tmp\n");
//ft_exit(cmd);
while (cmd->env[a])
{
// if (a == i)
// a++;
printf("%s\n", cmd->env[a]);
if (a != i)
{
tmp[b] = ft_substr(cmd->env[a], 0, ft_strlen(cmd->env[a]));
b++;
}
a++;
}
tmp[b] = NULL;
free_double(cmd->env);
a = 0;
cmd->env = malloc(sizeof(char *) * (tab_len(tmp) + 1));
if (!cmd->env)
printf("no env\n");
//ft_exit(cmd);
while (tmp[a])
{
cmd->env[a] = ft_strdup(tmp[a]);
// printf("%s\n", cmd->env[a]);
a++;
}
cmd->env[a] = NULL;
if (tmp)
free_double(tmp);
printf("2-------------\n");
}
void find_variable(char *variable, t_s_cmd *cmd)
{
char *str;
int i;
int j;
i = 0;
str = ft_strjoin(variable, "=");
j = 0;
// printf("variable == %s\n", variable);
while (str[j])
j++;
while (cmd->env[i] && !(ft_strncmp(cmd->env[i], str, j) == 0))
i++;
if (i == tab_len(cmd->env))
return ;
unset_variable(cmd, i);
free(str);
printf("%s\n", "3----------------");
}
void ft_unset(t_s_cmd *cmd)
{
int i;
i = 1;
while (cmd->args[i])
{
find_variable(cmd->args[i], cmd);
i++;
}
}

View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils_builtin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/16 15:04:12 by sadjigui #+# #+# */
/* Updated: 2022/04/05 03:47:53 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/minishell.h"
int find_len(char *input, int i, char c)
{
int j;
j = i;
while (input[j] && input[j] != c)
j++;
return (j);
}

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/02 18:51:31 by apommier #+# #+# */
/* Updated: 2022/04/02 18:51:32 by apommier ### ########.fr */
/* Updated: 2022/04/05 18:26:19 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -58,6 +58,11 @@ int wait_exit(t_cmd *cmd)
void exec_cmd(t_cmd *cmd, char **env, int *fdpipe)
{
if (is_builtin(cmd->current_s_cmd->cmd))
{
call_builtin(cmd, env);
return ;
}
cmd->current_s_cmd->child = fork();
if (cmd->current_s_cmd->child == 0)
{

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/08 15:19:42 by apommier #+# #+# */
/* Updated: 2022/04/03 18:19:55 by apommier ### ########.fr */
/* Updated: 2022/04/05 18:23:49 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -31,22 +31,28 @@ t_s_cmd *set_s_cmd(char *line, t_cmd *cmd, int index)
//printf("before redirect\n");
line = set_redirection(s_cmd, line, index);//SET REDIRECTION
split_line = ft_split(line, ' ');
s_cmd->cmd = get_command(split_line, cmd->path);
if (!s_cmd->cmd)
print_double_fd(split_line, 0);
if (!is_builtin(split_line[0]))
s_cmd->cmd = get_command(split_line, cmd->path);
else
s_cmd->cmd = ft_strjoin(split_line[0], 0);
/*if (!s_cmd->cmd)
{
free(line);
free_double(split_line);
free(s_cmd);
return (0);
}*/
if (s_cmd->cmd)
{
s_cmd->nb_args = double_size(split_line);
s_cmd->args = split_line;
}
s_cmd->nb_args = double_size(split_line);
//set_redirection(s_cmd);
s_cmd->args = split_line;
free(line);
return (s_cmd);
}
t_cmd *split_cmd(t_cmd *cmd, char **cmds)
t_cmd *split_cmd(t_cmd *cmd, char **cmds, char **env)
{
int i;
@ -60,6 +66,7 @@ t_cmd *split_cmd(t_cmd *cmd, char **cmds)
free_cmd(cmd);
return (0);
}
cmd->s_cmds[i]->env = env;
i++;
}
cmd->s_cmds[i] = 0;
@ -85,7 +92,7 @@ t_cmd *set_cmd(char *input, char **env)
cmd->outfile = 0;
cmd->infile = 0;
cmd->nb_s_cmd = double_size(cmds);
cmd = split_cmd(cmd, cmds); //split each cmd into args in s_cmd
cmd = split_cmd(cmd, cmds, env); //split each cmd into args in s_cmd
free(cmds);
if (cmd)
{