How legenduzo/simple_shell works
Project type and purpose
• Type: A CLI (“full‐stack” in the sense of user→shell, but really a single monolithic C program).
• Purpose: Read user input, parse it, resolve commands (built‐in vs external), execute, loop.
File structure
• Top‐level C modules:
– main.c → entry point
– loop_shell.c → the REPL loop
– manage_cmd.c → command‐handling & execution
– where.c → PATH lookup
– exctract_dir_from_string.c, check_dir.c → directory/executable checks
– split_string.c, check_spaces.c, check_char.c → string parsing
– string_manage.c → strcpy/strcat/strlen/strncmp clones
– free_split.c → memory cleanup for split results
– env.c → environment‐variable helpers
• shell.h → prototypes & shared headers
README insights
• Describes primary features: parsing, argument support, PATH resolution, built‐in vs external commands.
Main components to model
A. User Interface (stdin/stdout)
B. Shell Core
1. REPL Loop
2. Input Reader
3. Parser/Tokenizer
4. Command Manager
– Built‐in handler (e.g., “cd”, “exit”)
– External command resolver (uses where.c, PATH env)
5. Executor (fork + execve + wait)
C. Utility Modules
– String utilities (split_string, string_manage, check_spaces, check_char)
– Memory manager (free_split)
– Env helper (env.c)
D. OS Interactions
– File system (check_dir, exctract_dir_from_string)
– Process control syscalls (fork, execve, wait)
Relationships & data flow
1. User types a line → REPL loop (loop_shell.c)
2. Loop calls input reader (main.c or loop_shell.c)
3. Raw input → Parser/Tokenizer (split_string.c + check_spaces.c) → array of tokens
4. Tokens → Command Manager
• If built-in: handle inline
• Else: call where.c to locate binary on PATH
5. Command Manager → Executor
• fork() → child execve() → parent wait()
6. After execution → back to REPL loop
7. Utilities invoked throughout for memory management and string ops
Architectural patterns & design principles
• Modular C files each implement one responsibility
• Clear separation: parsing, resolution, execution, utilities
• Linear, synchronous REPL (no concurrency beyond fork/exec)
Technologies & frameworks
• Language: C (POSIX)
• Syscalls: fork, execve, wait, open/stat (via check_dir)
• No external libraries beyond standard libc