subsh bool

This commit is contained in:
Nathan Lebrun
2025-02-06 10:53:02 +01:00
parent 22c2f9ba02
commit 362a63a836
9 changed files with 29 additions and 28 deletions

1
.gitignore vendored
View File

@@ -1,6 +1,7 @@
minishell
.objs/*
ast.xml
.$ast.xml.bkp
.TEST_objs
file

View File

@@ -50,7 +50,7 @@ typedef struct s_ast_n
int _stdin;
int save_stdo;
int save_stdi;
t_redir *redir;
t_redir *redir;
char *input;
char **files;
bool sh;
@@ -67,7 +67,7 @@ t_nodell *cutll(t_node *lst, t_node *expected, size_t limiter);
t_node *get_top_token(t_node *lst, t_state *state);
// recurce
t_ast_n *create_ast_n(t_node *lst, t_ast_n *parent, t_msh *msh);
t_ast_n *create_ast_n(t_node *lst, t_ast_n *parent, t_msh *msh, bool subsh);
// redir
t_redir get_redir(t_node *node);
void create_redir(t_node *cpy, t_ast_n *self);

View File

@@ -18,11 +18,9 @@
typedef struct s_dio_node
{
const char *st;
const char *redir;
char *cmd;
char *args;
char *inf;
char *outf;
char *files;
} t_dio_node;
typedef struct s_elems
@@ -32,12 +30,12 @@ typedef struct s_elems
} t_elems;
// internal
char *replace_ampercent(char *src);
char *replace_left_red(char *src);
char *replace_ampercent(char *src);
char *replace_left_red(char *src);
t_dio_node get_cmd_txt(t_ast_n *node);
int print_ast(t_ast_n *node, t_elems *e, int fd);
int print_ast(t_ast_n *node, t_elems *e, int fd);
// external
void gen_dio_linked_list(t_node *head, int fd);
void gen_dio_ast(t_ast_n *head, int fd);
void gen_dio_linked_list(t_node *head, int fd);
void gen_dio_ast(t_ast_n *head, int fd);
#endif

View File

@@ -12,12 +12,12 @@
#include "../../../includes/minishell.h"
void create_and_or(t_ast_n *parrent, t_node *lst, t_node *token, t_msh *msh)
void create_and_or(t_ast_n *self, t_node *lst, t_node *token, t_msh *msh)
{
t_nodell *nodell;
nodell = cutll(lst, token, 1);
parrent->left = create_ast_n(nodell->node, parrent, msh);
parrent->right = create_ast_n(nodell->next->node, parrent, msh);
self->left = create_ast_n(nodell->node, self, msh, self->sh);
self->right = create_ast_n(nodell->next->node, self, msh, self->sh);
// free_lltab(sublsts);
}

View File

@@ -13,7 +13,7 @@
#include "../../../includes/minishell.h"
#include <unistd.h>
t_ast_n *create_ast_n(t_node *lst, t_ast_n *parent, t_msh *msh)
t_ast_n *create_ast_n(t_node *lst, t_ast_n *parent, t_msh *msh, bool subsh)
{
t_ast_n *node;
t_node *token;
@@ -29,6 +29,7 @@ t_ast_n *create_ast_n(t_node *lst, t_ast_n *parent, t_msh *msh)
node->_stdin = 0;
node->save_stdo = 1;
node->save_stdi = 0;
node->sh = subsh;
if (node->state == _AND || node->state == _OR)
create_and_or(node, lst, token, msh);
else if (node->state == _SUBSH)
@@ -44,6 +45,6 @@ t_ast_n *get_ast(t_msh *msh, t_node *lst)
{
t_ast_n *head;
head = create_ast_n(lst, NULL, msh);
head = create_ast_n(lst, NULL, msh, false);
return (head);
}

View File

@@ -32,7 +32,7 @@ void create_pline(t_ast_n *self, t_node *lst, t_node *token, t_msh *msh)
i = 0;
while (cpy)
{
self->pline[i] = create_ast_n(cpy->node, self, msh);
self->pline[i] = create_ast_n(cpy->node, self, msh, self->sh);
cpy = cpy->next;
i++;
}

View File

@@ -40,8 +40,9 @@ void create_subsh(t_ast_n *self, t_node *lst, t_msh *msh)
{
t_node *cutted;
self->sh = true;
cutted = remove_parentheses(lst);
self->left = create_ast_n(cutted, self, msh);
self->left = create_ast_n(cutted, self, msh, self->sh);
self->files = NULL;
self->redir = ft_calloc(1, sizeof(t_redir));
self->redir[0] = _NR;

View File

@@ -62,17 +62,13 @@ t_dio_node get_cmd_txt(t_ast_n *node)
// txt.redir = translate_redir(node->redir);
// txt.inf = ft_sprintf("Infile : %s%s", node->infile, NL);
// txt.outf = ft_sprintf("Outfile : %s", node->outfile);
txt.redir = "";
txt.inf = ft_sprintf("Infile : UNCHECKED");
txt.outf = ft_sprintf("Outfile : UNCHECKED");
txt.files = ft_sprintf("redir: UNCHECKED\n");
}
else
{
txt.cmd = ft_calloc(1, 1);
txt.args = ft_calloc(1, 1);
txt.redir = "";
txt.inf = ft_calloc(1, 1);
txt.outf = ft_calloc(1, 1);
txt.files = ft_calloc(1, 1);
}
return (txt);
}

View File

@@ -15,15 +15,19 @@
char *get_node_txt(t_ast_n *node)
{
t_dio_node txt;
char *out;
static char *subsh;
char *out;
txt = get_cmd_txt(node);
out = ft_sprintf("%s%s%s%s%s%s%s", txt.st, txt.cmd, txt.args,
NL, txt.redir, txt.inf, txt.outf);
if (node->sh == true)
subsh = " (subsh) ";
else
subsh = "";
out = ft_sprintf("%s%s%s%s%s", txt.st, txt.cmd, txt.args,
subsh, txt.files);
free(txt.cmd);
free(txt.args);
free(txt.inf);
free(txt.outf);
free(txt.files);
return (out);
}