How pedroferreira50/minishell_acabado works
Project Type & Purpose
• Project Type: A command‐line interpreter (“mini shell”) written in C
• Purpose: Read user commands, parse and expand them, execute built-in or external programs, manage I/O redirection and pipelines, and handle environment and signals.
File Structure & Key Modules
Top‐level files:
• main.c + main_utils.c → application entry point and loop
• minishell.h → central type definitions, constants
Major directories/modules:
• parse_input/ → tokenize raw input into command segments
• parse_command/ → build command AST or data structures, syntax validation
• expand_vars/ → variable and quote expansion logic
• builtins/ → implementations of shell built‐ins (cd, echo, export, etc.)
• pipes_and_execution/ → fork/exec logic, pipelines, redirections, heredoc
• libft/ → common utility functions (strings, memory, printing, lists)
Supporting files:
• signal.c → signal handling (SIGINT, SIGQUIT)
• error.c, free_*.c → error reporting and memory cleanup
• find_command_path.c → $PATH lookup for external commands
README
The README only provides the project name. All architectural details must be inferred from the file tree and naming conventions.
Core Components
a. User Interface (CLI Frontend)
– Reads input via readline or custom routines
– Sends raw string to parsing module
b. Parsing Layer
– parse_input: splits raw input into tokens/commands
– parse_command: validates syntax, constructs command structures
c. Expansion Layer
– expand_vars: performs environment‐variable and quote expansion
d. Dispatcher & Executor
– Determines if a command is built‐in or external
– builtins/*: runs built‐in functions in‐process
– pipes_and_execution/*: forks child processes, sets up pipes & redirections, execs external binaries
e. Environment Manager
– Maintains envp list, manipulated by export/unset
– print_env, env built‐in
f. Signal Handling
– signal.c: configures SIGINT/SIGQUIT behavior in parent and child processes
g. Utility Library
– libft: string, memory, list, I/O helpers reused by all modules
Relationships & Interactions
• Data Flow:
User Input → parse_input → parse_command → expand_vars → dispatcher
↳ If built‐in: builtins module → environment updates → return status
↳ Else external: pipes_and_execution → fork & exec → collect status
→ Loop back for next prompt
• Dependency Graph:
main
↳ parse_input
↳ parse_command
↳ expand_vars
↳ dispatcher ↔ builtins
↔ pipes_and_execution
↳ libft (used by all modules)
↳ signal
Architectural Patterns & Principles
– Modular separation (lexing, parsing, expansion, execution)
– Single responsibility per module
– In‐process built‐in vs. fork‐exec for external commands
– Explicit memory management and cleanup
Essential Elements
– Clear, concise labels for each module
– Note the signal handler’s influence on both parent and child process flows