|
Joined: Nov 2006
Posts: 1,559
Hoopy frood
|
OP
Hoopy frood
Joined: Nov 2006
Posts: 1,559 |
Hi, I tried some hours here and there to find a working way to "highlight" the matching parts of a %wildcard.mask in a $fulladdress (nick!ident@host.domain) I sampled (and failed) cycling the parts nick ident host with $mid $len $pos and the like... $regsub seems to be the most promising approach. I managed (trial and error, to be honest) simple replaces like: //var %test | noop $regsub(teststring,/s.+in/gi,8s*in,%test) | echo -a %test or //var %text = some!test@string | echo -a $regsubex(%text,/(ome.*!.*st)/gi,$+($chr(3),07\t,$chr(15))) ... but in fact, I am quite green with $regsub, therefore I need some skilled help The goal is to visualize the matching parts of a "full" %wildcard.mask (not an shortened *@host.domain or the like, maybe thats important for error handling) in some $fulladdress in two ways: 1) highlight matching "text" in some colour 12) highlight "text met by wildcards" in some other colour 2e.g.: to make the parts of "nic*!user@*.doma*n" in "nick!user@host.domain" become: " nick! user@ host.domain" Some problems I anticipate are: a) [can be resolved by a simple $replace in the beginning, but maybe this gotta be done in the $regsub somewhere, too] Escape possible metachars [ ] { } ^ | \ . * (which may be part of addresses and banmasks) with \[ \] \{ \} \^ \| \\ \. .* b) Stop regex comparison at ! and @ - as wildcards in masks like banmasks stop there, too c) If a part of the $fulladdress is already "met" (coloured) by a wilcard, but met exactly by more parts of the %wildcard.mask, the exact match shall have priority. e.g.: A highlighting of "A-test-nick!apple@pie" compared to "*t*!tomato@*" shall higlight as: A-test-nick!apple@ pie and not as: A-test-nick!apple@ pie Thoughts: I played with separating the $fulladdress and %wildcard.mask into its components (nick-user-host) to avoid b) There is also no need to make the $regsub as neat or short as possible, working code is what really counts Thx a lot in advance!
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
Here's a relatively simple alias that (hopefully) satisfies all your conditions except (c): alias wildcolor {
var %2 = $2, %c1 = 03, %c2 = 04
tokenize 64 $1
var %host = $2, %nick = $gettok($1,1,33), %user = $gettok($1,2,33)
tokenize 64 $replace(%2,\,\\,^,\^,$,\$,.,\.,[,\[,|,\|,+,\+,$chr(123),\ $+ $chr(123),?,(.),*,(.*?))
var %a = $regex(a,%host,$+(/^,$2,$!/i)), $&
%b = $regex(b,%nick,$+(/^,$gettok($1,1,33),$!/i)), $&
%c = $regex(c,%user,$+(/^,$gettok($1,2,33),$!/i))
tokenize 64 %2
if (%a) %host = $+(,%c2,$regsubex($2,/[*?]/g,$+(,%c1,$regml(a,\n),,%c2)),)
if (%b) %nick = $+(,%c2,$regsubex($gettok($1,1,33),/[*?]/g,$+(,%c1,$regml(b,\n),,%c2)),)
if (%c) %user = $+(,%c2,$regsubex($gettok($1,2,33),/[*?]/g,$+(,%c1,$regml(c,\n),,%c2)),)
return $replace($+(%nick,!,%user,@,%host),$+(,%c1,),,$+(,%c2,),)
} Usage is $wildcolor(full address, wildcard mask). You can change %c1 and %c2 at the top with whatever colour codes you want (just make sure they are zeropadded). Regarding (c), I'm not sure I get the logic or the exact way it's intended to work, but it looks like it can't be easily incorporated to this alias. If you explain it a little more, I (or others) may be able to help.
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
Joined: Nov 2006
Posts: 1,559
Hoopy frood
|
OP
Hoopy frood
Joined: Nov 2006
Posts: 1,559 |
First off, I have to say: whow... and thanks, qwerty! c) was intended as - how to put it - "greedy highlighting"... eg.: "*oo*" will match "yooyoo" two times, > mark both occurances of "oo" "test" will match "test-the-test" 2 times... "te?t" will match "test-tea-test" 2 times, too... but "te*t" matches "test-tea-test" a LOT more ... ... well, now I start to realize that this might get quite complicated - Most likely, the effort needed will not warrant the result. The output could even look confusing ....Thinking it over again, I hold that maybe it's a good idea to discard that c) -idea. And, in fact, the code you provided does the job perfectly: Highlighting if, and where parts of a fullmask are matched by a wildcard mask. Highlight ALL possible matches is of doubtful usage for my purpose. (I wonder how this could be done, nevertheless) Thanks.
|
|
|
|
Joined: Apr 2006
Posts: 464
Fjord artisan
|
Fjord artisan
Joined: Apr 2006
Posts: 464 |
Here's a relatively simple alias... Yeah right!
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
OK I get (c) now, however I'm afraid it can't be incorporated to the existing code. To implement (c) you'd probably have to script a wildcard matching routine from scratch. It would have to be exhaustive, trying all substrings that can be matched by each * char (a recursive approach would be most natural here). You can find examples of recursive wildcard matching algorithms on the net to get an idea, but I wouldn't bother if I were you. Scripting that would be neither simple nor fast.
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
Joined: Nov 2006
Posts: 1,559
Hoopy frood
|
OP
Hoopy frood
Joined: Nov 2006
Posts: 1,559 |
Hum, think I'll keep my hands off that I learned a lot meditating about your code, albeit I'd hardly be able to do it in such a way. Thx again.
|
|
|
|
|