aIRC — File Browser

aIRCv0.8.69 / aIRCv0.8.69 / script / ident1.mrc

ident1.mrc — 23.17 KB — Download this file

;/**********************************************************************
; *
; * aIRC
; * Identifiers
; *
; **********************************************************************/
;

;

; $_connected
_connected {
  if (%†connected) && ($server) { return 1 }
  return 0
}

; $_dccignore(filename)
_dccignore {
  if ($dccignore) && ($dccignore($1-)) { return 1 }
  return 0
}

; $_fixfilename(<filename>,[flags])
; If filename is invalid, returns $null
; $1 - Filename
; $2 - flags
;        f - If filename has invalid characters, replace them with "_"
;        n - Don't bother for invalid filenames
;        e - If file doesn't exist, returns $null
;        m - If file isin $mircdir, removes $mircdir
_fixfilename {
  var %file = $1,%flags = $2,%err1 = 0,%err2 = 0
  %file = $remove($replace(%file,/,\),")
  while (\\ isin %file) { %file = $replace(%file,\\,\) }
  if (?:\* iswm %file) {  }
  elseif (?:* iswm %file) { %file = $left(%file,2) $+ \ $+ $right(%file,-2) }
  elseif (\* iswm %file) { %file = $left($mircdir,2) $+ %file }
  else { %file = $mircdir $+ %file }
  if (~ isin %file) && ($longfn(%file) != $null) { %file = $ifmatch }
  if ($len($remove(%file,*,?,<,>,|)) < $len(%file)) || ($count(%file,:) > 1) {
    if (f isincs %flags) { %file = $left(%file,3) $+ $right(%file,-3) }
    elseif (n !isin %flags) { %err1 = 1 }
  }
  if ($nopath(%file) == $null) { %err2 = 1 }
  if (%err1) || (%err2) { return }
  if (e isincs %flags) && ($isfile(%file) == $false) { return }
  if (m isincs %flags) && ($mircdir* iswm %file) { return $remove(%file,$mircdir) }
  return %file
}

_fixdir {
  var %dir = $1,%flags = $2
  %dir = $remove($replace(%dir,/,\),")
  while (\\ isin %dir) { %dir = $replace(%dir,\\,\) }
  if (?:\* iswm %dir) {  }
  elseif (?:* iswm %dir) { %dir = $left(%dir,2) $+ \ $+ $right(%dir,-2) }
  elseif (\* iswm %dir) { %dir = $left($mircdir,2) $+ %dir }
  else { %dir = $mircdir $+ %dir }
  if ($len($remove(%dir,*,?,<,>,|)) < $len(%dir)) || ($count(%dir,:) > 1) { %dir = $left(%dir,3) $+ $right(%dir,-3) }
  if  (%dir == $null) { return }
  if (e isincs %flags) && ($isdir(%dir) == $false) { return }
  if (m isincs %flags) && ($mircdir* iswm %dir) { return $remove(%dir,$mircdir) }
  return %dir
}

; $_icofile(file.ico,dir)
_icofile {
  var %ico,%ico1 = $2 $+ $1,%ico2 = etc\icons\ $+ $1
  if ($2 != $null) && ($isfile(%ico1)) { %ico = %ico1 }
  elseif ($isfile(%ico2)) { %ico = %ico2 }
  else { %ico = etc\airc.ico }
  return $shortfn(%ico)
}

; $_randfile(extension)
_randfile { return $_randstring(21) $+ . $+ $iif($1 != $null,$1,tmp) }

; $_logfile(window)
_logfile {
  var %file
  if (@* iswm $1) { %file = $window($1).logfile }
  elseif (=* iswm $1) { %file = $chat($1).logfile }
  elseif ($_ischan($1)) { %file = $chan($1).logfile }
  else { %file = $query($1).logfile }
  if (%file == $null) { %file = $logdir $+ $mklogfn($1) }
  if ($isfile(%file)) { return %file }
  return
}

; $_getinitopicfromline(file,line)
_getinitopicfromline {
  var %file = $1,%line = $2,%win = @__getinitopicfromline,%i = %line,%fline
  if ($_not($_isint(%line))) || (%line > $lines(%file)) { return }
  _openwins %win
  loadbuf %win %file
  while (%i > 0) {
    %fline = $line(%win,%i)
    if ([?*] iswm %fline) && ($chr(32) !isin %fline) && ($count(%fline,[) == 1) && ($count(%fline,]) == 1) { return $remove(%fline,[,]) }
    dec %i
  }
}

; $_initopic2initopic(from,to,topic)
_initopic2initopic {
  var %f1 = $1,%f2 = $2,%topic = $3,%"f1" = $"(%f1),%"f2" = $"(%f2),%i,%n,%p
  if ($isfile(%f1)) && ($isfile(%f2)) && (%topic != $null) && ($chr(32) !isin %topic) {
    flushini %"f1"
    flushini %"f2"
    remini %"f2" %topic
    if ($ini(%f1,%topic)) {
      %i = 1
      %n = $ini(%f1,%topic,0)
      while (%i <= %n) {
        %p = $ini(%f1,%topic,%i)
        if ($_readini(%f1,%topic,%p) != $null) { writeini %"f2" %topic %p $ifmatch }
        inc %i
      }
    }
    flushini %"f2"
  }
}

; $_logdir(file)
_logdir { return $logdir $+ $1- }

; $_isdir(dir)
_isdir { return $iif($isdir($1-),$1-) }

; $_isfile(file)
_isfile { return $iif($isfile($1-),$1-) }

; $_isdisk(letter)
_isdisk { return $iif($disk($1).type),$1) }

; $_mini(section,item)
_mini { return $readini -n " $+ $mircini $+ " $1 $2 }

; $_minio(n,token)
_minio {
  var %tmp = n $+ $remove($1,n),%tmp = $readini -n " $+ $mircini $+ " options %tmp
  return $gettok(%tmp,$2,44)
}

; $_size(bytes)
_size {
  if ($1 !isnum) || ($1 < 0) { return }
  var %tmp = $bytes($1).suf,%num = $remove(%tmp,b,k,m,g,t)
  if (*mb iswm %tmp) || (*kb iswm %tmp) { return %num $upper($right(%tmp,2)) }
  if (*b iswm %tmp) { return %num bytes }
  return %num $right(%tmp,1) $+ B
}
;;
;
; -( Boolean operators )-
;
;;
;
; /---------------------------------------------------------------\
; | $1  $2 | NOT | AND | OR | XOR | EQV | IMP | NAND | NOR | NXOR |
; |--------+-----+-----+----+-----+-----+-----+------+-----+------|
; | 0   0  |  1  |  0  | 0  |  0  |  1  |  1  |  1   |  1  |  1   |
; | 0   1  |  1  |  0  | 1  |  1  |  0  |  1  |  1   |  0  |  0   |
; | 1   0  |  0  |  0  | 1  |  1  |  0  |  0  |  1   |  0  |  0   |
; | 1   1  |  0  |  1  | 1  |  0  |  1  |  1  |  0   |  0  |  1   |
; \---------------------------------------------------------------/
;
; 0 = $false , 0 , $null
; 1 = anything else
;
;;

_s2b {
  if ($1-) { return 1 }
  return 0
}

_not {
  if ($1-) { return 0 }
  return 1
}
_and {
  if ($1) && ($2) { return 1 }
  return 0
}
_or {
  if ($1) || ($2) { return 1 }
  return 0
}
_xor {
  if ($1) && ($2) { return 0 }
  if ($1) || ($2) { return 1 }
  return 0
}
_eqv {
  if ($1) && ($2) { return 1 }
  if ($1) || ($2) { return 0 }
  return 1
}
_imp {
  ;  return $_or($_not($1),$2)
  if ($2) { return 1 }
  if ($1) { return 0 }
  return 1
}
_nand {
  if ($1) && ($2) { return 0 }
  return 1
}
_nor {
  if ($1) || ($2) { return 0 }
  return 1
}
_nxor {
  if ($1) && ($2) { return 1 }
  if ($1) || ($2) { return 0 }
  return 1
}
;;
;
; -( Text/Strings Identifiers )-
;

; $_echocrap2return(string)
_echocrap2return {
  tokenize 32 $1-
  if ($1 == echo) {
    tokenize 32 $2-
    if (-* iswm $1) { tokenize 32 $2- }
    if ($left($1,1) == $chr(36)) && ($istok(active chan,$right($1,-1),32)) { tokenize 32 $2- }
  }
  return $1-
}

;;
; $_mirc2html(string)
_mirc2html {
  var %line = $_text2html($strip($1-,r)),%i,%left,%char,%right,%tmp,%bold = 0,%und = 0,%colr = 0,%lastspace = 0
  %i = 1
  while ($strip(%line) != %line) && (%i <= $len(%line)) {
    var %tmp,%char = $mid(%line,%i,1)

    if ($strip(%char) == $null) {
      %left = $left(%line,$calc(%i - 1))
      %right = $right(%line,$calc(%i * -1))

      ; colour (ctrl+k)
      if (%char == ) {
        if ($left(%right,1) isnum) {
          var %c1 = $ifmatch,%c2,%text = %right,%sexc = 2,%sext = 3,%sexr = 2
          if ($left(%right,2) isnum) { var %c1 = $ifmatch,%sexc = 3,%sext = 4,%sexr = 3 }
          if ($mid(%right,%sexc,1) == $chr(44)) && ($mid(%right,%sext,1) isnum) {
            inc %sexr 2
            var %c2 = %c1,%c1 = $ifmatch
            if ($mid(%right,%sext,2) isnum) {
              %c1 = $ifmatch
              inc %sexr
            }
            var %colr = 0,%tmp = </FONT><FONT>,%right = $right(%right,$calc(%sexr * -1 + 1))
          }
          else { var %colr = 1,%tmp = </FONT><FONT COLOR="# $+ $base($_mircol2rgbnum(%c1),10,16,6) $+ ">,%right = $right(%right,$calc(%sexr * -1 + 1)) }
        }
        else { var %colr = 0,%tmp = </FONT><FONT> }
      }

      ; bold (ctrl+b)
      elseif (%char == ) {
        if (%bold) { var %tmp = </B>,%bold = 0 }
        else { var %tmp = <B>,%bold = 1 }
      }

      ; underline (ctrl+u)
      elseif (%char == ) {
        if (%und) { var %tmp = </U>,%und = 0 }
        else { var %tmp = <U>,%und = 1 }
      }

      ; cancel (ctrl+o)
      elseif (%char == ) {
        var %tmp
        if (%bold) { %tmp = </B> }
        if (%und) { %tmp = %tmp $+ </U> }
        if (%colr) { %tmp = %tmp $+ </FONT><FONT> }
        var %bold = 0,%und = 0,%colr = 0
      }

      if (%tmp != $null) {
        if (%lastspace) { %line = %left %tmp $+ %right }
        else { %line = %left $+ %tmp $+ %right }
        if ($calc($len(%tmp) - 1)) { inc %i %ifmatch }
      }

      if (%chr == $chr(32)) { %lastspace = 1 }
      else { %lastspace = 0 }

    }
    inc %i
  }
  if (%bold) { %line = %line $+ </B> }
  if (%und) { %line = %line $+ </U> }
  var %bold = 0,%und = 0,%colr = 0
  return <FONT> $+ %line $+ </FONT>
}

; $_text2html(string)
_text2html {
  var %text = $1-
  %text = $replace(%text,&,&amp;,",&quot;,<,&lt;,>,&gt;,©,&copy;,®,&reg;,´,&acute;,«,&laquo;,»,&raquo;,¡,&iexcl;,¿,&iquest;,À,&Agrave;,à,&agrave;,Á,&Aacute;,á,&aacute;,Â,&Acirc;,â,&acirc;,Ã,&Atilde;,ã,&atilde;,Ä,&Auml;,ä,&auml;,Å,&Aring;,å,&aring;,Æ,&AElig;,æ,&aelig;,Ç,&Ccedil;,ç,&ccedil;,Ð,&ETH;,ð,&eth;,È,&Egrave;,è,&egrave;,É,&Eacute;,é,&eacute;,Ê,&Ecirc;,ê,&ecirc;,Ë,&Euml;,ë,&euml;,Ì,&Igrave;,ì,&igrave;,Í,&Iacute;,í,&iacute;,Î,&Icirc;,î,&icirc;,Ï,&Iuml;,ï,&iuml;,Ñ,&Ntilde;,ñ,&ntilde;,Ò,&Ograve;,ò,&ograve;,Ó,&Oacute;)
  %text = $replace(%text,ó,&oacute;,Ô,&Ocirc;,ô,&ocirc;,Õ,&Otilde;,õ,&otilde;,Ö,&Ouml;,ö,&ouml;,Ø,&Oslash;,ø,&oslash;,Ù,&Ugrave;,ù,&ugrave;,Ú,&Uacute;,ú,&uacute;,Û,&Ucirc;,û,&ucirc;,Ü,&Uuml;,ü,&uuml;,Ý,&Yacute;,ý,&yacute;,ÿ,&yuml;,Þ,&THORN;,þ,&thorn;,ß,&szlig;,§,&sect;,¶,&para;,µ,&micro;,¦,&brvbar;,±,&plusmn;,·,&middot;,¨,&uml;,¸,&cedil;,ª,&ordf;,º,&ordm;,¬,&not;,­,&shy;,¯,&macr;,°,&deg;,¹,&sup1;,²,&sup2;,³,&sup3;,¼,&frac14;,½,&frac12;,¾,&frac34;,×,&times;,÷,&divide;,¢,&cent;,£,&pound;,¤,&curren;,¥,&yen;)
  return %text
}

; $_validateurl(string)
_validateurl {
  var %result = $1-,%l,%tmp = $remove($1-,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,1,2,3,4,5,6,7,8,9,0,$chr(32),:,+,-,/,!,\,$chr(36),$chr(37),&,$chr(40),$chr(41),=,[,],$chr(35),^,~,*,.,:,$chr(44),;,\,|,?,_,@,$chr(123),$chr(125))
  if ($len(%tmp) == 0) { return $1- }
  %l = $left(%tmp,1)
  while (%l != $null) && (%tmp != $null) {
    %result = $remove(%result,%l)
    %tmp = $remove(%tmp,%l)
  }
  return %result
}

; $_mircol2rgbnum(0-15)
_mircol2rgbnum {
  var %n = $calc($round($1,0) % 16),%t = n $+ %n,%c = $_readini($mircini,rgb,%t)
  if (%c isnum) { return %c }
  return $gettok($_defrgbs,$calc(%n + 1),44)
}
_defrgbs { return 16777215,0,8323072,37632,255,127,10223772,32764,65535,64512,9671424,16776960,16515072,16711935,8355711,13816530 }

; $_wordisinstring(word,string)
_wordisinstring {
  if ($istok($replace($strip($2-),$chr(44), ,-, ,", ,', ,(, ,), ,[, ,], , ,$chr(32)),$1,32)) { return 1 }
  return 0
}

; $_randstring(length,flags)
;   Flags:
;     n - numbers
;     l - lowercase 
;     u - uppercase
;     c - other ascii characters
_randstring {
  var %i = 1,%n = $1,%flags = $2,%r,%t
  if (%flags == $null) { %flags =  nlu }
  if (n !isin %flags) && (l !isin %flags) && (u !isin %flags) && (c !isin %flags) { return }
  if (%n !isnum) || (%n < 1) { return }
  if (%n > 900) { %n = 900 }
  while (%i <= %n) {
    var %t
    if (n isin %flags) { %t = $rand(1,9) }
    if (l isin %flags) { %t = %t $rand(a,z) }
    if (u isin %flags) { %t = %t $rand(A,Z) }
    if (c isin %flags) { %t = %t $chr($rand(126,255)) }
    %r = %r $+ $_randtok(%t,32)
    inc %i
  }
  return %r
}

; $_randtok(text,C)
_randtok {
  if ($numtok($1,$2)) { return $gettok($1,$rand(1,$ifmatch),$2) }
  return
}

; $_fixmodes(modes)
_fixmodes {
  if ($1 == $null) { return }
  var %r,%i = 1,%t = $len($1),%s = +,%l
  while (%i <= %t) {
    if ($mid($1,%i,1) isin -+) { %s = $ifmatch }
    else { %r = %r $+ %s $+ $mid($1,%i,1) }
    inc %i
  }
  return %r
}

; $_unfixmodes(modes)
_unfixmodes {
  tokenize 32 $_fixmodes($1)
  if ($1 == $null) { return }
  var %i = 1,%l = $len($1),%r,%s = +
  while (%i <= %l) {
    if ($mid($1,%i,1) isin -+) {
      if ($ifmatch != %s) {
        %r = %r $+ $ifmatch
        %s = $ifmatch
      }
    }
    else {
      if (%r == $null) { %r = + }
      %r = %r $+ $mid($1,%i,1)
    }
    inc %i
  }
  if ($remove(%r,-,+) == $null) { return }
  return %r
}

; $_changemodes(originalmodes,+modes-modes)
_changemodes {
  tokenize 32 $1 $_fixmodes($2)
  var %m = $remove($_fixmodes($1),-,+),%i = 1,%t
  while ($mid($2,%i,2) != $null) {
    %t = $ifmatch
    if ($right(%t,1) isincs %m) {
      if ($left(%t,1) == -) { %m = $removecs(%m,$right(%t,1)) }
    }
    elseif ($left(%t,1) == +) { %m = %m $+ $right(%t,1) }
    inc %i 2
  }
  return %m
}

; $_reqchangemodes(originalmodes,newmodes)
_reqchangemodes {
  var %i,%n,%c,%+ = +,%- = -,%r,%1 = $1,%2 = $2
  if (%1 == $null) { var %1 }
  if (%2 == $null) { var %2 }
  %i = 1
  %n = $len(%2)
  while (%i <= %n) {
    %c = $mid(%2,%i,1)
    if (%c !isin -+) && (%c !isincs %1) { %+ = %+ $+ %c }
    inc %i
  }
  %i = 1
  %n = $len(%1)
  while (%i <= %n) {
    %c = $mid(%1,%i,1)
    if (%c !isin -+) && (%c !isincs %2) { %- = %- $+ %c }
    inc %i
  }
  %r = %- $+ %+
  return $_unfixmodes(%r)
}

; $_isactivegroup(#group)
_isactivegroup { return $iif($group($1) == on,1,0) }

; $_defmsg(type,msg)
_defmsg {
  if ($2- != $null) { return $2- }
  elseif ($__defmsg($1,r)) {
    var %file = $__defmsg($1,file),%line
    if ($isfile(%file) == $false) { return }
    %line = $read -n %file
    if (%line != $null) { return %line }
  }
  elseif ($__defmsg($1,text) != $null) { return $ifmatch }
  return
}
__defmsg {
  _rinitxt _msgedit. $+ $1 $+ . $+ $2
  return $result
}

; $_quitmsg(use vars,message)
_quitmsg {
  var %msg = $_evaltext($_defmsg(quit,$2-))
  if ($1) {
    set -u10 %c.quit.reason %msg
    set -u10 %c.quit.i 1
  }
  return %msg
}
_mircquit { return $_quitmsg(1) }

; $_nospaces(text)
_nospaces { return $remove($1-,$chr(32)) }

; $_filleft(N,string,text)
_filleft { return $str($2,$calc($1 - $len($strip($3-)))) $+ $3- }

; $_fillright(N,string,text)
_fillright { return $3- $+ $str($2,$calc($1 - $len($strip($3-)))) }

; $_color(name)
_color { return  $+ $iif($colour($1) < 10,0) $+ $colour($1) }

; $_isupper(letter)
_isupper { return $iif($istok($_uppercase,$1,32),$1) }

; $_islower(letter)
_islower { return $iif($istok($_lowercase,$1,32),$1) }

; $_ischan(channel)
_ischan {
  if ($left($1-,1) isin !#&+) && ($chr(32) !isin $1-) && ($chr(44) !isin $1-) && ($right($1-,-1) != $null) { return $1- }
  return
}

; $_ismail(email)
_ismail {
  if ($1- == $1) && ($count($1,@) == 1) && ($numtok($1,64) == 2) && ($right($1,1) != .) && ($numtok($gettok($1,2,64),46) > 1) && (($right($1,1) isletter) || ($right($1,1) isnum)) { return $1 }
  return
}

; $_isip(ip)
_isip {
  if ($__ishost($1-)) && ($numtok($1,46) == 4) && ($gettok($1,1,46) isnum 0-255) && ($gettok($1,2,46) isnum 0-255) && ($gettok($1,3,46) isnum 0-255) && ($gettok($1,4,46) isnum 0-255) { return $1 }
  return
}


; $_isvalidfilename(filename)
;   Filename may not exists
_isvalidfilename { return $iif((/ !isin $1-) && (\ !isin $1-) && (: !isin $1-) && (* !isin $1-) && (? !isin $1-) && (" !isin $1-) && (< !isin $1-) && (> !isin $1-) && (| !isin $1-),$1-) }


; $_ischanmode(channel,mode)
_ischanmode {
  if ($2- isincs $gettok($chan($1).mode,1,32)) { return 1 }
  return 0
}

; $_bracket(text)
_bracket {
  if ($1- != $null) { return [[ $+ $1- $+ ]] }
  return
}

; $_paren(text)
_paren {
  if ($1- != $null) { return ( $+ $1- $+ ) }
  return
}

; $_text(text)
_text { return $1- }

; $_evaluate(expression)
_evaluate { return [ [ $1- ] ] }

; $_strnumtok(string,tokens,C)
_strnumtok { return $str($1,$numtok($2,$3)) }

; $_singoplur(N,singular,plural)
_singoplur { return $iif($1 == 1,$2,$3) }

; $_nsingoplur(N,singular,plural)
_nsingoplur { return $1 $iif($1 == 1,$2,$3) }

; $_fixchans(channel1,channel2,channel3,...)
_fixchans {
  if ($1- == $null) { return }
  var %t = $replace($1-,$chr(32),$chr(44)),%r,%n = $numtok(%t,44),%i = 1
  while (%i <= %n) {
    tokenize 32 $gettok(%t,%i,44)
    if (@* iswm $1) || (+* iswm $1) || (.* iswm $1) { tokenize 32 $right($1-,-1) }
    %r = $addtok(%r,#$1,44)
    inc %i
  }
  return %r
}

; $_chanevent(event,chan)
;
;   event: joins parts quits modes topics ctcps nicks kicks
;   returns:
;     0 = on channel
;     1 = in status
;     2 = hide
_chanevent {
  var %tc,%tg,%r,%t = $findtok(joins parts quits modes topics ctcps nicks kicks,$1,32)
  if ($2 != $null) && ($_mini(events,$2) != $null) { %tc = $gettok($ifmatch,%t,44) }
  if (%tc > 0) { %r = %tc - 1 }
  else { %r = $gettok($_mini(events,default),%t,44) }
  return %r
}

; $_crypt(string)
_crypt {
  if ($_hook.call(crypt,$1-) != $null) { return $ifmatch }
  return $__crypt($1-)
}

; $_decrypt(crypted string)
;  - $_decrypt($_encrypt(string)) == string
_decrypt {
  if ($_hook.call(decrypt,$1-) != $null) { return $ifmatch }
  return $__decrypt($1-)
}
; aIRC's lame encryption system...
; $__decrypt($__crypt(string)) == string
; The encrypted string is 6 times longer than the normal string
; If you encrypt the same string multiple times, you'll always get different
; encrypted strings, but they will all return the original string when
; decrypted
; This shit needs to be rewritten...
__crypt {
  if ($len($1-) == 0) { return }
  var %t = $len($1-),%i = 1,%r,%_
  while (%i <= %t) { var %_ = $calc($asc($mid($1-,%i,1)) * 3 - 2 + $hash($chr(%i),32) - %i * 3),%_ = $len(%_) $+ $_randstring($calc(5 - $len(%_)),n) $+ %_,%r = %r $+ %_,%i = %i + 1 }
  return %r
}
__decrypt {
  if ($len($1-) == 0) { return }
  if ($1- !isnum) { return }
  var %t = $len($1-),%i = 1,%r,%_,%x,%n,%m,%l
  while (%i <= %t) {
    var %m = $mid($1-,%i,6),%n = $left(%m,1),%l = $right(%m,%n),%x = $calc((%i + 5) / 6),%_ = $calc((%l + 2 - $hash($chr(%x),32) + %x * 3) / 3)
    if (%_ != 032) { %r = %r $+ $chr(%_) }
    else { %r = %r $chr(%_) }
    inc %i 6
  }
  return %r
}

; $_encryptpass(string)
_encryptpass {
  if ($_hook.call(encrypt_pass,$1-) != $null) { return $ifmatch }
  if ($len($1-) == 0) { return }
  return $_hash($1-)
}

; $_hash(string)
_hash { return $hash($1-,32) }

; $_order(string,[1|0])
;   Orders a string of characters.
;   If $2 , removes duplicated characters.
_order {
  if ($1 == $null) { return }
  var %s,%r,%win = @__order
  close -@ %win
  window -hs %win
  var %i = $len($1)
  while (%i) {
    if ($mid($1,%i,1) != $chr(32)) { aline %win $ifmatch }
    dec %i
  }
  var %i = 1,%t = $line(%win,0)
  while (%i <= %t) {
    %s = $line(%win,%i)
    if ($2) { %r = $remove(%r,%s) }
    if (%r == $null) { var %r }
    %r = %r $+ %s
    inc %i
  }
  close -@ %win
  return %r
}

; $_inputcom(chr,string)
_inputcom {
  var %i = 1
  while ($mid($2-,%i,1) == $1) { inc %i }
  return $mid($2-,%i)
}
;;
;
; -( Math Identifiers )-
;
;;

; $_d2h(decimal number)
_d2h { return $base($1,10,16) }

; $_h2d(hex number)
_h2d { return $base($1,16,10) }

; $_d2b(decimal number,[zeropad])
_d2b { return $base($1,10,2,$iif($_isint($2),$2,8)) }

; $_b2d(binary number)
_b2d { return $base($1,2,10) }

; $_percent(number,number,[floating point number],[no "%"])
;   defaults: (floating pont: 0) (Show "%")
_percent { return $iif(($1 == 0) || ($2 == 0) || ($1 !isnum) || ($2 !isnum),0,$round($calc($1 * 100 / $2),$iif(($3 isnum) && ($3 >= 0),$3,0))) $+ $iif($_not($4),%) }

; $_isint(number)
_isint {
  if ($1- isnum) && ($1 > 0) { return $int($1) }
  return
}
; $_fixint(number)
_fixint {
  if ($1- isnum) && ($1 > 0) { return $int($1) }
  return 0
}

; $_round(N,D)
;   125.00 -> 125
;
_round {
  var %n = $round($1,$2)
  if (. isin %n) {
    while ($right(%n,1) != .) {
      if ($ifmatch == 0) { %n = $left(%n,-1) }
      else { return %n }
    }
  }
  if (*. iswm %n) { return $left(%n,-1) }
  return %n
}

;;
;
; -( Time and Date Identifiers )-
;

; $_gmt
_gmt { return $gettok($asctime($ctime,ZZZ),1,32) }

;;
; $_wtimer(mask,N)
;   Returns the Nth matching timer
;   If you specify zero for N, it returns the total number of matching timers
_wtimer {
  var %t = $timer(0),%r
  while (%t) {
    if ($1 iswm $timer(%t)) {
      inc %r
      if (%r == $2) { return $timer(%t) }
    }
    dec %t
  }
  if ($2 == 0) { return %r }
  return
}
; $_dhm2secs(XdXhXm)
; converts 2d3h21m to 184860
_dhm2secs {
  if ($remove($1,d,h,m) isnum) && ($remove($1,d,h,m) > 0) && (*d*h*m iswm $1) && ($count($1,d) == 1) && ($count($1,h) == 1) && ($count($1,m) == 1) {
    var %d = $gettok($1,1,$asc(d))
    var %h = $gettok($gettok($1,1,$asc(h)),2,$asc(d))
    var %m = $gettok($gettok($1,1,$asc(m)),2,$asc(h))
    var %s = $round($calc(%m * 60 + %h * 60 * 60 + %d * 24 * 60 * 60),0)
    if (%s < 0) { return 0 }
    return %s
  }
  return 0
}
_time {
  if ($1 == $null) { tokenize 32 $time }
  if ($numtok($1,58) == 2) { tokenize 32 1/1/70 $1 $+ :00 h:nntt }
  else { tokenize 32 1/1/70 $1 h:nn:sstt }
  return $time($ctime($1-2),$3)
}
__duration {
  if ($1 <= 0) { return 0secs }
  if ($2) && ($gettok($1,2,46) isnum) {
    var %t = $remove($duration($gettok($1,1,46)),secs,sec)
    if ($right(%t,1) isnum) { return %t $+ . $+ $mid($gettok($1,2,46),1,$2) $+ secs }
    else { return %t 0. $+ $mid($gettok($1,2,46),1,$2) $+ secs }
  }
  else { return $duration($round($1,0)) }
  return
}
; $_duration(seconds,[floating point number])
_duration { return $_dateformat.duration($__duration($1,$2)) }
_duratio { return $_dateformat.duratio($__duration($1,$2)) }
_durationosecs {
  var %t = $duration($1)
  if (sec isin $gettok(%t,-1,32)) { %t = $deltok(%t,-1,32) }
  return %t
}
; $_:duration(seconds)
_:duration {
  var %h = 0,%m = 0,%s = 0,%i = $1,%r
  if (%i > 3600) {
    %h = $int($calc(%i / 3600))
    dec %i $calc(%h * 3600)
  }
  if (%i > 60) {
    %m = $int($calc(%i / 60))
    dec %i $calc(%m * 60)
  }
  %s = %i
  if (%m < 10) { %m = 0 $+ %m }
  if (%s < 10) { %s = 0 $+ %s }
  %r = %m $+ : $+ %s
  if (%h) { %r = %h $+ : $+ %r }
  return %r
}
_miniduration { return $remove($duration($1),$chr(32),ks,k,ays,ay,rs,r,ins,in,ecs,ec) }
_minidurationosecs {
  var %t = $duration($1)
  if (sec isin $gettok(%t,-1,32)) { %t = $deltok(%t,-1,32) }
  return $remove(%t,$chr(32),ks,k,ays,ay,rs,r,ins,in,ecs,ec)
}
_lagtime { return $__lagtime($calc(($ticks - $1) / 1000)) }
__lagtime {
  var %t = $1
  if (%t < 1) { return $_duratio($ifmatch,3) }
  elseif (%t < 60) { return $_duratio($ifmatch,2) }
  else { return $_duratio(%t,0) }
  return
}
_asctime {
  tokenize 32 $1-
  if ($1 == $null) { tokenize 32 $ctime $2- }
  if ($1 !isnum) { tokenize 32 $ctime $1- }
  if ($2- == $null) { tokenize 32 $1 $_dateformat.date }
  return $_dateformat.oo($_dateformat.ddd($_dateformat.dddd($_dateformat.mmm($_dateformat.mmmm($asctime($1,$2-))))))
}

_date { return $_asctime($iif($1 isnum,$1,$ctime($1)),$_dateformat.date) }
_shortdate { return $_asctime($iif($1 isnum,$1,$ctime($1)),$_dateformat.shortdate) }
_longdate { return $_asctime($iif($1 isnum,$1,$ctime($1)),$_dateformat.longdate) }
_airctime2ctime {
  if (???????? iswm $1) && ($1 isnum) && (. !isin $1) && (- !isin $1) {
    var %return = 0,%year = $left($1,4),%month = $mid($1,5,2),%day = $right($1,2)
if (%day) { inc %return $calc(%day * 24 * 60 * 60) }
if (%month) { inc %return $calc(%month * 24 * 60 * 60) }
    return %year %month %day
  }
}