Merge branch 'master' into sadjigui
This commit is contained in:
commit
a7e04285e0
4
Makefile
4
Makefile
@ -6,7 +6,7 @@
|
|||||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2022/03/06 12:50:24 by apommier #+# #+# #
|
# Created: 2022/03/06 12:50:24 by apommier #+# #+# #
|
||||||
# Updated: 2022/04/09 21:11:51 by apommier ### ########.fr #
|
# Updated: 2022/04/10 21:11:14 by apommier ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
@ -26,6 +26,8 @@ SRCS = srcs/main.c\
|
|||||||
srcs/built_in/init_builtin.c\
|
srcs/built_in/init_builtin.c\
|
||||||
srcs/built_in/export2.c\
|
srcs/built_in/export2.c\
|
||||||
srcs/built_in/env.c\
|
srcs/built_in/env.c\
|
||||||
|
srcs/set_quote/set_quote.c\
|
||||||
|
srcs/set_quote/split_with_quote.c\
|
||||||
srcs/built_in/choose_builtin.c
|
srcs/built_in/choose_builtin.c
|
||||||
OBJS = ${SRCS:.c=.o}
|
OBJS = ${SRCS:.c=.o}
|
||||||
CC = clang
|
CC = clang
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/03/09 22:33:49 by apommier #+# #+# */
|
/* Created: 2022/03/09 22:33:49 by apommier #+# #+# */
|
||||||
/* Updated: 2022/04/09 21:24:05 by apommier ### ########.fr */
|
/* Updated: 2022/04/10 21:14:03 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -77,6 +77,9 @@ char *get_command(char **exec, char **env);
|
|||||||
void free_cmd(t_cmd *cmd);
|
void free_cmd(t_cmd *cmd);
|
||||||
void exit_shell(t_cmd *cmd);
|
void exit_shell(t_cmd *cmd);
|
||||||
|
|
||||||
|
//set_quote.c
|
||||||
|
char **ft_split_with_quote(char const *s, char c);
|
||||||
|
|
||||||
//redirection.c set redirection and input good
|
//redirection.c set redirection and input good
|
||||||
char *set_redirection(t_s_cmd *cmd, char *line, int index);
|
char *set_redirection(t_s_cmd *cmd, char *line, int index);
|
||||||
char next_space(char *str, int i);
|
char next_space(char *str, int i);
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/03/06 13:27:11 by apommier #+# #+# */
|
/* Created: 2022/03/06 13:27:11 by apommier #+# #+# */
|
||||||
/* Updated: 2022/04/09 19:24:43 by apommier ### ########.fr */
|
/* Updated: 2022/04/10 21:46:50 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -20,8 +20,8 @@ void crtl_c(int num)
|
|||||||
num = 0;
|
num = 0;
|
||||||
|
|
||||||
close(0);
|
close(0);
|
||||||
//dup2(tmpin, 0);
|
dup2(tmpin, 0);
|
||||||
//close(tmpin);
|
close(tmpin);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
rl_replace_line("", 0);
|
rl_replace_line("", 0);
|
||||||
rl_on_new_line();
|
rl_on_new_line();
|
||||||
@ -100,7 +100,7 @@ int main(int ac, char **av, char **path)
|
|||||||
av = 0;
|
av = 0;
|
||||||
if (ac != 1)
|
if (ac != 1)
|
||||||
{
|
{
|
||||||
printf("too much arguments\n");
|
ft_putstr_fd("Error: too much arguments\n", 2);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
printf("---MINISHELL START---\n");
|
printf("---MINISHELL START---\n");
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/04/02 18:51:31 by apommier #+# #+# */
|
/* Created: 2022/04/02 18:51:31 by apommier #+# #+# */
|
||||||
/* Updated: 2022/04/09 21:35:09 by apommier ### ########.fr */
|
/* Updated: 2022/04/10 21:07:36 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -84,7 +84,9 @@ void exec_cmd(t_cmd *cmd, char **env, int *fdpipe)
|
|||||||
}
|
}
|
||||||
if (!cmd->current_s_cmd->cmd || access(cmd->current_s_cmd->cmd, F_OK))
|
if (!cmd->current_s_cmd->cmd || access(cmd->current_s_cmd->cmd, F_OK))
|
||||||
{
|
{
|
||||||
ft_putstr_fd("Minishell: command not found\n", 2);
|
ft_putstr_fd("Minishell: command not found: ", 2);
|
||||||
|
ft_putstr_fd(cmd->current_s_cmd->cmd + 1, 2);
|
||||||
|
ft_putstr_fd("\n", 2);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
if (-1 == execve(cmd->current_s_cmd->cmd, cmd->current_s_cmd->args, env))
|
if (-1 == execve(cmd->current_s_cmd->cmd, cmd->current_s_cmd->args, env))
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/03/08 16:58:40 by apommier #+# #+# */
|
/* Created: 2022/03/08 16:58:40 by apommier #+# #+# */
|
||||||
/* Updated: 2022/04/08 01:03:54 by apommier ### ########.fr */
|
/* Updated: 2022/04/10 21:07:05 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ char *does_access(char **path, char **exec)
|
|||||||
swap = ft_strjoin(swap, exec[0]);
|
swap = ft_strjoin(swap, exec[0]);
|
||||||
free(cmd);
|
free(cmd);
|
||||||
}
|
}
|
||||||
if (path[i])
|
//if (path[i])
|
||||||
return (swap);
|
return (swap);
|
||||||
free(swap);
|
free(swap);
|
||||||
return (0);
|
return (0);
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/03/09 12:33:30 by apommier #+# #+# */
|
/* Created: 2022/03/09 12:33:30 by apommier #+# #+# */
|
||||||
/* Updated: 2022/04/09 19:19:58 by apommier ### ########.fr */
|
/* Updated: 2022/04/10 21:33:46 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -36,6 +36,7 @@ void free_cmd(t_cmd *cmd)
|
|||||||
while (cmd->s_cmds[i])
|
while (cmd->s_cmds[i])
|
||||||
{
|
{
|
||||||
free_double(cmd->s_cmds[i]->args);
|
free_double(cmd->s_cmds[i]->args);
|
||||||
|
if (cmd->s_cmds[i]->cmd)
|
||||||
free(cmd->s_cmds[i]->cmd);
|
free(cmd->s_cmds[i]->cmd);
|
||||||
if (cmd->s_cmds[i]->infile)
|
if (cmd->s_cmds[i]->infile)
|
||||||
free(cmd->s_cmds[i]->infile);
|
free(cmd->s_cmds[i]->infile);
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/03/08 15:19:42 by apommier #+# #+# */
|
/* Created: 2022/03/08 15:19:42 by apommier #+# #+# */
|
||||||
/* Updated: 2022/04/09 18:47:25 by apommier ### ########.fr */
|
/* Updated: 2022/04/10 21:45:17 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -32,12 +32,12 @@ t_s_cmd *set_s_cmd(char *line, t_cmd *cmd, int index)
|
|||||||
s_cmd->outfile = 0;
|
s_cmd->outfile = 0;
|
||||||
//printf("before redirect\n");
|
//printf("before redirect\n");
|
||||||
line = set_redirection(s_cmd, line, index);//SET REDIRECTION
|
line = set_redirection(s_cmd, line, index);//SET REDIRECTION
|
||||||
split_line = ft_split(line, ' ');
|
split_line = ft_split_with_quote(line, ' ');
|
||||||
//print_double_fd(split_line, 0);
|
//print_double_fd(split_line, 0);
|
||||||
if (!is_builtin(split_line[0]))
|
if (!is_builtin(split_line[0]))
|
||||||
s_cmd->cmd = get_command(split_line, cmd->path);
|
s_cmd->cmd = ft_strdup(get_command(split_line, cmd->path));
|
||||||
else
|
else
|
||||||
s_cmd->cmd = ft_strjoin(split_line[0], 0);
|
s_cmd->cmd = ft_strdup(split_line[0]);
|
||||||
/*if (!s_cmd->cmd)
|
/*if (!s_cmd->cmd)
|
||||||
{
|
{
|
||||||
free(line);
|
free(line);
|
||||||
@ -81,7 +81,9 @@ t_cmd *set_cmd(char *input, char **env)
|
|||||||
t_cmd *cmd;
|
t_cmd *cmd;
|
||||||
char **cmds;
|
char **cmds;
|
||||||
|
|
||||||
cmds = ft_split(input, '|');
|
cmds = ft_split_with_quote(input, '|');
|
||||||
|
printf("-after split | -\n");
|
||||||
|
print_double_fd(cmds, 1);
|
||||||
if (!cmds)
|
if (!cmds)
|
||||||
return (0);
|
return (0);
|
||||||
cmd = malloc(sizeof(t_cmd));
|
cmd = malloc(sizeof(t_cmd));
|
||||||
|
|||||||
39
srcs/set_quote/set_quote.c
Normal file
39
srcs/set_quote/set_quote.c
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* set_quote.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/04/09 23:58:21 by apommier #+# #+# */
|
||||||
|
/* Updated: 2022/04/10 21:03:07 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../../includes/minishell.h"
|
||||||
|
|
||||||
|
int is_quote_even(char *str)
|
||||||
|
{
|
||||||
|
int simple_quote;
|
||||||
|
int double_quote;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = -1;
|
||||||
|
simple_quote = 0;
|
||||||
|
double_quote = 0;
|
||||||
|
while (str[i++])
|
||||||
|
{
|
||||||
|
if (str[i] == 39)
|
||||||
|
simple_quote++;
|
||||||
|
else if (str[i] == 34)
|
||||||
|
double_quote++;
|
||||||
|
}
|
||||||
|
if (simple_quote % 2 || double_quote % 2)
|
||||||
|
return (0);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*int parse_quote(char *str)
|
||||||
|
{
|
||||||
|
|
||||||
|
}*/
|
||||||
136
srcs/set_quote/split_with_quote.c
Normal file
136
srcs/set_quote/split_with_quote.c
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* split_with_quote.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/04/10 19:50:50 by apommier #+# #+# */
|
||||||
|
/* Updated: 2022/04/10 21:50:37 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../../includes/minishell.h"
|
||||||
|
|
||||||
|
int next_quote(const char *s, int i)
|
||||||
|
{
|
||||||
|
int simple_quote;
|
||||||
|
int double_quote;
|
||||||
|
|
||||||
|
simple_quote = 0;
|
||||||
|
double_quote = 0;
|
||||||
|
if (s[i] == '"' || s[i] == '\'')
|
||||||
|
{
|
||||||
|
|
||||||
|
if (s[i] == '"')
|
||||||
|
double_quote = 1;
|
||||||
|
else if (s[i] == '\'')
|
||||||
|
simple_quote = 1;
|
||||||
|
else
|
||||||
|
printf("qu'es tu fous ?\n");
|
||||||
|
i++;
|
||||||
|
if (simple_quote)
|
||||||
|
{
|
||||||
|
while (s[i] != '\'')
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (s[i] != '"')
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int fill_tab(char *s, char c, char **dest, size_t index)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int size;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
//printf("split: s= %s\n", s);
|
||||||
|
while (s[i] != c && s[i])
|
||||||
|
{
|
||||||
|
if (s[i] == '"' || s[i] == '\'')
|
||||||
|
i = next_quote(s, i);
|
||||||
|
else
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
//printf("split: size= %d\n", i);
|
||||||
|
dest[index] = (char *)ft_calloc(i + 1, sizeof(char));
|
||||||
|
if (dest[index] == 0)
|
||||||
|
return (0);
|
||||||
|
size = i;
|
||||||
|
i = 0;
|
||||||
|
while (i < size)
|
||||||
|
{
|
||||||
|
dest[index][i] = s[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void call(char *s, char c, char **dest, int j)
|
||||||
|
{
|
||||||
|
int index;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
index = 0;
|
||||||
|
while (j > index)
|
||||||
|
{
|
||||||
|
while (s[i] != '"' && s[i] != '\'' && s[i] == c && s[i])
|
||||||
|
i++;
|
||||||
|
if (!s[i])
|
||||||
|
return ;
|
||||||
|
fill_tab(s + i, c, dest, index);
|
||||||
|
index++;
|
||||||
|
while (s[i] != c && s[i])
|
||||||
|
{
|
||||||
|
if (s[i] == '"' || s[i] == '\'')
|
||||||
|
i = next_quote(s, i);
|
||||||
|
else
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char **ft_split_with_quote(char const *s, char c)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
char **dest;
|
||||||
|
|
||||||
|
j = 0;
|
||||||
|
i = 0;
|
||||||
|
if (!s)
|
||||||
|
return (0);
|
||||||
|
i = next_quote(s, i);
|
||||||
|
if (i)
|
||||||
|
j++;
|
||||||
|
//printf("j= %d\n", j);
|
||||||
|
while (s[i] == c && s[i])
|
||||||
|
i++;
|
||||||
|
while (s[i])
|
||||||
|
{
|
||||||
|
while (s[i] != c && s[i])
|
||||||
|
{
|
||||||
|
if (s[i] == '"' || s[i] == '\'')
|
||||||
|
i = next_quote(s, i);
|
||||||
|
else
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
j++;
|
||||||
|
while (s[i] == c && s[i])
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
dest = (char **)ft_calloc(sizeof(char *), (1 + j));//modif i + j en 1 + j
|
||||||
|
if (!dest)
|
||||||
|
return (0);
|
||||||
|
dest[j] = 0;
|
||||||
|
//printf("split: j= %d\n", j);
|
||||||
|
call((char *)s, c, dest, j);
|
||||||
|
return (dest);
|
||||||
|
}
|
||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/03/09 15:18:58 by apommier #+# #+# */
|
/* Created: 2022/03/09 15:18:58 by apommier #+# #+# */
|
||||||
/* Updated: 2022/04/09 21:05:43 by apommier ### ########.fr */
|
/* Updated: 2022/04/10 18:13:00 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -214,6 +214,8 @@ void wait_prompt(t_s_cmd *cmd, int index)
|
|||||||
{
|
{
|
||||||
ft_putstr_fd("> ", 0);
|
ft_putstr_fd("> ", 0);
|
||||||
input = get_next_line(0);
|
input = get_next_line(0);
|
||||||
|
//input = readline("");
|
||||||
|
printf("input= %s\n", input);
|
||||||
if (!input)
|
if (!input)
|
||||||
return ;
|
return ;
|
||||||
input[ft_strlen(input) - 1] = 0;
|
input[ft_strlen(input) - 1] = 0;
|
||||||
@ -245,7 +247,7 @@ char *set_redirection(t_s_cmd *cmd, char *line, int index)
|
|||||||
else if(line[i] == '>')
|
else if(line[i] == '>')
|
||||||
{
|
{
|
||||||
line = ft_output(line, cmd, i);
|
line = ft_output(line, cmd, i);
|
||||||
if (cmd->in_type == 0)
|
//if (cmd->in_type == 0)
|
||||||
set_file(cmd->outfile);
|
set_file(cmd->outfile);
|
||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user