-
Couldn't load subscription status.
- Fork 54
refactoring some scripts #1
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mknos
added a commit
to mknos/PerlPowerTools
that referenced
this pull request
Apr 13, 2023
* Standard ed treats the address 0 as valid for both "a" and "i" commands [1] * The meaning of address 0 is, add text at start of buffer * When starting ed with no file argument, buffer is empty and current address is 0 * This version of ed accepts "0a" (or just "a") on empty buffer * "0i" command results in error: Can't insert before line 0 * When the buffer is not empty, GNU ed treats 0i the same as 1i * shift(@lines) in edInsert() is safe if the list is empty, so this patch treats address 0 and 1 the same for $INSERT_MODE (aka "i") briandfoy#1 https://www.gnu.org/software/ed/manual/ed_manual.html#Commands Existing output for "a": $ perl ed # a == 0a ME: a ME: hey ME: . ME: 1 ED: hey ME: Q New output for "i": $ perl ed # i == 0i ME: i ME: yo ME: . ME: 1 ED: yo ME: Q
mknos
added a commit
to mknos/PerlPowerTools
that referenced
this pull request
May 5, 2023
* When viewing text in less(1) and editing with vi(1) I usually enable line numbers * Standard ed supports the n command [1], which prints a tab after a line number prefix * Implement the n command by adding a parameter to edPrint() * Note: "l" is still not implemented but could be a future change to edPrint() briandfoy#1 https://pubs.opengroup.org/onlinepubs/009604599/utilities/ed.html
mknos
added a commit
to mknos/PerlPowerTools
that referenced
this pull request
Apr 17, 2024
* When temporarily enabling warnings in bc I observe warnings for incorrect use of "next" * Function yy_err_recover() jumped to a label outside of itself, within yyparse() * yyparse() was strucured so that it first initialises flags then enters main loop * Jumping back to yyparse() was unsafe because the flags would all be cleared again, including $yyssp (yy_err_recover() already adjusts $yyssp) * Clear flags before calling yyparse(), and let yyparse() enter the loop immediately so that it's safe to call it from yy_err_recover() %perl bc # before patch 4++ line 1: syntax error Exiting subroutine via next at bc line 1387, <STDIN> line 1 (briandfoy#1)
briandfoy
pushed a commit
that referenced
this pull request
Apr 17, 2024
* When temporarily enabling warnings in bc I observe warnings for incorrect use of "next" * Function yy_err_recover() jumped to a label outside of itself, within yyparse() * yyparse() was strucured so that it first initialises flags then enters main loop * Jumping back to yyparse() was unsafe because the flags would all be cleared again, including $yyssp (yy_err_recover() already adjusts $yyssp) * Clear flags before calling yyparse(), and let yyparse() enter the loop immediately so that it's safe to call it from yy_err_recover() %perl bc # before patch 4++ line 1: syntax error Exiting subroutine via next at bc line 1387, <STDIN> line 1 (#1)
mknos
added a commit
to mknos/PerlPowerTools
that referenced
this pull request
Aug 7, 2024
* patch failed with a strictness error when I specified a file * Patch::apply() calls back into Patch::Context::apply() on L714 with the wrong params * When setting a breakpoint in Patch::apply(), its params are not identical to Patch::Context::apply(), so passing @_ as parameter fails * Reading the code, this would only be a problem for applying context diffs (no callback to self->apply() happened for the other diff types) * I confirmed that this error was not caused by the recent use-base.diff (now I suspect it goes back to 1999) * Removing the code with the incorrect self->apply() call causes patch to correctly report that applying Hunk briandfoy#1 failed, then the program exits with status 1 to indicate that >=1 lines could not be applied
briandfoy
pushed a commit
that referenced
this pull request
Aug 7, 2024
* patch failed with a strictness error when I specified a file * Patch::apply() calls back into Patch::Context::apply() on L714 with the wrong params * When setting a breakpoint in Patch::apply(), its params are not identical to Patch::Context::apply(), so passing @_ as parameter fails * Reading the code, this would only be a problem for applying context diffs (no callback to self->apply() happened for the other diff types) * I confirmed that this error was not caused by the recent use-base.diff (now I suspect it goes back to 1999) * Removing the code with the incorrect self->apply() call causes patch to correctly report that applying Hunk #1 failed, then the program exits with status 1 to indicate that >=1 lines could not be applied
mknos
added a commit
to mknos/PerlPowerTools
that referenced
this pull request
Aug 12, 2024
* Remove note about GNU patch requiring a space between -D and argument (this might've been the case for ancient versions but not anymore) * This version of patch outputs a trailing comment for the ifndef blocks; this matches the OpenBSD version %ifconfig > A %sed 's/eth0/ent0/' A > B %perl diff -u A B > AB.diff %/usr/bin/patch --version GNU patch 2.7.6 %/usr/bin/patch -Dostuff -o C A AB.diff patching file C (read from A) %perl patch -Dostuff -o D A AB.diff Hmm... Looks like a unified diff to me... Patching file A using Plan B... Hunk briandfoy#1 succeeded at 1. done %perl diff C D 5c5 < #endif --- > #endif /* ostuff */
briandfoy
pushed a commit
that referenced
this pull request
Aug 12, 2024
* Remove note about GNU patch requiring a space between -D and argument (this might've been the case for ancient versions but not anymore) * This version of patch outputs a trailing comment for the ifndef blocks; this matches the OpenBSD version %ifconfig > A %sed 's/eth0/ent0/' A > B %perl diff -u A B > AB.diff %/usr/bin/patch --version GNU patch 2.7.6 %/usr/bin/patch -Dostuff -o C A AB.diff patching file C (read from A) %perl patch -Dostuff -o D A AB.diff Hmm... Looks like a unified diff to me... Patching file A using Plan B... Hunk #1 succeeded at 1. done %perl diff C D 5c5 < #endif --- > #endif /* ostuff */
mknos
added a commit
to mknos/PerlPowerTools
that referenced
this pull request
Feb 25, 2025
* When processing an "a" (append text) command in an ed-style diff, line number ranges are not parsed correctly
* If a range (e.g. "1,2") is given as a prefix to "a", the 2nd address ("2") is used as the target address
* Regular diff tools don't output "a" commands with 2 addresses
* ed-style diffs can be pasted from a previous ed editor session or typed manually, so having extra validation here is helpful
* To test this, I bypassed the code for running an external ed program
* I modified a diff generated by "diff -e", changing the "322a" command to "1,322a"... the file is patched successfully
%cat bad.diffe
1,322a
my $Maxlen = 1; # longest string for current directory
.
317,318d
113d
%perl patch -e ls bad.diffe
Hmm... Looks like an ed diff to me...
Patching file ls using Plan A...
Hunk briandfoy#1 succeeded at 113
Hunk briandfoy#2 succeeded at 317
Hunk briandfoy#3 succeeded at 322
done
%cmp ls ls2
briandfoy
pushed a commit
that referenced
this pull request
Feb 25, 2025
* When processing an "a" (append text) command in an ed-style diff, line number ranges are not parsed correctly
* If a range (e.g. "1,2") is given as a prefix to "a", the 2nd address ("2") is used as the target address
* Regular diff tools don't output "a" commands with 2 addresses
* ed-style diffs can be pasted from a previous ed editor session or typed manually, so having extra validation here is helpful
* To test this, I bypassed the code for running an external ed program
* I modified a diff generated by "diff -e", changing the "322a" command to "1,322a"... the file is patched successfully
%cat bad.diffe
1,322a
my $Maxlen = 1; # longest string for current directory
.
317,318d
113d
%perl patch -e ls bad.diffe
Hmm... Looks like an ed diff to me...
Patching file ls using Plan A...
Hunk #1 succeeded at 113
Hunk #2 succeeded at 317
Hunk #3 succeeded at 322
done
%cmp ls ls2
mknos
added a commit
to mknos/PerlPowerTools
that referenced
this pull request
Mar 5, 2025
* I generated a Context diff with 2 hunks * I manually swapped the 2 numbers at the top of hunk1, from "1,4" to "4,1" (the line number range for the hunk) * GNU patch correctly rejected this invalid diff, but this version crashed with an ARRAY error * Add validation for backwards range, based on code previously added for Normal diffs %cat diff.ctx *** id Wed Mar 5 09:16:33 2025 --- id2 Wed Mar 5 09:14:36 2025 *************** *** 4,1 **** - #!/usr/bin/perl =begin metadata --- 1,3 ---- *************** *** 12,24 **** =cut - # - # An implementation of the 'id' utility in Perl. Written for the Perl Power - # Tools (PPT) project by Theo Van Dinter (felicity@kluge.net). - # - # $Id: id,v 1.2 2004/08/05 14:17:43 cwest Exp $ - # - use strict; use File::Basename qw(basename); --- 11,16 ---- %perl -Mwarnings -Mdiagnostics patch -c id diff.ctx Hmm... Looks like a context diff to me... Patching file id using Plan A... Short hunk ignored...no second line range. 1 out of 1 hunks ignored--saving rejects to id.rej Can't use an undefined value as an ARRAY reference at patch line 382, <$in_fh> line 249 (briandfoy#1) (F) A value used as either a hard reference or a symbolic reference must be a defined value. This helps to delurk some insidious errors. Uncaught exception from user code: Can't use an undefined value as an ARRAY reference at patch line 382, <$in_fh> line 249. Patch::bless(Patch::Context=HASH(0x55908a4f50)) called at patch line 161
briandfoy
pushed a commit
that referenced
this pull request
Mar 5, 2025
* I generated a Context diff with 2 hunks * I manually swapped the 2 numbers at the top of hunk1, from "1,4" to "4,1" (the line number range for the hunk) * GNU patch correctly rejected this invalid diff, but this version crashed with an ARRAY error * Add validation for backwards range, based on code previously added for Normal diffs %cat diff.ctx *** id Wed Mar 5 09:16:33 2025 --- id2 Wed Mar 5 09:14:36 2025 *************** *** 4,1 **** - #!/usr/bin/perl =begin metadata --- 1,3 ---- *************** *** 12,24 **** =cut - # - # An implementation of the 'id' utility in Perl. Written for the Perl Power - # Tools (PPT) project by Theo Van Dinter (felicity@kluge.net). - # - # $Id: id,v 1.2 2004/08/05 14:17:43 cwest Exp $ - # - use strict; use File::Basename qw(basename); --- 11,16 ---- %perl -Mwarnings -Mdiagnostics patch -c id diff.ctx Hmm... Looks like a context diff to me... Patching file id using Plan A... Short hunk ignored...no second line range. 1 out of 1 hunks ignored--saving rejects to id.rej Can't use an undefined value as an ARRAY reference at patch line 382, <$in_fh> line 249 (#1) (F) A value used as either a hard reference or a symbolic reference must be a defined value. This helps to delurk some insidious errors. Uncaught exception from user code: Can't use an undefined value as an ARRAY reference at patch line 382, <$in_fh> line 249. Patch::bless(Patch::Context=HASH(0x55908a4f50)) called at patch line 161
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Program: morse
The morse program
Program: ping
The ping program
Status: released
there is a new release with this fix
Type: modernization
updating programs to current practices
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.