|
maxishell
Implementation of a shell for Linux-like systems
|
#include "../lib/libft/inc/libft.h"#include <stdlib.h>#include <stdio.h>#include <unistd.h>#include <readline/readline.h>#include <readline/history.h>#include <pwd.h>#include "shell.h"#include "env.h"

Go to the source code of this file.
Classes | |
| struct | s_token |
| struct | s_ast |
| struct | s_loop_data |
Macros | |
| #define | HISTORY_PATH "./src/utils/.maxishell_history" |
Typedefs | |
| typedef enum e_token_type | t_token_type |
| typedef struct s_token | t_token |
| typedef struct s_ast | t_ast |
| typedef struct s_loop_data | t_loop_data |
Enumerations | |
| enum | e_token_type { PHRASE , PIPE , ENV_VAR , REDIR_IN , REDIR_OUT , REDIR_APPEND , REDIR_HEREDOC , NONE } |
Functions | |
| void | final_quote_removal (int arg_count, t_ast *command_node) |
| char * | expand_env_var (char *arg, t_ms_data *data) |
| void | post_process_command_args (t_ast *command_node, int arg_count, t_ms_data *data) |
| void | add_node (t_token **head, char *str) |
| void | print_stack (t_token **stack) |
| void | free_stack (t_token **stack) |
| int | calc_stack_size (t_token *stack) |
| char ** | list_to_array (t_token *head) |
| void | build_linked_list (t_token **tokens, char **argv) |
| void | handle_quotes (char **tokens, int *pos, char **input) |
| char * | handle_special_chars (char *str, t_token **tokens) |
| void | skip_delimiters (char **input, char *delim) |
| void | reallocate_tokens (char ***tokens, int *bufsize) |
| void | parse_loop (char **input, char **tokens, int *pos, int *bufsize) |
| char ** | parse_input (char *input) |
| char * | generate_prompt (t_ms_data *data) |
| void | make_history (char *line) |
| void | loop_cleanup (t_loop_data *loop_data, t_token *tokens_head) |
| void | free_ms_data (t_ms_data *data) |
| char * | check_heredoc (char *line) |
| char * | heredoc (char *eof) |
| void | init_ms_data (t_ms_data *data, char **argv, char **envp) |
| void | initialise (int argc, char **argv) |
| void | execute_command (char **parsed_text, t_token **tokens) |
| void | print_maxishell (void) |
| int | input_error_checks (t_loop_data *loop_data) |
| t_token * | tokenise (char *str) |
| void | print_tokens (t_token *tokens, char *name) |
| t_ast * | parse_tokens (t_token **tokens, t_ms_data *data) |
| void | visualize_ast (t_ast *root) |
| void | free_ast (t_ast *node) |
| void | free_all_tokens (t_token *tokens) |
| t_token * | new_token (char *value, t_token_type type) |
| void | append_token (t_token **tokens, t_token *new_token) |
| int | valid_operator (const char **str) |
| t_ast * | new_ast_node (void) |
| t_ast * | create_redir (t_token **tokens, t_token *tmp, t_ms_data *data) |
| int | arg_len (t_token *current) |
| void | set_command_args (t_ast *command_node, t_token **tokens, int arg_count) |
| t_ast * | manage_commands (t_token **tokens, t_ms_data *data) |
| void | handle_local_vars (t_ms_data *data, char *arg) |
| t_ast * | create_redir_node (t_token *token) |
| int | is_redir_node (t_token *tokens) |
| t_ast * | manage_redirs (t_token **tokens, t_ms_data *data) |
| t_ast * | manage_pipe (t_token **tokens, t_ms_data *data) |
| char * | trim_input (char *str) |
| void | print_ast_root (t_ast *root) |
| void | execute_tree (t_ast *node, t_ms_data *data) |
| char * | expand_env_and_loc_var (char *arg, t_ms_data *data) |
| char * | append_literal (char **start, char *processed_arg) |
| char * | process_argument (char *arg, t_ms_data *data) |
| char * | expand_variable (char **start, t_ms_data *data) |
| void | clear_history_file (void) |
| int | is_in_single_quotes (char *arg) |
| void | print_ast_args (t_ast *node) |
| void | append_word_if_valid (char *start, char *str, t_token **tokens) |
| char * | exit_status_adj (char *arg) |
| char * | str_start_adj (char *arg) |
| char * | tmp_adj (char *arg) |
| int | cmd_arg_len (t_token *current) |
| char ** | ft_split_preserve_quotes (char *str, char delimiter) |
| char ** | ft_add_segment (char **result, char *start, size_t length, int *count) |
| char ** | initialize_result_array (int *count) |
| int | toggle_quotes (int in_quotes, char current_char) |
| char ** | add_segment_on_delimiter (char **result, char **start, char *str, int *count) |
| char ** | finalize_result_array (char **result, int count) |
| typedef struct s_loop_data t_loop_data |
| typedef enum e_token_type t_token_type |
| enum e_token_type |
| Enumerator | |
|---|---|
| PHRASE | |
| PIPE | |
| ENV_VAR | |
| REDIR_IN | |
| REDIR_OUT | |
| REDIR_APPEND | |
| REDIR_HEREDOC | |
| NONE | |
Definition at line 29 of file tokens.h.
| void add_node | ( | t_token ** | head, |
| char * | str | ||
| ) |
Definition at line 15 of file stack_control.c.
References s_token::data, and s_token::next.
Referenced by build_linked_list().

| char ** add_segment_on_delimiter | ( | char ** | result, |
| char ** | start, | ||
| char * | str, | ||
| int * | count | ||
| ) |
Definition at line 33 of file loc_env_var_handler_utils_utils_utils_utils.c.
References ft_add_segment().
Referenced by ft_split_preserve_quotes().


| char * append_literal | ( | char ** | start, |
| char * | processed_arg | ||
| ) |
Definition at line 74 of file loc_env_var_handler_utils_utils_utils.c.
References ft_strjoin(), and ft_substr().
Referenced by process_argument().


Definition at line 85 of file tokeniser.c.
References new_token(), and s_token::next.
Referenced by append_word_if_valid(), and handle_special_chars().


| void append_word_if_valid | ( | char * | start, |
| char * | str, | ||
| t_token ** | tokens | ||
| ) |
Definition at line 49 of file tokeniser_helpers.c.
References append_token(), ft_printf(), ft_strndup(), new_token(), and PHRASE.
Referenced by handle_phrase().


| int arg_len | ( | t_token * | current | ) |
| void build_linked_list | ( | t_token ** | tokens, |
| char ** | argv | ||
| ) |
Definition at line 15 of file stack_control_2.c.
References add_node().

| int calc_stack_size | ( | t_token * | stack | ) |
Definition at line 65 of file stack_control.c.
References s_token::next.
Referenced by list_to_array().

| char * check_heredoc | ( | char * | line | ) |
| void clear_history_file | ( | void | ) |
Definition at line 31 of file builtins_utils.c.
References HISTORY_PATH.
Referenced by cleanup_exit_resources(), main(), and main_loop().

| int cmd_arg_len | ( | t_token * | current | ) |
Definition at line 88 of file AST_utils.c.
References s_token::next, PHRASE, and s_token::type.
Referenced by manage_commands().

Definition at line 62 of file AST.c.
References s_ast::args, s_token::data, ft_strdup(), new_ast_node(), s_token::type, and s_ast::type.
Referenced by manage_redirs().


| void execute_command | ( | char ** | parsed_text, |
| t_token ** | tokens | ||
| ) |
| char * exit_status_adj | ( | char * | arg | ) |
Definition at line 21 of file loc_env_var_handler_utils_utils_utils.c.
References ft_strcmp().
Referenced by expand_env_and_loc_var().


| char * expand_env_and_loc_var | ( | char * | arg, |
| t_ms_data * | data | ||
| ) |
Definition at line 45 of file loc_env_var_handler_utils_utils.c.
References exit_status_adj(), ft_strcmp(), ft_strdup(), get_env_variable(), get_exit_status(), and handle_trailing_quote().
Referenced by ev_loop().


| char * expand_env_var | ( | char * | arg, |
| t_ms_data * | data | ||
| ) |
| char * expand_variable | ( | char ** | start, |
| t_ms_data * | data | ||
| ) |
Definition at line 40 of file loc_env_var_handler_utils.c.
References ev_loop(), ft_strdup(), ft_strjoin_free(), ft_substr(), and str_start_adj().
Referenced by process_argument(), and process_single_token().


| void final_quote_removal | ( | int | arg_count, |
| t_ast * | command_node | ||
| ) |
Definition at line 21 of file loc_env_var_handler_utils_utils.c.
References s_ast::args, ft_print_2d_arr(), ft_strlen(), and ft_strndup().

| char ** finalize_result_array | ( | char ** | result, |
| int | count | ||
| ) |
Definition at line 41 of file loc_env_var_handler_utils_utils_utils_utils.c.
Referenced by ft_split_preserve_quotes().

| void free_all_tokens | ( | t_token * | tokens | ) |
Definition at line 17 of file clean_utils.c.
References s_token::data, and s_token::next.
| void free_ast | ( | t_ast * | node | ) |
Definition at line 74 of file clean.c.
References s_ast::args, free_ast(), s_ast::left, and s_ast::right.
Referenced by free_ast(), and loop_cleanup().


| void free_ms_data | ( | t_ms_data * | data | ) |
Definition at line 51 of file clean.c.
References s_ms_data::current_dir, s_ms_data::envp, free_shell_var_list(), s_ms_data::shell_variables, s_ms_data::std_err, s_ms_data::std_in, and s_ms_data::std_out.
Referenced by cleanup_exit_resources(), and main().


| void free_stack | ( | t_token ** | stack | ) |
Definition at line 51 of file stack_control.c.
References s_token::next.
| char ** ft_add_segment | ( | char ** | result, |
| char * | start, | ||
| size_t | length, | ||
| int * | count | ||
| ) |
Definition at line 91 of file loc_env_var_handler_utils.c.
References ft_strndup().
Referenced by add_segment_on_delimiter(), and ft_split_preserve_quotes().


| char ** ft_split_preserve_quotes | ( | char * | str, |
| char | delimiter | ||
| ) |
Definition at line 99 of file loc_env_var_handler_utils.c.
References add_segment_on_delimiter(), finalize_result_array(), ft_add_segment(), initialize_result_array(), and toggle_quotes().
Referenced by split_loc_vars().


| char * generate_prompt | ( | t_ms_data * | data | ) |
Definition at line 20 of file prompt.c.
References EXIT_FAILURE, ft_strcat(), ft_strcpy(), and ft_strlen().

| void handle_local_vars | ( | t_ms_data * | data, |
| char * | arg | ||
| ) |
Definition at line 69 of file loc_env_var_handler_utils.c.
References ft_isalnum(), ft_strchr(), handle_add_set_shell_variable(), and s_ms_data::shell_variables.

| void handle_quotes | ( | char ** | tokens, |
| int * | pos, | ||
| char ** | input | ||
| ) |
| char * handle_special_chars | ( | char * | str, |
| t_token ** | tokens | ||
| ) |
Definition at line 39 of file tokeniser.c.
References append_token(), new_token(), PIPE, REDIR_APPEND, REDIR_HEREDOC, REDIR_IN, and REDIR_OUT.
Referenced by tokenise().


| char * heredoc | ( | char * | eof | ) |
| void init_ms_data | ( | t_ms_data * | data, |
| char ** | argv, | ||
| char ** | envp | ||
| ) |
Definition at line 20 of file initialise.c.
References s_ms_data::args, s_ms_data::current_dir, s_ms_data::envp, s_ms_data::exit_status, handle_add_set_shell_variable(), init_env(), set_shell_var(), s_ms_data::shell_variables, s_ms_data::std_err, s_ms_data::std_in, and s_ms_data::std_out.
Referenced by main().


| void initialise | ( | int | argc, |
| char ** | argv | ||
| ) |
Definition at line 36 of file initialise.c.
References EXIT_FAILURE, ft_printf(), and HISTORY_PATH.
Referenced by main().


| char ** initialize_result_array | ( | int * | count | ) |
Definition at line 15 of file loc_env_var_handler_utils_utils_utils_utils.c.
Referenced by ft_split_preserve_quotes().

| int input_error_checks | ( | t_loop_data * | loop_data | ) |
Definition at line 96 of file input_checker.c.
References check_open_quotes(), check_operators(), check_redirections(), ft_printf(), and s_loop_data::trimmed_input.
Referenced by main_loop().


| int is_in_single_quotes | ( | char * | arg | ) |
Definition at line 28 of file loc_env_var_handler_utils_utils_utils.c.
Referenced by post_process_command_args().

| int is_redir_node | ( | t_token * | tokens | ) |
Definition at line 79 of file AST.c.
References REDIR_APPEND, REDIR_HEREDOC, REDIR_IN, REDIR_OUT, and s_token::type.
Referenced by manage_redirs().

| char ** list_to_array | ( | t_token * | head | ) |
Definition at line 80 of file stack_control.c.
References calc_stack_size(), s_token::data, ft_strdup(), and s_token::next.

| void loop_cleanup | ( | t_loop_data * | loop_data, |
| t_token * | tokens_head | ||
| ) |
Definition at line 67 of file clean.c.
References free_all_tokens(), free_ast(), s_loop_data::tree, and s_loop_data::trimmed_input.
Referenced by process_command().


| void make_history | ( | char * | line | ) |
Definition at line 15 of file aux.c.
References HISTORY_PATH.
Referenced by main_loop().

Definition at line 72 of file AST_utils.c.
References s_ast::args, cmd_arg_len(), new_ast_node(), PHRASE, post_process_command_args(), set_command_args(), and s_ast::type.
Referenced by manage_redirs().


Definition at line 56 of file AST_utils.c.
References create_pipe_node(), manage_redirs(), s_token::next, PIPE, and s_token::type.
Referenced by create_pipe_node(), and parse_tokens().


Definition at line 20 of file AST.c.
References create_redir_node(), is_redir_node(), s_ast::left, manage_commands(), s_token::next, and s_ast::right.
Referenced by create_pipe_node(), and manage_pipe().


| t_ast * new_ast_node | ( | void | ) |
Definition at line 89 of file AST.c.
References s_ast::args, s_ast::left, NONE, s_ast::right, and s_ast::type.
Referenced by create_pipe_node(), create_redir_node(), and manage_commands().

| t_token * new_token | ( | char * | value, |
| t_token_type | type | ||
| ) |
Definition at line 67 of file tokeniser.c.
References s_token::data, ft_strdup(), s_token::next, and s_token::type.
Referenced by append_token(), append_word_if_valid(), finalize_token(), handle_special_chars(), and process_single_token().


| char ** parse_input | ( | char * | input | ) |
| void parse_loop | ( | char ** | input, |
| char ** | tokens, | ||
| int * | pos, | ||
| int * | bufsize | ||
| ) |
Definition at line 23 of file AST_utils.c.
References manage_pipe().
Referenced by main_loop().


Definition at line 60 of file loc_env_var_handler.c.
References s_ast::args, ft_remove_quotes(), ft_strlen(), ft_substr(), handle_local_vars(), is_in_single_quotes(), process_argument(), and split_loc_vars().
Referenced by manage_commands().


| void print_ast_args | ( | t_ast * | node | ) |
Definition at line 37 of file tokeniser_helpers.c.
References s_ast::args, and ft_printf().

| void print_ast_root | ( | t_ast * | root | ) |
Definition at line 103 of file visualiser.c.
References print_ast_graphical().

| void print_maxishell | ( | void | ) |
Definition at line 56 of file prompt.c.
References ft_printf().
Referenced by main().


| void print_stack | ( | t_token ** | stack | ) |
Definition at line 36 of file stack_control.c.
References s_token::data, ft_printf(), and s_token::next.

| void print_tokens | ( | t_token * | tokens, |
| char * | name | ||
| ) |
Definition at line 19 of file tokeniser_helpers.c.
References s_token::data, ft_printf(), ft_strlen(), GRN, s_token::next, and RESET.

| char * process_argument | ( | char * | arg, |
| t_ms_data * | data | ||
| ) |
Definition at line 104 of file loc_env_var_handler.c.
References append_expanded_var(), append_literal(), expand_variable(), and ft_strdup().
Referenced by post_process_command_args().


| void reallocate_tokens | ( | char *** | tokens, |
| int * | bufsize | ||
| ) |
Definition at line 48 of file AST.c.
References s_ast::args, ft_strdup(), and s_token::next.
Referenced by manage_commands().


| void skip_delimiters | ( | char ** | input, |
| char * | delim | ||
| ) |
| char * str_start_adj | ( | char * | arg | ) |
Definition at line 42 of file loc_env_var_handler_utils_utils_utils.c.
References ft_strcmp().
Referenced by expand_variable().


| char * tmp_adj | ( | char * | arg | ) |
Definition at line 51 of file loc_env_var_handler_utils_utils_utils.c.
References ft_isdigit(), and ft_strdup().
Referenced by append_expanded_var().


| int toggle_quotes | ( | int | in_quotes, |
| char | current_char | ||
| ) |
Definition at line 26 of file loc_env_var_handler_utils_utils_utils_utils.c.
Referenced by ft_split_preserve_quotes().

| t_token * tokenise | ( | char * | str | ) |
Definition at line 22 of file tokeniser.c.
References ft_strchr(), handle_phrase(), and handle_special_chars().
Referenced by main_loop().


| char * trim_input | ( | char * | str | ) |
Definition at line 15 of file input_checker_helpers.c.
References ft_strtrim().
Referenced by main_loop().


| int valid_operator | ( | const char ** | str | ) |
Definition at line 25 of file input_checker_helpers.c.
References ft_exclude_delimiters().
Referenced by check_redirections().


| void visualize_ast | ( | t_ast * | root | ) |