Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/uu/sed/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ pub fn compile(
}
patch_block_endings(result.clone());

// TODO: setup append & match structures
Ok(result)
}

Expand Down Expand Up @@ -229,8 +228,25 @@ fn compile_sequence(

loop {
line.eat_spaces();

// According to POSIX: "If the first two characters in the script are
// "#n", the default output shall be suppressed".
if !line.eol()
&& line.current() == '#'
&& lines.get_line_number() == 1
&& line.get_pos() == 0
{
line.advance();
if !line.eol() && line.current() == 'n' {
context.quiet = true;
}
// Ignore rest of line
while !line.eol() {
line.advance();
}
}

if line.eol() || line.current() == '#' {
// TODO: set context.quiet for StringVal starting with #n
match lines.next_line()? {
None => {
return Ok(head);
Expand Down
6 changes: 6 additions & 0 deletions tests/by-util/test_sed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ const LINES1: &str = "input/lines1";
const LINES2: &str = "input/lines2";
const NO_NEW_LINE: &str = "input/no-new-line.txt";

////////////////////////////////////////////////////////////
// Comments
check_output!(comment, ["-n", "-e", "4p;# comment", LINES1]);
check_output!(comment_silent, ["-e", "#n", "-e", "4p", LINES1]);
check_output!(comment_no_silent, ["-e", "4p;#n comment", LINES1]);

////////////////////////////////////////////////////////////
// Address ranges: One and two, numeric and pattern
check_output!(addr_one_line, ["-n", "-e", "4p", LINES1]);
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/sed/output/comment
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
l1_4
15 changes: 15 additions & 0 deletions tests/fixtures/sed/output/comment_no_silent
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
l1_1
l1_2
l1_3
l1_4
l1_4
l1_5
l1_6
l1_7
l1_8
l1_9
l1_10
l1_11
l1_12
l1_13
l1_14
1 change: 1 addition & 0 deletions tests/fixtures/sed/output/comment_silent
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
l1_4
Loading