Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .minishell_history
Empty file.
18 changes: 9 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ NAME = minishell
CFLAGS = -g -Wall -Wextra -Werror
LIBFT = ./libft/libft.a
LIBS = -lreadline
INCLUDES = -I./include -I./libft/include -I./src/wildcard
INCLUDES = -I./include -I./libft/include -I./src/wildcard -I./src/tokenizer
SRC_DIR = src
OBJ_DIR = obj

Expand All @@ -13,10 +13,10 @@ UNAME_S := $(shell uname -s)
# # Set include paths conditionally
ifeq ($(UNAME_S), Darwin)
CFLAGS += -fsanitize=address -g -O1
INCLUDES = -I./include -I./libft/include -I/opt/homebrew/opt/readline/include -I./libft/include -I/usr/local/opt/readline/include -I./src/wildcard
INCLUDES = -I./include -I./libft/include -I/opt/homebrew/opt/readline/include -I./libft/include -I/usr/local/opt/readline/include -I./src/wildcard -I./src/tokenizer

else
INCLUDES = -I./include -I./libft/include -I./src/wildcard
INCLUDES = -I./include -I./libft/include -I./src/wildcard -I./src/tokenizer
endif

ifeq ($(UNAME_S), Darwin)
Expand All @@ -39,16 +39,16 @@ endif
# endif

SRCS = minishell.c \
tokenizer/tokenizer.c tokenizer/utils.c tokenizer/assign.c tokenizer/count_words.c tokenizer/assign_redirect.c tokenizer/reshuffle_quotes.c tokenizer/reshuffle_quotes_utils.c \
tokenizer/tokenizer.c tokenizer/utils.c tokenizer/assign.c tokenizer/count_words.c tokenizer/assign_redirect.c tokenizer/reshuffle_quotes.c tokenizer/reshuffle_quotes_utils.c tokenizer/assign_bonus.c \
wildcard/wildcard.c wildcard/build_pattern.c wildcard/build_pattern_init.c wildcard/free.c wildcard/utils.c wildcard/init_entries.c wildcard/matching.c wildcard/matching_utils.c \
lexer/lexer.c lexer/lexemes_redirect.c lexer/lexemes.c lexer/quotes.c lexer/var_subs.c lexer/wrappers.c lexer/lexer_helper.c lexer/check_syntax.c lexer/lexer_helper.c lexer/quotes_helper.c \
parser/parser.c parser/create_node.c parser/fill_node_cmd_args.c parser/fill_node_redirects.c parser/parser_utils.c \
lexer/lexer.c lexer/lexemes_redirect.c lexer/lexemes.c lexer/lexemes_bonus.c lexer/quotes.c lexer/var_subs.c lexer/wrappers.c lexer/lexer_helper.c lexer/lexer_helper_bonus.c lexer/check_syntax.c lexer/lexer_helper.c lexer/quotes_helper.c \
parser/parser.c parser/create_node.c parser/fill_node_cmd_args.c parser/fill_node_redirects.c parser/parser_utils.c parser/free.c \
utils/check_input.c utils/free_functions.c utils/init.c \
builtins/pwd.c builtins/env.c builtins/export.c builtins/unset.c builtins/cd.c builtins/exit.c builtins/echo.c builtins/exit_utils.c utils/read_input.c \
executor/redirections.c executor/heredoc.c executor/execute_builtins.c executor/executor.c executor/utils.c executor/handle_pipe.c executor/handle_single_cmd.c executor/ft_realpath.c executor/path_finder.c executor/cmd_and_args_arr.c \
executor/redirections.c executor/heredoc.c executor/execute_builtins.c executor/executor.c executor/utils.c executor/handle_pipe.c executor/handle_single_cmd.c executor/ft_realpath.c executor/path_finder.c executor/cmd_and_args_arr.c executor/wait.c \
envp/env_vars.c envp/free.c envp/hash_table.c envp/utils.c \
utils/ft_isvalidvarname.c tokenizer/reshuffle_quotes.c \
utils/signals.c executor/wait.c debug/debug.c tokenizer/reshuffle_quotes_utils.c
utils/ft_isvalidvarname.c utils/signals.c \
debug/debug.c debug/print_ast_new.c

OBJS = $(addprefix $(OBJ_DIR)/, $(SRCS:.c=.o))
OBJS := $(OBJS:/=_)
Expand Down
79 changes: 59 additions & 20 deletions include/minishell.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "libft.h"
#include "tokenizer.h"
#include <stdio.h>
// Comment needed to prevent autoformat to move the include above the comment
#include <errno.h>
Expand Down Expand Up @@ -31,7 +32,7 @@ typedef enum e_debug_level
DEBUG_ALL // Debug everything
} t_debug_level;

extern t_debug_level g_debug_level;
// extern t_debug_level debug_level;

/* Error messages*/

Expand Down Expand Up @@ -86,9 +87,14 @@ typedef enum e_token_type
// 7 - " the whole string in between " quotes included
T_SINGLE_QUOTE,
// 8 - ' the whole string in between ' quotes included
T_ENV_VAR, // 9 - $ followed by a valid variable name
T_SHELL_VAR, // 10 - $ followed by a shell variable symbol like $?
T_END, // 11 - End of token array
T_ENV_VAR, // 9 - $ followed by a valid variable name
T_SHELL_VAR, // 10 - $ followed by a shell variable symbol like $?
T_END, // 11 - End of token array
T_UNKNOWN, // 12 - Unknown token
T_LOG_OR, // 13 - ||
T_LOG_AND, // 14 - &&
T_PARENTHESIS_OPEN, // 15 - (
T_PARENTHESIS_CLOSED, // 16 - )
} t_token_type;

typedef struct s_token
Expand Down Expand Up @@ -158,18 +164,22 @@ int find_next_env_var_if_any(const char **str);
# define CMD_FOUND 1
typedef enum e_lexeme_type
{
L_COMMAND, // Command to be executed
L_ARGUMENT, // Argument to a command
L_PIPE, // Pipe operdator, signaling chaining of commands
L_REDIRECT_INPUT, // Input redirection operator (<)
L_REDIRECT_OUTPUT, // Output redirection operator (>)
L_REDIRECT_APPEND, // Append redirection operator (>>)
L_HEREDOC, // Heredoc redirection operator (<<)
L_HEREDOC_DELIMITER, // Delimiter for heredoc (<<)
L_FILENAME_STDIN, // Filename used in redirections
L_FILENAME_STDOUT, // Filename used in redirections
L_UNDEFINED, // Undefined lexeme type
L_END // End of lexeme array
L_COMMAND, // Command to be executed
L_ARGUMENT, // Argument to a command
L_PIPE, // Pipe operdator, signaling chaining of commands
L_REDIRECT_INPUT, // Input redirection operator (<)
L_REDIRECT_OUTPUT, // Output redirection operator (>)
L_REDIRECT_APPEND, // Append redirection operator (>>)
L_HEREDOC, // Heredoc redirection operator (<<)
L_HEREDOC_DELIMITER, // Delimiter for heredoc (<<)
L_FILENAME_STDIN, // Filename used in redirections
L_FILENAME_STDOUT, // Filename used in redirections
L_LOG_AND, // Logical AND operator (&&)
L_LOG_OR, // Logical OR operator (||)
L_PARENTHESIS_OPEN, // Open parentheses
L_PARENTHESIS_CLOSED, // Close parentheses
L_UNDEFINED, // Undefined lexeme type
L_END // End of lexeme array
} t_lexeme_type;

typedef enum e_lexeme_status
Expand All @@ -181,8 +191,7 @@ typedef enum e_lexeme_status
typedef struct s_lexeme
{
t_lexeme_type type;
char *str; // The actual value (could be after variable substitution)
char *original; // Original value (useful for environment variables)
char *str; // The actual value (could be after variable substitution)
t_lexeme_status status;
} t_lexeme;

Expand All @@ -196,6 +205,10 @@ t_lexeme redirect_out_target_lexeme(t_token *token,
t_lexeme redirect_append_lexeme(t_token *token, t_data *data);
t_lexeme heredoc_lexeme(t_token *token, t_data *data);
t_lexeme heredoc_delimiter_lexeme(t_token *token, t_data *data);
t_lexeme log_or_lexeme(t_token *token, t_data *data);
t_lexeme log_and_lexeme(t_token *token, t_data *data);
t_lexeme parentheses_open_lexeme(t_token *token, t_data *data);
t_lexeme parentheses_close_lexeme(t_token *token, t_data *data);
t_lexeme t_double_quotes_var_subs(t_token *token, t_data *data);
t_lexeme single_quote_lexeme(t_token *token, t_data *data);
t_lexeme t_env_var_subs(t_token *token, t_data *data);
Expand All @@ -220,6 +233,8 @@ void lexer_t_var_subs(t_data *data, size_t i);
void lexer_t_quotes_var_subs(t_data *data, size_t i);
void lexer_t_pipe(t_data *data, size_t i);
void lexer_t_redirects_and_word(t_data *data, size_t *i);
void lexer_t_log_and_or(t_data *data, size_t i);
void lexer_t_parentheses(t_data *data, size_t i);

void finalize_lexeme_array(t_data *data, size_t i);
void command_and_args(size_t token_count,
Expand All @@ -231,6 +246,9 @@ typedef enum e_node_type
{
N_PIPE,
N_COMMAND,
N_PARENTHESES,
N_LOG_OR,
N_LOG_AND,
} t_node_type;

typedef struct s_ast_node
Expand All @@ -249,6 +267,15 @@ typedef struct s_ast_node
struct s_ast_node *children[2]; // For output redirection.
} t_ast_node;

typedef struct s_parser
{
int i;
t_ast_node *node;
int parenthesis_sibling;
int end;
int start;
} t_parser;

typedef struct s_node_list
{
t_ast_node *node;
Expand All @@ -272,6 +299,7 @@ typedef struct s_data
t_lexeme *lexeme_arr;
t_ast_node *ast_root;
int last_exit_status;
t_debug_level debug_level;
} t_data;

t_ast_node *parser(t_lexeme *lexemes, int start, int end,
Expand All @@ -298,7 +326,7 @@ int ft_arrlen(char **arr);

/* Varia */
void check_input(int argc, char **argv);
char *read_input(void);
char *read_input(t_data *data);
t_token *tokenizer(t_data *data, const char *input);
size_t count_words_tokenizer(const char *input);

Expand All @@ -318,7 +346,15 @@ void debug_ast(t_ast_node *node);
void print_hash_table(t_env_table *env_table);
void print_envp_arr(char **envp);
t_ast_node *create_node(t_node_type type, t_data *data);

void free_str_arr(char **arr);
void free_cmd_node(t_ast_node *node);
void free_ast(t_ast_node *node);
void init_parser_vars(t_parser *vars, int start, int end);
int find_parenthesis_sibling(t_lexeme *lexemes, int start,
int end);
t_ast_node *build_parentheses_node(t_ast_node *node,
t_lexeme *lexemes, int start, int end,
t_data *data);
/* Heredoc */

int handle_heredocs(t_ast_node *node, t_data *data);
Expand Down Expand Up @@ -394,4 +430,7 @@ int ft_free_ret(char **ret, size_t i);
int check_parenthesis(t_ast_node *cmd);
void free_exit_code(t_data *data, char *error_message,
int exit_code);
bool is_command_entirely_enclosed(t_lexeme *lexemes,
int start, int end);
void print_node_info(t_ast_node *node, int level);
#endif
Binary file added minishell_bonus
Binary file not shown.
Loading