From WikiChip
Difference between revisions of "mirc/identifiers/$*"
< mirc‎ | identifiers

(Notes & quirks)
 
(18 intermediate revisions by 7 users not shown)
Line 1: Line 1:
The '''$*''' allows you to iterates over all the token contained in $1-, like a while loop, $* left the help file a while ago, after while loops were introduced, it's now an undocumented identifier.
+
{{mirc title|$* Identifier}}'''$*''' is a construct, not an identifier, it allows you to iterate over all of the tokens contained within $1-. The way this works is much like a while loop. ''$*'' has been omitted from the help file since while loops were introduced, especially because the behavior of $* is quirky in some places.
  
$* is extremely powerful because is it much faster than using a while loop on a list of token, consider the following:
+
''$*'' is extremely powerful, because it is much faster than using a while loop on a list of tokens. Understanding how this works is pretty simple, so consider the following:
  
<syntaxhighlight lang="mIRC">
+
<syntaxhighlight lang="mIRC">var %list a b c d,%a 1
var %list a b c d,%a 1
 
 
while ($gettok(%list,%a,32)) {
 
while ($gettok(%list,%a,32)) {
echo -a $v1
+
    echo -a $v1
inc %a
+
    inc %a
}
+
}</syntaxhighlight>
</syntaxhighlight>
+
This can be written as:
this can be written as
+
<syntaxhighlight lang="mIRC">tokenize 32 a b c d | echo -a $*</syntaxhighlight>
<syntaxhighlight lang="mIRC">
+
 
tokenize 32 a b c d | echo -a $*
+
The above is much smaller, and a lot faster. Pretty cool, isn't it?
</syntaxhighlight>
 
And it's faster, cool isn't it?
 
  
 
== Notes & quirks ==
 
== Notes & quirks ==
 +
Why was the ''$*'' identifier removed from the help file in the first place? Well, ''$*'' was removed because it does not really work the same way that the other identifiers do, and because it is quirky.
 +
 +
Quirky? Quirky, how?
 +
 +
Well, mIRC takes the command ''$*'' appears in, and replaces all of the occurrences in the line by a special marker: ''`~$*:'' An example of how this is accomplished is shown below:
 +
 +
<syntaxhighlight lang="mIRC">//tokenize 32 abcd | echo -a $left($*,1) $+ $chr(3) $+ $mid($*,2)</syntaxhighlight>
 +
 +
Further examining the code, it is easy to understand why the above returns such a value:
 +
<syntaxhighlight lang="mIRC">//tokenize 32 abcd | echo -a $mid($*,2)</syntaxhighlight>
 +
 +
Why isn't this returning bcd? Because of the usage of the special marker ''`~$*'', mIRC has stored the command as actually '''echo -a $mid(`~$*,2)'''.
 +
 +
Then, for each token (here only '''$1 == abcd'''), mIRC evaluates the line. '''$mid(`~$*,2)''' becomes ''~$*'', and then mIRC replaces the marker by the token and executes the echo command. However, after an operation like ''$mid'' in this example, that marker cannot be found. Basically, it cannot be guaranteed that the correct value of the marker inside an identifier can be found later for replacement of that marker.
  
Why was the $* identifiers removed from the help file? Well because it doesn't really work the same way the others identifiers does, and because it's quirky:
+
There is a workaround for the above issue, and that is by using scid and scon:
 +
<syntaxhighlight lang="mIRC">//tokenize 32 abcd | scon -r echo -a $!mid( $* ,2)</syntaxhighlight>
  
mIRC takes the command $* appears in and replace all of its occurences in the line by a special marker: `~$*: you can see that by doing for example:
+
'''Note''': This workaround will double evaluate the content of the token, replace "abcd" above with $!time and it will evaluate.
  
//tokenize 32 abcd | echo -a $left($*,1) $+ $chr(3) $+ $mid($*,2)
+
mIRC replaces '''$*'''  by the marker, but scon has an extra evaluation system which fits perfectly. The ''$*'' mechanism is enabled on scon, and mIRC stores the command of the ''$*'' as '''scon -r echo -a $!mid( `~$* ,2)''' mIRC then evaluates the line for each token, which then becomes: "scon -r echo -a $mid( abcd ,2)" Finally, the scon command is executed, resulting in the expected value being echoed.
  
Let's take a look at this: //tokenize 32 abcd | echo -a $mid($*,2)
+
Another issue is that you cannot call ''$*'' more than once in the same scope; the command will simply be skipped. However, this can also be circumvented/worked-around :)
  
Why isn't this returning bcd? That's because of the usage of the special marker `~$*, mIRC store that the command is "echo -a $mid(`~$*,2)".
+
Simply retokenize after using ''$*''.
 +
However, note that '''$*''' will remember the number of token it already went through, ''$*'' will only start from the previous number of tokens + 1, look at this example:
  
Then for each token, (here only $1 == abcd), evaluate the line first, here $mid(`~$*,2) is ~$*, and then mIRC replaces the marker by the token and execute the echo command, however after an operation like $mid here, that marker can't be found, you basically cannot get the correct value of $* inside an identifier.
+
<syntaxhighlight lang="mIRC">//tokenize 32 1 2 3 | echo -a $* | tokenize 32 4 5 6 7 8 | echo -a $* | echo -a here</syntaxhighlight>
  
There is a workaround to that issue though, with scid and scon:
+
The first three tokens of the second tokenize, "4 5 6", are dummy tokens which are passed to fill in the gap. '''$*''' is actually starting from the 4th token.
<syntaxhighlight lang="mIRC">
+
If you are dealing with dynamic parameter and want to use $* again in the same scope, you can use '''$str(AT,$0) $+''' as the dummy tokens, where A is a non token character, and where T is a token character, that indeed makes sure the correct number of dummy tokens is used:
//tokenize 32 abcd | scon -r echo -a $!mid( $* ,2)
 
</syntaxhighlight>
 
  
Here mIRC replace $* by the marker, but scon has an extra evaluation system which fits perfectly here, $* mechanism is enabled on scon, mIRC store the command of the $* as "scon -r echo -a $!mid( `~$* ,2)"
+
<syntaxhighlight lang="mIRC">//tokenize 32 1 2 3 | echo -a $* | tokenize 32 $str(A $chr(32),$0) $+ 7 8 | echo -a $* | echo -a here</syntaxhighlight>
  
Then for each token, mIRC evaluates the line, which becomes: "scon -r echo -a $mid( abcd ,2)" and then finally the scon command is executed, resulting in the expected value echoed.
+
'''Note''': This sexy workaround works even inside a loop, but a better workaround is to call an alias and to execute the new $* in there, the previous tokens will be cleared.
  
Another issue is that you cannot call $* more than once in the same scope the command will simply be skipped, however... this can be worked around :)
+
== Compatibility ==
 +
{{mIRC compatibility|2.1a}}
  
If you retokenize after using $*, forcing the update of $1-, you can use $* again but only if the number of tokens you pass is higher than the previous number of token you passed, and $* will only start from that previous number of token + 1:
+
== See Also ==
<syntaxhighlight lang="mIRC">
+
[[List of identifiers - mIRC|mIRC Identifiers]]
//tokenize 32 1 2 3 | echo -a $* | tokenize 32 4 5 6 7 8 | echo -a $* | echo -a here
+
{{mIRC identifier list}}
</syntaxhighlight>
 
  
As you can see with this line, the second tokenize's first 3 token "4 5 6" are dumb tokens passed to fill in the gap, you can use $1- in front of your next tokenize command to start from those new tokens, like a normal situation.
+
[[Category:mIRC identifiers|$* identifier - mIRC]]

Latest revision as of 14:42, 16 February 2020

$* is a construct, not an identifier, it allows you to iterate over all of the tokens contained within $1-. The way this works is much like a while loop. $* has been omitted from the help file since while loops were introduced, especially because the behavior of $* is quirky in some places.

$* is extremely powerful, because it is much faster than using a while loop on a list of tokens. Understanding how this works is pretty simple, so consider the following:

var %list a b c d,%a 1
while ($gettok(%list,%a,32)) {
    echo -a $v1
    inc %a
}

This can be written as:

tokenize 32 a b c d | echo -a $*

The above is much smaller, and a lot faster. Pretty cool, isn't it?

Notes & quirks[edit]

Why was the $* identifier removed from the help file in the first place? Well, $* was removed because it does not really work the same way that the other identifiers do, and because it is quirky.

Quirky? Quirky, how?

Well, mIRC takes the command $* appears in, and replaces all of the occurrences in the line by a special marker: `~$*: An example of how this is accomplished is shown below:

//tokenize 32 abcd | echo -a $left($*,1) $+ $chr(3) $+ $mid($*,2)

Further examining the code, it is easy to understand why the above returns such a value:

//tokenize 32 abcd | echo -a $mid($*,2)

Why isn't this returning bcd? Because of the usage of the special marker `~$*, mIRC has stored the command as actually echo -a $mid(`~$*,2).

Then, for each token (here only $1 == abcd), mIRC evaluates the line. $mid(`~$*,2) becomes ~$*, and then mIRC replaces the marker by the token and executes the echo command. However, after an operation like $mid in this example, that marker cannot be found. Basically, it cannot be guaranteed that the correct value of the marker inside an identifier can be found later for replacement of that marker.

There is a workaround for the above issue, and that is by using scid and scon:

//tokenize 32 abcd | scon -r echo -a $!mid( $* ,2)

Note: This workaround will double evaluate the content of the token, replace "abcd" above with $!time and it will evaluate.

mIRC replaces $* by the marker, but scon has an extra evaluation system which fits perfectly. The $* mechanism is enabled on scon, and mIRC stores the command of the $* as scon -r echo -a $!mid( `~$* ,2) mIRC then evaluates the line for each token, which then becomes: "scon -r echo -a $mid( abcd ,2)" Finally, the scon command is executed, resulting in the expected value being echoed.

Another issue is that you cannot call $* more than once in the same scope; the command will simply be skipped. However, this can also be circumvented/worked-around :)

Simply retokenize after using $*. However, note that $* will remember the number of token it already went through, $* will only start from the previous number of tokens + 1, look at this example:

//tokenize 32 1 2 3 | echo -a $* | tokenize 32 4 5 6 7 8 | echo -a $* | echo -a here

The first three tokens of the second tokenize, "4 5 6", are dummy tokens which are passed to fill in the gap. $* is actually starting from the 4th token. If you are dealing with dynamic parameter and want to use $* again in the same scope, you can use $str(AT,$0) $+ as the dummy tokens, where A is a non token character, and where T is a token character, that indeed makes sure the correct number of dummy tokens is used:

//tokenize 32 1 2 3 | echo -a $* | tokenize 32 $str(A $chr(32),$0) $+ 7 8 | echo -a $* | echo -a here

Note: This sexy workaround works even inside a loop, but a better workaround is to call an alias and to execute the new $* in there, the previous tokens will be cleared.

Compatibility[edit]

Added: mIRC v2.1a
Added on: 28 Feb 1995
Note: Unless otherwise stated, this was the date of original functionality.
Further enhancements may have been made in later versions.


See Also[edit]

mIRC Identifiers

v · d · e mIRC identifier list

$ $$, $, $0, $1-, $!, $&, $*, $+, $++, $?

A $abook, $abs, $acos, $active, $activecid, $activewid, $adate, $address, $addtok, $addtokcs, $agent, $agentname, $agentstat, $agentver, $alias, $and, $anick, $ansi2mirc, $aop, $appactive, $appstate, $asc, $asctime, $asin, $atan, $atan2, $auto, $avoice, $away, $awaymsg, $awaytime

B $banlist, $banmask, $base, $beta, $bfind, $bindip, $bitoff, $biton, $bits, $bnick, $bvar, $bytes

C $calc, $caller, $cancel, $cb, $cd, $ceil, $chan, $chanmodes, $channel, $chantypes, $chat, $chr, $cid, $clevel, $click, $cmdbox, $cmdline, $cnick, $color, $colour, $com, $comcall, $comchan, $comchar, $comerr, $compact, $compress, $comval, $cos, $cosh, $count, $countcs, $cr, $crc, $creq, $crlf, $ctime, $ctimer, $ctrlenter

D $date, $day, $daylight, $dbuh, $dbuw, $dccignore, $dccport, $dde, $ddename, $debug, $decode, $decompress, $deltok, $devent, $dialog, $did, $didreg, $didtok, $didwm, $dir, $disk, $dlevel, $dll, $dllcall, $dname, $dns, $donotdisturb, $dqwindow, $duration

E $ebeeps, $editbox, $email, $emailaddr, $encode, $envvar, $error, $eval, $evalnext, $event, $eventid, $eventparms, $exists, $exiting

F $false, $feof, $ferr, $fgetc, $file, $filename, $filtered, $find, $finddir, $finddirn, $findfile, $findfilen, $findtok, $findtokcs, $fline, $flinen, $floor, $font, $fopen, $fread, $fromeditbox, $fserv, $fserve, $fulladdress, $fulldate, $fullname, $fullscreen

G $get, $getdir, $getdot, $gettok, $gmt, $group

H $halted, $hash, $height, $hfile, $hfind, $hget, $highlight, $hmac $hmatch, $hnick, $host, $hotline, $hotlinepos, $hotlink, $hotp, $hregex, $hypot

I $iaddress, $ial, $ialchan, $ibl, $idle, $iel, $ifmatch, $ifmatch2, $ignore, $iif, $iil, $inellipse, $ini, $initopic, $inmidi, $inmode, $inmp3, $inpaste, $inpoly, $input, $inrect, $inroundrect, $insong, $insongpause, $instok, $int, $intersect, $inwave, $inwho, $ip, $iptype, $iql, $isadmin, $isalias, $isbit, $isdde, $isdir, $isfile, $isid, $islower, $istok, $istokcs, $isupper, $isutf

K $keychar, $keyrpt, $keyval, $knick

L $lactive, $lactivecid, $lactivewid, $left, $leftwin, $leftwincid, $leftwinwid, $len, $level, $lf, $line, $lines, $link, $lock, $locked, $lof, $log, $log10, $logdir, $logstamp, $logstampfmt, $longfn, $longip, $lower, $ltimer

M $maddress, $mask, $matchkey, $matchtok, $matchtokcs, $maxlenl, $maxlenm, $maxlens, $md5, $me, $menu, $menubar, $menucontext, $menutype, $mid, $mididir, $mircdir, $mircexe, $mircini, $mkfn, $mklogfn, $mknickfn, $mnick, $mode, $modefirst, $modelast, $modespl, $mouse, $mousecx, $mousecy, $mousedx, $mousedy, $mousekey, $mouselb, $mousex, $mousey, $mousewin, $mp3, $mp3dir, $msfile, $msgstamp, $msgtags

N $N, $naddress, $network, $newnick, $nhnick, $nick, $nickmode, $no, $nofile, $nopath, $nopnick, $noqt, $not, $notags, $notify, $null, $numeric, $numtok, $nvnick

O $ok, $online, $onlineserver, $onlinetotal $onpoly, $opnick, $or, $ord, $os

P $parmN, $parms, $parseline, $parsetype, $parseutf, $passivedcc, $pi, $pic, $play, $pnick, $portable, $portfree, $pos, $poscs, $prefix, $prop, $protect, $puttok

Q $qt, $query

R $r, $raddress, $rand, $rands, $rawbytes, $rawmsg, $read, $readini, $readn, $regbr, $regerrstr, $regex, $regml, $regmlex, $regsub, $regsubex, $remote, $remove, $removecs, $remtok, $remtokcs, $replace, $replacecs, $replacex, $replacexcs, $reptok, $reptokcs, $result, $rgb, $right, $rnick, $round

S $samepath, $scid, $scon, $script, $scriptdir, $scriptline, $sdir, $send, $server, $serverip, $servertarget, $sfile, $sha1, $sha256, $sha384, $sha512, $shortfn, $show, $signal, $sin, $sinh, $site, $sline, $snick, $snicks, $snotify, $sock, $sockbr, $sockerr, $sockname, $sorttok, $sorttokcs, $sound, $speak, $sqrt, $sreq, $ssl, $sslcertsha1, $sslcertsha256, $sslcertvalid, $ssldll, $ssllibdll, $sslready, $sslversion, $starting, $status, $str, $strip, $stripped, $style, $submenu, $switchbar, $sysdir

T $tan, $tanh, $target, $tempfn, $ticks, $time, $timeout, $timer, $timestamp, $timestampfmt, $timezone, $tip, $tips, $titlebar, $token, $toolbar, $topic, $totp, $treebar, $true, $trust

U $ulevel, $ulist, $unsafe, $upper, $uptime, $url, $usermode, $utfdecode, $utfencode

V $v1, $v2, $var, $vc, $vcmd, $vcmdstat, $vcmdver, $version, $vnick, $vol

W $wavedir, $wid, $width, $wildsite, $wildtok, $wildtokcs, $window, $wrap

X $xor

Y $yes

Z $zip

= =$nick