start norm (delete commentary)

This commit is contained in:
kinou-p 2022-04-19 12:06:52 +02:00
parent 13ab6456d0
commit 10abbb572d
8 changed files with 17 additions and 173 deletions

View File

@ -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/19 08:23:56 by apommier ### ########.fr */ /* Updated: 2022/04/19 12:05:20 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,26 +19,12 @@ void crtl_c(int num)
rl_replace_line("", 0); rl_replace_line("", 0);
rl_on_new_line(); rl_on_new_line();
rl_redisplay(); rl_redisplay();
//ft_putstr_fd("test\n", 0);
} }
void sig_quit(int num) void sig_quit(int num)
{ {
(void)num; (void)num;
ft_putstr_fd("\b \b\b \b", 1); ft_putstr_fd("\b \b\b \b", 1);
//printf("quit num= %d\n", num);
//exit(0);
}
void sig_quit2(int num)
{
num = 0;
//ft_putchar_fd(127, 1);
//ft_putchar_fd(127, 1);
ft_putstr_fd("\b \b\b \b", 1);
ft_putstr_fd("sigquit2\n", 1);
//printf("sig_quit2\n");
//exit(0);
} }
char **ft_dup_double(char **env) char **ft_dup_double(char **env)
@ -66,8 +52,6 @@ void print_prompt(char **path)
{ {
char *input; char *input;
t_cmd *cmd; t_cmd *cmd;
//int tmpin = dup(0);
//int tmpout = dup(1);
int err_var; int err_var;
struct sigaction test; struct sigaction test;
@ -82,8 +66,6 @@ void print_prompt(char **path)
printf("Minishell: sigaction error\n"); printf("Minishell: sigaction error\n");
exit(1); exit(1);
} }
/*else
printf("sigaction good\n");*/
while (1) while (1)
{ {
input = readline("\033[1;31m~$ \033[0m"); input = readline("\033[1;31m~$ \033[0m");
@ -96,12 +78,9 @@ void print_prompt(char **path)
if (ft_strlen(input) && next_space(input, 0) && input && path) if (ft_strlen(input) && next_space(input, 0) && input && path)
{ {
cmd = set_cmd(input, path, err_var); cmd = set_cmd(input, path, err_var);
//path = ft_dup_double(path);
if (cmd) if (cmd)
{ {
free_double(path); free_double(path);
//cmd->err_var = 0;
execute(cmd, cmd->env); execute(cmd, cmd->env);
err_var = cmd->err_var; err_var = cmd->err_var;
@ -109,14 +88,6 @@ void print_prompt(char **path)
free_cmd(cmd); free_cmd(cmd);
cmd = 0; cmd = 0;
} }
/*else
{
close(0);
close(1);
dup2(tmpin, 0);
dup2(tmpout, 1);
ft_putstr_fd("Minishell: error while parsing command\n", 2);
}*/
} }
free(input); free(input);
} }
@ -131,7 +102,6 @@ int main(int ac, char **av, char **path)
printf("Not today\n"); printf("Not today\n");
return (0); return (0);
} }
//print_double_fd(path, 1);
env = ft_dup_double(path); env = ft_dup_double(path);
av = 0; av = 0;
if (ac != 1) if (ac != 1)
@ -141,7 +111,6 @@ int main(int ac, char **av, char **path)
} }
printf("---MINISHELL START---\n"); printf("---MINISHELL START---\n");
signal(SIGINT, crtl_c); signal(SIGINT, crtl_c);
//signal(SIGQUIT, sig_quit);
if (env) if (env)
ft_shlvl(env); ft_shlvl(env);
print_prompt(env); print_prompt(env);

View File

@ -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/19 08:26:07 by apommier ### ########.fr */ /* Updated: 2022/04/19 12:00:46 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -48,22 +48,13 @@ int wait_exit(t_cmd *cmd)
close(cmd->s_cmds[i]->fd[0]); close(cmd->s_cmds[i]->fd[0]);
close(cmd->s_cmds[i]->fd[1]); close(cmd->s_cmds[i]->fd[1]);
if (WIFEXITED(status)) if (WIFEXITED(status))
{
//printf("return normally cmd = -%s-\n", cmd->s_cmds[i]->cmd);
//if (!cmd->err_var)
cmd->err_var = WEXITSTATUS(status); cmd->err_var = WEXITSTATUS(status);
//printf("err_var= %d\n", cmd->err_var);
//printf("code= %d\n", cmd->err_var);
}
else if (WIFSIGNALED(status)) else if (WIFSIGNALED(status))
{ {
//printf("return by signal cmd = -%s-\n", cmd->s_cmds[i]->cmd);
//printf("signal= %d\n", WTERMSIG(status));
if (WTERMSIG(status) != 13) if (WTERMSIG(status) != 13)
cmd->err_var = WTERMSIG(status); cmd->err_var = WTERMSIG(status);
if (WTERMSIG(status) == 3) if (WTERMSIG(status) == 3)
ft_putstr_fd("^\\Quit", 1); ft_putstr_fd("^\\Quit", 1);
//if (cmd->err_var == 2)
ft_putstr_fd("\b\b\b\b\b", 1); ft_putstr_fd("\b\b\b\b\b", 1);
} }
} }
@ -108,14 +99,7 @@ void exec_cmd(t_cmd *cmd, char **env, int *fdpipe)
else if (!cmd->current_s_cmd->cmd || access(cmd->current_s_cmd->cmd, F_OK)) else if (!cmd->current_s_cmd->cmd || access(cmd->current_s_cmd->cmd, F_OK))
cmd->err_var = 127; cmd->err_var = 127;
else else
cmd->err_var = 126; cmd->err_var = 131;
/*if (cmd->current_s_cmd->child)
{
if (cmd->current_s_cmd->infile)
close(cmd->current_s_cmd->infile);
if (cmd->current_s_cmd->outfile)
close(cmd->current_s_cmd->outfile);
}*/
} }
void execute(t_cmd *cmd, char **env) void execute(t_cmd *cmd, char **env)
@ -135,7 +119,6 @@ void execute(t_cmd *cmd, char **env)
tmpout = dup(1); tmpout = dup(1);
cmd->tmpin = tmpin; cmd->tmpin = tmpin;
cmd->tmpout = tmpout; cmd->tmpout = tmpout;
//printf("infile= %s\n", cmd->current_s_cmd->infile);
if (cmd->current_s_cmd->infile) if (cmd->current_s_cmd->infile)
{ {
fdin = open(cmd->current_s_cmd->infile, O_RDWR); fdin = open(cmd->current_s_cmd->infile, O_RDWR);
@ -146,8 +129,6 @@ void execute(t_cmd *cmd, char **env)
fdin = dup(tmpin); fdin = dup(tmpin);
while(cmd->current_s_cmd) while(cmd->current_s_cmd)
{ {
//if (i != 0)
// close(fdout);
cmd->current_s_cmd->child = 1; cmd->current_s_cmd->child = 1;
fdout = -1; fdout = -1;
if (i > 0 && cmd->current_s_cmd->infile) if (i > 0 && cmd->current_s_cmd->infile)
@ -186,13 +167,11 @@ void execute(t_cmd *cmd, char **env)
fdin=fdpipe[0]; fdin=fdpipe[0];
exec_cmd(cmd, env, fdpipe); exec_cmd(cmd, env, fdpipe);
close(cmd->current_s_cmd->fd[0]); close(cmd->current_s_cmd->fd[0]);
//close(fdin); //bad thing
} }
if (fdpipe[1] != -1) if (fdpipe[1] != -1)
close(fdpipe[1]); close(fdpipe[1]);
i++; i++;
cmd->current_s_cmd = cmd->s_cmds[i]; cmd->current_s_cmd = cmd->s_cmds[i];
//printf("cmd->err_var= %d\n", cmd->err_var);
} }
close_pipe(cmd); close_pipe(cmd);
dup2(tmpin, 0); dup2(tmpin, 0);
@ -200,8 +179,4 @@ void execute(t_cmd *cmd, char **env)
close(tmpin); close(tmpin);
close(tmpout); close(tmpout);
wait_exit(cmd); wait_exit(cmd);
//close(tmpin);
//tmpin = -1;
//close(tmpout);
//tmpout = -1;
} }

View File

@ -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/19 08:09:11 by apommier ### ########.fr */ /* Updated: 2022/04/19 12:01:06 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -41,19 +41,12 @@ char **get_path(char **env)
return (0); return (0);
} }
//verify access with cmd access
char *does_access(char **path, char **exec) char *does_access(char **path, char **exec)
{ {
int i; int i;
char *cmd; char *cmd;
char *swap; char *swap;
// if (!path)
// {
// ft_putstr_fd("Minishell: no PATH\n", 2);
// return (0);
// }
swap = 0; swap = 0;
cmd = 0; cmd = 0;
i = 0; i = 0;
@ -84,10 +77,7 @@ char *get_command(char **exec, char **path)
if (!path) if (!path)
return (0); return (0);
if ((exec[0][0] == '/' || exec[0][0] == '.') && !access(exec[0], F_OK)) if ((exec[0][0] == '/' || exec[0][0] == '.') && !access(exec[0], F_OK))
{
//free_double(path);
return (exec[0]); return (exec[0]);
}
else if (exec[0][0] == '/') else if (exec[0][0] == '/')
return(0); return(0);
swap = does_access(path, exec); swap = does_access(path, exec);

View File

@ -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/19 07:14:17 by apommier ### ########.fr */ /* Updated: 2022/04/19 12:01:16 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,8 +17,6 @@ void exit_shell(t_cmd *cmd, int ret)
int i; int i;
i = 0; i = 0;
//if (cmd)
// free_double(cmd->env);
ft_putstr_fd("exit\n", 1); ft_putstr_fd("exit\n", 1);
if (!cmd) if (!cmd)
exit(ret); exit(ret);
@ -38,10 +36,6 @@ void exit_shell(t_cmd *cmd, int ret)
close(cmd->current_s_cmd->fd[1]); close(cmd->current_s_cmd->fd[1]);
free_cmd(cmd); free_cmd(cmd);
clear_history(); clear_history();
//print_double_fd(cmd->s_cmds[0]->env, 1);
//if (cmd->path)
//free_double(cmd->path);
cmd = 0; cmd = 0;
exit(ret); exit(ret);
} }

View File

@ -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/19 09:59:04 by apommier ### ########.fr */ /* Updated: 2022/04/19 12:01:46 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -25,7 +25,6 @@ t_s_cmd *set_s_cmd(char *line, int index)
int i; int i;
i = 0; i = 0;
//line = ft_split(line, ' ');
s_cmd = malloc(sizeof(t_s_cmd)); s_cmd = malloc(sizeof(t_s_cmd));
if (!s_cmd) if (!s_cmd)
return (0); return (0);
@ -34,8 +33,7 @@ t_s_cmd *set_s_cmd(char *line, int index)
s_cmd->args = 0; s_cmd->args = 0;
s_cmd->infile = 0; s_cmd->infile = 0;
s_cmd->outfile = 0; s_cmd->outfile = 0;
//printf("before redirect\n"); line = set_redirection(s_cmd, line, index);
line = set_redirection(s_cmd, line, index);//SET REDIRECTION
if (!line) if (!line)
{ {
free(s_cmd); free(s_cmd);
@ -61,7 +59,6 @@ t_cmd *split_cmd(t_cmd *cmd, char **cmds)
free_cmd(cmd); free_cmd(cmd);
return (0); return (0);
} }
//cmd->s_cmds[i]->env = env;
cmd->s_cmds[i]->big_cmd = cmd; cmd->s_cmds[i]->big_cmd = cmd;
i++; i++;
} }
@ -107,7 +104,6 @@ t_cmd *set_cmd(char *input, char **env, int nb)
return (0); return (0);
cmd->s_cmds = ft_calloc(sizeof(t_s_cmd), double_size(cmds) + 1); cmd->s_cmds = ft_calloc(sizeof(t_s_cmd), double_size(cmds) + 1);
if (!cmd->s_cmds) if (!cmd->s_cmds)
//free(cmd);
return (0); return (0);
cmd->tmpin = -1; cmd->tmpin = -1;
cmd->tmpout = -1; cmd->tmpout = -1;
@ -115,20 +111,17 @@ t_cmd *set_cmd(char *input, char **env, int nb)
cmd->path = get_path(env); cmd->path = get_path(env);
cmd->env = ft_dup_double(env); cmd->env = ft_dup_double(env);
cmd->nb_s_cmd = double_size(cmds); cmd->nb_s_cmd = double_size(cmds);
//printf("call split cmd\n"); cmd = split_cmd(cmd, cmds);
cmd = split_cmd(cmd, cmds); //split each cmd into args in s_cmd
//printf("end split cdm\n");
if (!cmd) if (!cmd)
{ {
free(cmds); free(cmds);
//printf("no cmd\n");
return (0); return (0);
} }
parse_quote(cmd); parse_quote(cmd);
free(cmds); free(cmds);
if (cmd) if (cmd)
{ {
cmd->current_s_cmd = cmd->s_cmds[0];//set first s_cmd cmd->current_s_cmd = cmd->s_cmds[0];
cmd->err_var = 0; cmd->err_var = 0;
return (cmd); return (cmd);
} }

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/09 23:58:21 by apommier #+# #+# */ /* Created: 2022/04/09 23:58:21 by apommier #+# #+# */
/* Updated: 2022/04/19 10:37:55 by apommier ### ########.fr */ /* Updated: 2022/04/19 12:03:24 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -72,11 +72,7 @@ int is_quote_good(char *str)
i++; i++;
} }
if (simple_quote % 2 || double_quote % 2) if (simple_quote % 2 || double_quote % 2)
{
printf("bad quote\n");
return (0); return (0);
}
//printf("good_quote\n");
return (1); return (1);
} }
@ -86,22 +82,12 @@ char *del_char(char *str, int *index)
char *swap2; char *swap2;
swap = 0; swap = 0;
//printf("index= %d\n", *index);
//printf("before del char -%s-\n", str);
// if (ft_strlen(str) > 1)
swap = ft_strdup(str + *index + 1); swap = ft_strdup(str + *index + 1);
// else
// swap =
//printf("in del char after dup -%s-\n", swap);
// if (str)
str[*index] = 0; str[*index] = 0;
swap2 = str; swap2 = str;
str = ft_strjoin(str, swap); str = ft_strjoin(str, swap);
free(swap2); free(swap2);
free(swap); free(swap);
//if (*index)
// (*index)--;
//printf("after del char -%s-\n", str);
return (str); return (str);
} }
@ -114,7 +100,6 @@ char *get_var(t_cmd *cmd, char *var_name)
line = 0; line = 0;
if (!ft_strcmp(var_name, "?")) if (!ft_strcmp(var_name, "?"))
return (ft_itoa(cmd->err_var)); return (ft_itoa(cmd->err_var));
//printf("var_name -%s-\n", var_name);
index = find_it(cmd->env, var_name); index = find_it(cmd->env, var_name);
if (index >= 0) if (index >= 0)
{ {
@ -126,8 +111,6 @@ char *get_var(t_cmd *cmd, char *var_name)
return (0); return (0);
free_double(split_line); free_double(split_line);
} }
//printf("get_var line= -%s-\n", line);
return (line); return (line);
} }
@ -153,6 +136,7 @@ char *change_var(t_cmd *big_cmd, char *cmd, int *index)
free(var); free(var);
var = ret; var = ret;
ret = ft_strjoin(ret, swap2); ret = ft_strjoin(ret, swap2);
free(var);
free(swap2); free(swap2);
return (ret); return (ret);
} }
@ -162,18 +146,12 @@ char *set_var(t_cmd *big_cmd, char *cmd)
int i; int i;
char *del; char *del;
//printf("set_var\n");
i = 0; i = 0;
while (cmd[i]) while (cmd[i])
{ {
//printf("set var str= %s et i= %d\n", cmd, i);
//printf("char= -%c-\n", cmd[i]);
if (cmd[i] == '\'') if (cmd[i] == '\'')
{ {
//del = cmd;
cmd = del_char(cmd, &i); cmd = del_char(cmd, &i);
//free(del);
//printf("i= %d char= -%c- str= -%s-\n", i, cmd[i], cmd);
if (cmd[i]) if (cmd[i])
{ {
while (cmd[i] != '\'') while (cmd[i] != '\'')
@ -185,38 +163,23 @@ char *set_var(t_cmd *big_cmd, char *cmd)
} }
else if (cmd[i] == '"') else if (cmd[i] == '"')
{ {
//del = cmd;
cmd = del_char(cmd, &i); cmd = del_char(cmd, &i);
//free(del);
//printf("cmd after del char= %s\n", cmd);
//printf("i= %d char= -%c-\n", i, cmd[i]);
if (cmd[i]) if (cmd[i])
{ {
while (cmd[i] != '"') while (cmd[i] != '"')
{ {
if (cmd[i] == '$') if (cmd[i] == '$')
{
cmd = change_var(big_cmd, cmd, &i); cmd = change_var(big_cmd, cmd, &i);
//printf("i= %d et cmd= -%s-\n", i, cmd);
}
i++; i++;
} }
//del = cmd;
//printf("cmd before del char2= %s\n", cmd);
cmd = del_char(cmd, &i); cmd = del_char(cmd, &i);
//printf("cmd after del char2= %s\n", cmd);
//free(del);
} }
//printf("cmd after \"= %s\n", cmd);
//printf("i= %d char= -%c-\n", i, cmd[i]);
//i++;
} }
else if (cmd[i] == '$') else if (cmd[i] == '$')
cmd = change_var(big_cmd, cmd, &i); cmd = change_var(big_cmd, cmd, &i);
else else
i++; i++;
} }
//printf("after all -%s-\n", cmd);
return (cmd); return (cmd);
} }
@ -231,16 +194,11 @@ int parse_quote(t_cmd *cmd)
{ {
j = -1; j = -1;
//print_double_fd(cmd->s_cmds[i]->args, 1);
while (cmd->s_cmds[i]->args[++j]) while (cmd->s_cmds[i]->args[++j])
{ {
//printf("parse quote args= -%s-\n", cmd->s_cmds[i]->args[j]);
swap = cmd->s_cmds[i]->args[j]; swap = cmd->s_cmds[i]->args[j];
cmd->s_cmds[i]->args[j] = set_var(cmd, cmd->s_cmds[i]->args[j]); cmd->s_cmds[i]->args[j] = set_var(cmd, cmd->s_cmds[i]->args[j]);
//if (cmd->s_cmds[i]->args[j] != swap)
// free(swap);
} }
//printf("parse quote -%s-\n", cmd->s_cmds[i]->args[0]);
if (!is_builtin(cmd->s_cmds[i]->args[0])) if (!is_builtin(cmd->s_cmds[i]->args[0]))
{ {
cmd->s_cmds[i]->cmd = get_command(cmd->s_cmds[i]->args, cmd->path); cmd->s_cmds[i]->cmd = get_command(cmd->s_cmds[i]->args, cmd->path);
@ -251,17 +209,6 @@ int parse_quote(t_cmd *cmd)
cmd->s_cmds[i]->cmd = ft_strdup(cmd->s_cmds[i]->args[0]); cmd->s_cmds[i]->cmd = ft_strdup(cmd->s_cmds[i]->args[0]);
if (!cmd->s_cmds[i]->cmd) if (!cmd->s_cmds[i]->cmd)
cmd->s_cmds[i]->cmd = ft_strdup(cmd->s_cmds[i]->args[0]); cmd->s_cmds[i]->cmd = ft_strdup(cmd->s_cmds[i]->args[0]);
// else
// {
// swap = cmd->s_cmds[i]->cmd;
// cmd->s_cmds[i]->cmd = ft_strdup(cmd->s_cmds[i]->cmd);
// free(swap)
// }
//free(cmd->s_cmds[i]->cmd);
//cmd->s_cmds[i]->cmd = ft_strdup(cmd->s_cmds[i]->args[0]);
//printf("parse quote -%s-\n", cmd->s_cmds[i]->cmd);
i++; i++;
} }
return (0); return (0);

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/10 19:50:50 by apommier #+# #+# */ /* Created: 2022/04/10 19:50:50 by apommier #+# #+# */
/* Updated: 2022/04/10 21:50:37 by apommier ### ########.fr */ /* Updated: 2022/04/19 12:03:45 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -50,7 +50,6 @@ static int fill_tab(char *s, char c, char **dest, size_t index)
int size; int size;
i = 0; i = 0;
//printf("split: s= %s\n", s);
while (s[i] != c && s[i]) while (s[i] != c && s[i])
{ {
if (s[i] == '"' || s[i] == '\'') if (s[i] == '"' || s[i] == '\'')
@ -58,7 +57,6 @@ static int fill_tab(char *s, char c, char **dest, size_t index)
else else
i++; i++;
} }
//printf("split: size= %d\n", i);
dest[index] = (char *)ft_calloc(i + 1, sizeof(char)); dest[index] = (char *)ft_calloc(i + 1, sizeof(char));
if (dest[index] == 0) if (dest[index] == 0)
return (0); return (0);
@ -110,7 +108,6 @@ char **ft_split_with_quote(char const *s, char c)
i = next_quote(s, i); i = next_quote(s, i);
if (i) if (i)
j++; j++;
//printf("j= %d\n", j);
while (s[i] == c && s[i]) while (s[i] == c && s[i])
i++; i++;
while (s[i]) while (s[i])
@ -126,11 +123,10 @@ char **ft_split_with_quote(char const *s, char c)
while (s[i] == c && s[i]) while (s[i] == c && s[i])
i++; i++;
} }
dest = (char **)ft_calloc(sizeof(char *), (1 + j));//modif i + j en 1 + j dest = (char **)ft_calloc(sizeof(char *), (1 + j));
if (!dest) if (!dest)
return (0); return (0);
dest[j] = 0; dest[j] = 0;
//printf("split: j= %d\n", j);
call((char *)s, c, dest, j); call((char *)s, c, dest, j);
return (dest); return (dest);
} }

View File

@ -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/18 15:48:57 by apommier ### ########.fr */ /* Updated: 2022/04/19 12:04:35 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,7 +14,6 @@
char next_space(char *str, int i) char next_space(char *str, int i)
{ {
//i++;
while (str[i] == ' ') while (str[i] == ' ')
i++; i++;
return (str[i]); return (str[i]);
@ -51,7 +50,6 @@ char *get_word(char *str, int start)
while (new[i] && new[i] != ' ' && new[i] != '>' && new[i] != '<') while (new[i] && new[i] != ' ' && new[i] != '>' && new[i] != '<')
i++; i++;
new[i] = 0; new[i] = 0;
//printf("get word= %s\n", new);
return (new); return (new);
} }
@ -107,7 +105,6 @@ char *set_output(char *line, t_s_cmd *cmd, int index)
return (line); return (line);
} }
//choose type of redirection, check error
char *ft_input(char *line, t_s_cmd *cmd, int index) char *ft_input(char *line, t_s_cmd *cmd, int index)
{ {
int i; int i;
@ -124,11 +121,9 @@ char *ft_input(char *line, t_s_cmd *cmd, int index)
cmd->in_type = 0; cmd->in_type = 0;
if (next == '<' || next == '>' || !next) if (next == '<' || next == '>' || !next)
return (0); return (0);
//printf("line bf set_input -%s-", line);
line = set_input(line, cmd, i); line = set_input(line, cmd, i);
if (!line) if (!line)
return (0); return (0);
//printf("line -%s-\n", line);
return (line); return (line);
} }
@ -149,7 +144,6 @@ char *ft_output(char *line, t_s_cmd *cmd, int index)
if (next == '<' || next == '>' || !next) if (next == '<' || next == '>' || !next)
return (0); return (0);
line = set_output(line, cmd, i); line = set_output(line, cmd, i);
//printf("line -%s-\n", line);
return (line); return (line);
} }
@ -157,7 +151,6 @@ int set_file(char *file)
{ {
int fd; int fd;
//printf("setfile= %s\n", file);
fd = open(file, O_TRUNC | O_CREAT, 0644); fd = open(file, O_TRUNC | O_CREAT, 0644);
if (fd == -1) if (fd == -1)
{ {
@ -166,7 +159,6 @@ int set_file(char *file)
ft_putstr_fd(": Permission denied\n", 2); ft_putstr_fd(": Permission denied\n", 2);
return (0); return (0);
} }
//error_redirect("can't set file");
if (fd) if (fd)
close(fd); close(fd);
return (1); return (1);
@ -198,11 +190,6 @@ char **add_line(char **tab, char *line)
return(ret); return(ret);
} }
/*void del_heredoc()
{
}*/
char *set_heredoc(int index, char **in) char *set_heredoc(int index, char **in)
{ {
char *nbr_file; char *nbr_file;
@ -236,7 +223,6 @@ void sig_heredoc(int num)
memset(&base, 0, sizeof(base)); memset(&base, 0, sizeof(base));
base.sa_handler = &crtl_c; base.sa_handler = &crtl_c;
base.sa_flags = 0; base.sa_flags = 0;
//close(1);
ft_putchar_fd('\n', 1); ft_putchar_fd('\n', 1);
if (sigaction(SIGINT, &base, 0) == -1) if (sigaction(SIGINT, &base, 0) == -1)
{ {
@ -266,7 +252,6 @@ int wait_prompt(t_s_cmd *cmd, int index)
printf("sigaction error\n"); printf("sigaction error\n");
exit(1); exit(1);
} }
//printf("wait_prompt\n");
history = 0; history = 0;
input = 0; input = 0;
i = 0; i = 0;
@ -307,11 +292,8 @@ char *set_redirection(t_s_cmd *cmd, char *line, int index)
int i; int i;
i= 0; i= 0;
// printf("enter redirection\n");
while (line[i]) while (line[i])
{ {
//printf("line[i] i= %d\n", i);
//printf("-%s-\n", line);
if(line[i] == '<') if(line[i] == '<')
{ {
if (!is_in_quote(line, i)) if (!is_in_quote(line, i))
@ -324,7 +306,6 @@ char *set_redirection(t_s_cmd *cmd, char *line, int index)
if (wait_prompt(cmd, index) == -1) if (wait_prompt(cmd, index) == -1)
{ {
free(line); free(line);
//printf("no waitpromt\n");
return (0); return (0);
} }
} }
@ -336,7 +317,6 @@ char *set_redirection(t_s_cmd *cmd, char *line, int index)
if (!is_in_quote(line, i)) if (!is_in_quote(line, i))
{ {
line = ft_output(line, cmd, i); line = ft_output(line, cmd, i);
//if (cmd->in_type == 0)
if (!set_file(cmd->outfile)) if (!set_file(cmd->outfile))
return (0); return (0);
i = 0; i = 0;