Dish (dope interactive shell) is a basic custom shell in C, providing features such as raw mode input handling, tokenizing input strings, and executing basic commands. The shell supports pipes (|
) and background execution (&
).
-
Initialization and Raw Mode
- Enables raw mode for character-by-character input processing
- Allocates memory for input string
- Initializes variables for input tracking
-
Main Function
- Processes input into a single string
- Handles program exit safely without memory leaks
-
Lexer
- Breaks input into tokens
- Handles spaces and special characters
- Returns a null-terminated array of token structures
-
Execute Function
- Creates new processes using fork()
- Runs commands using execvp()
- Handles parent and child processes
-
Input Processing
- Handles Enter key for command execution
- Manages backspace for input editing
- Ignores arrow keys to prevent errors
-
Error Handling
- Checks for maximum input size
- Provides error messages for invalid inputs
-
Cleanup
- Frees allocated memory before program exit
- Raw mode input handling
- Tokenizing input strings
- Executing basic commands
- Piping support
- Background execution support
- Enhanced keyboard functionality (e.g., arrow key navigation)
- Implementation of a linked list for input tracking
- Additional built-in commands
- Command history functionality
The program is divided into several key functions:
enable_raw_mode()
: Sets up the terminal for raw inputnum_tokens()
: Counts the number of tokens in the inputtokenize()
: Breaks the input into tokensexecute()
: Creates new processes and runs commands- Main loop: Handles input processing and command execution
The shell provides a basic but functional command-line interface, with room for further enhancements and features.