rectif bquote

This commit is contained in:
wescande 2017-03-20 15:11:04 +01:00
parent f8753646e2
commit 378aa39ceb
5 changed files with 35 additions and 52 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */
/* Updated: 2017/03/20 14:43:04 by wescande ### ########.fr */
/* Updated: 2017/03/20 15:01:01 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -81,8 +81,8 @@ void token_print(t_list *lst);
int reduce_parens(t_list **alst, char *str);
int bquotes_expand(t_list **alst);
char *command_getoutput(char *command, char *const av[], char **env, int pipe_mode);
int command_setoutput(char *command, char *const av[], char **env, int pipe_mode);
char *command_getoutput(char *command);
int command_setoutput(char *const av[], char **env);
int ft_is_delim(char c);
int ft_is_delim_list(char c);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 14:14:20 by jhalford #+# #+# */
/* Updated: 2017/03/20 14:43:49 by wescande ### ########.fr */
/* Updated: 2017/03/20 15:02:31 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -110,7 +110,7 @@ int builtin_env(const char *path,
ft_putchar('\n');
}
else
pid = command_setoutput(NULL, argv, env, 0);
pid = command_setoutput(argv, env);
ft_tabdel(&env);
return (builtin_return_status(pid, 0));
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */
/* Updated: 2017/03/20 11:38:54 by wescande ### ########.fr */
/* Updated: 2017/03/20 14:57:26 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -36,9 +36,10 @@ int do_the_muther_forker(t_process *p)
exit(p->map.launch(p));
}
static int should_i_fork(t_process *p)
static int do_the_fork_if_i_have_to(t_process *p)
{
if (IS_PIPESINGLE(*p) && p->type != PROCESS_FILE && p->type != PROCESS_SUBSHELL)
if (IS_PIPESINGLE(*p)
&& p->type != PROCESS_FILE && p->type != PROCESS_SUBSHELL)
{
if (process_redirect(p))
{
@ -46,8 +47,6 @@ static int should_i_fork(t_process *p)
return (0);
}
return (p->map.launch(p));
/* set_exitstatus(p->map.launch(p), 1); */
/* return (0); */
}
return (do_the_muther_forker(p));
}
@ -58,7 +57,7 @@ int process_launch(t_process *p)
DG("p->type=%i", p->type);
p->state = PROCESS_RUNNING;
if (!(pid = should_i_fork(p)))
if (!(pid = do_the_fork_if_i_have_to(p)))
{
DG("launcher did not fork!");
process_resetfds(p);

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/14 19:44:25 by wescande #+# #+# */
/* Updated: 2017/03/20 11:36:03 by wescande ### ########.fr */
/* Updated: 2017/03/20 15:10:40 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -49,11 +49,12 @@ static char *manage_command(char *const av_cmd[])
return (command);
}
static void execute_command(char *command, char *const av[], char **env)
static void execute_command(char *const av[], char **env)
{
t_list *token;
t_btree *ast;
t_data *data;
char *command;
token = NULL;
ast = NULL;
@ -61,7 +62,7 @@ static void execute_command(char *command, char *const av[], char **env)
data->env = env;
data->opts &= ~SH_INTERACTIVE;
data->opts &= ~SH_OPTS_JOBC;
command = command ? command : manage_command(av);
command = manage_command(av);
DG("command is %s", command);
if (do_lexer_routine(&token, command))
{
@ -78,43 +79,37 @@ static void execute_command(char *command, char *const av[], char **env)
exit(data_singleton()->parser.state == SUCCESS && ft_exec(&ast) < 0);
}
char *command_getoutput(char *command, char *const av[], char **env, int pipe_mode)
char *command_getoutput(char *command)
{
int ret;
int pid;
int fds[2];
char **av;
if (!command && !av)
if (!command)
return (NULL);
if (pipe_mode)
pipe(fds);
if (!(pid = fork()))
pipe(fds);
if (!(pid = do_the_muther_forker(NULL)))
{
if (pipe_mode)
{
close(fds[PIPE_READ]);
dup2_close(fds[PIPE_WRITE], STDOUT);
}
execute_command(command, av, env);
close(fds[PIPE_READ]);
dup2_close(fds[PIPE_WRITE], STDOUT);
av = ft_sstradd(NULL, data_singleton()->argv[0]);
av = ft_sstradd(av, "-c");
av = ft_sstradd(av, command);
execve(data_singleton()->argv[0], av, data_singleton()->env);
exit(1);
}
waitpid(pid, &ret, WUNTRACED);
if (pipe_mode)
return (manage_output(fds));
return (NULL);
return (manage_output(fds));
}
int command_setoutput(char *command, char *const av[], char **env, int pipe_mode)
int command_setoutput(char *const av[], char **env)
{
/* int ret; */
int pid;
(void)pipe_mode;
if (!command && !av)
if (!av)
return (0);
if (!(pid = do_the_muther_forker(NULL)))
execute_command(command, av, env);
execute_command(av, env);
return (pid);
/* waitpid(pid, &ret, WUNTRACED); */
/* if (pipe_mode) */
/* return (manage_output(fds)); */
/* return (NULL); */
}

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/17 17:47:53 by wescande #+# #+# */
/* Updated: 2017/03/19 17:33:11 by wescande ### ########.fr */
/* Updated: 2017/03/20 15:10:32 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -72,7 +72,7 @@ static char *get_output(char *command)
char *output;
int len;
if (!(output = command_getoutput(command, NULL, data_singleton()->env, 1)))
if (!(output = command_getoutput(command)))
return (NULL);
len = ft_strlen(output);
while (output[--len] == '\n')
@ -80,18 +80,6 @@ static char *get_output(char *command)
return (output);
}
static char *treat_str(t_bquote *me, char *sta)
{
if (sta && *me->str == '\n'
&& !is_char_esc(me->esc, CH(*me->wk)[0], me->str))
*me->str = ';';
if (sta && *me->str == '\n'
&& is_char_esc(me->esc, CH(*me->wk)[0], me->str))
*me->str = ' ';
return (*me->str == '`' && !sta
&& !is_char_esc(me->esc2, CH(*me->wk)[0], me->str) ? me->str : sta);
}
static int search_bquote(t_bquote *me)
{
char *sta;
@ -100,7 +88,8 @@ static int search_bquote(t_bquote *me)
sta = NULL;
while (*(++me->str))
{
sta = treat_str(me, sta);
sta = *me->str == '`' && !sta
&& !is_char_esc(me->esc2, CH(*me->wk)[0], me->str) ? me->str : sta;
if (sta && *me->str == '`' && me->str != sta
&& !is_char_esc(me->esc2, CH(*me->wk)[0], me->str))
{