backquotes ok for simple, need to do furthur testing later, also check how bash handles nested backquotes

This commit is contained in:
Jack Halford 2017-01-18 14:28:49 +01:00
parent dfdf245b1a
commit 4b22633cab
4 changed files with 13 additions and 23 deletions

View file

@ -11,7 +11,7 @@
/* ************************************************************************** */
#include "minishell.h"
#define BUF_SIZE 10
#define BUF_SIZE 1024
char *command_getoutput(char *command)
{
@ -19,11 +19,12 @@ char *command_getoutput(char *command)
t_btree *ast;
t_astnode item;
char *output;
char *buf;
char buf[BUF_SIZE + 1];
int ret;
t_exec *exec;
output = NULL;
buf = NULL;
exec = &data_singleton()->exec;
item.type = TK_SUBSHELL;
item.data.sstr = malloc(4 * sizeof(char *));
item.data.sstr[0] = ft_strdup(data_singleton()->argv[0]);
@ -32,25 +33,15 @@ char *command_getoutput(char *command)
item.data.sstr[3] = NULL;
ast = btree_create_node(&item, sizeof(item));
pipe(fds);
dup2(fds[PIPE_WRITE], 1);
close(fds[PIPE_WRITE]);
exec->process.fdout = fds[PIPE_WRITE];
ft_exec(&ast);
/* DG("gonna parse"); */
/* token_print(token); */
/* if (ft_parse(&ast, &token)) */
/* return (NULL); */
/* DG("gonna exec"); */
/* if (ft_exec(&ast)) */
/* return (NULL); */
DG("gonna read from pipe");
exec->process.fdout = STDOUT;
close(fds[PIPE_WRITE]);
while ((ret = read(fds[PIPE_READ], buf, BUF_SIZE)))
{
buf[ret] = 0;
DG("read '%s' from pipe", buf);
ft_strappend(&output, buf);
}
DG("finished reading from pipe");
close(fds[PIPE_READ]);
return (output);
}

View file

@ -44,6 +44,7 @@ int reduce_bquotes(t_list **alst, char **str)
ft_strdel(str);
*str = new;
ft_lstdel(alst, token_free);
ft_tokenize(alst, new, DEFAULT);
return (1);
}
return (0);

View file

@ -21,7 +21,6 @@ void token_print(t_list *lst)
while (lst)
{
i = -1;
DG("lst at %p", lst);
token = lst->content;
type = token->type;
while (type >> (i++ + 2))

View file

@ -31,21 +31,20 @@ int shell_single_command(char *command)
return (1);
DG("after post_tokenize");
token_print(token);
/* if (ft_parse(&ast, &token)) */
/* return (1); */
if (ft_parse(&ast, &token))
return (1);
/* btree_print(STDBUG, ast, &ft_putast); */
/* /1* ft_dprintf(STDBUG, "\n--- INFIX BREAKDOWN ---\n"); *1/ */
/* /1* btree_apply_infix(ast, &ft_putast2); *1/ */
/* if (ft_exec(&ast)) */
/* return (1); */
if (ft_exec(&ast))
return (1);
return (0);
}
int main(int ac, char **av)
{
DG("{inv}{bol}{gre}start of shell");
DG("{inv}{bol}{gre}start of shell{eoc} job_control is %s", data_singleton()->opts & SHELL_OPTS_JOBC ? "ON" : "OFF");
shell_init(ac, av);
DG("job_control is %s", data_singleton()->opts & SHELL_OPTS_JOBC ? "ON" : "OFF");
if (data_singleton()->opts & SHELL_OPTS_LC)
{
shell_single_command(shell_get_avdata());