Skip to content

Add T command (branch on no-substitution) #395

@sylvestre

Description

@sylvestre

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions