๐ฏ Objective
Implement the main shell lifecycle (Read-Eval-Print Loop) and ensure the program is resilient to user interruptions (Ctrl+C, Ctrl+D, Ctrl+), emulating Bash behavior.
๐๏ธ Proposed Architecture.
- Global State Structure (t_shell)
A persistent state is required to track environment variables, exit codes, and the main loop status.
typedef struct s_shell {
char **envp; // Copy of environment variables
int last_status; // Value of $? (exit code)
int running; // Loop control flag
char *line; // Raw input from readline
} t_shell;
- Function Definitions (Signatures)
Module: signals.c
- void setup_signals(void); -> Configures initial handlers using sigaction.
- void handle_sigint(int sig); -> Handler for SIGINT (Ctrl+C). It must clear the readline buffer and move to a new line.
- void ignore_sigquit(void); -> Sets SIGQUIT (Ctrl+) to be ignored.
Module: core.c
- void init_shell(t_shell *sh, char **env); -> Allocates initial memory and duplicates the environment.
- void shell_loop(t_shell *sh); -> Contains the while(sh->running) logic.
- char *get_prompt_text(void); -> Generates the prompt string (e.g., user@minishell:~$ ).
- void cleanup_shell(t_shell *sh); -> Frees all memory before exiting (prevents leaks).
๐ ๏ธ TODO List
โ ๏ธ Technical Considerations
Memory Leaks: Every line returned by readline must be freed.
Signal Modes: Note that signal behavior must change once we implement fork(). For now, we only care about the shell in its waiting for input state.
Compilation: Remember to link the library using the -lreadline flag in your Makefile.
๐ฏ Objective
Implement the main shell lifecycle (Read-Eval-Print Loop) and ensure the program is resilient to user interruptions (Ctrl+C, Ctrl+D, Ctrl+), emulating Bash behavior.
๐๏ธ Proposed Architecture.
A persistent state is required to track environment variables, exit codes, and the main loop status.
Module: signals.c
Module: core.c
๐ ๏ธ TODO List
Memory Leaks: Every line returned by readline must be freed.
Signal Modes: Note that signal behavior must change once we implement fork(). For now, we only care about the shell in its waiting for input state.
Compilation: Remember to link the library using the -lreadline flag in your Makefile.