mIRC Home    About    Download    Register    News    Help

Print Thread
binvar named & #266011 06/09/19 07:52 PM
Joined: Jan 2004
Posts: 1,187
maroon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,187
mIRC doesn't allow creating & as binvar name in some places, but once it's created, it won't always permit using it as a parameter. This means you can't use $bvar(%var) or $bvar(%var,0) to guarantee that %var contains name of a binvar that works with a particular command. It seems /bwrite and $regsubex are the exceptions to identifiers accepting it and commands rejecting it.

This is different than the issue where you can create a variable named % but not echo it, because every command and identifier using a binvar is either a command specifically for usage by &binvar only, or is an identifier where it's either not ambiguous whether & means binary not text, or it uses a switch to indicate that & means binary. i.e. 5th parm of $regsubex always begins with % or $

//set % test | echo 3 -a % [ % ] | echo 4 -a $var(%,0) $var(%,1) $var(%,1).value

The regsubex issue might be related to being an exception where square braces are normally allowed to touch commas and parenthesis, but the 5th parm won't accept without the spaces

bug: //tokenize 32 &v | echo -a $regsubex(foo,abc,,,[ $1 ]) $bvar(&v,1-).text
ok:: //tokenize 32 &v | echo -a $regsubex(foo,abc,,, [ $1 ] ) $bvar(&v,1-).text

Using binvar named & :

works: $hget yes $bvar yes

//hadd -m table item abc | echo -a $hget(table, item, &) - $bvar(&, 1-)

(repeating the $hget again, showing that once the binvar named & is created, that other commands don't always accept it)

bcopy as source no
//hadd -m table item abc | echo -a $hget(table, item, &) - $bvar(&, 1-) | bcopy &test 1 & 1 -1 | echo -a $bvar(&test,1-)
bcopy as destination no
//bset &v 1 abc | bcopy & 1 &v 1 -1

bread no
//bread $qt($mircexe) 0 2 & | echo -a $bvar(&,1-)

breplace no
//hadd -m table item abc | echo -a $hget(table, item, &) - $bvar(&,1-) | breplace & 97 98 | echo -a $bvar(&,1-)

bset no
//bset -t & 1 abc | echo -a $bvar(&,1-)

bunset no
//hadd -m table item abc | echo -a $hget(table, item, &) - $bvar(&,1-) | bunset & | echo 4 -a $bvar(&,1-)

bwrite yes
//hadd -m table item abc | echo -a $hget(table, item, &) - $bvar(&,1-) | bwrite -c test.dat 0 9 & | echo 4 -a $file(test.dat).size

$encode $decode yes
//hadd -m table item abc | echo -a $hget(table, item, &) - $bvar(&) | echo 4 -a $encode(&,bm) $decode(&,bm)

$regsubex no
//echo -a $regsubex(foo,abc,,,&) | echo -a $bvar(&,1-)

$bfind yes
//hadd -m table item abc | echo -a $hget(table, item, &) - $bvar(&,1-) | echo 4 -a $bfind(&,1,98)

crc & crypto hashes yes
//hadd -m table item abc | echo -a $hget(table, item, &) - $bvar(&) | echo 4 -a $crc(&,1) $md5(&,1) $sha1(&,1) $sha256(&,1) $sha384(&,1) $sha512(&,1) $hmac(&,key,sha1,1)

$cb yes
//clipboard test | echo 4 -a $cb(1,,&) $bvar(&,1-).text

$com yes
alias sendkeys_b { var %a = $ticks | hadd -m table item abc | noop $hget(table, item, &) | .comopen %a WScript.Shell | if (!$comerr) .comclose %a $com(%a,SendKeys,3,&bstr,&) }

$compress $decompress yes
//hadd -m table item $str(abc,100) | echo -a $hget(table, item, &) - $bvar(&) | echo 4 -a $compress(&,b) $bvar(&,0) $decompress(&,b) $bvar(&,0)

Re: binvar named & #266016 07/09/19 04:50 PM
Joined: Jul 2006
Posts: 3,568
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,568
None of the command and identifier should work with a binvar named with only the '&' sign, just like '%' shouldn't be allowed in normal variables routines.

The $regsubex issue may or may not be a bug
Spaced out [ ] will be evaluated before the identifier itself is, so there's no problem with $1 there.
Non spaced out [ ] won't be evaluated before the identifier but when the identifier is parsing its parameters.. except in $regsubex:
It is known that the replacement parameter is not evaluated in $regsubex until the regex matches have been done and replacement occurs and that $N- are used to store markers such as \n.
Here the parameter is not the replacement but it looks like $regsubex is also not evaluating the parameter until it is replacing, which may not be that useful, but in fact it may allow one to store each replacement into a different variables this way, which may have been intended, and the fact that $1 is $null could come from the fact that $1- is restored when $regsubex finishes, before it was the last parameter so it was only a problem there, but yeah now you would have to watch out for the output param as well.

I believe none of the binvar '&' usage being allowed can be changed at this point, just like '%' can't, but it's so bad that i'd still like to see this fixed, all of it.

Last edited by Wims; 07/09/19 04:52 PM.

Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: binvar named & [Re: maroon] #266017 07/09/19 08:30 PM
Joined: Jan 2004
Posts: 1,187
maroon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,187
Update

Add "/sockread &" as another way to create a binvar named &

I didn't care whether the fix is to make binvar named & work everywhere, or make it work nowhere. Just that it's consistent.

Re: binvar named & [Re: maroon] #266018 07/09/19 09:13 PM
Joined: Dec 2002
Posts: 4,538
Khaled Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 4,538
Thanks for your bug report. This is a known issue. You will find that % also has the same issue.

I have looked into this several times and there is commented out code that makes the core var/binvar routines reject single character % or & names. Unfortunately fixing this issue is not that clear cut.

There are hundreds of places in the code where commands/identifiers/features check if a string begins with % or &. In many cases, a stricter check for length is performed. In other cases, it is not. Changing all of these to strict/non-strict checks would affect different features in different ways.

For example, if a strict check is performed and & or % are treated as a non-valid names, some features will execute a completely different code path. Other features will return an empty string. And other features will report an error. These features were all implemented at different times, requested by different users with different demands, and updated at different times to handle new features, over the last 20+ years.

Basically, this cannot be implemented as a general fix without affecting backward compatibility. However, I might be able to make changes to some features where its clear that the code flow is not affected. But in general, it will be inconsistent. The solution, of course, is to not use single character % or & var/binvar names.

Quote
bug: //tokenize 32 &v | echo -a $regsubex(foo,abc,,,[ $1 ]) $bvar(&v,1-).text

The [] brackets need to be separate from all other characters in order for them to be parsed. Note that even if there was an issue with how [] are parsed, I will not change their behaviour in any way. This is some of the oldest code in the parser and it is far too brittle to be changed without causing backward compatibility issues.

Re: binvar named & [Re: Khaled] #266019 07/09/19 10:05 PM
Joined: Jul 2006
Posts: 3,568
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,568
There should not be a bug with [ ]. Can you confirm that the output parameter of $regsubex is not evaluated before the replacement takes place (just like the replacement parameter isn't)?


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: binvar named & [Re: Khaled] #266020 08/09/19 05:15 AM
Joined: Jan 2004
Posts: 1,187
maroon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,187
As I mentioned, I don't see a problem with forbidding the creation of a binvar named &, as that avoids needing to make several other commands support it, and avoids the problem where a script could use $bvar(parameter,0) to verify it exists only to have the script error when trying to do something with that binvar.

As for the [brackets], I'd noticed it was an exception to spaces buffer not being needed lots of places, like with:

Code
//var %text string , %from i , %to o | echo -a $replace([ %text ],[ %from ],[ %to ])