|
Joined: Jan 2004
Posts: 162
Vogon poet
|
OP
Vogon poet
Joined: Jan 2004
Posts: 162 |
Dunno if this a realistic suggestion, but I have a list to filter that consists of token strings and I like to have these characters in them, and be able to search them without chance of filtering wrong lines due to seen as wildcard symbol.
Example: /filter -wwcm*? @bla @temp & & hello? & & that should filter out a line: "yes yo hello? you there" and not match a line: "yes yo hello! you there"
So it should see the given matchstring character-also wildcard symbols after -m as literal. It could be possible with some regex stuff, but I cant really expect users that wanna search the list to have knowledge of them eh?
|
|
|
|
Joined: Oct 2006
Posts: 166
Vogon poet
|
Vogon poet
Joined: Oct 2006
Posts: 166 |
You can use the g flag " regular expression" just backslash your wildmatches and it will work. I've been trying to escape wildmatches in /filter but couldn't.
//window @@ | aline @@ yes yo hello? you there | aline @@ yes yo hello! you there | filter -cwwg @@ @@ \S+ \S+ hello\? \S+ \S+
Kind Regards, blink
|
|
|
|
Joined: Oct 2006
Posts: 166
Vogon poet
|
Vogon poet
Joined: Oct 2006
Posts: 166 |
You can use this custom alias for a while:
alias mfilter {
var %a = $1,%b = $+(/,$chr(40),[,$remove(*?&,$3),],$chr(41),/g),%c = $2
%c = $regsubex(%c,%b,$replace(\1,&,\S+,*,.*,?,.))
%c = $regsubex(%c,$+(/,$chr(40),[,$3,],$chr(41),/g),\\1)
tokenize 32 %a
!filter $+(-,$iif($prop = c,c),$iif($left($1,1) = @,w,f),$iif($left($2,1) = @,w,f),g) $1 $2 %c
}
$mfilter(input output,matchtext,wildmatches)[.c]Example: //noop $mfilter(@@ @@,& & hello? & &,?).c This will filter yes yo hello? you thereuse the .c property to clear the output.
Kind Regards, blink
|
|
|
|
Joined: Oct 2006
Posts: 166
Vogon poet
|
Vogon poet
Joined: Oct 2006
Posts: 166 |
Use the below code. (I made some improvements before releasing)
alias mfilter {
if (!$4) { echo 2 -a * $!mfilter: insufficient parameters | return }
var %a = $3
%a = $regsubex(%a,/([ $+ $4])/g,\\1)
%a = $regsubex(%a,$remove(/([*?&])/g, [ $regsubex($4,/(.)(?!$)/g,\1$chr(44)) ] ),$replace(\1,&,\S+,*,.*,?,.))
!filter $+(-,$iif($prop = c,c),$iif($left($1,1) = @,w,f),$iif($left($2,1) = @,w,f),g) $1 $2 %a
}
$mfilter(input,output,matchtext,wildcards)[.c]
Last edited by b1ink; 29/12/06 03:48 PM.
Kind Regards, blink
|
|
|
|
Joined: Jan 2004
Posts: 162
Vogon poet
|
OP
Vogon poet
Joined: Jan 2004
Posts: 162 |
Actually, what I described was not enough. For the token string lists I use, it should be token-specific. For example, one list (a queue) has a format: ; $1 = id $2 = status $3 = network $4 = irc command $5 = mirc switches or <none> $6 = irc parameter or <none> $7 = irc command flag(s) or <none> $8 = system ; $9 = system related data $10 = passthrough system or <none> $11 = passthrough system related data or <none> $12 = priority 00 (first) - 99 (last) $13 = $ctime
..using 215 as token separator. Now, suppose it sends a /silence +*!*@* to server, server may reply with the named raw SILENCE, in that event, I use condition if (!$SC_IRCQueue_Check(SRV,SILENCE,$1,<none>)). Alias SC_IRCQueue_Check puts 'SILENCE' and the value of $1 on the correct positions, resulting in a matchtext token-string of 13 tokens (the total amount tokens in a line of the @window), of which some are * (any string on that token position) and 3 literal (network, SILENCE and content of $1, being the silence mask). This means I need to be able to specify which token positions should be treated as literal and which should handle wildcard symbols as wildcards. This all could be done in a line per line loop, where every line is tokenized, and some tokens are compared with == and some with iswm (or maybe == *). The problem though is, it becomes alot slower than /filter since alot more is done through the script engine instead of machine-closer executable language. Your regex using alias is a black box to me since I dont know regex. So first question is, can that alias be written so that it accepts a per-token flag wildcard symbols to be taken literal or not? And second question is of course native support by /filter for this. I think /filter is the most powerful of all mIRC commands, it already has alot switches, so the correct parsing of them may already be a demanding task. It already knows tokens, the -t <position> <ascii token separator> provides sorting. A quick not so thought-through proposal could be similar to /window -t[N,...,N], for example /filter -T2,3,7 32 would treat the tokens on positions 2,3 and 7 as literal, using a space (32) as token separator (uppercase T to distinguish from the existing -t). Of course, this is all quite some work, and my proposal could be too personal to take it into account. My situation is a big script, so every bit performance gain gives extra 'room' to provide more without mIRC hanging too often in the trees. Though, mr. Author of mIRC reacted on a performance issue I had with /filter so this could already have eliminated the step to open the code editor with focus on the /filter code.
|
|
|
|
Joined: Jan 2004
Posts: 162
Vogon poet
|
OP
Vogon poet
Joined: Jan 2004
Posts: 162 |
A scripted version for /filter looping through all lines:
; Input: $1 = name of input window $2 = ascii token separator used in input window
; $3 = <LlWw><position1>,<LlWw><position2>,etc $4- = token matchstring
; L (literal case sensitive) l (literal case insensitive) W (wildcard case sensitive) w (wildcard case insensitive)
; Output: $result = $null or name of results temp window with line format <original line position> <record>
alias SC_filterwin {
var %w = $1, %a = $2, %list = $3, %wm = $4-
var %total1 = $line(%w,0), %total2 = $numtok(%list,44), %i1 = 1, %wr = $SC_rw
while (%i1 <= %total1) {
var %rec = $line(%w,%i1), %i2 = 1
while (%i2 <= %total2) {
var %tok = $gettok(%list,%i2,44), %pos = $mid(%tok,2), %s1 = $gettok(%wm,%pos,%a), %s2 = $gettok(%rec,%pos,%a)
goto $+(M,$asc($left(%tok,1)))
:M76 | if (%s1 !== %s2) { goto nexti1 } | inc %i2 | continue
:M108 | if (%s1 != %s2) { goto nexti1 } | inc %i2 | continue
:M87 | if (%s1 !iswmcs %s2) { goto nexti1 } | inc %i2 | continue
:M119 | if (%s1 !iswm %s2) { goto nexti1 } | inc %i2 | continue
}
aline -p %wr %i1 %rec
:nexti1 | inc %i1
}
if ($line(%wr,0)) { return %wr } | window -c %wr | return
}
|
|
|
|
|