-
Notifications
You must be signed in to change notification settings - Fork 13
use restart, kill-timeout=0, return all group info #12
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
Open
bkerin
wants to merge
23
commits into
akinomyoga:master
Choose a base branch
from
bkerin:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
1c886bb
use restart, kill-timeout=0, return all group info
bkerin 4c4ef62
Move changes to -server2, restore original
bkerin 65d799e
Near emulation of vim-wordmotion
bkerin f12816d
use ble/util/print-lines
bkerin 8400007
Move perl server script to separate file
bkerin 1bbeac2
Typo fix
bkerin fa9cc54
Comment changes
bkerin 04bd939
Merge remote-tracking branch 'upstream/master'
bkerin 436a00d
Numerous small fixes
bkerin 6aa8152
Rename a widget. Model commit.
bkerin 577cd58
Rename .impl per upstream pattern. Model commit.
bkerin 4b0719a
Rename widgets
bkerin 88746a4
More rename. All my gone now
bkerin a2e5eb3
Merge remote-tracking branch 'upstream/master'
bkerin d731859
Improve delta detection diagnostic
bkerin f1988ec
Resolve inconsequential delta vs stock ble.sh func
bkerin 2c4271f
Fix error message
bkerin c9b064b
Added some comments
bkerin 15ee276
Merge remote-tracking branch 'upstream/master'
bkerin d53b850
Incorporate upsteam, improve delta dection
bkerin fe3da96
Remove left-over instrumentation
bkerin 1b5390d
Merge remote-tracking branch 'upstream/master'
bkerin 0dfc8cd
Merge branch 'master' of https://github.com/akinomyoga/blesh-contrib
bkerin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| # ble.sh contrib/config/github302-perlre-server2.bash | ||
| # Copyright 2023 Britton Kerin <https://lists.gnu.org/archive/html/help-bash/2023-03/msg00068.html> | ||
| # Copyright 2023 Koichi Murase <[email protected]> | ||
|
|
||
| # This module implements an interface to a perl regex server (a background | ||
| # process which waits to perform perform regex matches without the overhead | ||
| # of starting a perl interpreter each time). | ||
|
|
||
| ble-import util.bgproc | ||
|
|
||
| function ble/contrib/config:github302/perlre-server2 { | ||
| # We redirect 2>/dev/tty here to ensure errors show up | ||
| exec perl <(cat <<' END_PERL' | ||
| use strict; use warnings; use warnings FATAL => 'all'; use 5.10.0; | ||
| use Data::Dumper; | ||
akinomyoga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| STDOUT->autoflush(1); | ||
| STDERR->autoflush(1); | ||
| # ble.sh is eating STDERR at this point so to get feedback we do this: | ||
| $SIG{__WARN__} = sub { | ||
| print STDERR "in perlRegexServer bgproc: ".$_[0]; | ||
| }; | ||
| $SIG{__DIE__} = sub { | ||
| print STDERR "in perlRegexServer bgproc: ".$_[0]; exit 1; | ||
| }; | ||
| my $mlf = undef; # My Log File (leave undef to disable logging) | ||
| #open($mlf, ">>/tmp/mlf") or die; $mlf->autoflush(1); | ||
| while ( 1 ) { | ||
| chomp(my $rex = <>); # First line is regex | ||
| defined($rex) or exit; # undef might mean end of pipe. I think | ||
| defined($mlf) and print $mlf "from perl: \$rex: $rex\n"; | ||
| chomp(my $lc = <>); # Next line is number of lines in string to match | ||
| defined($lc) or exit; # undef might mean end of pipe. I think | ||
| defined($mlf) and print $mlf "from perl: \$lc: $lc\n"; | ||
| my $str = ''; # String to match | ||
| for ( my $ii = 0 ; $ii < $lc ; $ii++ ) { # Get Lines | ||
| my $nsl = <>; # New String Line | ||
| defined($nsl) or exit; # undef might mean end of pipe. I think | ||
| $str .= $nsl; | ||
| } | ||
| chomp($str); # Remove trailing "\n" of last line | ||
| defined($mlf) and print $mlf "from perl: \$str: $str\n"; | ||
| # Respond with blank line if the match fails, otherwise with a single | ||
| # line of the form: | ||
| # epm eps epl g1m g1s g1l g2m g2s g2l ... | ||
| # where epm/eps/epl are Entire Pattern Matched (1)/Start/Length and | ||
| # g1m/g1s/g1l are (capture) Group 1 Matched (0 or 1)/Start/Lengh, etc. | ||
| # (where Start/Length may be 'undef'). Note that epm is always 1 since | ||
| # we return an empty line if the match fails. | ||
| if ( $str =~ m/$rex/ ) { | ||
| join( | ||
| ' ', | ||
| map { | ||
| defined($+[$_]) | ||
| ? "1 $-[$_] ".($+[$_] - $-[$_]) | ||
| : '0 undef undef' | ||
| } | ||
| (0 .. $#+) ); | ||
| } | ||
| print "\n"; | ||
| } | ||
| END_PERL | ||
| ) 2>/dev/tty | ||
| } | ||
|
|
||
| # restart so user can easily try again if they send a bad regex. | ||
| # kill-timeout=0 because on some terminals ble.sh will end up exiting slowly | ||
| # if we wait before sending SIGTERM | ||
| if ble/util/bgproc#open perlre_server2 ble/contrib/config:github302/perlre-server2 restart:kill-timeout=0; then | ||
| # The main shell can send a request to fd ${perlre_server2_bgproc[1]} and can | ||
| # read from fd ${perlre_server2_bgproc[0]}. | ||
| ble/util/print "ble/contrib/config:github30: perlre-server2 (${perlre_server2_bgproc[4]}) has started." >&2 | ||
| else | ||
| ble/util/print 'ble/contrib/config:github30: failed to start perlre-server2' >&2 | ||
| return 1 | ||
| fi | ||
|
|
||
| ## @fn ble/contrib/config:github302/perlre-match2 rex str | ||
| ## | ||
| ## Matches the regex REX against the string STR | ||
| ## | ||
| ## @param[in] rex | ||
| ## The regex to match in "perlre" syntax. Must be exactly one line long. | ||
| ## @param[in] str | ||
| ## The string to be matched by REX. May be multiple lines. | ||
| ## @var[out] ret | ||
| ## A blank line if the match failed, otherwise a single line of the form: | ||
| ## epm eps eml g1m g1s g1l g2m g2s g2l ... | ||
| ## where epm/eps/epl are Entire Pattern Matched (1)/Start/Length and | ||
| ## g1m/g1s/g1l are (capture) Group 1 Matched (0 or 1)/Start/Lengh, etc. | ||
| ## (where Start/Length may be 'undef'). Note that epm is always 1 here | ||
| ## since we return an empty line if the match fails. | ||
| ## @exit 0 if REX successfully matches STR, or otherwise 1. | ||
| ## | ||
| function ble/contrib/config:github302/perlre-match2 { | ||
|
|
||
| # FIXXME: could use #post instead of #use followed by echo but I'm too lazy | ||
| # and scared to figure how to get all the lines through correctly right now | ||
|
|
||
| ble/util/bgproc#use perlre_server2 | ||
|
|
||
| { \ | ||
| echo "$1" \ | ||
| && \ | ||
| local tmp="${2//[!$'\n']/}" \ | ||
| && \ | ||
| echo $((${#tmp} + 1)) \ | ||
| && \ | ||
| echo "$2"; \ | ||
| } \ | ||
| >&"${perlre_server2_bgproc[1]}"; | ||
bkerin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # We can read the resposnes from fd ${perlre_server2_bgproc[0]}. We set a | ||
| # timeout to `read' so that it doesn't lock forever in case that the expected | ||
| # output is not obtained by accident. | ||
| ble/bash/read-timeout 1 -r -u "${perlre_server2_bgproc[0]}" ret | ||
|
|
||
| [[ $ret ]] | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.