How m4nnb3ll/minishell works
Main Components
• Input Handling & Signals: Include components such as main.c and main_signals.c which initialize the shell, handle startup, and manage signals.
• Tokenizer: Represent the tokenization process (the "tokenizing" directory) which breaks up input strings into tokens. Components include tokenizer.c, tokenizer_appenders.c, tokenizer_handlers.c, etc.
• Parser: Show the parsing stage (directory "parsing") where tokens are analyzed and arranged into a command structure. Include parser.c and its associated helper, clear, error, nodes, and utils files.
• Expander: Illustrate the expansion process (the "expander" directory) where variables, globbing, and quotes are handled and replaced. Components here include ft_expand* functions, ft_globber functions, and heredoc_expander.
• Execution Manager: Represent the execution logic found in the "exec" directory. This handles overall execution logic, checking for errors, performing redirections, and calling built-in commands when needed. Include exec.c files, exec_builtin.c, and related utility and error message modules.
• Cleanup/Miscellaneous: Incorporate a module for cleaning resources (the "cleaning" directory) which likely ensures that allocated data is freed properly.
• Utility Library: Show that the project leverages a custom utility library (in "libraries/libft") to provide common C functions (e.g., string manipulation, memory functions).
• Files: While not a runtime component, the "include" directory holds header files (minishell.h, parsing.h, tokenizing.h, etc.) which define the interfaces and data structures across modules.
Relationships and Data Flow
• From the Tokenizer, data flows into the Parser which constructs the command structure.
• The parsed command information is then sent to the Expander to resolve environment variables, handle quotes, and deal with globbing (e.g., asterisk expansion).
• After expansion, the execution component takes over: it determines whether a command is a built-in (redirecting execution to the Built-ins component) or an external utility (managing forking and calling binaries via PATH resolution).
• The Execution Manager may interface with Cleanup for resource management post execution.
• Utility functions from the Libft library are used throughout the flow for various tasks.
Architectural Patterns & Design Principles
• Modular Separation: Each major phase of command processing (tokenization, parsing, expansion, execution) is clearly separated into its own directories/modules.
• Layered/Sequential Processing: The design follows a strict linear pipeline – from reading input to final execution.
• Reusability & Abstraction: The use of an external libraries folder (for Libft) and modular built-ins helps keep functionality decoupled and maintains a single responsibility per module.