uutils/sed

Add `T` command (branch on no-substitution)

Open

#395 创建于 2026年4月30日

在 GitHub 查看
 (0 评论) (0 反应) (0 负责人)Rust (23 fork)github user discovery
enhancementgood first issue

仓库指标

Star
 (91 star)
PR 合并指标
 (PR 指标待抓取)

描述

Bug

The GNU T command — branch to label if no s/// substitution has been performed since the last input line was read — is not implemented. It is the inverse of t.

Reproduction

$ echo a | /usr/bin/sed -n 'Tend; p; :end'
a

$ echo a | ./target/release/sed -n 'Tend; p; :end'
sed: <script argument 1>:1:1: error: invalid command code `T'

What it should do

From the GNU manual:

T LABEL If no s/// has done a successful substitution since the last input line was read or branch was taken, branch to LABEL.

Same address/parsing rules as t. Already-implemented t lives in compile_label_command (compiler.rs:1308); T should be parsed by the same handler.

Suspected place to add it

src/sed/compiler.rs:1276get_cmd_spec:

'b' | 't' | 'T' => Ok(CommandSpec {
    n_addr: 2,
    handler: compile_label_command,
}),

…then in the execution side (look near the t handler in processor.rs), branch when the substitution flag is false instead of true, and clear it the same way t does.

Affected GNU testsuite tests

Indirect — the broader compile-tests/compile-errors suites assert that T is rejected under --posix and accepted otherwise.

贡献者指南