How ohssineabdelfatah/42_minishell works
Main Components
• Command Input & Terminal Interface – Represents the interactive layer where the user types commands.
• Parser – Located in the sources/parse directory. Its job is to tokenize the input and validate the syntax.
• Expander – Found in sources/expander. This module handles variable expansion (translating environment variables to their values) and processes heredoc.
• Builtin Commands – In sources/builtins. Implements built-in functionalities like cd, pwd, env, export, unset, and exit.
• Execution Manager – Modules in sources/execution deal with running commands, managing pipes, redirections (sources/redirection_things), and handling signals (e.g., Ctrl+C or Ctrl+D).
• Error Handler – Located in sources/errors. Ensures that errors during command parsing and execution produce readable, accurate messages.
• Utility Libraries – The project uses external/shared libraries:
• Libft (lib/libft): Contains utility functions common to many 42 projects.
• Get-Next-Line (lib/gnl0): For reading input streams.
• Memory & Resource Cleanup – Sources/freedom provides functions to free resources and manage deallocation.
Relationships and Interactions
• Input flows from the terminal into the Command Input module.
• The Parser reads the raw input, tokenizes it, and hands over structured commands to the Expander.
• The Expander resolves environment variables and expands tokens related to heredoc.
• If a command is a builtin (redirected to the Builtins module)
• Or if it should be executed as an external command (using system calls such as fork/exec, with pipe/redirection processing).
• The Error Handler monitors all interactions throughout the process and ensures appropriate error messages are generated.
• Utility libraries support various functions across modules (e.g., string operations, memory management, file reading).
Architectural Patterns and Design Principles
• Modular Design: The project is clearly modularized—the separation into directories (parse, expander, builtins, execution, redirection, etc.) shows a strong separation of concerns.
• Layered Processing Pipeline: Input is processed in distinct stages (parsing → expansion → execution) which helps isolate functionality.
• Reuse of Common Libraries: The use of Libft and Get-Next-Line underlines a design emphasis on leveraging shared utility code.
• Robust Error and Signal Handling: There are dedicated modules for error handling and signal processing, indicating attention to process management and system-level robustness.