How f0lio/minishell works
Main Components
• Main Shell Loop – At the heart of the application is the “minishell.c” file within the src directory. This file represents the entry point where the shell receives user input and manages the high-level flow.
• Tokenizer – The tokenization phase is handled by the files in the “src/tokenizer” directory (e.g., tokenize_quoted.c, get_token.c, etc.). This module breaks down the user input into meaningful tokens that subsequent processes will use.
• Syntax Analyser – Located in “src/syntax_analyser”, this component verifies that the tokenized commands follow valid syntax before execution.
• Expansion Module – Found in “src/expansion”, these files manage the expansion of environment variables and handle quoted strings, ensuring that tokens are correctly interpreted.
• Execution Subsystem – Under “src/execution”, various files implement built-in commands (like echo, export, unset, etc.), command execution (using execve), piping, redirection, and error handling. This is the operational core that actually interfaces with the operating system.
• Constructors/Environment Management – The “src/constructors” portion (e.g., env.c) is likely involved in setting up the environment structures used across the shell.
• Utility Functions – In “src/utils”, numerous helper functions exist to manage signals, error handling, string manipulation, and more.
• Support Files – The “include” directory contains the public headers defining shared functions, macros, structures, and interfaces across modules.
Relationships and Interactions
• User Input Flow: The shell (minishell.c) reads user input (perhaps via terminal), sending it first to the Tokenizer.
• Tokenizer → Syntax Analyser: Once input is broken into tokens, the syntax analyser validates command structure.
• Syntax Analyser → Expansion: Valid tokens are then passed to the Expansion module where environment variables are expanded.
• Expansion → Execution: The fully processed commands are executed by the Execution subsystem by forking new processes, invoking built-ins, managing redirections, executing external commands, and handling pipes.
• Support/Data Sharing: The Constructors module prepares environment data, and the Util functions support error/signal handling across modules.
Architectural Patterns or Design Principles
• Modular Structure: The clear separation between tokenization, syntax analysis, expansion, and execution shows a layered design common in interpreters/shells.
• Separation of Concerns: Each directory focuses on a specific aspect of the shell’s functionality.
• Process Management and IPC: The execution modules emphasize handling processes (fork, execve), pipes, redirections, and signals.
Relevant Technologies/Frameworks
• C standard libraries and allowed functions (e.g., malloc, free, fork, pipe, execve, dup2) are in heavy use.
• The use of Makefile and Dockerfile suggests that the project supports both local builds and containerized environments.
• External documentation references (like the provided PDFs and websites) highlight design inspirations and allowed system calls.