Skip to content

Commit 4ab1f40

Browse files
feat: simpliest shell support
1 parent f980b3a commit 4ab1f40

1 file changed

Lines changed: 16 additions & 17 deletions

File tree

Roadmap.md

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ CFBox 是一个 C++23 BusyBox 替代品,当前版本有 33 个 applet。项目
1515
| 阶段 | 主题 | 新增 Applet | 核心基础设施 | 累计 |
1616
|------|------|------------|-------------|------|
1717
| 0 | 构建系统现代化 ✅ | 0 | CMake 配置、help 系统、UTF-8、彩色输出 | 17 |
18-
| 1 | POSIX Shell + Coreutils I 🔨 | ~17 | Shell 引擎、进程管理、信号处理 | ~34 |
18+
| 1 | POSIX Shell + Coreutils I | ~17 | Shell 引擎、进程管理、信号处理 | ~34 |
1919
| 2 | Coreutils II + findutils | ~41 | 流处理管线、校验和框架 | ~75 |
2020
| 3 | 编辑器 + 归档 + 压缩 | ~15 | 终端抽象、压缩框架 | ~90 |
2121
| 4 | 进程/Init + util-linux | ~38 | /proc 解析器、TUI 框架 | ~128 |
@@ -48,7 +48,7 @@ CFBox 是一个 C++23 BusyBox 替代品,当前版本有 33 个 applet。项目
4848

4949
---
5050

51-
## Phase 1:POSIX Shell + Coreutils 第一批 🔨
51+
## Phase 1:POSIX Shell + Coreutils 第一批
5252

5353
**目标**:实现交互式 POSIX Shell——这是在真实 Linux 上使用的基础。同时实现简单的 coreutils 建立势头。
5454

@@ -58,24 +58,23 @@ CFBox 是一个 C++23 BusyBox 替代品,当前版本有 33 个 applet。项目
5858

5959
`basename` ✅, `dirname` ✅, `true` ✅, `false` ✅, `yes` ✅, `sleep` ✅, `pwd` ✅, `tty` ✅, `uname` ✅, `whoami` ✅, `hostname` ✅, `id` ✅, `logname` ✅, `nproc` ✅, `test` ✅, `link`
6060

61-
### Shell 架构(`src/applets/sh/`
61+
### POSIX Shell
6262

63-
Shell 是最复杂的单一组件,按模块拆分
63+
Shell 已实现为第一个多文件 applet(`src/applets/sh/`,8 个模块,~2400 行)
6464

65-
| 模块 | 文件 | 功能 |
65+
| 模块 | 文件 | 状态 |
6666
|------|------|------|
67-
| 词法分析 | `sh_lexer.cpp` | 分词、引号处理、here-document |
68-
| 语法解析 | `sh_parser.cpp` | AST 构建:管道、列表、复合命令、函数定义 |
69-
| 执行器 | `sh_executor.cpp` | AST 遍历执行,fork/exec,管道/重定向设置 |
70-
| 内建命令 | `sh_builtins.cpp` | cd, export, exit, test, read, trap, umask, eval, source 等 |
71-
| 行编辑 | `sh_lineedit.cpp` | 原生实现(不依赖 readline):行编辑、历史记录、Tab 补全 |
72-
| 作业控制 | `sh_jobs.cpp` | 进程组、会话管理、jobs/fg/bg、Ctrl+Z |
73-
| 变量系统 | `sh_vars.cpp` | 环境变量、Shell 变量、特殊参数、位置参数 |
74-
| 词展开 | `sh_expand.cpp` | 波浪号、参数展开、命令替换、算术展开、文件名展开 |
75-
76-
### 需要的基础设施
77-
- **进程管理** `include/cfbox/process.hpp`:fork/exec/pipe/dup2/waitpid RAII 封装
78-
- **信号处理** `include/cfbox/signal.hpp`:RAII 信号处理器
67+
| 共享类型 | `sh.hpp` | ✅ AST 节点、Token、ShellState |
68+
| 词法分析 | `sh_lexer.cpp` | ✅ 分词、引号、$展开、运算符 |
69+
| 语法解析 | `sh_parser.cpp` | ✅ 递归下降:管道、列表、if/while/for、子shell、花括号组 |
70+
| 执行器 | `sh_executor.cpp` | ✅ fork/exec/pipe、重定向 < > >>、内置命令 |
71+
| 内建命令 | `sh_builtins.cpp` | ✅ echo/cd/pwd/export/exit/set/unset/shift/read/eval/source |
72+
| 词展开 | `sh_expand.cpp` | ✅ $VAR、${VAR}、$?、$$、$#/$@/$*、命令替换、波浪号、glob |
73+
| 变量系统 | `sh_vars.cpp` | ✅ 变量存储、环境同步、位置参数、特殊参数 |
74+
75+
**已实现功能**:管道 `|`、重定向 `< > >>``&&` `||``if/elif/else/fi``while/until/do/done``for/in/do/done`、子shell `()`、花括号组 `{}`、变量赋值、变量展开、命令替换 `$(...)`、tilde 展开、glob 展开、15 个内置命令。
76+
77+
**待后续迭代**:here-document `<<`、函数定义、算术展开 `$(( ))`、行编辑(readline 风格)、作业控制(jobs/fg/bg)、`case/esac`
7978

8079
### 验证
8180
- `./cfbox sh -c "echo hello | wc -l"` 管道工作

0 commit comments

Comments
 (0)