How melvinredondotanis/holbertonschool-shell_v2 works
Project type and purpose
• This is a lightweight, Unix-style command-line shell written in C (“holbertonschool-shell_v2”).
• Its purpose is to parse user input, manage environment variables, handle built-in commands (exit, env, setenv, unsetenv), support I/O redirection, pipelines, and execute external programs.
File structure
• Top-level C files:
• main.c – bootstrap, argument handling (interactive vs non-interactive)
• interpreter.c – high-level driver for parsing & execution loops
• prompt.c – print/read prompt
• tokenizer.c – split raw input into tokens
• builtins.c / builtins_env.c – implement built-in commands
• *_getenv.c, _setenv.c, etc. – environment variable helpers
• _putenv.c, _realloc.c, etc. – utility functions for string and memory ops
• man_1_hsh – manual page
• hsh.h – global declarations, structs, constants
README
• Lists features: interactive/non-interactive mode, heredoc, pipelines, env vars, built-ins, redirection.
• Describes build (Makefile → hsh) and use cases.
Components
a. Main logical components
1. CLI Frontend (Prompt & Input Reader)
2. Lexer/Tokenizer
3. Parser / Command Data Structure Builder
4. Execution Engine
• Built-in Command Handler
• External Command Launcher (fork + execve)
5. I/O Redirection & Pipeline Manager
6. Environment Variable Manager
7. Utility Library (string & memory helpers)
8. Underlying OS Services (file descriptors, process control, signals)
b. Relationships & interactions
• User types a command → Prompt reads line → Tokenizer produces tokens → Parser builds command AST/struct → Execution Engine inspects command type
• If built-in → call Built-in Handler → may modify environment via Environment Manager
• Else → fork child → apply I/O redirects/pipes → execve external binary
• For pipelines, Execution Engine coordinates multiple child processes, connecting stdout of one to stdin of next.
• All components may log errors to stderr and check memory via Utility Library.
c. Architectural patterns & design principles
• Modular layering: I/O layer → Lexing → Parsing → Execution
• Single Responsibility: each C module focuses on one aspect
• Separation of concerns: built-ins vs external commands vs environment management
• Reusable utilities for common operations
d. Key technologies/frameworks
• C Standard Library (stdio.h, stdlib.h, string.h)
• POSIX system calls (fork, execve, dup2, pipe, waitpid)
• valgrind for memory checking (development tool)
Detailed capture of essential elements
• Don’t overcrowd: keep high-level modules but show sub-components where behavior diverges (built-ins vs external).
• Both interactive (prompt loop) and non-interactive (read from file/stdin) entry points.
• Error handling points (e.g., invalid commands, memory errors) if desired for completeness.