gros merge

This commit is contained in:
gazhonsepaskwa
2025-02-03 13:00:47 +01:00
parent 30dd017198
commit 2fdfa68256
37 changed files with 109 additions and 372 deletions

View File

@@ -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>

View File

@@ -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>

View File

@@ -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);

View File

@@ -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

View File

@@ -3,17 +3,18 @@
/* ::: :::::::: */
/* ast.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/24 08:23:27 by lderidde #+# #+# */
/* Updated: 2025/01/28 10:49:53 by lderidde ### ########.fr */
/* Created: 2025/01/24 08:23:27 by nalebrun #+# #+# */
/* Updated: 2025/01/24 08:23:27 by nalebrun ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef AST_H
# define AST_H
# include "../lib/libft/libft.h"
/*# include "../../includes/env.h"*/
# include "../minishell.h"
typedef enum e_state
{
@@ -21,7 +22,8 @@ typedef enum e_state
_AND,
_OR,
_CMD,
_PLINE
_PLINE,
_SUBSH
} t_state;
typedef enum e_redir
@@ -39,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];
@@ -49,10 +50,20 @@ typedef struct s_ast_n
t_redir redir;
char *infile;
char *outfile;
int shlvl;
char **env;
bool sh;
} t_ast_n;
t_ast_n *return_hardcode_ast(char **envp);
typedef struct s_nodell
{
t_node *node;
struct s_nodell *next;
} t_nodell;
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);
// env TMP
char **init_env(char **envp);
#endif

43
includes/parser/drawio.h Normal file
View File

@@ -0,0 +1,43 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* drawio.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/27 14:20:35 by nalebrun #+# #+# */
/* Updated: 2025/01/27 14:20:35 by nalebrun ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef DRAWIO_H
# define DRAWIO_H
# include "../minishell.h"
typedef struct s_dio_node
{
const char *st;
const char *redir;
char *cmd;
char *args;
char *inf;
char *outf;
} t_dio_node;
typedef struct s_elems
{
t_dio_elem rect;
t_dio_elem arrow;
} t_elems;
// internal
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);
// external
void gen_dio_linked_list(t_node *head, int fd);
void gen_dio_ast(t_ast_n *head, int fd);
#endif

20
includes/parser/parsing.h Normal file
View File

@@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parsing.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/24 14:45:28 by nalebrun #+# #+# */
/* Updated: 2025/01/24 14:45:28 by nalebrun ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef PARSING_H
# define PARSING_H
# include "../minishell.h"
t_ast_n *parser(char *input, char **envp, t_msh *msh);
#endif

View File

@@ -0,0 +1,66 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tokenizer.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/15 13:30:12 by nalebrun #+# #+# */
/* Updated: 2025/01/20 13:15:34 by nalebrun ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TOKENIZER_H
# define TOKENIZER_H
# include "../minishell.h"
typedef enum e_token
{
UNSET,
OPERATOR,
WORD
} t_token;
typedef enum e_pres
{
UNDEFINED,
COMMAND,
AND,
OR,
PIPE,
SUBSH_S,
SUBSH_E,
RED_L,
RED_R,
HEREDOC,
D_RED_R,
PARAMETER,
RED_FILE,
LIM
} t_pres;
typedef struct s_node
{
struct s_node *next;
char *val;
enum e_token token;
enum e_pres pressision;
} t_node;
t_node *tokenize(char *str);
t_node *create_node(char *val, t_token token);
int add_node_back(t_node **head, char *val, t_token token, t_pres pres);
int merge_with_next_node(t_node *node);
void free_linked_list(t_node *stack);
t_token get_token(char *str);
t_pres get_pressision(char *s, t_token token, t_token last_token, t_pres last_pres);
int create_node_after(t_node *elem, char *val);
char *copy_meta_xor(char *val, int *copied, int rev);
int is_meta(char c);
int is_sticked(char *val);
int trim_nodes(t_node *head);
void debug_linked_list(t_node *head, char *msg);
int find_quote_node(t_node *head, char q);
#endif