Advertisement
imk0tter

Untitled

May 7th, 2021
2,072
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 3.99 KB | None | 0 0
  1. alias parsecalc {
  2.   var %x 1
  3.   var %open $false
  4.  
  5.   var %count 0
  6.  
  7.   var %ret
  8.   while (%x < $len($1-)) {
  9.     if ($mid($1-,%x,1) == $chr(40)) {
  10.       if %open == $false {
  11.         var %open $true
  12.         var %ret $+(%ret,%x,$chr(1))
  13.       }
  14.       inc %count
  15.     }
  16.     else if ($v1 == $chr(41)) {
  17.       dec %count
  18.       if (%count == 0 && %open)  {
  19.         var %open $false
  20.         var %ret $+(%ret,%x,$chr(4))
  21.       }
  22.     }
  23.     inc %x
  24.   }
  25.   var %ret $+(%ret,$iif($right(%ret,1) == $chr(1),%x))
  26.   return %ret
  27. }
  28.  
  29. alias calctok {
  30.   hinc -m CALCTOKEN COUNT
  31.   var %htable CALCTOKEN $+ $hget(CALCTOKEN,COUNT)
  32.   hadd -m %htable COUNT 0
  33.  
  34.   var %tokens $1-
  35.  
  36.   var %numberOfTokens $pos(%tokens,$chr(40),0)
  37.   var %currentCalculation
  38.  
  39.   while %numberOfTokens {
  40.     var %numberOfOpeners $pos(%tokens,$chr(40),0)
  41.  
  42.     var %currentOpenerOffset $pos(%tokens, $chr(40), %numberOfOpeners)
  43.     var %currentCloserOffset $calc(%currentOpenerOffset + $pos($mid(%tokens,%currentOpenerOffset $+ -),$chr(41),1))
  44.     var %length $calc(%currentCloserOffset - %currentOpenerOffset)
  45.  
  46.     var %currentCalculation $mid($mid(%tokens,$calc(%currentOpenerOffset),%length),2,-1)
  47.  
  48.     var %tokens $mid(%tokens,1,$calc(%currentOpenerOffset - 1))  $mid(%tokens, %currentCloserOffset $+ -)
  49.     if ( !isin %currentCalculation) spush %htable %currentCalculation
  50.     else {
  51.       var %z $pos(%currentCalculation,,0)
  52.  
  53.       while %z {
  54.         var %currTok $spop(%htable)
  55.         var %currentCalculation $replacetok(%currentCalculation,,-1,$calc(%currTok))
  56.         if ( !isin %currentCalculation) spush %htable %currentCalculation        
  57.         dec %z  
  58.       }
  59.     }
  60.     dec %numberOfTokens
  61.   }
  62.   hfree %htable
  63.   return $calc(%currentCalculation)
  64. }
  65.  
  66. alias replacetok {
  67.   var %pos $pos($1,$2,$iif($3 > 0,$3,$calc($pos($1,$2,0) + $3 + 1)))
  68.   return $+($left($1,$calc(%pos - 1)),$$4,$right($1,- $+ $calc(%pos + $len($2) - 1)))
  69. }
  70.  
  71. alias -l spush {
  72.   var %htable $1
  73.   hinc -m %htable COUNT
  74.   hadd -m %htable $hget(%htable,COUNT) $2-
  75. }
  76.  
  77. alias -l spop {
  78.   var %htable $1, %count $hget(%htable,COUNT)
  79.   hdec -m %htable COUNT
  80.   return $hget(%htable,%count)
  81. }
  82.  
  83. alias parseidentifiers {
  84.   var %x 1
  85.   var %inIdentifier
  86.   var %currentIdentifier
  87.   var %return $1-
  88.   while %x <= $len($1-) {
  89.     var %currentChar $mid($1-,%x,1)
  90.     if %currentChar == $ {
  91.       var %inIdentifier $true
  92.       var %currentIdentifier $
  93.     }
  94.     else if %currentChar == $chr(40) || %currentChar == $chr(32) {
  95.  
  96.       if (%inIdentifier) && %currentChar == $chr(40) {
  97.         var %z $token($parsecalc($right($1-,- $+ $calc(%x - 1))),1,4)
  98.  
  99.         var %start $calc($token(%z,1,1) - 1)
  100.         var %end $token(%z,2,1))
  101.  
  102.         var %length $calc(%end - %start + 1)
  103.  
  104.         var %currentIdentifier %currentIdentifier $+ $mid($right($1-, - $+ $calc(%x - 1)),%start,%length)
  105.         var %return $replacetok(%return,%currentIdentifier,1,$(%currentIdentifier,2))
  106.  
  107.         var %inIdentifier $false
  108.       }
  109.       else if %inIdentifier && %currentChar == $chr(32) {
  110.  
  111.         var %return $replacetok(%return,%currentIdentifier,1,$(%currentIdentifier,2))
  112.         var %inIdentifier $false
  113.       }
  114.     }
  115.     else if %inIdentifier {
  116.       if (%currentChar != $chr(41)) {
  117.         var %currentIdentifier %currentIdentifier $+ %currentChar
  118.       }
  119.     }
  120.     inc %x
  121.   }
  122.  
  123.   if (%inIdentifier) {
  124.     var %return $replacetok(%return,%currentIdentifier,1$(%currentIdentifier,2))
  125.   }
  126.   return %return
  127. }
  128.  
  129. on 1:input:@DEBUG: {
  130.   if ($left($1-,1) != /) {
  131.     tokenize 32 $parseidentifiers($1-)
  132.     var %x $parsecalc($1-)
  133.     var %y $numtok(%x,4)
  134.  
  135.     var %ret $1-
  136.  
  137.     while %y {
  138.       var %currTok $token(%x,%y,4)
  139.  
  140.       var %start $token(%currTok,1,1)
  141.       var %end $token(%currTok,2,1)
  142.       var %len $calc(%end - %start + 1)
  143.  
  144.       var %substr $mid($1-,%start,%len)
  145.       var %calc $calctok(%substr)
  146.       var %ret $replacetok(%ret,%substr,1,$+($chr(40),%substr == %calc,$chr(41)))
  147.       dec %y
  148.     }
  149.     echo @DEBUG %ret
  150.   }
  151. }
  152.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement