Sephiroth
http://sephiroth.scifi-action.de/board/

/do command with "endless loop fix" (50% ;))
http://sephiroth.scifi-action.de/board/viewtopic.php?f=4&t=40
Seite 1 von 1

Autor:  Sephiroth [ 18. März 2008 00:26 ]
Betreff des Beitrags:  /do command with "endless loop fix" (50% ;))

alias do {
  if ($1 == -n) { tokenize 32 $2- | var %output.sendÿ = $true }
  var %t = $ticks,%f = $left($2,1),%o = $iif($istok(% $,%f,32) || $2- == $chr(35),return $2-,$2-),%output
  convert %o
  !.load -rs tmp.mrc
  %output = $protect.debugalias
  goto done
  :error
  %output = $gettok($error,$+(2-,$calc($findtok($error,$chr(40) $+ line,1,32) -1)),32)
  reseterror
  :done
  $iif($1 ischan,msg,.notice) $1 $iif(!%output.sendÿ,$2- ->) $iif(%output != $null,%output,<empty string>) - $ms($calc($ticks - %t))
  if ($isfile(tmp.mrc)) {
    !.unload -rs tmp.mrc
    !.remove tmp.mrc
  }
  unset %output
}
alias -l convert {
  var %t = $md5($ticks)
  var %o = $1-
  write -c tmp.mrc
  if (while isin $1- && ($chr(123) !isin $1- && $chr(125) !isin $1-)) { error Please use exact while loops: "while (ifmatch) $!chr(123) command $!chr(125) $!+ " | goto end }
  if ($count(%o,$chr(32) $+ $chr(123)) != $count(%o,$chr(32) $+ $chr(125))) { error Bracket mismatch | goto end }
  if ($len($1-) > 300) { error String to long | goto end }
  if (!$lines(tmp.mrc)) {
    add alias protect.debugalias $chr(123)
    add var % $+ %t = $!ticks
    if ($1 != return) {
      %o = $replace(%o,$+($chr(32),$chr(123),$chr(32)),$+($chr(32),$chr(123),$lf))
      %o = $replace(%o,$+($chr(32),$chr(124),$chr(32)),$lf)
      %o = $replace(%o,$+($chr(32),$chr(125),$chr(32)),$+($lf,$chr(125),$lf))
      %o = $replace(%o,$+($chr(32),$chr(125)),$+($chr(32),$lf,$chr(125)))
    }
    add %o
    var %x = $read(tmp.mrc,nw,while * $chr(123))
    var %newline = $readn
    if (%newline) {
      write -il $+ $calc(%newline +1) tmp.mrc if ($calc($ticks - % $+ %t $+ ) > 300000) $chr(123) break $chr(125)
    }
    add $chr(125)
  }
  ;checking while loops
  var %x = $read(tmp.mrc,nw,while *)
  if (%x) {
    if ($right(%x,1) != $chr(123)) { write -c tmp.mrc | error Please check your while loops (maybe you missed some brackets :p) | goto end }
    while ($read(tmp.mrc,nw,while *,$calc($readn +1))) {
      %x = $ifmatch
      if ($right(%x,1) != $chr(123)) { write -c tmp.mrc | error Please check your while loops (maybe you missed some brackets :p) | goto end }
    }
  }
  :end
}
alias -l error { add alias protect.debugalias return $1- }
alias -l add { write tmp.mrc $1- }
alias -l ms return $duration($left($1,-3)) $iif($int($right($1,3)) != $null,$ifmatch $+ ms)

Seite 1 von 1 Alle Zeiten sind UTC + 1 Stunde
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/