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 minishell
.objs/* .objs/*
ast.xml ast.xml
.$ast.xml.bkp
.TEST_objs .TEST_objs
file file

View File

@@ -50,7 +50,7 @@ typedef struct s_ast_n
int _stdin; int _stdin;
int save_stdo; int save_stdo;
int save_stdi; int save_stdi;
t_redir *redir; t_redir *redir;
char *input; char *input;
char **files; char **files;
bool sh; 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); t_node *get_top_token(t_node *lst, t_state *state);
// recurce // 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 // redir
t_redir get_redir(t_node *node); t_redir get_redir(t_node *node);
void create_redir(t_node *cpy, t_ast_n *self); void create_redir(t_node *cpy, t_ast_n *self);

View File

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

View File

@@ -12,12 +12,12 @@
#include "../../../includes/minishell.h" #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; t_nodell *nodell;
nodell = cutll(lst, token, 1); nodell = cutll(lst, token, 1);
parrent->left = create_ast_n(nodell->node, parrent, msh); self->left = create_ast_n(nodell->node, self, msh, self->sh);
parrent->right = create_ast_n(nodell->next->node, parrent, msh); self->right = create_ast_n(nodell->next->node, self, msh, self->sh);
// free_lltab(sublsts); // free_lltab(sublsts);
} }

View File

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

View File

@@ -40,8 +40,9 @@ void create_subsh(t_ast_n *self, t_node *lst, t_msh *msh)
{ {
t_node *cutted; t_node *cutted;
self->sh = true;
cutted = remove_parentheses(lst); 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->files = NULL;
self->redir = ft_calloc(1, sizeof(t_redir)); self->redir = ft_calloc(1, sizeof(t_redir));
self->redir[0] = _NR; 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.redir = translate_redir(node->redir);
// txt.inf = ft_sprintf("Infile : %s%s", node->infile, NL); // txt.inf = ft_sprintf("Infile : %s%s", node->infile, NL);
// txt.outf = ft_sprintf("Outfile : %s", node->outfile); // txt.outf = ft_sprintf("Outfile : %s", node->outfile);
txt.redir = ""; txt.files = ft_sprintf("redir: UNCHECKED\n");
txt.inf = ft_sprintf("Infile : UNCHECKED");
txt.outf = ft_sprintf("Outfile : UNCHECKED");
} }
else else
{ {
txt.cmd = ft_calloc(1, 1); txt.cmd = ft_calloc(1, 1);
txt.args = ft_calloc(1, 1); txt.args = ft_calloc(1, 1);
txt.redir = ""; txt.files = ft_calloc(1, 1);
txt.inf = ft_calloc(1, 1);
txt.outf = ft_calloc(1, 1);
} }
return (txt); return (txt);
} }

View File

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