le retour des BQUOTE
This commit is contained in:
parent
0d4f441670
commit
30556cdba2
3 changed files with 50 additions and 83 deletions
|
|
@ -3,23 +3,24 @@
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* command_getoutput.c :+: :+: :+: */
|
/* command_getoutput.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/12 14:01:59 by jhalford #+# #+# */
|
/* Created: 2017/03/14 19:44:25 by wescande #+# #+# */
|
||||||
/* Updated: 2017/03/13 23:32:52 by jhalford ### ########.fr */
|
/* Updated: 2017/03/14 19:44:37 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
#define BUF_SIZE 1024
|
#define BUF_SIZE 1024
|
||||||
|
|
||||||
/*static char *manage_output(int *fds)
|
static char *manage_output(int *fds)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
char buf[BUF_SIZE + 1];
|
char buf[BUF_SIZE + 1];
|
||||||
char *output;
|
char *output;
|
||||||
|
|
||||||
output = NULL;
|
output = NULL;
|
||||||
|
close(fds[PIPE_WRITE]);
|
||||||
while ((ret = read(fds[PIPE_READ], buf, BUF_SIZE)) > 0)
|
while ((ret = read(fds[PIPE_READ], buf, BUF_SIZE)) > 0)
|
||||||
{
|
{
|
||||||
buf[ret] = 0;
|
buf[ret] = 0;
|
||||||
|
|
@ -27,69 +28,28 @@
|
||||||
}
|
}
|
||||||
close(fds[PIPE_READ]);
|
close(fds[PIPE_READ]);
|
||||||
return (output);
|
return (output);
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
static t_btree *gen_t_btree(const char *command)
|
|
||||||
{
|
|
||||||
t_btree *ast;
|
|
||||||
t_astnode item;
|
|
||||||
int len;
|
|
||||||
unsigned char *esc;
|
|
||||||
|
|
||||||
ft_bzero(&item, sizeof(t_astnode));
|
|
||||||
item.type = SUBSHELL;
|
|
||||||
ast = btree_create_node(&item, sizeof(t_astnode));
|
|
||||||
ft_bzero(&item, sizeof(t_astnode));
|
|
||||||
item.type = CMD;
|
|
||||||
len = ft_strlen(command);
|
|
||||||
esc = ft_memalloc((len >> 3) + 1);
|
|
||||||
ft_ld_pushfront(&item.data.cmd.token, gen_tab(command, esc, esc, 1));
|
|
||||||
ast->right = btree_create_node(&item, sizeof(t_astnode));
|
|
||||||
return (ast);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *command_getoutput(char *command)
|
char *command_getoutput(char *command)
|
||||||
{
|
{
|
||||||
t_btree *ast;
|
|
||||||
char *output;
|
char *output;
|
||||||
char buf[BUF_SIZE + 1];
|
|
||||||
t_exec *exec;
|
|
||||||
t_process p;
|
|
||||||
int ret;
|
int ret;
|
||||||
int pid;
|
int pid;
|
||||||
|
int fds[2];
|
||||||
|
|
||||||
|
if (!command)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
output = NULL;
|
pipe(fds);
|
||||||
exec = &data_singleton()->exec;
|
if (!(pid = fork()))
|
||||||
DG("%p exec ?", exec);
|
|
||||||
DG("\033[38;5;46mbefore");
|
|
||||||
ast = gen_t_btree(command);
|
|
||||||
DG();
|
|
||||||
if (process_set(&p, ast))
|
|
||||||
return (NULL);
|
|
||||||
DG();
|
|
||||||
if (!(pid = plaunch_subshell(&p)))
|
|
||||||
return (NULL);
|
|
||||||
waitpid(pid, &ret, WUNTRACED);
|
|
||||||
DG();
|
|
||||||
// exec_leaf(&ast);
|
|
||||||
/*
|
|
||||||
DG();
|
|
||||||
set_process(&p, ast);
|
|
||||||
DG();
|
|
||||||
launch_process(&p);
|
|
||||||
DG();
|
|
||||||
close(p.fdout);*/
|
|
||||||
DG();
|
|
||||||
while ((ret = read(exec->fdin, buf, BUF_SIZE)) > 0)
|
|
||||||
{
|
{
|
||||||
buf[ret] = 0;
|
close(fds[PIPE_READ]);
|
||||||
ft_strappend(&output, buf);
|
dup2_close(fds[PIPE_WRITE], STDOUT);
|
||||||
|
execle(data_singleton()->argv[0],data_singleton()->argv[0],
|
||||||
|
"-c", command, NULL,
|
||||||
|
data_singleton()->env);
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
DG();
|
waitpid(pid, &ret, WUNTRACED);
|
||||||
close(exec->fdin);
|
output = manage_output(fds);
|
||||||
DG("done with %s\033[0m", output);
|
|
||||||
|
|
||||||
return (output);
|
return (output);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/17 17:47:53 by wescande #+# #+# */
|
/* Created: 2017/02/17 17:47:53 by wescande #+# #+# */
|
||||||
/* Updated: 2017/02/24 22:04:59 by ariard ### ########.fr */
|
/* Updated: 2017/03/14 20:07:47 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -75,7 +75,7 @@ static char *get_output(char *command)
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
if (!(output = command_getoutput(command)))
|
if (!(output = command_getoutput(command)))
|
||||||
return (ft_strnew(0));
|
return (NULL);//ft_strnew(0));
|
||||||
len = ft_strlen(output);
|
len = ft_strlen(output);
|
||||||
while (output[--len] == '\n')
|
while (output[--len] == '\n')
|
||||||
output[len] = '\0';
|
output[len] = '\0';
|
||||||
|
|
@ -98,10 +98,8 @@ static int search_bquote(t_bquote *me)
|
||||||
me->mid = ft_strsub(sta, 1, me->str - sta - 1);
|
me->mid = ft_strsub(sta, 1, me->str - sta - 1);
|
||||||
me->s1 = ft_strsub(CH(*me->wk)[0], 0, sta - CH(*me->wk)[0]);
|
me->s1 = ft_strsub(CH(*me->wk)[0], 0, sta - CH(*me->wk)[0]);
|
||||||
me->s2 = ft_strdup(me->str + 1);
|
me->s2 = ft_strdup(me->str + 1);
|
||||||
content = get_output(me->mid);
|
if ((content = get_output(me->mid)))
|
||||||
DG();
|
|
||||||
init_expand(me, content, is_char_esc(me->esc, CH(*me->wk)[0], sta));
|
init_expand(me, content, is_char_esc(me->esc, CH(*me->wk)[0], sta));
|
||||||
DG();
|
|
||||||
ft_strdel(&me->mid);
|
ft_strdel(&me->mid);
|
||||||
ft_strdel(&me->s1);
|
ft_strdel(&me->s1);
|
||||||
ft_strdel(&me->s2);
|
ft_strdel(&me->s2);
|
||||||
|
|
@ -113,6 +111,13 @@ static int search_bquote(t_bquote *me)
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void delete(t_ld **tmp, t_ld **src)
|
||||||
|
{
|
||||||
|
if (*tmp == *src)
|
||||||
|
ft_ld_del(src, &ft_tabdel);
|
||||||
|
else
|
||||||
|
ft_ld_del(tmp, &ft_tabdel);
|
||||||
|
}
|
||||||
void expand_bquote(t_glob *gl)
|
void expand_bquote(t_glob *gl)
|
||||||
{
|
{
|
||||||
t_ld *tmp;
|
t_ld *tmp;
|
||||||
|
|
@ -133,8 +138,9 @@ void expand_bquote(t_glob *gl)
|
||||||
me.str = CH(gl->m_pat)[0];
|
me.str = CH(gl->m_pat)[0];
|
||||||
if ((tmp = gl->m_pat) &&
|
if ((tmp = gl->m_pat) &&
|
||||||
(do_it = search_bquote(&me)) == 1)
|
(do_it = search_bquote(&me)) == 1)
|
||||||
ft_ld_del(&tmp, &ft_tabdel);
|
delete(&tmp, &gl->m_pat);
|
||||||
if (!gl->m_pat->next)
|
// ft_ld_del(&tmp, &ft_tabdel);
|
||||||
|
if (!gl->m_pat || !gl->m_pat->next)
|
||||||
break ;
|
break ;
|
||||||
gl->m_pat = gl->m_pat->next;
|
gl->m_pat = gl->m_pat->next;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
|
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/13 22:19:53 by jhalford ### ########.fr */
|
/* Updated: 2017/03/14 20:19:22 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -36,6 +36,7 @@ void process_free(void *content, size_t content_size)
|
||||||
/* return ; */
|
/* return ; */
|
||||||
/* if (g_freemap[p->type].f) */
|
/* if (g_freemap[p->type].f) */
|
||||||
/* (g_freemap[p->type].f)(p); */
|
/* (g_freemap[p->type].f)(p); */
|
||||||
|
if (p->map.free)
|
||||||
(p->map.free)(p);
|
(p->map.free)(p);
|
||||||
ft_lstdel(&p->redirs, redir_free);
|
ft_lstdel(&p->redirs, redir_free);
|
||||||
free(p);
|
free(p);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue