13 #include <readline/readline.h>
14 #include <readline/history.h>
16 #include "get_next_line.h"
55 status = 128 + SIGINT;
78 return (readline(
"MiniDevil $> "));
79 line = get_next_line(STDIN_FILENO);
82 len = ft_strlen(line);
83 if (len > 0 && line[len - 1] ==
'\n')
102 if (!input || input[0] ==
'\0')
105 while (input[i] && ft_isspace(input[i]))
107 if (input[i] ==
'\0')
135 ft_putstr_fd(
"exit\n", STDOUT_FILENO);
163 int main(
int ac,
char **av,
char **envp)
167 ft_memset(&shell, 0,
sizeof(
t_shell));
170 shell.
interactive = (isatty(STDIN_FILENO) && isatty(STDOUT_FILENO));
174 if (ac > 1 && ft_strncasecmp(av[1],
"--ui", 5) == 0)
AST node creation and destruction prototypes.
void free_ast(t_ast *node)
Recursively free an entire AST tree.
Environment variable management prototypes.
t_env * init_env(char **envp)
Initialize the environment linked list from main()'s envp.
void free_env_list(t_env **env_list)
Free all nodes in the env linked list.
int executor(t_ast *node, t_shell *shell)
Main AST executor that dispatches by node type.
Executor prototypes for commands, pipes, redirections & heredocs.
int expand_all_tokens(t_token *tokens, t_shell *shell)
Expand all token values before parsing.
int collect_heredocs(t_ast *node, t_shell *shell)
Pre collect all heredocs in the AST before the execution phase.
static char * read_input(t_shell *shell)
Read 1 line of input from the user.
static int process_input(char *input, t_shell *shell)
tokenize -> expand -> parse -> execute
static void main_loop(t_shell *shell)
Main REPL (standard mode)
static void handle_input(char *input, t_shell *shell)
Filter and dispatch input to processing.
int main(int ac, char **av, char **envp)
Entry point.
UI mode structures, macros & function prototypes.
t_ast * parse(t_token *tokens)
Parse a token list into an AST.
Parser entry point & sub parser prototypes.
volatile sig_atomic_t g_signal
The single global variable.
void setup_execution_signals(void)
Ignore signals during command execution in the parent.
void setup_interactive_signals(void)
Configure signals for the interactive prompt.
Signal handler prototypes.
int interactive
1 if STDIN is a tty
t_env * env
Environment linked list.
int is_child
Child flag (to avoid leaks)
int running
1 while main loop is active
char * current_input
Current input line.
int exit_status
Last command's exit status.
struct s_ast * current_ast
Currently executing AST.
struct s_ui * ui
UI state (NULL if off)
int ui_mode
1 if UI mode (–ui)
Lexer token (singly linked list)
void free_token_list(t_token *head)
Free the entire token linked list.
Lexer, tokenizer, expander, and quote handling prototypes.
t_token * tokenize(char *input)
Tokenize the input string into a linked list of tokens.
void run_ui_mode(t_shell *shell)
Entry point for UI mode.