Core
XWSH Core: Command parsing algorithm, thread model, error handling, and internal state management.
2 minute read
XWSH (XWOS Shell) is the command line interpreter module of XWOS, providing users with an interactive command line interface. It is located in the xwmd/cli/xwsh/ directory of the source code and belongs to the command line interface (cli) submodule of the XWOS middleware layer (xwmd).
The core functionality of XWSH includes:
XWSH adopts a layered design. The relationships between components are as follows:
User Input
↓
[m] Readline Layer (CherryRL Integration)
↓
[c] Core Layer (Command Parsing and Execution)
↓
├── [c] Built-in Command Table
├── [c] External Command Table (User Extensions)
└── [c] Command Lookup and Dispatch
↓
[c] Command Handler Functions
mi.h)core.h/core.c)readline.h/readline.c)cmd.c)help, clear, rd (read memory), wr (write memory)#include "xwmd/cli/xwsh/mi.h"
xwstk_t xwsh_stack[1024];
xwer_t rc = xwsh_start(xwsh_stack, sizeof(xwsh_stack));
#include "xwmd/cli/xwsh/mi.h"
xwsh_init();
while (1) {
char buf[XWSH_MAXINPUT];
xwsh_loop(buf);
}
| Module Component | Source File | Description |
|---|---|---|
| Public Interface | xwmd/cli/xwsh/mi.hxwmd/cli/xwsh/mi.c |
Module integration API |
| Core | xwmd/cli/xwsh/core.hxwmd/cli/xwsh/core.c |
Command parsing and execution |
| Line Editing | xwmd/cli/xwsh/readline.hxwmd/cli/xwsh/readline.c |
CherryRL integration |
| Built-in Commands | xwmd/cli/xwsh/cmd.c |
Default command implementation |
Note: The XWSH module requires standard input/output (stdin/stdout), typically implemented via serial port or virtual console.
XWSH Core: Command parsing algorithm, thread model, error handling, and internal state management.
XWSH Command System: Built-in command details, external command adding methods, and duplicate name checking mechanism.
XWSH Extension Mechanism: CherryRL library integration details, callback function descriptions, and history implementation.
XWSH Integration Guide: Detailed comparison of both running modes, code examples, and best practices.
XWSH module API Reference: Detailed descriptions of all public and internal functions.