fixed backquotes

This commit is contained in:
Jack Halford 2017-02-02 14:57:30 +01:00
parent 97ac417f81
commit 073ef322e4
16 changed files with 55 additions and 42 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */
/* Updated: 2017/01/31 18:35:34 by wescande ### ########.fr */
/* Updated: 2017/02/02 14:55:46 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -75,7 +75,7 @@ extern int (*g_lexer[])(t_list **alst, char *str);
t_token *token_init();
int ft_tokenize(t_list **alst, char *str, t_lexstate state);
int ft_post_tokenize(t_list **alst, char *str);
int ft_post_tokenize(t_list **alst, char **str);
int token_append(t_token *token, char c, short int esc);
void token_free(void *data, size_t size);
int token_cmp_type(t_token *token, t_type *ref);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
/* Updated: 2017/01/30 13:07:38 by wescande ### ########.fr */
/* Updated: 2017/02/02 14:46:23 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */
/* Updated: 2017/01/31 19:17:25 by wescande ### ########.fr */
/* Updated: 2017/02/02 14:03:15 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,31 +6,39 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
/* Updated: 2017/02/01 19:29:27 by wescande ### ########.fr */
/* Updated: 2017/02/02 14:49:22 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "exec.h"
static char **return_array_expand(t_ld *ld)
static char **token_to_argv(t_astnode *node)
{
char **my_tab;
int index;
char **expand;
char **content;
char **my_tab;
int index;
char **expand;
char **content;
t_ld *ld;
my_tab = NULL;
while (ld)
if (node->type == TK_COMMAND)
{
content = ld->content;
expand = glob(content[0], (unsigned char *)content[1]);
index = -1;
while (expand[++index])
my_tab = ft_sstradd(my_tab, expand[index]);
ft_tabdel(&expand);
ld = ld->next;
ld = node->data.token;
my_tab = NULL;
while (ld)
{
content = ld->content;
expand = glob(content[0], (unsigned char *)content[1]);
index = -1;
while (expand[++index])
my_tab = ft_sstradd(my_tab, expand[index]);
ft_tabdel(&expand);
ld = ld->next;
}
return (my_tab);
}
return (my_tab);
else if (node->type == TK_SUBSHELL)
return (ft_sstrdup(node->data.sstr));
return (NULL);
}
int exec_command(t_btree **ast)
@ -42,7 +50,7 @@ int exec_command(t_btree **ast)
node = (*ast)->item;
p = &data_singleton()->exec.process;
job = &data_singleton()->exec.job;
p->av = return_array_expand(node->data.token);
p->av = token_to_argv(node);
process_setexec(node->type, p);
if (!(launch_process(p)))
{

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
/* Updated: 2017/01/11 18:01:05 by jhalford ### ########.fr */
/* Updated: 2017/02/02 14:49:49 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -38,7 +38,6 @@ int ft_exec(t_btree **ast)
while (g_execmap[i].type)
{
if (item->type & g_execmap[i].type)
/* return ((*g_execmap[i].f)(ast)); */
(*g_execmap[i].f)(ast);
i++;
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */
/* Updated: 2017/01/31 13:47:57 by jhalford ### ########.fr */
/* Updated: 2017/02/02 14:28:55 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/04 16:29:54 by wescande #+# #+# */
/* Updated: 2017/01/24 16:52:50 by wescande ### ########.fr */
/* Updated: 2017/02/02 14:22:46 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
/* Updated: 2017/01/02 19:11:34 by jhalford ### ########.fr */
/* Updated: 2017/02/02 14:34:40 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,8 +17,12 @@ void process_free(void *content, size_t content_size)
t_process *p;
(void)content_size;
DG("check 0");
p = content;
DG("check 1");
ft_strdel(&p->path);
DG("check 2");
ft_sstrfree(p->av);
DG("check 3");
free(p);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/12 14:01:59 by jhalford #+# #+# */
/* Updated: 2017/01/31 16:07:17 by wescande ### ########.fr */
/* Updated: 2017/02/02 14:52:30 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,22 +6,22 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/11 16:11:11 by jhalford #+# #+# */
/* Updated: 2017/01/12 13:58:20 by jhalford ### ########.fr */
/* Updated: 2017/02/02 14:54:57 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "lexer.h"
int ft_post_tokenize(t_list **alst, char *str)
int ft_post_tokenize(t_list **alst, char **str)
{
int ret;
while ((ret = reduce_parens(alst, str)))
while ((ret = reduce_parens(alst, *str)))
if (ret == -1)
return (-1);
while ((ret = reduce_bquotes(alst, &str)))
while ((ret = reduce_bquotes(alst, str)))
if (ret == -1)
return (-1);
DG("new command from bquotes: '%s'", str);
DG("new command from bquotes: '%s'", *str);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:37:11 by jhalford #+# #+# */
/* Updated: 2017/01/31 13:42:01 by jhalford ### ########.fr */
/* Updated: 2017/02/02 14:55:43 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/11 16:46:27 by jhalford #+# #+# */
/* Updated: 2017/01/12 15:10:16 by jhalford ### ########.fr */
/* Updated: 2017/02/02 14:52:28 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */
/* Updated: 2017/02/02 13:34:47 by gwojda ### ########.fr */
/* Updated: 2017/02/02 14:38:30 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
/* Updated: 2017/01/31 19:41:25 by wescande ### ########.fr */
/* Updated: 2017/02/02 14:55:29 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -24,16 +24,18 @@ int shell_single_command(char *command)
DG("{inv}{mag}got command '%s'", command);
if (ft_tokenize(&token, command, DEFAULT))
return (1);
if (ft_post_tokenize(&token, &command))
return (1);
if (!token)
return (0);
if (ft_post_tokenize(&token, command))
return (1);
ft_strdel(&command);
token_print(token);
if (ft_parse(&ast, &token))
return (1);
btree_print(STDBUG, ast, &ft_putast);
if (ft_exec(&ast))
return (1);
DG("after exec!");
return (0);
}
@ -44,14 +46,14 @@ int main(int ac, char **av)
shell_init(ac, av);
if (data_singleton()->opts & SHELL_OPTS_LC)
{
shell_single_command(shell_get_avdata());
shell_single_command(ft_strdup(shell_get_avdata()));
return (0);
}
while (1)
{
if (ft_readline())
return (1);
if (shell_single_command(data_singleton()->line.input))
if (shell_single_command(ft_strdup(data_singleton()->line.input)))
return (1);
}
return (0);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/11 16:52:44 by jhalford #+# #+# */
/* Updated: 2017/01/12 15:10:24 by jhalford ### ########.fr */
/* Updated: 2017/02/02 14:11:09 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */
/* Updated: 2017/01/31 19:17:58 by wescande ### ########.fr */
/* Updated: 2017/02/02 14:24:53 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */