-
Notifications
You must be signed in to change notification settings - Fork 34
sed: start a range whose numeric first address was already passed #581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,7 +124,15 @@ fn applies( | |
| } | ||
| } else if let Some(addr1) = &command.addr1 { | ||
| // See if latch must start. | ||
| if match_address(addr1, reader, pattern, context, &command.location)? { | ||
| let starts = match addr1 { | ||
| // Numeric start already passed (block, d, n, branch): start once here. | ||
| Address::Line(n) if linenum > *n => { | ||
| !command.range_started && !matches!(addr2, Address::Line(m) if *m < linenum) | ||
| } | ||
| _ => match_address(addr1, reader, pattern, context, &command.location)?, | ||
| }; | ||
| if starts { | ||
| command.range_started = true; | ||
| match addr2 { | ||
| Address::Line(n) if linenum >= *n => { | ||
| context.last_address = true; | ||
|
|
@@ -961,13 +969,10 @@ fn reset_latched_address_ranges(range_commands: &mut [Rc<RefCell<Command>>]) { | |
| for cmd_rc in range_commands.iter() { | ||
| let mut cmd = cmd_rc.borrow_mut(); | ||
|
|
||
| cmd.start_line = | ||
| // Check for address-spec line 0 pre-latch extension. | ||
| if let Some(addr1) = &cmd.addr1 && matches!(addr1, Address::Line(0)) { | ||
| Some(0) | ||
| } else { | ||
| None | ||
| }; | ||
| // Check for address-spec line 0 pre-latch extension. | ||
| let pre_latched = matches!(cmd.addr1, Some(Address::Line(0))); | ||
| cmd.start_line = if pre_latched { Some(0) } else { None }; | ||
| cmd.range_started = pre_latched; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add a test where this reset matters, e.g. with -s and two files, so
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added the test it runs the same range on two files with -s and checks that both files print lines 3 and 4, the same as GNU sed |
||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
start_line+range_startedcould be a small enum (inactive / active(start) / closed), no?not blocking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be happy to change it now if you prefer