How adpn/minishell works
Main Components
• Shell Core: This is represented by the main entry point (srcs/main.c) that initializes the shell and manages the main loop.
• Lexer: Located in srcs/lexer, this module tokenizes the input command string into tokens; include components like lexer.c, lexer_utils.c, and nodes.c.
• Parser: Found in srcs/parser, this component’s responsibility is to create the abstract representation of the commands (AST or similar) from the tokens, processing commands, redirects, and counters.
• Expander: In srcs/expander, this module expands variables, handles quotes, and prepares the command arguments by calling expand_get.c and related files.
• Executor: In srcs/executor, this block handles command execution, including redirections (check_redirects.c, heredoc.c) and launching executables after interpreting PATH.
• Built-in Commands: Under srcs/builtins, these files implement internal shell commands (cd, echo, export, etc.).
• Error Handling: Under srcs/errors, the module manages printing error messages and possibly cleaning resources.
• Utility Functions: Aggregated in srcs/utils (and includes from libft) covering common operations (memory, strings, etc.).
• Library (libft): Provides general-purpose code such as string manipulation, memory functions, and linked-list utilities that support other modules.
Relationships and Interactions
• Data Flow:
• The main loop in main.c reads user input and sends it to the Lexer.
• The Lexer converts the raw input into tokens and forwards these tokens to the Parser.
• The Parser builds the command structure, considering redirections, pipes, and command grouping.
• The Expander processes the parsed data to replace environment variables and handle quoting semantics.
• The Executor receives the final command structure and decides whether to invoke built-in commands (via srcs/builtins) or external executables with the help of PATH resolution.
• The Error Handling component is integrated throughout these modules for reporting and managing errors.
Architectural Patterns and Design Principles
• Modular Design: Each primary functionality (lexing, parsing, executing) is modularized into its own directory and corresponding files.
• Separation of Concerns: The clear separation between built-in commands, external execution logic, and parsing logic helps maintain well-defined boundaries.
• Reusability: The use of the libft library reinforces common reusability principles by encapsulating utilities that are used across the shell.
• Error Propagation: A distinct error handling mechanism is present to catch and communicate issues at various processing stages.
Relevant Technologies and Libraries
• Programming Language: C
• Custom Libraries: libft – a homemade library offering memory management, string functions, list utilities, etc.
• Unix System Calls: While not explicit in the file names, typical Unix APIs (fork, execve, pipe, etc.) are used in the Executor.
• Use clear labels: Each component should be labeled (e.g., “Lexer”, “Parser”, “Executor”, “Built-ins”, “Error Handling”, “Utility Library”).
• Data Flow and Dependencies: Clearly indicate how data (command strings, tokens, parsed commands) flows between modules and what interfaces are used for interactions (for example, highlighting that the parsed command structure is shared between Parser, Expander, and Executor).