gros merge
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,6 +1,4 @@
|
|||||||
minishell
|
minishell
|
||||||
.objs/*
|
.objs/*
|
||||||
test.c
|
|
||||||
parser
|
|
||||||
ast.xml
|
ast.xml
|
||||||
.TEST_objs
|
.TEST_objs
|
||||||
|
|||||||
24
Makefile
24
Makefile
@@ -32,28 +32,6 @@ $(NAME): $(LIBFT) $(OBJS)
|
|||||||
@$(CC) $(WFLAGS) $(OBJS) $(LIBFT) -o $(NAME) $(LINK)
|
@$(CC) $(WFLAGS) $(OBJS) $(LIBFT) -o $(NAME) $(LINK)
|
||||||
@echo "$(CYAN)Build completed: $(NAME)$(RESET)"
|
@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:
|
clean:
|
||||||
@rm -rf $(OBJDIR) $(TEST_OBJDIR)
|
@rm -rf $(OBJDIR) $(TEST_OBJDIR)
|
||||||
@make -C $(LIBFT_DIR) clean
|
@make -C $(LIBFT_DIR) clean
|
||||||
@@ -61,7 +39,7 @@ clean:
|
|||||||
|
|
||||||
fclean: clean
|
fclean: clean
|
||||||
@make -C $(LIBFT_DIR) fclean
|
@make -C $(LIBFT_DIR) fclean
|
||||||
@rm $(NAME) test
|
@rm $(NAME)
|
||||||
@echo "$(CYAN)Executable removed$(RESET)"
|
@echo "$(CYAN)Executable removed$(RESET)"
|
||||||
|
|
||||||
re: fclean all
|
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
|
# define BUILTINS_H
|
||||||
|
|
||||||
# include "../lib/libft/libft.h"
|
# include "../lib/libft/libft.h"
|
||||||
# include "env.h"
|
# include "../minishell.h"
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
# include <signal.h>
|
# include <signal.h>
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
# define ENV_H
|
# define ENV_H
|
||||||
|
|
||||||
# include "../lib/libft/libft.h"
|
# include "../lib/libft/libft.h"
|
||||||
# include "ast.h"
|
# include "../minishell.h"
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
# include <stdbool.h>
|
# include <stdbool.h>
|
||||||
@@ -13,12 +13,12 @@
|
|||||||
#ifndef EXEC_H
|
#ifndef EXEC_H
|
||||||
#define EXEC_H
|
#define EXEC_H
|
||||||
|
|
||||||
|
# include "../minishell.h"
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
# include <sys/wait.h>
|
# include <sys/wait.h>
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include "ast.h"
|
|
||||||
|
|
||||||
int execute_command(t_ast_n *node);
|
int execute_command(t_ast_n *node);
|
||||||
|
|
||||||
@@ -13,6 +13,18 @@
|
|||||||
#ifndef MINISHELL_H
|
#ifndef MINISHELL_H
|
||||||
# define 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 <stdio.h>
|
||||||
# include <readline/readline.h>
|
# include <readline/readline.h>
|
||||||
# include <readline/history.h>
|
# include <readline/history.h>
|
||||||
@@ -21,10 +33,14 @@
|
|||||||
# include <stdbool.h>
|
# include <stdbool.h>
|
||||||
|
|
||||||
# include "../lib/libft/libft.h"
|
# include "../lib/libft/libft.h"
|
||||||
# include "builtins.h"
|
# include "parser/ast.h"
|
||||||
# include "env.h"
|
# include "parser/drawio.h"
|
||||||
# include "exec.h"
|
# include "parser/tokenizer.h"
|
||||||
# include "ast.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 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"
|
# 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 POW4 "\033[0;38;2;204;205;209;48;2;39;39;39m"
|
||||||
# define POW5 "\033[1;38;2;39;39;39m"
|
# define POW5 "\033[1;38;2;39;39;39m"
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -14,8 +14,7 @@
|
|||||||
# define AST_H
|
# define AST_H
|
||||||
|
|
||||||
/*# include "../../includes/env.h"*/
|
/*# include "../../includes/env.h"*/
|
||||||
# include "../../lib/libft/libft.h"
|
# include "../minishell.h"
|
||||||
# include "../tokenizer/tokenizer.h"
|
|
||||||
|
|
||||||
typedef enum e_state
|
typedef enum e_state
|
||||||
{
|
{
|
||||||
@@ -42,8 +41,7 @@ typedef struct s_ast_n
|
|||||||
struct s_ast_n *left;
|
struct s_ast_n *left;
|
||||||
struct s_ast_n *right;
|
struct s_ast_n *right;
|
||||||
struct s_ast_n **pline;
|
struct s_ast_n **pline;
|
||||||
int ex_code;
|
t_msh *msh;
|
||||||
struct s_ast_n *head;
|
|
||||||
char *cmd;
|
char *cmd;
|
||||||
char **args;
|
char **args;
|
||||||
int fds[2];
|
int fds[2];
|
||||||
@@ -52,8 +50,7 @@ typedef struct s_ast_n
|
|||||||
t_redir redir;
|
t_redir redir;
|
||||||
char *infile;
|
char *infile;
|
||||||
char *outfile;
|
char *outfile;
|
||||||
int shlvl;
|
bool sh;
|
||||||
char **env;
|
|
||||||
} t_ast_n;
|
} t_ast_n;
|
||||||
|
|
||||||
typedef struct s_nodell
|
typedef struct s_nodell
|
||||||
@@ -62,9 +59,9 @@ typedef struct s_nodell
|
|||||||
struct s_nodell *next;
|
struct s_nodell *next;
|
||||||
} t_nodell;
|
} 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_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);
|
||||||
|
|
||||||
// env TMP
|
// env TMP
|
||||||
char **init_env(char **envp);
|
char **init_env(char **envp);
|
||||||
@@ -13,9 +13,7 @@
|
|||||||
#ifndef DRAWIO_H
|
#ifndef DRAWIO_H
|
||||||
# define DRAWIO_H
|
# define DRAWIO_H
|
||||||
|
|
||||||
# include "../../lib/libft/libft.h"
|
# include "../minishell.h"
|
||||||
# include "../tokenizer/tokenizer.h"
|
|
||||||
# include "../ast/ast.h"
|
|
||||||
|
|
||||||
typedef struct s_dio_node
|
typedef struct s_dio_node
|
||||||
{
|
{
|
||||||
@@ -13,15 +13,8 @@
|
|||||||
#ifndef PARSING_H
|
#ifndef PARSING_H
|
||||||
# define PARSING_H
|
# define PARSING_H
|
||||||
|
|
||||||
# define DEBUG 1
|
# include "../minishell.h"
|
||||||
|
|
||||||
# include "tokenizer/tokenizer.h"
|
t_ast_n *parser(char *input, char **envp, t_msh *msh);
|
||||||
# include "ast/ast.h"
|
|
||||||
|
|
||||||
// drawio
|
|
||||||
# include "drawio/drawio.h"
|
|
||||||
|
|
||||||
// tmp_env
|
|
||||||
char **init_env(char **envp);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
#ifndef TOKENIZER_H
|
#ifndef TOKENIZER_H
|
||||||
# define TOKENIZER_H
|
# define TOKENIZER_H
|
||||||
|
|
||||||
# include "../../lib/libft/libft.h"
|
# include "../minishell.h"
|
||||||
|
|
||||||
typedef enum e_token
|
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)
|
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)
|
int is_silent(char *str)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../../includes/builtins.h"
|
#include "../../includes/minishell.h"
|
||||||
|
|
||||||
int builtin_env(char **arg, char **envp)
|
int builtin_env(char **arg, char **envp)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../../includes/builtins.h"
|
#include "../../includes/minishell.h"
|
||||||
|
|
||||||
int ft_isnumeric(char *str)
|
int ft_isnumeric(char *str)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../../includes/builtins.h"
|
#include "../../includes/minishell.h"
|
||||||
|
|
||||||
int is_export_valid(char *str)
|
int is_export_valid(char *str)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../../includes/builtins.h"
|
#include "../../includes/minishell.h"
|
||||||
|
|
||||||
int builtin_pwd(char **arg)
|
int builtin_pwd(char **arg)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../../includes/builtins.h"
|
#include "../../includes/minishell.h"
|
||||||
|
|
||||||
// void builtin_unset(char *str, char **envp)
|
// 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)
|
int err_msg_cmd(char *cmd, char *arg, char *msg, int code)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,9 +10,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../../includes/exec.h"
|
#include "../../includes/minishell.h"
|
||||||
#include "../../lib/libft/libft.h"
|
|
||||||
#include "../../includes/builtins.h"
|
|
||||||
|
|
||||||
void handle_file(t_ast_n *node, int check)
|
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);
|
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)
|
int main(int ac, char **av, char **envp)
|
||||||
{
|
{
|
||||||
// char *input;
|
char *input;
|
||||||
t_ast_n *node;
|
t_msh *msh;
|
||||||
|
|
||||||
(void)ac;
|
(void)ac;
|
||||||
(void)av;
|
(void)av;
|
||||||
// if (!envp[0])
|
if (!envp[0])
|
||||||
// env = ft_setnewenv();
|
msh->env = ft_setnewenv();
|
||||||
node = return_hardcode_ast(envp);
|
else
|
||||||
return (execute_command(node));
|
msh->env = copy_env_var(envp, count_var(envp));
|
||||||
// while (1)
|
while (1)
|
||||||
// {
|
{
|
||||||
// input = powerline();
|
input = powerline();
|
||||||
// if (ft_strncmp(input, "exit", 4) == 0)
|
msh->head = parser(input, envp, msh);
|
||||||
// builtin_exit(input, true);
|
execute_command(msh->head);
|
||||||
// if (ft_strncmp(input, "pwd", 3) == 0)
|
free(input);
|
||||||
// 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);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
t_nodell *nodell;
|
||||||
|
|
||||||
nodell = cutll(lst, token, 1);
|
nodell = cutll(lst, token, 1);
|
||||||
parrent->left = create_ast_n(nodell->node, parrent);
|
parrent->left = create_ast_n(nodell->node, parrent, msh);
|
||||||
parrent->right = create_ast_n(nodell->next->node, parrent);
|
parrent->right = create_ast_n(nodell->next->node, parrent, msh);
|
||||||
// free_lltab(sublsts);
|
// 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 *nodell;
|
||||||
t_nodell *cpy;
|
t_nodell *cpy;
|
||||||
@@ -137,7 +137,7 @@ void create_pline(t_ast_n *self, t_node *lst, t_node *token)
|
|||||||
i = 0;
|
i = 0;
|
||||||
while (cpy)
|
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;
|
cpy = cpy->next;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@@ -145,10 +145,6 @@ void create_pline(t_ast_n *self, t_node *lst, t_node *token)
|
|||||||
// free_lltab(sublsts);
|
// 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;
|
t_node *cpy;
|
||||||
|
|
||||||
@@ -194,7 +190,7 @@ void create_subsh(t_ast_n *parent, t_node *lst)
|
|||||||
ft_printf("%s\n", cpy->val);
|
ft_printf("%s\n", cpy->val);
|
||||||
cpy = cpy->next;
|
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_ast_n *node;
|
||||||
t_node *token;
|
t_node *token;
|
||||||
|
|
||||||
node = malloc(sizeof(t_ast_n));
|
node = malloc(sizeof(t_ast_n));
|
||||||
token = get_top_token(lst, &node->state);
|
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->left = NULL;
|
||||||
node->right = NULL;
|
node->right = NULL;
|
||||||
node->pline = NULL;
|
node->pline = NULL;
|
||||||
|
node->msh = msh;
|
||||||
node->parent = parent;
|
node->parent = parent;
|
||||||
|
|
||||||
if (node->state == _AND || node->state == _OR)
|
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)
|
else if (node->state == _SUBSH)
|
||||||
create_subsh(node, lst);
|
create_subsh(node, lst, msh);
|
||||||
else if (node->state == _PLINE)
|
else if (node->state == _PLINE)
|
||||||
create_pline(node, lst, token);
|
create_pline(node, lst, token, msh);
|
||||||
else
|
else
|
||||||
create_cmd(node, lst);
|
create_cmd(node, lst);
|
||||||
|
|
||||||
return (node);
|
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;
|
t_ast_n *head;
|
||||||
(void)envp;
|
|
||||||
|
|
||||||
head = create_ast_n(lst, NULL);
|
head = create_ast_n(lst, NULL, msh);
|
||||||
return (head);
|
return (head);
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ast.h"
|
#include "../../../includes/minishell.h"
|
||||||
|
|
||||||
static void add_nodell(t_nodell **nodell, t_node *node)
|
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)
|
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)
|
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)
|
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)
|
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)
|
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)
|
static int get_char_count(char *str, char c)
|
||||||
{
|
{
|
||||||
@@ -3,14 +3,14 @@
|
|||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* test.c :+: :+: :+: */
|
/* test.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
|
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/15 08:23:41 by lderidde #+# #+# */
|
/* Created: 2025/01/15 08:23:41 by nalebrun #+# #+# */
|
||||||
/* Updated: 2025/01/31 14:05:34 by lderidde ### ########.fr */
|
/* Updated: 2025/02/03 11:49:21 by nalebrun ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "parsing.h"
|
#include "../../includes/minishell.h"
|
||||||
|
|
||||||
void truncate_comment(char *str)
|
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_node *lst;
|
||||||
t_ast_n *ast;
|
t_ast_n *ast;
|
||||||
int dio;
|
int dio;
|
||||||
(void)envp;
|
|
||||||
|
|
||||||
if (ac != 3)
|
truncate_comment(input);
|
||||||
{
|
lst = tokenize(input);
|
||||||
ft_error("./test drawio_file command_str\n");
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
truncate_comment(av[1]);
|
|
||||||
lst = tokenize(av[2]);
|
|
||||||
if (!lst)
|
if (!lst)
|
||||||
return (1);
|
return (NULL);
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
{
|
{
|
||||||
dio = drawio_init(av[1]);
|
dio = drawio_init("ast.xml");
|
||||||
gen_dio_linked_list(lst, dio);
|
gen_dio_linked_list(lst, dio);
|
||||||
}
|
}
|
||||||
ast = get_ast(envp, lst);
|
ast = get_ast(msh, lst);
|
||||||
if (!ast)
|
if (!ast)
|
||||||
return (1);
|
return (NULL);
|
||||||
|
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
{
|
{
|
||||||
gen_dio_ast(ast, dio);
|
gen_dio_ast(ast, dio);
|
||||||
@@ -68,4 +61,5 @@ int main(int ac, char **av, char **envp)
|
|||||||
ft_debug(" draw.io file generated !\n");
|
ft_debug(" draw.io file generated !\n");
|
||||||
}
|
}
|
||||||
free_linked_list(lst);
|
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)
|
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)
|
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)
|
static t_node *tokenize_base(char *str)
|
||||||
{
|
{
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "tokenizer.h"
|
#include "../../../includes/minishell.h"
|
||||||
|
|
||||||
int is_meta(char c)
|
int is_meta(char c)
|
||||||
{
|
{
|
||||||
@@ -1,44 +1,31 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* tmp_env.c :+: :+: :+: */
|
/* unstick_node_utils.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/27 12:35:29 by nalebrun #+# #+# */
|
/* Created: 2025/02/03 12:53:08 by nalebrun #+# #+# */
|
||||||
/* Updated: 2025/01/27 12:35:29 by nalebrun ### ########.fr */
|
/* Updated: 2025/02/03 12:53:08 by nalebrun ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include "../../../includes/minishell.h"
|
||||||
#include "../lib/libft/libft.h"
|
|
||||||
|
|
||||||
static int count_var(char **envp)
|
char *copy_meta_xor(char *val, int *copied, int rev)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
if (!envp)
|
|
||||||
return (-1);
|
|
||||||
while (envp[i])
|
|
||||||
i++;
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
|
|
||||||
char **init_env(char **envp)
|
|
||||||
{
|
|
||||||
char **env;
|
|
||||||
int i;
|
int i;
|
||||||
|
int j;
|
||||||
|
char *out;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
env = malloc(sizeof(char *) * (count_var(envp) + 1));
|
while (is_meta(val[i]) ^ rev)
|
||||||
if (!env)
|
|
||||||
return (NULL);
|
|
||||||
env[count_var(envp)] = NULL;
|
|
||||||
while (envp[i])
|
|
||||||
{
|
|
||||||
env[i] = ft_strdup(envp[i]);
|
|
||||||
i++;
|
i++;
|
||||||
}
|
*copied = i;
|
||||||
return (env);
|
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