mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jan 2004
Posts: 2,127
maroon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
-t changes /bwrite's behavior from double-evaluation to single evaluation of %variables and $identifiers, but the absence of -t doesn't evaluate the entire %variable or $identifier if they contain/return strings where the first token begins with a percent.

Without using -t, if the first token of the string to be bwritten begins with a percent or ampersand, /bwrite ignores all later tokens. And if the first token is the name of a non-existent %variable, /bwrite returns an error as if it had been told to write $null.

Both aliases write the contents of the %b or &b variable to disk without also writing the remainder of the contents of %a or $2-. If you change the 1st alias to bwrite $2- instead of $1-, it writes to disk the literal string 'foo %b bar' because the string does not begin with a percent. If you remove the semi-colon from either "unset %b", /bwrite ignores the remainder of the %a or $2- string, generating an error as if you tried to write $null.

Code:
alias bwritetest1 {
  tokenize 32 % $+ b foo % $+ b bar
  var %a % $+ b
  var %b contents of b
  echo 4 -a 1-= $1-
  echo 4 -a a= %a foo % $+ b bar
  echo 4 -a b= %b
  ;unset %b
  bwrite -c test.dat 0 -1 %a
  echo 2 -a writing % $+ a file= $read(test.dat,nt,1)
  ;unset %b
  bwrite -c test.dat 0 -1 $1-
  echo 2 -a writing $ $+ 1- file= $read(test.dat,nt,1)
}
bwritetest2 {
  tokenize 32 & $+ b 7 8
  bset &b 1 4 5 6
  echo 4 -a b= $bvar(&b,1-)
  echo 4 -a 1-= $1-
  ;bunset &b
  bwrite -c test.dat 0 -1 $1-
  bread     test.dat 0 99 &c
  echo 2 -a writing & $+ 1- excludes $2- file= $bvar(&c,1-)
}


/bwrite and $calc() both double-evaluate strings beginning with percent, but not the same way:

Code:
alias bwritetest3 {
  var %b 10 | tokenize 32 % $+ b + 5
  echo 4 -a 1-= $1-
  echo 4 -a b= %b
  bwrite -c test.dat 0 -1 $1-
  echo 2 -a calc result: $calc( $1- )
  echo 2 -a file contains: $read(test.dat,nt,1)
}


$calc evaluates the contents of %b along with the contents of $2- returning 15
/bwrite evaluates the contents of %b but ignores the contents of $2- returning 10

So based on this, even though -t isn't required in order to write most normal text strings to disk, /bwrite should always use -t when writing a %variable or $identifier whose contents could possibly begin with either a percent or ampersand.

Joined: Dec 2002
Posts: 5,420
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,420
Thanks for your bug report. This is by design and was requested at the time of implementation. /bwrite takes the value of %var directly from the variable, so that it does not get tokenized, which preserves the line. I will add a note to the help file about this.

Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
Hello, this report was actually reporting multiple issues.

So passing only a %variable name to /bwrite without -t preserve tokenization.
But if that were the only purpose of this syntax (which is a nice feature I wasn't aware of, don't get me wrong), then the following:

Code:
//var -s %a % $+ b $chr(32) B,%b A | bwrite -c test 0 -1 %a | var %r $read(test,tn,1) | echo -a space would be lost due to /echo but: len: $len(%r) -- %r

It shows that mIRC is doing much more than just not tokenizing.
mIRC sees that the content of %a starts with a variable (%b in this case), it evaluates that variable (which results in double evaluation, which is very dangerous) and then completely ignores the rest of the content of %a, which would be
Code:
"   B"
in this case.
I would expect bwrite to write the plain text
Code:
"%b   B"
text to the file there.

The only other command which document this syntax with seperated "text|%var" is /sockwrite, and "/sockwrite socket %var" does not prevent the tokenization of %var, nor does it have this behavior of only evaluating the first token if it's a %variable & ignoring following tokens.

Regardless if this "weird" behavior was implemented on purpose, it would break backward compatibility to change /bwrite (or /sockwrite eh), but maybe we could get some new switch to rectify this and improve others commands:

- a new switch for /bwrite which makes it so the %variable is not tokenized, preserving spaces, but nothing gets double evaluated either ($unsafe cannot be used)

- a new switch for /sockwrite, honoring the text|%var syntax, where if only a variable is passed, no tokenization happens.

- a new switch for /fwrite, improving the syntax to support text|%var, where it would also prevent the tokenization of the variable





#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Dec 2002
Posts: 5,420
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,420
Quote:
So passing only a %variable name to /bwrite without -t preserve tokenization.

The -t switch is not to preserve tokenization. The -t switch treats the parameters as plain text.

If -t is not specified and mIRC sees a &binvar or %var, it assumes that those are the parameters that contain the data.

When /bwrite was implemented, scripters specifically asked for it to work this way.

Quote:
- a new switch for /bwrite which makes it so the %variable is not tokenized, preserving spaces, but nothing gets double evaluated either ($unsafe cannot be used)

That is not possible because that is not how the command parser works and it cannot be changed to work that way.

Quote:
- a new switch for /sockwrite, honoring the text|%var syntax, where if only a variable is passed, no tokenization happens.

- a new switch for /fwrite, improving the syntax to support text|%var, where it would also prevent the tokenization of the variable

Please submit these as feature suggestions.

Last edited by Khaled; 13/01/18 07:31 PM.
Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
Quote:
Quote:
So passing only a %variable name to /bwrite without -t preserve tokenization.

The -t switch is not to preserve tokenization. The -t switch treats the parameters as plain text.
I am not saying that -t is to preserve tokenization, I said "without the -t switch".
Quote:
If -t is not specified and mIRC sees a &binvar or %var, it assumes that those are the parameters that contain the data.
Yes this is what I'm talking about, /bwrite without -t, aka -t is not specified.

Quote:
When /bwrite was implemented, scripters specifically asked for it to work this way.
Ok so I thought that what you were saying was that:
Code:
var -s %a a $chr(32) b | bwrite test 0 -1 %a
would result in /bwrite writting "a   b" but I now realize that this is the way it works:
Code:
var -s %a % $+ b,%b a $chr(32) b | bwrite test 0 -1 %a


It then makes more sense to skip the others tokens there:
Code:
//var -s %a % $+ b $chr(32) B,%b A | bwrite -c test 0 -1 %a



Quote:
Quote:
- a new switch for /bwrite which makes it so the %variable is not tokenized, preserving spaces, but nothing gets double evaluated either ($unsafe cannot be used)

That is not possible because that is not how the command parser works and it cannot be changed to work that way.
This was asked without realizing how it was really behaving there, sorry.

And given the realisation, I do not like this feature of /bwrite, so I won't be suggesting the others two grin


#mircscripting @ irc.swiftirc.net == the best mIRC help channel

Link Copied to Clipboard