How nickdotht/minishell works
Project Type & Purpose
• This is a monolithic, full-C implementation of a minimal Unix-style command‐line shell (“minishell”).
• It provides a REPL: reads user commands, parses them, executes built-in commands or external executables, manages environment variables, and handles signals.
Top-Level Components
A. Core Loop & I/O
• main.c
• display_prompt_msg.c
• get_next_line (in libft) / read input
B. Parser & Tokenizer
• (Implicit in exec_command.c and utility functions in libft, e.g., ft_strsplit)
C. Executor
• exec_command.c
• forks, execve external commands, waits for completion
D. Built-in Commands
• cd_builtin.c
• echo_builtin.c
• setenv_builtin.c
• unsetenv_builtin.c
• (env and exit implemented in exec_command or separate)
E. Environment Manager
• minishell’s in-memory env array (setenv, unsetenv, env)
F. Signal Handling
• signal_handler.c
• traps SIGINT (Ctrl-C), SIGQUIT, EOF (Ctrl-D)
G. Utility Library (libft)
• all generic string, memory, list, I/O helpers
H. OS Kernel / System Calls
• fork, execve, wait*, open/close/read/write, stat, opendir/readdir, chdir/getcwd, signals
Relationships & Data Flow
• User (stdin/stdout) → Prompt Display → Input Reader (read or get_next_line)
→ Parser (tokenize with libft functions)
→ Executor
• If token matches built-in → route to Built-in Module → updates Environment
• Else → fork() → child calls execve() (searching PATH using access()) → kernel loads external program
→ Parent waits (waitpid) → collects exit status → returns to core loop
• Signal Handler runs in parallel: catches interrupts and updates shell state (break loop or reset prompt).
• Throughout, Utility Library functions support string ops, dynamic arrays, memory management.
Key Architectural Patterns & Principles
• Modular C design: one .c per logical feature (single responsibility).
• Layered I/O → Parser → Executor → OS
• Explicit environment struct/array rather than global state
• Synchronous command execution with fork/exec + wait
• Minimal external dependencies (only libft)
Essential Elements
• Clear labels for each module/file group.
• Core shell logic vs. built-ins vs. external processes vs. utility library.
• Annotations for key syscalls (fork, execve, wait, open, read, write, chdir, signal).