Skip to content
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

ed: simplify edInsert() #550

Merged
merged 1 commit into from
Apr 12, 2024
Merged

ed: simplify edInsert() #550

merged 1 commit into from
Apr 12, 2024

Conversation

mknos
Copy link
Contributor

@mknos mknos commented Apr 12, 2024

  • Rewrite edInsert() without @tmplines2 and $tmp_chars
  • Use splice() to add @tmp_lines into @lines directly
  • Use scalar(@tmp_lines) instead of $tmp_chars to indicate whether @lines needs to be updated (early return added)
  • Input address normally counts from 1 so handles the placeholder at $lines[0]
  • Input address 0 is allowed for 'a' and 'i' commands, so be careful not to move $lines[0] placeholder
  • In edEdit() be more careful to reset @lines if no file is being read; the array needs to have one element
  • test1: start ed on empty buffer and run '0i' or '0a', enter text terminated with '.' line
  • test2: start ed with text file with 9 lines and run '9a'; text is appended starting from line 10
  • test3: apply an ed patch containing 'a' commands (below)
%perl diff -e ed.new ed > patch.ed
%echo w >> patch.ed 
%perl ed ed.new < patch.ed 
30368
29383
%perl sum -a md5 ed ed.new 
e5748aef0ba835feb1daba4a99778b9c  ed
e5748aef0ba835feb1daba4a99778b9c  ed.new

* Rewrite edInsert() without @tmplines2 and $tmp_chars
* Use splice() to add @tmp_lines into @lines directly
* Use scalar(@tmp_lines) instead of $tmp_chars to indicate whether @lines needs to be updated (early return added)
* Input address normally counts from 1 so handles the placeholder at $lines[0]
* Input address 0 is allowed for 'a' and 'i' commands, so be careful not to move $lines[0] placeholder
* In edEdit() be more careful to reset @lines if no file is being read; the array needs to have one element
* test1: start ed on empty buffer and run '0i' or '0a', enter text terminated with '.' line
* test2: start ed with text file with 9 lines and run '9a'; text is appended starting from line 10
* test3: apply an ed patch containing 'a' commands (below)

%perl diff -e ed.new ed > patch.ed
%echo w >> patch.ed 
%perl ed ed.new < patch.ed 
30368
29383
%perl sum -a md5 ed ed.new 
e5748aef0ba835feb1daba4a99778b9c  ed
e5748aef0ba835feb1daba4a99778b9c  ed.new
@github-actions github-actions bot added Type: enhancement improve a feature that already exists Priority: low get to this whenever Program: ed The ed program labels Apr 12, 2024
@briandfoy briandfoy self-assigned this Apr 12, 2024
@briandfoy briandfoy merged commit 8c09f7e into briandfoy:master Apr 12, 2024
1 of 2 checks passed
@briandfoy briandfoy added Status: accepted The fix is accepted and removed Priority: low get to this whenever labels Apr 12, 2024
@briandfoy briandfoy added Status: released there is a new release with this fix and removed Status: accepted The fix is accepted labels Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Program: ed The ed program Status: released there is a new release with this fix Type: enhancement improve a feature that already exists
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants