alias m2x { 
  if ($exists($scriptdirMtX-Converter.hsh)) && (!$hget($mtxc.hash)) {
    hmake $mtxc.hash 100
    hload $mtxc.hash $qt($scriptdirMtX-Converter.hsh)
  }
  if (!$dcx(Version)) && ($exists($scriptdirdcx\dcx_tools.mrc)) { load -rs $qt($scriptdirdcx\dcx_tools.mrc) }
  if ($dialog(Dia.mtxc)) { dialog -v Dia.mtxc }
  else { dialog -ma Dia.mtxc Dia.mtxc_table }
}

dialog Dia.mtxc_table {
  title "Menu to XPopup Converter - coded by Flobse"
  size -1 -1 625 485
}

on *:dialog:Dia.mtxc:*:*: {
  if ($devent == init) {
    dcx Mark $dname Dia.mtxc_cb
    xdialog -b $dname +ty

    ;Menu Code
    xdialog -c $dname 1 box 15 10 400 460 | xdid -t $dname 1 Menu Code: | xdid -l $dname 1 root $chr(9) +pl 0 1 0 0
    xdid -c $dname 1 100 text 20 23 65 15 | xdid -t $dname 100 Menu name:
    xdid -c $dname 1 101 edit 90 20 290 20 autohs autovs tabstop | xdid -a $dname 101 custom-menu
    xdid -c $dname 1 2 edit 20 45 360 365 tabstop multi autovs return autohs left hsbar vsbar
    xdid -c $dname 1 3 button 20 420 150 25 tabstop | xdid -t $dname 3 Generate XPopup Code
    xdid -c $dname 1 4 button 187 420 75 25 tabstop | xdid -t $dname 4 Clear All
    xdid -c $dname 1 5 button 280 420 100 25 tabstop | xdid -t $dname 5 Test
    xdid -i $dname 2 1 menu Channel $chr(123)
    xdid -i $dname 2 2 Example
    xdid -i $dname 2 3 .SayTime : echo -a $ $+ time
    xdid -i $dname 2 4 .-
    xdid -i $dname 2 5 .Another group
    xdid -i $dname 2 6 ..SayMyName : echo -a $ $+ nick
    xdid -i $dname 2 7 $chr(125)

    ;XPopup Settings
    xdialog -c $dname 10 box 430 10 180 460 | xdid -t $dname 10 XPopup Settings: | xdid -l $dname 10 root $chr(9) +pl 0 1 0 0
    xdid -c $dname 10 11 text 15 25 30 20 | xdid -t $dname 11 Style:
    xdid -c $dname 10 12 comboex 55 20 105 300 dropdown tabstop
    xdid -a $dname 12 0 0 0 0 0 Office 2003 
    xdid -a $dname 12 0 0 0 0 0 Office 2003 rev
    xdid -a $dname 12 0 0 0 0 0 Office XP 
    xdid -a $dname 12 0 0 0 0 0 Icy
    xdid -a $dname 12 0 0 0 0 0 Icy rev 
    xdid -a $dname 12 0 0 0 0 0 Grade
    xdid -a $dname 12 0 0 0 0 0 Grade rev 
    xdid -a $dname 12 0 0 0 0 0 Normal
    xdid -a $dname 12 0 0 0 0 0 Vertical 
    xdid -a $dname 12 0 0 0 0 0 Vertical rev
    xdid -a $dname 12 0 0 0 0 0 Custom 
    xdid -c $dname 12 $iif($hget($mtxc.hash,Style),$v1,1)

    xdid -c $dname 10 13 check 15 45 145 20 tabstop | xdid -t $dname 13 Sel.-Box for disabled items | if ($hget($mtxc.hash,check13)) { xdid -c $dname 13 }
    xdid -c $dname 10 14 check 15 65 150 20 tabstop | xdid -t $dname 14 3D shadow effect for icons | if ($hget($mtxc.hash,check14)) { xdid -c $dname 14 }
    xdid -c $dname 10 15 check 15 85 150 20 tabstop | xdid -t $dname 15 3D effect for icons | if ($hget($mtxc.hash,check15)) { xdid -c $dname 15 }
    xdid -c $dname 10 16 check 15 105 150 20 tabstop | xdid -t $dname 16 Rounded selection box | if ($hget($mtxc.hash,check16)) { xdid -c $dname 16 }
    xdid -c $dname 10 17 check 15 125 90 20 tabstop | xdid -t $dname 17 Transparency | if ($hget($mtxc.hash,check17)) { xdid -c $dname 17 }
    xdid -c $dname 10 18 comboex 105 125 60 400 dropdown tabstop
    var %x 5 | while (%x < 100) { xdid -a $dname 18 0 0 0 0 0 %x $+ % | inc %x 5 }
    xdid -c $dname 18 $iif($hget($mtxc.hash,Transparency),$v1,1)

    xdid -c $dname 10 19 line 15 145 150 15
    xdid -c $dname 10 20 check 15 155 70 20 tabstop | xdid -t $dname 20 BG-Image | if ($hget($mtxc.hash,check20)) { xdid -c $dname 20 }
    xdid -c $dname 10 21 button 85 155 85 20 tabstop | xdid -t $dname 21 $iif($remove($gettok($hget($mtxc.hash,Background),$numtok($hget($mtxc.hash,Background),92),92),.bmp),$v1,Browse)
    xdid -c $dname 10 22 check 15 180 45 20 tabstop disabled | xdid -t $dname 22 Icon
    xdid -c $dname 10 23 comboex 60 180 55 300 dropdown tabstop
    xdid -c $dname 10 24 button 120 179 50 25 tabstop | xdid -t $dname 24 Add
    xdid -c $dname 10 102 check 15 205 140 20 tabstop | xdid -t $dname 102 Generate Easychange | if ($hget($mtxc.hash,check102)) { xdid -c $dname 102 }

    ;Colors
    xdid -c $dname 10 30 box 15 232 150 80 | xdid -t $dname 30 Colors | xdid -l $dname 30 root $chr(9) +pl 0 1 0 0
    xdid -c $dname 30 31 comboex 10 20 130 300 dropdown tabstop
    xdid -a $dname 31 0 0 0 0 0 Menu background 
    xdid -a $dname 31 0 0 0 0 0 Icon box
    xdid -a $dname 31 0 0 0 0 0 Checkbox 
    xdid -a $dname 31 0 0 0 0 0 Disabled Checkbox
    xdid -a $dname 31 0 0 0 0 0 Disabled selection box 
    xdid -a $dname 31 0 0 0 0 0 Disabled text
    xdid -a $dname 31 0 0 0 0 0 Selection box 
    xdid -a $dname 31 0 0 0 0 0 Selection box border
    xdid -a $dname 31 0 0 0 0 0 Seperator 
    xdid -a $dname 31 0 0 0 0 0 Text
    xdid -a $dname 31 0 0 0 0 0 Selected Text 
    xdid -c $dname 31 1
    xdid -c $dname 30 32 edit 15 50 120 20 autohs autovs tabstop center 
    xdid -a $dname 32 $iif($hget($mtxc.hash,Colors),$rgb($gettok($v1,1,32)),$+(0,$chr(44),0,$chr(44),0))

    ;Get RGB
    xdid -c $dname 10 40 box 15 320 150 125 | xdid -t $dname 40 Get RGB | xdid -l $dname 40 root $chr(9) +pl 0 1 0 0
    xdid -c $dname 40 41 richedit 10 20 20 20 notheme | xdid -k $dname 41 $rgb(255,0,0)
    xdid -c $dname 40 42 trackbar 35 17 100 25 tabstop noticks both | xdid -t $dname 42 top | xdid -n $dname 42 10 | xdid -r $dname 42 0 255
    xdid -c $dname 40 43 richedit 10 45 20 20 notheme | xdid -k $dname 43 $rgb(0,255,0) 
    xdid -c $dname 40 44 trackbar 35 42 100 25 tabstop noticks both | xdid -t $dname 44 top | xdid -n $dname 44 10 | xdid -r $dname 44 0 255
    xdid -c $dname 40 45 richedit 10 70 20 20 notheme  | xdid -k $dname 45 $rgb(0,0,255)
    xdid -c $dname 40 46 trackbar 35 67 100 25 tabstop noticks both | xdid -t $dname 46 top | xdid -n $dname 46 10 | xdid -r $dname 46 0 255
    xdid -c $dname 40 47 richedit 10 95 45 20 notheme | xdid -k $dname 47 0
    xdid -c $dname 40 48 edit 60 95 80 20 autohs autovs tabstop center | xdid -a $dname 48 0,0,0
} }

alias Dia.mtxc_cb {
  if ($3 == 42) || ($3 == 44) || ($3 == 46) { ;Get RGB
    var %red $xdid($1,42).value, %green $xdid($1,44).value, %blue $xdid($1,46).value
    xdid -ra $1 48 $+(%red,$chr(44),%green,$chr(44),%blue)
    xdid -k $1 47 $rgb(%red,%green,%blue)
  }
  elseif ($2 == edit) {
    if ($3 == 32) { ;Colors - RGB Edit
      if ($regex($xdid($1,$3).text,/^((?:25[0-5])|(?:2[0-4]\d)|(?:1\d{2})|(?:\d{1,2}))\x2C((?:25[0-5])|(?:2[0-4]\d)|(?:1\d{2})|(?:\d{1,2}))\x2C((?:25[0-5])|(?:2[0-4]\d)|(?:1\d{2})|(?:\d{1,2}))$/)) {
        hadd -m $mtxc.hash Colors $puttok($hget($mtxc.hash,Colors),$($!rgb( $xdid($1,$3).text ),2),$xdid($1,31).sel,32)
    } }
    elseif ($3 == 48) { ;Get RGB - Edit
      if ($regex($xdid($1,$3).text,/^((?:25[0-5])|(?:2[0-4]\d)|(?:1\d{2})|(?:\d{1,2}))\x2C((?:25[0-5])|(?:2[0-4]\d)|(?:1\d{2})|(?:\d{1,2}))\x2C((?:25[0-5])|(?:2[0-4]\d)|(?:1\d{2})|(?:\d{1,2}))$/)) {
        xdid -k $1 47 $rgb($regml(1),$regml(2),$regml(3))
        xdid -v $1 42 $regml(1)
        xdid -v $1 44 $regml(2)
        xdid -v $1 46 $regml(3)
  } } }
  elseif ($2 == sclick) {
    if ($3 == 2) { ;Menu-Code Iconline
      hadd -m $mtxc.hash Caretpos $xdid($1,2).caretpos
      var %s $xdid($1,$3,$gettok($xdid($1,$3).caretpos,1,32)).text
      if (!$regex(%s,/^\s*(?:menu\s*.+?\s*)?\x7B\s*/i)) && (!$regex(%s,/^\s*\x7D\s*/)) && (!$regex(%s,/^\s*\.*\s*\-/)) && ($xdid($1,23).seltext) { 
        xdid -e $1 22
        if ($regex(%s,/^\+i(\d+)\s/)) {
          xdid -c $1 23 $regml(1)
          xdid -c $1 22
        } 
        else { xdid -u $1 22 }
      }
      else {
        xdid -b $1 22
        xdid -u $1 22
    } }
    if ($3 == 22) { ;Icon Checkbox
      var %c $xdid($1,22).state, %p $gettok($hget($mtxc.hash,CaretPos),1,32), %s $xdid($1,2,%p).text
      noop $regex(%s,/^\s*(?:(\+i\d+)\s)(.+?)\s*$/i)
      if ($regml(2)) && (!%c) { xdid -o $1 2 %p $regml(2) }
      elseif (!$regml(2)) && (%c) { xdid -o $1 2 %p +i $+ $xdid($1,23).sel %s }
      xdid -S $1 2 %p
    }
    if ($3 == 3) { ;Generate XPopup Code
      set %mtxc.generate.time $ticks
      if ($mtxc.generate) { .run $qt($scriptdirMtXC-Output.mrc) }
    }
    elseif ($3 == 4) { ;Clear All
      if ($hget($mtxc.hash)) { hfree $v1 }
      hadd -m $mtxc.hash Colors 15461355 10855845 10855845 10855845 10855845 8882055 13158600 5263440 5263440 0
      xdid -r $1 2,23,101
      xdid -c $1 12 1
      xdid -u $1 13,14,15,16,17,20,22
      xdid -c $1 18 1
      xdid -t $1 21 Browse
      xdid -c $1 31 1
      xdid -ra $1 32 $rgb($gettok($hget($mtxc.hash,Colors),1,32))
      xdid -c $1 102
      xdid -F $1 101
      if ($script(MtXC-Output.mrc)) { .unload -rs MtXC-Output.mrc }
      if ($exists($scriptdirMtXC-Output.mrc)) { .remove $qt($scriptdirMtXC-Output.mrc) }
    }
    elseif ($3 == 5) { ;Test Button
      if ($mtxc.generate) {
        .load -rs $qt($scriptdirMtXC-Output.mrc)
        .timer -m 1 1 $xdid($1,101).text
    } }
    elseif ($3 == 12) { ;Style Combo
      if ($xdid($1,$3).sel == 11) { xdid -e $1 20,21 }
      else {
        xdid -b $1 20,21 
        xdid -u $1 20
    } }
    elseif ($3 == 14) || ($3 == 15) { ;3D Shadow Checks
      if ($3 == 14) && ($xdid($1,$3).state == 1) && ($xdid($1,15).state == 1) { xdid -u $1 15 }
      elseif ($3 == 15) && ($xdid($1,$3).state == 1) && ($xdid($1,14).state == 1) { xdid -u $1 14 }
    }
    elseif ($3 == 21) || (($3 == 20) && ($xdid($1,20).state == 1) && (!$hget($mtxc.hash,Background))) { ;Background Check & Browse
      if ($sfile($hget($mtxc.hash,LastDir) $+ *.bmp,Choose a menu-background in .bmp format,Ok)) {
        var %p $v1
        hadd -m $mtxc.hash LastDir $nofile(%p)
        if ($right(%p,3) == bmp) {
          hadd -m $mtxc.hash Background %p
          xdid -c $1 20
          xdid -t $1 21 $remove($gettok(%p,$numtok(%p,92),92),.bmp)
        }
        else { 
          noop $input(The background picture is only in .bmp format supported.,-wo,Menu to XPopup Converter) 
          xdid -t $1 21 Browse
      } }
      else { 
        xdid -t $1 21 Browse 
        xdid -u $1 20
        hdel $mtxc.hash Background
    } }
    elseif ($3 == 24) { ;Icon Add Button
      if ($sfile($hget($mtxc.hash,IconDir) $+ *.ico;*.dll;*.icl;*.exe,Choose a .ico or dll/icl/exe file which contains Icon in 16x16,Ok)) {
        var %f $v1, %index 0
        if ($gettok(%f,-1,46) != ico) {
          var %index
          if ($dcx(PickIcon,0,%f)) {
            var %fp $v1
            if ($asc($gettok(%fp,3,32)) == 37) { var %fp $gettok(%fp,1-2,32) $envar($gettok($gettok(%fp,3-,32),1,37)) $+ $gettok($gettok(%fp,3-,32),2-,37) }
            if ($gettok(%fp,1,32) == D_OK) { var %index $gettok(%fp,2,32), %f $gettok(%fp,3-,32) }
            else { return }
        } }
        if (%index != $null) {
          if (!$hfind($mtxc.hash,%f,1,w).data) {
            hinc $mtxc.hash Icons
            hadd -m $mtxc.hash IconDir $nofile(%f)
            hadd -m $mtxc.hash Icon. $+ $hget($mtxc.hash,Icons) %index %f
            xdid -r $1 23
            xdid -y $1 23
            var %x 1
            while ($hget($mtxc.hash,Icon. $+ %x)) {
              xdid -w $1 23 + $v1
              xdid -a $1 23 0 0 %x %x 0 %x
              inc %x
            }
            if (!$xdid($1,23).sel) { xdid -c $1 23 1 }
    } } } }
    elseif ($3 == 31) { ;Colors - Combo
      xdid -ra $1 32 $rgb($gettok($hget($mtxc.hash,Colors),$xdid($1,$3).sel,32)) 
  } }
  elseif ($2 == close) {
    if ($hget($mtxc.hash,Colors)) { var %colors $v1 }
    if ($hget($mtxc.hash,Background)) { var %background $v1 }
    if ($hget($mtxc.hash,IconDir)) { var %icondir $v1 }
    if ($hget($mtxc.hash)) { hfree $v1 }
    if (%colors) { hadd -m $mtxc.hash Colors %colors }
    if (%background) { hadd -m $mtxc.hash Background %background }
    if (%icondir) { hadd -m $mtxc.hash IconDir %icondir }
    hadd -m $mtxc.hash Style $xdid($1,12).sel
    if ($xdid($1,13).state == 1) { hadd -m $mtxc.hash check13 1 }
    if ($xdid($1,14).state == 1) { hadd -m $mtxc.hash check14 1 }
    if ($xdid($1,15).state == 1) { hadd -m $mtxc.hash check15 1 }
    if ($xdid($1,16).state == 1) { hadd -m $mtxc.hash check16 1 }
    if ($xdid($1,17).state == 1) { hadd -m $mtxc.hash check17 1 }
    if ($xdid($1,20).state == 1) { hadd -m $mtxc.hash check20 1 }
    if ($xdid($1,102).state == 1) { hadd -m $mtxc.hash check102 1 }
    hadd -m $mtxc.hash Transparency $xdid($1,18).sel
    hsave $mtxc.hash $qt($scriptdirMtX-Converter.hsh)
    if ($script(MtXC-Output.mrc)) { .unload -rs MtXC-Output.mrc }
    if ($exists($scriptdirMtXC-Output.mrc)) { .remove $qt($scriptdirMtXC-Output.mrc) }
} }

alias -l mtxc.checker {
  var %d Dia.mtxc
  if ($dialog(%d)) {

    ;MenuName check
    if (!$xdid(%d,101).text) { noop $input(You have to set a Menuname. $crlf $+ With that alias-name you call the XPopup-Menu.,-wo,Menu to XPopup Converter) | halt }
    if ($isalias($xdid(%d,101).text)) && ($nopath($isalias($xdid(%d,101).text).fname) != MtXC-Output.mrc) { noop $input(Use a other menu-name. $crlf $+ That alias name allready exists.,-wo,Menu to XPopup Converter) | halt }
    if ($numtok($xdid(%d,101).text,32) > 1) { noop $input(Use a other menu-name. $crlf $+ "Space" in the name is not supported.,-wo,Menu to XPopup Converter) | halt }

    ;Spacelines delete
    var %x $xdid(%d,2).num
    while (%x >= 1) {
      if (!$remove($xdid(%d,2,%x).text,$chr(32),$chr(160),$chr(10))) { xdid -d %d 2 %x }
      dec %x
    }
    if (!$xdid(%d,2,1).text) && (!$1) { noop $input(There is no Menu-Code which i could generate.,-wo,Menu to XPopup Converter) | halt }

    ;Rewrite Code
    var %x 1
    while (%x <= $xdid(%d,2).num) {
      var %s $xdid(%d,2,%x).text
      noop $regex(Points,%s,/^(?:\+i\d+\s*)?(\.*)\s*[^\.]/)
      noop $regex(Icon,%s,/^(\+i\d+)/)
      noop $regex(Item,%s,/^(?:\+i\d+\s*)?\.*\s*(.+?)\s*:\s*/?/?\s*(.+?)\s*\x0A*\s*$/)
      noop $regex(SubI,%s,/^(?:\+i\d+\s*)?\.*\s*(.+?)\s*\x0A*\s*$/)
      if ($regml(Item,1)) { xdid -o %d 2 %x $regml(Icon,1) $regml(Points,1) $+ $regml(Item,1) : $regml(Item,2) }
      else { xdid -o %d 2 %x $regml(Icon,1) $regml(Points,1) $+ $regml(SubI,1) }
      inc %x
    }
    return $true
} }

alias -l mtxc.generate {
  var %d Dia.mtxc, %mn $xdid(%d,101).text, %ec $xdid(%d,102).state
  if ($dialog(%d)) {
    if (!$mtxc.checker) { return }
    if ($hget($mtxc.hash)) { hdel -w $v1 generate.* }
    if ($script(MtXC-Output.mrc)) { .unload -rs MtXC-Output.mrc }
    if ($fopen(mtxc)) { .fclose mtxc }
    .fopen -o mtxc $qt($scriptdirMtXC-Output.mrc)
    if ($ferr) { return $input(An error occured while writing Xpopup-Code. $crlf $+ Delete MTXC-Output.mrc and try it again.,ow,Menu To Xpopup Converter) }

    ;Menu alias call
    if ($regex(menu,$xdid(%d,2,1).text,/menu\s(.+?)\s\x7B\s*/i)) {
      .fwrite -n mtxc menu $regml(menu,1) $chr(123)
      .fwrite -n mtxc $ $+ %mn $+ ($1-)
      .fwrite -n mtxc $chr(125) $lf
    }

    ;XPopup Alias
    .fwrite -n mtxc alias %mn $chr(123)
    if (%ec) { .fwrite -n mtxc var % $+ MenuName $xdid(%d,101).text }
    .fwrite -n mtxc if ($xpopup( $+ $iif(%ec,% $+ MenuName,%mn) $+ ).ismenu) $chr(123) xpopup -d $iif(%ec,% $+ MenuName,%mn) $chr(125)
    .fwrite -n mtxc xpopup -c $iif(%ec,% $+ MenuName,%mn) $lower($remove($xdid(%d,12).seltext,$chr(32)))
    .fwrite -n mtxc xpopup -p $iif(%ec,% $+ MenuName,%mn) $hget($mtxc.hash,Colors)
    if ($xdid(%d,13).state == 1) || ($xdid(%d,14).state == 1) || ($xdid(%d,15).state == 1) { 
      .fwrite -n mtxc xpopup -x $iif(%ec,% $+ MenuName,%mn) + $+ $iif($xdid(%d,13).state == 1,d) $+ $iif($xdid(%d,14).state == 1,i) $+ $iif($xdid(%d,15).state == 1,p)
    }
    if ($xdid(%d,16).state == 1) { .fwrite -n mtxc xpopup -R $iif(%ec,% $+ MenuName,%mn) +r 1 }
    if ($xdid(%d,17).state == 1) { .fwrite -n mtxc xpopup -R $iif(%ec,% $+ MenuName,%mn) +a $int($calc(255-255/100* $remove($xdid(Dia.mtxc,18).seltext,%))) }
    if ($xdid(%d,20).state == 1) && ($hget($mtxc.hash,Background)) { .fwrite -n mtxc xpopup -b $iif(%ec,% $+ MenuName,%mn) $hget($mtxc.hash,Background) }

    ;Icons
    var %x 1
    while ($hget($mtxc.hash,Icon. $+ %x)) {
      .fwrite -n mtxc xpopup -i $iif(%ec,% $+ MenuName,%mn) +a $iif($mircdir isin $hget($mtxc.hash,Icon. $+ %x),$replace($v2,$mircdir,$ $+ mircdir),$v2)
      inc %x
    }

    menupath reset
    if (%ec) { .fwrite -n mtxc menupath reset }
    var %x $iif($regml(menu,1),2,1), %id 1
    while ($xdid(%d,2,%x).text) {
      if ($v1 != $chr(125)) {
        var %v1 $v1

        ;Style
        noop $regex(Style,%v1,/^(?:\+i\d+\s*)?\.*\s*(.+?)\s*(?::|-|/|$)/)
        if ($+(*,$chr(36),style,$chr(40),*,$chr(41),*) iswm $mtxc.style($regml(style,1))) {
          var %style $replace($v2,$+($chr(36),style,$chr(40),1,$chr(41)),+c,$+($chr(36),style,$chr(40),2,$chr(41)),+g,$+($chr(36),style,$chr(40),3,$chr(41)),+cg)
          var %v1 $remove(%v1,$v2)
        }
        else { var %style + }

        ;Items
        noop $regex(Icon,%v1,/^\+i(\d+)/)
        noop $regex(Points,%v1,/^(?:\+i\d+\s)?(\.*)\s*[^\.]/)
        noop $regex(Item,%v1,/^(?:\+i\d+\s*)?\.*\s*(.+?)\s*:\s*/?/?\s*(.+?)\s*$/)
        noop $regex(SubI,%v1,/^(?:\+i\d+\s*)?\.*\s*(.+?)\s*$/)
        var %points . $+ $regml(Points,1), %icon $iif($regml(Icon,1),$v1,0)
        if ($regml(Item,1)) {
          .fwrite -n mtxc xpop -a $iif(%ec,% $+ MenuName,%mn) $iif(%ec,$!menupath( $+ %points $+ ),$menupath(%points)) $!chr(9) %style %id %icon $regml(Item,1)
          hadd -m $mtxc.hash Generate. $+ %id $regml(Item,2)
          inc %id
        }
        else { .fwrite -n mtxc xpop -a $iif(%ec,% $+ MenuName,%mn) $iif(%ec,$!menupath( $+ %points $+ ),$menupath(%points)) $!chr(9) $iif($regml(SubI,1),$replace(%style,+,+s),%style) 0 %icon $regml(SubI,1) }
      } 
      inc %x
    }
    .fwrite -n mtxc hadd -m System MenuToXpopup $!1-
    .fwrite -n mtxc xpopup -s $iif(%ec,% $+ MenuName,%mn) + $!mouse.dx $!mouse.dy
    .fwrite -n mtxc $chr(125) $lf

    ;XPopup Signal
    .fwrite -n mtxc on *:signal:XPopup- $+ %mn $+ : $chr(123)
    .fwrite -n mtxc var % $+ id $!1
    .fwrite -n mtxc tokenize 32 $!hget(System,MenuToXpopup)
    var %x 1
    while (%x <= $xdid(%d,2).num) {
      if ($hget($mtxc.hash,generate. $+ %x)) { .fwrite -n mtxc $iif(%x == 1,if,elseif) (%id == %x $+ ) $chr(123) $hget($mtxc.hash,generate. $+ %x) $chr(125) }
      inc %x
    }
    .fwrite -n mtxc $chr(125) $lf

    ;$MenuPath
    if (%ec) {
      .fwrite -n mtxc alias -l menupath $chr(123)
      .fwrite -n mtxc if ($1- == reset) $chr(123) hadd -m System Menu 0 $chr(125)
      .fwrite -n mtxc elseif ($hget(System,Menu) != $!null) $chr(123)
      .fwrite -n mtxc hadd System Menu $!iif($len($1) > 1,$gettok($hget(System,Menu),$($+(1-,$calc($len($1) -1)),2),32)) $!calc($gettok($hget(System,Menu),$len($1),32) +1) 0
      .fwrite -n mtxc return $!gettok($hget(System,Menu),1- $!len($1),32)
      .fwrite -n mtxc $chr(125)
      .fwrite -n mtxc return $!false
      .fwrite -n mtxc $chr(125) $lf
    }

    ;Time to generate
    if (%mtxc.generate.time) {
      .fwrite -n mtxc ;### Code generated in $calc($ticks - $v1) $+ ms
      unset %mtxc.generate.time
    }
    .fwrite -n mtxc ;### Menu to XPopup Converter - coded by Flobse $lf
    .fclose mtxc
    hdel -w $mtxc.hash generate.*
    return $true
} }

alias -l mtxc.hash { return XPopup_converter_hash }

alias -l menupath {
  if ($1- == reset) { hadd -m System Menu 0 }
  elseif ($hget(System,Menu) != $null) {
    hadd System Menu $iif($len($1) > 1,$gettok($hget(System,Menu),$($+(1-,$calc($len($1) -1)),2),32)) $calc($gettok($hget(System,Menu),$len($1),32) +1) 0
    return $gettok($hget(System,Menu),1- $len($1),32)
  }
  return $false
}

alias -l mtxc.style {
  var %x 1, %r, %< 0, %> 0, %s
  while (%x <= $len($1)) {
    var %m $mid($1,%x,1)
    if (%m == $chr(36)) || (%s) {
      var %r $+(%r,$iif(%m == $chr(32),$chr(32)),%m)
      if (%m == $chr(40)) { inc %< }
      if (%m == $chr(41)) { inc %> }
      if ((%< == %>) && (%< != 0)) || ((%m == $chr(32)) && (%< == 0)) || (%x == $len($1)) { return %r }
      inc %s
    }
    inc %x
} }

alias envar { ;by FiberOPtics -- mirc.fiberoptics@gmail.com
  var %wsh = wsh $+ $ticks, %tmp = $$1
  .comopen %wsh wscript.shell
  if ($isid) {
    %tmp = $com(%wsh,expandenvironmentstrings,1,bstr*,% $+ $1%)
    %tmp = $com(%wsh).result
  }
  else {
    var %env = env $+ $ticks
    %tmp = $com(%wsh,environment,2,bstr*,process,dispatch* %env)
    %tmp = $iif($0 < 2,$com(%env,remove,1,bstr*,$1),$com(%env,item,4,bstr*,$1,bstr*,$2-))
  }
  :error
  if ($com(%wsh)) .comclose %wsh
  if ($com(%env)) .comclose %env
  if ($isid) && ($+(%,$1,%) !iswm %tmp) return %tmp
}
