gros merge
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,6 +1,4 @@
|
||||
minishell
|
||||
.objs/*
|
||||
test.c
|
||||
parser
|
||||
ast.xml
|
||||
.TEST_objs
|
||||
|
||||
24
Makefile
24
Makefile
@@ -32,28 +32,6 @@ $(NAME): $(LIBFT) $(OBJS)
|
||||
@$(CC) $(WFLAGS) $(OBJS) $(LIBFT) -o $(NAME) $(LINK)
|
||||
@echo "$(CYAN)Build completed: $(NAME)$(RESET)"
|
||||
|
||||
|
||||
|
||||
# test part
|
||||
|
||||
TEST_SRCDIR = test
|
||||
TEST_OBJDIR = .TEST_objs
|
||||
TEST_SRCS = $(shell find $(TEST_SRCDIR) -name "*.c")
|
||||
TEST_OBJS = $(patsubst $(TEST_SRCDIR)/%.c, $(TEST_OBJDIR)/%.o, $(TEST_SRCS))
|
||||
TEST_DEPS = $(TEST_OBJS:.o=.d)
|
||||
|
||||
$(TEST_OBJDIR)/%.o: $(TEST_SRCDIR)/%.c
|
||||
@mkdir -p $(dir $@)
|
||||
@$(CC) $(WFLAGS) -MMD -MP -I$(INCDIR) -c $< -o $@ $(LINK)
|
||||
|
||||
parser: $(LIBFT) $(TEST_OBJS)
|
||||
@$(CC) $(WFLAGS) $(TEST_OBJS) $(LIBFT) -o parser $(LINK)
|
||||
@echo "$(CYAN)Test build completed: parser$(RESET)"
|
||||
|
||||
# test part end
|
||||
|
||||
|
||||
|
||||
clean:
|
||||
@rm -rf $(OBJDIR) $(TEST_OBJDIR)
|
||||
@make -C $(LIBFT_DIR) clean
|
||||
@@ -61,7 +39,7 @@ clean:
|
||||
|
||||
fclean: clean
|
||||
@make -C $(LIBFT_DIR) fclean
|
||||
@rm $(NAME) test
|
||||
@rm $(NAME)
|
||||
@echo "$(CYAN)Executable removed$(RESET)"
|
||||
|
||||
re: fclean all
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ast.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/24 08:23:27 by lderidde #+# #+# */
|
||||
/* Updated: 2025/01/28 10:49:53 by lderidde ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef AST_H
|
||||
# define AST_H
|
||||
|
||||
# include "../lib/libft/libft.h"
|
||||
|
||||
typedef enum e_state
|
||||
{
|
||||
UNDEF,
|
||||
_AND,
|
||||
_OR,
|
||||
_CMD,
|
||||
_PLINE
|
||||
} t_state;
|
||||
|
||||
typedef enum e_redir
|
||||
{
|
||||
_NR,
|
||||
_RED_L,
|
||||
_RED_R,
|
||||
_RED_DR
|
||||
} t_redir;
|
||||
|
||||
typedef struct s_ast_n
|
||||
{
|
||||
t_state state;
|
||||
struct s_ast_n *parent;
|
||||
struct s_ast_n *left;
|
||||
struct s_ast_n *right;
|
||||
struct s_ast_n **pline;
|
||||
int ex_code;
|
||||
struct s_ast_n *head;
|
||||
char *cmd;
|
||||
char **args;
|
||||
int fds[2];
|
||||
int _stdout;
|
||||
int _stdin;
|
||||
t_redir redir;
|
||||
char *infile;
|
||||
char *outfile;
|
||||
int shlvl;
|
||||
char **env;
|
||||
} t_ast_n;
|
||||
|
||||
t_ast_n *return_hardcode_ast(char **envp);
|
||||
|
||||
#endif
|
||||
@@ -14,7 +14,7 @@
|
||||
# define BUILTINS_H
|
||||
|
||||
# include "../lib/libft/libft.h"
|
||||
# include "env.h"
|
||||
# include "../minishell.h"
|
||||
# include <stdio.h>
|
||||
# include <sys/types.h>
|
||||
# include <signal.h>
|
||||
@@ -14,7 +14,7 @@
|
||||
# define ENV_H
|
||||
|
||||
# include "../lib/libft/libft.h"
|
||||
# include "ast.h"
|
||||
# include "../minishell.h"
|
||||
# include <unistd.h>
|
||||
# include <stdlib.h>
|
||||
# include <stdbool.h>
|
||||
@@ -13,12 +13,12 @@
|
||||
#ifndef EXEC_H
|
||||
#define EXEC_H
|
||||
|
||||
# include "../minishell.h"
|
||||
# include <stdio.h>
|
||||
# include <sys/wait.h>
|
||||
# include <sys/types.h>
|
||||
# include <stdlib.h>
|
||||
# include <unistd.h>
|
||||
# include "ast.h"
|
||||
|
||||
int execute_command(t_ast_n *node);
|
||||
|
||||
@@ -13,6 +13,18 @@
|
||||
#ifndef MINISHELL_H
|
||||
# define MINISHELL_H
|
||||
|
||||
# define DEBUG 1
|
||||
|
||||
typedef struct s_ast_n t_ast_n;
|
||||
typedef struct s_node t_node;
|
||||
|
||||
typedef struct s_msh
|
||||
{
|
||||
int ex_code;
|
||||
t_ast_n *head;
|
||||
char **env;
|
||||
} t_msh;
|
||||
|
||||
# include <stdio.h>
|
||||
# include <readline/readline.h>
|
||||
# include <readline/history.h>
|
||||
@@ -21,10 +33,14 @@
|
||||
# include <stdbool.h>
|
||||
|
||||
# include "../lib/libft/libft.h"
|
||||
# include "builtins.h"
|
||||
# include "env.h"
|
||||
# include "exec.h"
|
||||
# include "ast.h"
|
||||
# include "parser/ast.h"
|
||||
# include "parser/drawio.h"
|
||||
# include "parser/tokenizer.h"
|
||||
# include "parser/parsing.h"
|
||||
# include "exec/builtins.h"
|
||||
# include "exec/env.h"
|
||||
# include "exec/exec.h"
|
||||
|
||||
|
||||
# define POW1 "\033[1;38;2;21;22;26;48;2;92;106;178m"
|
||||
# define POW2 "\033[1;38;2;92;106;178;48;2;54;54;54m"
|
||||
@@ -32,4 +48,5 @@
|
||||
# define POW4 "\033[0;38;2;204;205;209;48;2;39;39;39m"
|
||||
# define POW5 "\033[1;38;2;39;39;39m"
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -14,8 +14,7 @@
|
||||
# define AST_H
|
||||
|
||||
/*# include "../../includes/env.h"*/
|
||||
# include "../../lib/libft/libft.h"
|
||||
# include "../tokenizer/tokenizer.h"
|
||||
# include "../minishell.h"
|
||||
|
||||
typedef enum e_state
|
||||
{
|
||||
@@ -42,8 +41,7 @@ typedef struct s_ast_n
|
||||
struct s_ast_n *left;
|
||||
struct s_ast_n *right;
|
||||
struct s_ast_n **pline;
|
||||
int ex_code;
|
||||
struct s_ast_n *head;
|
||||
t_msh *msh;
|
||||
char *cmd;
|
||||
char **args;
|
||||
int fds[2];
|
||||
@@ -52,8 +50,7 @@ typedef struct s_ast_n
|
||||
t_redir redir;
|
||||
char *infile;
|
||||
char *outfile;
|
||||
int shlvl;
|
||||
char **env;
|
||||
bool sh;
|
||||
} t_ast_n;
|
||||
|
||||
typedef struct s_nodell
|
||||
@@ -62,7 +59,7 @@ typedef struct s_nodell
|
||||
struct s_nodell *next;
|
||||
} t_nodell;
|
||||
|
||||
t_ast_n *get_ast(char **envp, t_node *lst);
|
||||
t_ast_n *get_ast(t_msh *msh, t_node *lst);
|
||||
t_nodell *cutll(t_node *lst, t_node *expected, size_t limiter);
|
||||
t_node *get_top_token(t_node *lst, t_state *state);
|
||||
|
||||
@@ -13,9 +13,7 @@
|
||||
#ifndef DRAWIO_H
|
||||
# define DRAWIO_H
|
||||
|
||||
# include "../../lib/libft/libft.h"
|
||||
# include "../tokenizer/tokenizer.h"
|
||||
# include "../ast/ast.h"
|
||||
# include "../minishell.h"
|
||||
|
||||
typedef struct s_dio_node
|
||||
{
|
||||
@@ -13,15 +13,8 @@
|
||||
#ifndef PARSING_H
|
||||
# define PARSING_H
|
||||
|
||||
# define DEBUG 1
|
||||
# include "../minishell.h"
|
||||
|
||||
# include "tokenizer/tokenizer.h"
|
||||
# include "ast/ast.h"
|
||||
|
||||
// drawio
|
||||
# include "drawio/drawio.h"
|
||||
|
||||
// tmp_env
|
||||
char **init_env(char **envp);
|
||||
t_ast_n *parser(char *input, char **envp, t_msh *msh);
|
||||
|
||||
#endif
|
||||
@@ -13,7 +13,7 @@
|
||||
#ifndef TOKENIZER_H
|
||||
# define TOKENIZER_H
|
||||
|
||||
# include "../../lib/libft/libft.h"
|
||||
# include "../minishell.h"
|
||||
|
||||
typedef enum e_token
|
||||
{
|
||||
109
srcs/ast/ast.c
109
srcs/ast/ast.c
@@ -1,109 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ast.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/24 08:22:16 by lderidde #+# #+# */
|
||||
/* Updated: 2025/01/31 11:01:25 by lderidde ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/ast.h"
|
||||
|
||||
t_ast_n *created_ast_n(t_state st, t_ast_n *prt, t_ast_n *he)
|
||||
{
|
||||
t_ast_n *node;
|
||||
|
||||
node = malloc(sizeof(t_ast_n));
|
||||
if (!node)
|
||||
return (NULL);
|
||||
node->state = st;
|
||||
node->parent = prt;
|
||||
node->head = he;
|
||||
node->ex_code = 0;
|
||||
node->cmd = NULL;
|
||||
node->args = NULL;
|
||||
node->_stdout = 1;
|
||||
node->_stdin = 0;
|
||||
node->redir = _NR;
|
||||
node->infile = NULL;
|
||||
node->outfile = NULL;
|
||||
if (prt)
|
||||
node->shlvl = prt->shlvl;
|
||||
else
|
||||
node->shlvl = 0;
|
||||
node->env = NULL;
|
||||
return (node);
|
||||
}
|
||||
|
||||
static int count_var(char **envp)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if (!envp)
|
||||
return (-1);
|
||||
while (envp[i])
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
|
||||
static char **init_env(char **envp)
|
||||
{
|
||||
char **env;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
env = malloc(sizeof(char *) * (count_var(envp) + 1));
|
||||
if (!env)
|
||||
return (NULL);
|
||||
env[count_var(envp)] = NULL;
|
||||
while (envp[i])
|
||||
{
|
||||
env[i] = ft_strdup(envp[i]);
|
||||
i++;
|
||||
}
|
||||
return (env);
|
||||
}
|
||||
|
||||
void setup_cmd(t_ast_n *node, char *cmd, char *args)
|
||||
{
|
||||
node->cmd = ft_strdup(cmd);
|
||||
node->args = ft_split(args, " ");
|
||||
}
|
||||
|
||||
t_ast_n *return_hardcode_ast(char **envp)
|
||||
{
|
||||
t_ast_n *head;
|
||||
|
||||
// head = created_ast_n(_CMD, NULL, NULL);
|
||||
// head->head = head;
|
||||
// setup_cmd(head, "sdd", "ls -l");
|
||||
head = created_ast_n(_AND, NULL, NULL);
|
||||
head->env = init_env(envp);
|
||||
head->left = created_ast_n(_CMD, head, head);
|
||||
setup_cmd(head->left, "cd", "cd srcs");
|
||||
// head->right = created_ast_n(_AND, head, head);
|
||||
// head->right->left = created_ast_n(_CMD, head->right, head);
|
||||
// setup_cmd(head->right->left, "echo", "echo $PWD");
|
||||
// head->right->right = created_ast_n(_CMD, head->right, head);
|
||||
// setup_cmd(head->right->right, "ls", "ls -l");
|
||||
head->right = created_ast_n(_PLINE, head, head);
|
||||
head->right->pline = malloc(sizeof(t_ast_n *) * 5);
|
||||
head->right->pline[0] = created_ast_n(_CMD, head->right, head);
|
||||
setup_cmd(head->right->pline[0], "ls", "ls -la");
|
||||
head->right->pline[1] = created_ast_n(_CMD, head->right, head);
|
||||
setup_cmd(head->right->pline[1], "cat", "cat -e");
|
||||
head->right->pline[2] = created_ast_n(_CMD, head->right, head);
|
||||
setup_cmd(head->right->pline[2], "grep", "grep builtins");
|
||||
head->right->pline[3] = created_ast_n(_CMD, head->right, head);
|
||||
setup_cmd(head->right->pline[3], "wc", "wc -l");
|
||||
// head->right->pline[1]->redir = _RED_R;
|
||||
// head->right->pline[1]->outfile = "file";
|
||||
// head->right->pline[3]->redir = _RED_R;
|
||||
// head->right->pline[3]->outfile = "file";
|
||||
head->right->pline[4] = NULL;
|
||||
return (head);
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/builtins.h"
|
||||
#include "../../includes/minishell.h"
|
||||
|
||||
void pwd_update(t_ast_n *head, char *src, char *dest)
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/builtins.h"
|
||||
#include "../../includes/minishell.h"
|
||||
|
||||
int is_silent(char *str)
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/builtins.h"
|
||||
#include "../../includes/minishell.h"
|
||||
|
||||
int builtin_env(char **arg, char **envp)
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/builtins.h"
|
||||
#include "../../includes/minishell.h"
|
||||
|
||||
int ft_isnumeric(char *str)
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/builtins.h"
|
||||
#include "../../includes/minishell.h"
|
||||
|
||||
int is_export_valid(char *str)
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/builtins.h"
|
||||
#include "../../includes/minishell.h"
|
||||
|
||||
int builtin_pwd(char **arg)
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/builtins.h"
|
||||
#include "../../includes/minishell.h"
|
||||
|
||||
// void builtin_unset(char *str, char **envp)
|
||||
// {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/builtins.h"
|
||||
#include "../../includes/minishell.h"
|
||||
|
||||
int err_msg_cmd(char *cmd, char *arg, char *msg, int code)
|
||||
{
|
||||
|
||||
@@ -10,9 +10,7 @@
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/exec.h"
|
||||
#include "../../lib/libft/libft.h"
|
||||
#include "../../includes/builtins.h"
|
||||
#include "../../includes/minishell.h"
|
||||
|
||||
void handle_file(t_ast_n *node, int check)
|
||||
{
|
||||
|
||||
47
srcs/main.c
47
srcs/main.c
@@ -52,43 +52,22 @@ char **ft_setnewenv(void)
|
||||
return (envp);
|
||||
}
|
||||
|
||||
// static t_data *init_data(char **envp)
|
||||
// {
|
||||
// t_data *data;
|
||||
//
|
||||
// data = malloc (sizeof(t_data));
|
||||
// data->env = init_env(envp);
|
||||
// return (data);
|
||||
// }
|
||||
|
||||
int main(int ac, char **av, char **envp)
|
||||
{
|
||||
// char *input;
|
||||
t_ast_n *node;
|
||||
char *input;
|
||||
t_msh *msh;
|
||||
|
||||
(void)ac;
|
||||
(void)av;
|
||||
// if (!envp[0])
|
||||
// env = ft_setnewenv();
|
||||
node = return_hardcode_ast(envp);
|
||||
return (execute_command(node));
|
||||
// while (1)
|
||||
// {
|
||||
// input = powerline();
|
||||
// if (ft_strncmp(input, "exit", 4) == 0)
|
||||
// builtin_exit(input, true);
|
||||
// if (ft_strncmp(input, "pwd", 3) == 0)
|
||||
// builtin_pwd(input);
|
||||
// if (ft_strncmp(input, "echo", 4) == 0)
|
||||
// builtin_echo(ft_split(input, " "), data->env);
|
||||
// if (ft_strncmp(input, "env", 3) == 0)
|
||||
// builtin_env(input, data->env);
|
||||
// if (ft_strncmp(input, "unset", 5) == 0)
|
||||
// builtin_unset(ft_split(input, " "), data);
|
||||
// if (ft_strncmp(input, "cd", 2) == 0)
|
||||
// builtin_cd(ft_split(input, " "), data);
|
||||
// if (ft_strncmp(input, "export", 6) == 0)
|
||||
// builtin_export(ft_split(input, " "), data);
|
||||
// free(input);
|
||||
// }
|
||||
if (!envp[0])
|
||||
msh->env = ft_setnewenv();
|
||||
else
|
||||
msh->env = copy_env_var(envp, count_var(envp));
|
||||
while (1)
|
||||
{
|
||||
input = powerline();
|
||||
msh->head = parser(input, envp, msh);
|
||||
execute_command(msh->head);
|
||||
free(input);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ast.h"
|
||||
#include "../../../includes/minishell.h"
|
||||
|
||||
// ===================================================================
|
||||
|
||||
@@ -19,13 +19,13 @@ t_ast_n *create_ast_n(t_node *lst, t_ast_n *parent);
|
||||
// ====================================================================
|
||||
|
||||
|
||||
void create_and_or(t_ast_n *parrent, t_node *lst, t_node *token)
|
||||
void create_and_or(t_ast_n *parrent, 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);
|
||||
parrent->right = create_ast_n(nodell->next->node, parrent);
|
||||
parrent->left = create_ast_n(nodell->node, parrent, msh);
|
||||
parrent->right = create_ast_n(nodell->next->node, parrent, msh);
|
||||
// free_lltab(sublsts);
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ void create_cmd(t_ast_n *self, t_node *lst)
|
||||
|
||||
|
||||
|
||||
void create_pline(t_ast_n *self, t_node *lst, t_node *token)
|
||||
void create_pline(t_ast_n *self, t_node *lst, t_node *token, t_msh *msh)
|
||||
{
|
||||
t_nodell *nodell;
|
||||
t_nodell *cpy;
|
||||
@@ -137,7 +137,7 @@ void create_pline(t_ast_n *self, t_node *lst, t_node *token)
|
||||
i = 0;
|
||||
while (cpy)
|
||||
{
|
||||
self->pline[i] = create_ast_n(cpy->node, self);
|
||||
self->pline[i] = create_ast_n(cpy->node, self, t_msh *msh);
|
||||
cpy = cpy->next;
|
||||
i++;
|
||||
}
|
||||
@@ -145,10 +145,6 @@ void create_pline(t_ast_n *self, t_node *lst, t_node *token)
|
||||
// free_lltab(sublsts);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//======================================================================
|
||||
|
||||
|
||||
@@ -176,7 +172,7 @@ void remove_parentheses(t_node **lst)
|
||||
}
|
||||
}
|
||||
|
||||
void create_subsh(t_ast_n *parent, t_node *lst)
|
||||
void create_subsh(t_ast_n *parent, t_node *lst, t_msh *msh)
|
||||
{
|
||||
t_node *cpy;
|
||||
|
||||
@@ -194,7 +190,7 @@ void create_subsh(t_ast_n *parent, t_node *lst)
|
||||
ft_printf("%s\n", cpy->val);
|
||||
cpy = cpy->next;
|
||||
}
|
||||
parent->left = create_ast_n(lst, parent);
|
||||
parent->left = create_ast_n(lst, parent, msh);
|
||||
}
|
||||
|
||||
|
||||
@@ -203,45 +199,33 @@ void create_subsh(t_ast_n *parent, t_node *lst)
|
||||
|
||||
|
||||
|
||||
t_ast_n *create_ast_n(t_node *lst, t_ast_n *parent)
|
||||
t_ast_n *create_ast_n(t_node *lst, t_ast_n *parent, t_msh *msh)
|
||||
{
|
||||
t_ast_n *node;
|
||||
t_node *token;
|
||||
|
||||
node = malloc(sizeof(t_ast_n));
|
||||
token = get_top_token(lst, &node->state);
|
||||
|
||||
ft_debug("================\n");
|
||||
ft_debug("NEW NODE CREATED\n");
|
||||
if (token && token->val)
|
||||
ft_debug("token val: %s\n", token->val);
|
||||
else
|
||||
ft_debug("token val : NULL\n");
|
||||
ft_debug("node state : %d\n", node->state);
|
||||
ft_debug("================\n\n");
|
||||
|
||||
node->left = NULL;
|
||||
node->right = NULL;
|
||||
node->pline = NULL;
|
||||
node->msh = msh;
|
||||
node->parent = parent;
|
||||
|
||||
if (node->state == _AND || node->state == _OR)
|
||||
create_and_or(node, lst, token);
|
||||
create_and_or(node, lst, token, msh);
|
||||
else if (node->state == _SUBSH)
|
||||
create_subsh(node, lst);
|
||||
create_subsh(node, lst, msh);
|
||||
else if (node->state == _PLINE)
|
||||
create_pline(node, lst, token);
|
||||
create_pline(node, lst, token, msh);
|
||||
else
|
||||
create_cmd(node, lst);
|
||||
|
||||
return (node);
|
||||
}
|
||||
|
||||
t_ast_n *get_ast(char **envp, t_node *lst)
|
||||
t_ast_n *get_ast(t_msh *msh, t_node *lst)
|
||||
{
|
||||
t_ast_n *head;
|
||||
(void)envp;
|
||||
|
||||
head = create_ast_n(lst, NULL);
|
||||
head = create_ast_n(lst, NULL, msh);
|
||||
return (head);
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ast.h"
|
||||
#include "../../../includes/minishell.h"
|
||||
|
||||
static void add_nodell(t_nodell **nodell, t_node *node)
|
||||
{
|
||||
@@ -10,7 +10,7 @@
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ast.h"
|
||||
#include "../../../includes/minishell.h"
|
||||
|
||||
static int last_tok_subsh(t_node *lst)
|
||||
{
|
||||
@@ -10,7 +10,7 @@
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "drawio.h"
|
||||
#include "../../../includes/minishell.h"
|
||||
|
||||
void set_ast_rect(t_dio_elem *rect)
|
||||
{
|
||||
@@ -10,7 +10,7 @@
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "drawio.h"
|
||||
#include "../../../includes/minishell.h"
|
||||
|
||||
const char *translate_state(t_state state)
|
||||
{
|
||||
@@ -10,7 +10,7 @@
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "drawio.h"
|
||||
#include "../../../includes/minishell.h"
|
||||
|
||||
void set_ll_rect(t_dio_elem *rect)
|
||||
{
|
||||
@@ -10,7 +10,7 @@
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "drawio.h"
|
||||
#include "../../../includes/minishell.h"
|
||||
|
||||
char *get_node_txt(t_ast_n *node)
|
||||
{
|
||||
@@ -10,7 +10,7 @@
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "drawio.h"
|
||||
#include "../../../includes/minishell.h"
|
||||
|
||||
static int get_char_count(char *str, char c)
|
||||
{
|
||||
@@ -3,14 +3,14 @@
|
||||
/* ::: :::::::: */
|
||||
/* test.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/15 08:23:41 by lderidde #+# #+# */
|
||||
/* Updated: 2025/01/31 14:05:34 by lderidde ### ########.fr */
|
||||
/* Created: 2025/01/15 08:23:41 by nalebrun #+# #+# */
|
||||
/* Updated: 2025/02/03 11:49:21 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parsing.h"
|
||||
#include "../../includes/minishell.h"
|
||||
|
||||
void truncate_comment(char *str)
|
||||
{
|
||||
@@ -36,31 +36,24 @@ void truncate_comment(char *str)
|
||||
}
|
||||
}
|
||||
|
||||
int main(int ac, char **av, char **envp)
|
||||
t_ast_n *parser(char *input, t_msh *msh)
|
||||
{
|
||||
t_node *lst;
|
||||
t_ast_n *ast;
|
||||
int dio;
|
||||
(void)envp;
|
||||
|
||||
if (ac != 3)
|
||||
{
|
||||
ft_error("./test drawio_file command_str\n");
|
||||
return (1);
|
||||
}
|
||||
truncate_comment(av[1]);
|
||||
lst = tokenize(av[2]);
|
||||
truncate_comment(input);
|
||||
lst = tokenize(input);
|
||||
if (!lst)
|
||||
return (1);
|
||||
return (NULL);
|
||||
if (DEBUG)
|
||||
{
|
||||
dio = drawio_init(av[1]);
|
||||
dio = drawio_init("ast.xml");
|
||||
gen_dio_linked_list(lst, dio);
|
||||
}
|
||||
ast = get_ast(envp, lst);
|
||||
ast = get_ast(msh, lst);
|
||||
if (!ast)
|
||||
return (1);
|
||||
|
||||
return (NULL);
|
||||
if (DEBUG)
|
||||
{
|
||||
gen_dio_ast(ast, dio);
|
||||
@@ -68,4 +61,5 @@ int main(int ac, char **av, char **envp)
|
||||
ft_debug(" draw.io file generated !\n");
|
||||
}
|
||||
free_linked_list(lst);
|
||||
return (ast);
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "tokenizer.h"
|
||||
#include "../../../includes/minishell.h"
|
||||
|
||||
t_node *create_node(char *val, t_token token)
|
||||
{
|
||||
@@ -10,7 +10,7 @@
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "./tokenizer.h"
|
||||
#include "../../../includes/minishell.h"
|
||||
|
||||
static t_pres get_operator(char *s)
|
||||
{
|
||||
@@ -10,7 +10,7 @@
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "tokenizer.h"
|
||||
#include "../../../includes/minishell.h"
|
||||
|
||||
static t_node *tokenize_base(char *str)
|
||||
{
|
||||
@@ -10,7 +10,7 @@
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "tokenizer.h"
|
||||
#include "../../../includes/minishell.h"
|
||||
|
||||
int is_meta(char c)
|
||||
{
|
||||
@@ -1,44 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* tmp_env.c :+: :+: :+: */
|
||||
/* unstick_node_utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/27 12:35:29 by nalebrun #+# #+# */
|
||||
/* Updated: 2025/01/27 12:35:29 by nalebrun ### ########.fr */
|
||||
/* Created: 2025/02/03 12:53:08 by nalebrun #+# #+# */
|
||||
/* Updated: 2025/02/03 12:53:08 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "../lib/libft/libft.h"
|
||||
#include "../../../includes/minishell.h"
|
||||
|
||||
static int count_var(char **envp)
|
||||
char *copy_meta_xor(char *val, int *copied, int rev)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
char *out;
|
||||
|
||||
i = 0;
|
||||
if (!envp)
|
||||
return (-1);
|
||||
while (envp[i])
|
||||
while (is_meta(val[i]) ^ rev)
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
|
||||
char **init_env(char **envp)
|
||||
{
|
||||
char **env;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
env = malloc(sizeof(char *) * (count_var(envp) + 1));
|
||||
if (!env)
|
||||
return (NULL);
|
||||
env[count_var(envp)] = NULL;
|
||||
while (envp[i])
|
||||
{
|
||||
env[i] = ft_strdup(envp[i]);
|
||||
i++;
|
||||
}
|
||||
return (env);
|
||||
*copied = i;
|
||||
out = malloc(i + 1);
|
||||
j = -1;
|
||||
while (++j < i)
|
||||
out[j] = val[j];
|
||||
out[i] = 0;
|
||||
return (out);
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
#include "tokenizer.h"
|
||||
|
||||
char *copy_meta_xor(char *val, int *copied, int rev)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
char *out;
|
||||
|
||||
i = 0;
|
||||
while (is_meta(val[i]) ^ rev)
|
||||
i++;
|
||||
*copied = i;
|
||||
out = malloc(i + 1);
|
||||
j = -1;
|
||||
while (++j < i)
|
||||
out[j] = val[j];
|
||||
out[i] = 0;
|
||||
return (out);
|
||||
}
|
||||
Reference in New Issue
Block a user