Peace & Protection 4.00 — File Browser

PeaceProtection4.00v4.0 / PeaceProtection4.00v4.0 / SCRIPT / ALIASES.MRC

ALIASES.MRC — 27.97 KB — Download this file

; #= P&P -a
; **********************
; Unsorted routines
; **********************

;;;###*** Not yet divided ***###;;;

; Pass one or more file extensions, returns wildcard mask matching all (or *)
_glurp {
  tokenize 32 $1-
  if ($2 == $null) return $1
  var %n = 2,%min = $len($1),%max = $len($1),%tot = $numtok($1-,32)
  :len
  if ($len($ [ $+ [ %n ] ] ) > %max) %max = $ifmatch
  if ($len($ [ $+ [ %n ] ] ) < %min) %min = $ifmatch
  if (%n < %tot) { inc %n | goto len }
  var %ch = 1,%done
  :out
  var %n = 2,%bit = $mid($1,%ch,1)
  :in
  if ($mid($ [ $+ [ %n ] ] ,%ch,1) == %bit) {
    if (%n < %tot) { inc %n | goto in }
    %done = %done $+ %bit
  }
  else %done = %done $+ ?
  if (%ch < %min) { inc %ch | goto out }
  if (%ch < %max) %done = %done $+ *
  if ($remove(%done,?,*) == $null) return *
  return %done
}

; Randomer than $r()? returns 1 to n given
_pprand return $calc(($r(1,$1) + $ticks) % $1 + 1)

; Used before writing and after reading an INI to allow control codes (same as 3.x formats)
_writeprep if ($1 == $null) return | return $replace($1-,,$chr(141),,$chr(142),,$chr(143),,$chr(144),,$chr(157))
_readprep if ($1 == $null) return | return $replace($1-,$chr(141),,$chr(142),,$chr(143),,$chr(144),,$chr(157),)

; $_colorword(n)
_colorword return $gettok(white black blue green red brown purple orange yellow lt.green cyan lt.cyan lt.blue pink grey lt.grey,$calc($1 % 16 + 1),32)

; $_isbot(nick)
_isbot return $istok(%!servnick,$1,32)
; $_chanbot(#chan) returns nothing if none found
_chanbot var %num = $numtok(%!servnick,32) | :loop | if ($gettok(%!servnick,%num,32) ison $1) return $ifmatch | if (%num > 1) { dec %num | goto loop }
; $_isserv(type)
_isserv return $istok(%!serv,$1,44)


;
; Internal timers
;

_tut.on .timer.internal -o 0 10 _internal.timer | .timer.titleupd -o 0 1 _upd.title
_internal.timer {
  _aa.chk
  if (*last.mrc !iswm $script($script(0))) _screload
}
_screload {
  if ($exists(script\last.mrc) == $false) halt
  _progress.1 Script load detected...
  _progress.2 0 Reordering PnP scripts...
  .unload -rs " $+ $script(rawdisp.mrc) $+ "
  .unload -rs " $+ $script(last.mrc) $+ "
  _progress.2 33 Reordering PnP scripts...
  .load -rs "script\rawdisp.mrc"
  _progress.2 66 Reordering PnP scripts...
  .load -rs "script\last.mrc"
  _progress.2 100 Reordering of scripts complete!
}

;
; generic flood prot-
; $_genflood(var,on,max,secs)
; stores in var %$1, returns value hit (>1) if flood, else 0
; flood is defined as $3 within $4 secs; $2 = flood prot on/off
;
_genflood {
  tokenize 32 $1-
  if (($2) && ($3)) {
    inc -u [ $+ [ $4 ] ] % $+ $1
    if (% [ $+ [ $1 ] ] >= $3) return $ifmatch
  }
  return 0
}

;
; Basic identifiers
;

; evaluates and returns
_eval return $1-

; performs (mainly for recursion)
_recurse $1- | return $result

; perform without abort (errors will not halt script) although without return value
_blackbox .timer.blackbox 1 1 _unkludge $replace($1-,$chr(32),ย) | .timer.blackbox -e

; perform using timer, to allow $?/$dialog/$dir; remember to $! identifiers, etc, and that it doesn't halt the script
_juryrig .timer -om 1 0 $1-

; Same as _juryrig but w/o reevaluation (except, first word MUST be a command, not some var or ident etc)
_juryrig2 .timer -om 1 0 _unkludge $replace($1-,$chr(32),ย)
_unkludge $replace($1-,ย,$chr(32))

; Lines up commands, doing max one per second.
_linedance if ($timer(.line.dance) == $null) { write -c $_temp(ld) $1- | _dolinedance 1 } | else write $_temp(ld) $1-
_dolinedance if ($read -nl [ $+ [ $1 ] ] $_temp(ld) != $null) { .timer.line.dance -m 1 $calc((4 - $gettok(3 2 1,$1,32)) * 500) _dolinedance $calc($1 + 1) | $ifmatch } | else .remove $_temp(ld)

; returns same (converts 0/1/blah/$null/$true/$false to 1/0)
_tf return $iif($1,1,0)
; returns opposite
_not return $iif($1,0,1)
; If $1 isin $2, removes it, otherwise adds it. If $1 == $2, returns 0 (zero)
_toggle if ($1 == $2) return 0 | if ($1 isin $2) return $remove($2,$1) | else return $2 $+ $1

;
; is... identifiers
;

_isaddr if ((@ isin $1) && (! isin $1) && (. isin $1)) return 1 | return 0
_ischan if ($left($1,1) isin +&#) return 1 | return 0
_ismask if ((* isin $1) || (? isin $1)) return 1 | return 0

;
; Channel identifiers
;

; adds # to channel name(s) if not present
_patch {
  var %ret = $1,%num = $numtok($1,44)
  :loop
  if ($left($gettok($1,%num,44),1) !isin +&#) if ($gettok($1,%num,44) != 0) if ($chr(35) $+ $ifmatch) %ret = $puttok(%ret,$ifmatch,%num,44)
  if (%num > 1) { dec %num | goto loop }
  return %ret
}

;
; Text identifiers
;

; replaces spaces with ctrl+bksp
_s2p return $replace($1-,$chr(32),)
; replaces ctrl+bksp with spaces
_p2s return $replace($1-,,$chr(32))
; replaces spaces with chr 160
_s2f return $replace($1-,$chr(32),ย )
; replaces chr 160 with spaces
_f2s return $replace($1-,ย ,$chr(32))
; Capitalizes first letter, leaves rest alone
_cap1st return $upper($left($1,1)) $+ $right($1,-1)
; Makes a number exactly two digits
_cprep if ($1 < 10) return 0 $+ $calc($1 + 0) | return $right($1,2)
; Commas to spaces
_c2s return $replace($1-,$chr(44),$chr(32))
; Spaces to commas
_s2c return $replace($1-,$chr(32),$chr(44))
; Spaces to comma+space
_s2cs if ($1 == $null) return | var %s2cs | %s2cs = , $+ $chr(160) | return $_f2s($replace($1-,$chr(32),%s2cs))

;
; Userhost queueing
;

; _Q.userhost command errorcmd nick1 nick2 ...
; command is _s2p; any number of nicks can be given (will break up into sets of 5)
; command is run for each nick replacing &n with nick &a with address &h with +/- for here/away
; errorcmd is _s2p and run if none of the nicks resolve (can be 'halt')
_Q.userhost {
  var %num = 0
  :loop
  if (5 // %num) {
    .raw userhost $3-7
    if (%num) {
      inc %-uhq.add
      %-uhq. [ $+ [ %-uhq.add ] ] = *
    }
  }
  inc %-uhq.add
  %-uhq. [ $+ [ %-uhq.add ] ] = $3 $1-2
  if ($4) {
    tokenize 32 $1-2 $4-
    inc %num
    goto loop
  }
  inc %-uhq.add
  %-uhq. [ $+ [ %-uhq.add ] ] = *
}
; User-requested userhost
userhost {
  if ($1) {
    if ($show) {
      disps Looking up userhost of $:l($1-)
      _Q.userhost _showUH&n&a&h&i dispsUser&nnotfound $_c2s($1-)
    }
    else _Q.userhost return return $_c2s($1-)
  }
  else _qhelp /userhost
}
_showUH disps Userhost of $:t($1) - $:s($2) (user is $iif($3 == +,not) away) $iif($4,(IRCop))

; Hostmask lookup
host {
  if (@ isin $1) {
    if ($2 isnum) disp Hostmask (type $:s($2) $+ ) of $:t($gettok($1,1,33)) is- $:s($_ppmask($1,$_stmasku($2)))
    else disp Hostmask of $:t($gettok($1,1,33)) is- $:s($_ppmask($1,$_stmasku(3)))
  }
  elseif ($1) {
    tokenize 32 $_nc($1) $2-
    if ($address($1,5)) _recurse host $address($1,5) $2
    elseif ($2 isnum) {
      disp Looking up type $:s($2) hostmask of $:t($1) $+ ...
      _Q.userhost host&n!&a $+ $2 dispUser $+ $:t($1) $+ notfound $1
    }
    else {
      disp Looking up hostmask of $:t($1) $+ ...
      _Q.userhost host&n!&a dispUser $+ $:t($1) $+ notfound $1
    }
  }
  else _qhelp /host
}

;
; File commands
;

edit {
  if ($1 isin -n) run notepad $2-
  elseif ($1 isin -w) run wordpad $2-
  elseif ($1 isin -l) viewlog $2-
  else run notepad $1-
}
viewlog {
  var %log = $1
  if ($1 == $null) %log = $gettok($active,1,32)
  if (=* iswm %log) %log = $right(%log,-1)
  %log = $logdir $+ $_renlogfile(%log)
  if ($exists(%log)) run notepad " $+ %log $+ "
  else dispa Log file ' $+ $:s(%log) $+ ' does not exist!
}
dellog {
  var %log = $1
  if (%log == $null) %log = $gettok($active,1,32)
  if (=* iswm %log) %log = $right(%log,-1)
  remove " $+ $logdir $+ $_renlogfile(%log) $+ "
}

; _remove filename
; Deletes file and displays note on success or failure
_remove {
  if ($exists($1-)) {
    .remove " $+ $1- $+ "
    if ($exists($1-)) disp File ' $+  $1- $+ ' could not be deleted
    else disp File ' $+  $1- $+ ' has been deleted
  }
  else disp File ' $+ $1- $+ ' does not exist
}

;
; Window identifiers
;

; _targ(types) where types is one or more of =?#
; returns active window name (minus = for dcc chat) if it is of the proper type else nothing
_targ {
  if (($_ischan($active)) && ($chr(35) isin $1)) return #
  if ((=* iswm $active) && (= isin $1)) return $remove($active,=)
  if (($query($active)) && (? isin $1)) return $active
  return
}
_isopen {
  if (-* iswm $1) return 1
  elseif ($left($1,1) isin +&#) return $iif($chan($1),1,0)
  elseif (=* iswm $1) return $iif($chat($remove($1,=)),1,0)
  elseif (@* iswm $1) return $iif($window($1),$true,$false)
  elseif ($query($1)) return 1
  return 0
}
; $_center(width,height[,desk[,xadd,yadd]])
; xadd/yadd are added to final offsets (mainly for use with -f)
; if desk is present and true, calculated as desktop window
_center return $int($calc(($window($iif($3,-1,-3)).w - $1) / 2 + [ $4 ] )) $int($calc(($window($iif($3,-1,-3)).h - $2) / 2 + [ $5 ] )) $1 $2
; $_winpos(top,bottom,left,right)
; Returns position and size for a window with padding in percents, nondesktop
_winpos return $int($calc($window(-3).w * $3 / 100)) $int($calc($window(-3).h * $1 / 100)) $int($calc($window(-3).w * (100 - $3 - $4) / 100)) $int($calc($window(-3).h * (100 - $1 - $2) / 100))
; loadbuf using base color and verifying file exists
_loadbuf if ($exists($2-)) loadbuf -c [ $+ [ $:d ] ] $1 " $+ $2- $+ "

;
; Dynamic popup identifiers
;

; $_dynpop(1) or $_dynpopn(0) returns a 'mark'; opposite returns a 'blank'; $_dynpopf returns a blank always
;;; make changable
_dynpop if ($1) return %`popupmark | return $iif($os == Win3.x,$chr(160),$str($chr(160),2))
_dynpopn if ($1) { return $iif($os == Win3.x,$chr(160),$str($chr(160),2)) } | return %`popupmark
_dynpopf return $iif($os == Win3.x,$chr(160),$str($chr(160),2))

;
; Tabbed underlines
;

; $_ultab(4,5,2,3) etc returns tab-seperated sets of lines 4,5,etc widw
_ultab {
  var %pos = 1,%curr,%line = %`horizline
  :loop
  if ($ [ $+ [ %pos ] ] == $null) return %curr
  %curr = $instok(%curr,$str(%line,$ [ $+ [ %pos ] ] ),0,9)
  inc %pos
  goto loop
}

;
; F-Key queueing
;
; _Q.fkey 0/1 expiretime cmd
; returns name of fkey used
; 0 = prefer F7; 1 = prefer F10
_Q.fkey {
  var %index = 1,%set = $iif($iif($1 == $_cfgi(reserve.fkey),$calc(1 - $1),$1),214365,123456)
  :loop
  if (($isalias($gettok(f7-f10-sf7-sf10-cf7-cf10,$mid(%set,%index,1),45)).alias == $3-) || (%!key.exp. [ $+ [ $mid(%set,%index,1) ] ] < $ctime)) {
    %!key.exp. [ $+ [ $mid(%set,%index,1) ] ] = $2
    alias $gettok(f7-f10-sf7-sf10-cf7-cf10,$mid(%set,%index,1),45) $3-
    return $gettok(F7-F10-ShiftF7-ShiftF10-CtrlF7-CtrlF10,$mid(%set,%index,1),45)
  }
  if (%index < 6) {
    inc %index
    goto loop
  }
  unset %!key.exp.?
  %!key.exp. [ $+ [ $left(%set,1) ] ] = $2
  alias $gettok(f7-f10,$left(%set,1),45) $3-
  return $gettok(F7-F10,$left(%set,1),45)
}
; Clears fkey queue
_Q.fkey.clr alias f7 halt | alias sf7 halt | alias cf7 halt | alias f10 halt | alias sf10 halt | alias cf10 halt

;
; Userlevel/address identifiers
;

; $_level(#channel,levels)
_level var %level = $chr(44) $+ = $+ $1ยฌ | if (%level isin $2) return $gettok($mid($2,$calc($pos($2,%level,1) + $len(%level)),$len($2)),1,44) | else return $gettok($2,1,44)

; $_chanlevel(#channel,levels)
; same as $_level except returns null if a channel doesn't have a spec level.
_chanlevel var %level = $chr(44) $+ = $+ $1ยฌ | if (%level isin $2) return $gettok($mid($2,$calc($pos($2,%level,1) + $len(%level)),$len($2)),1,44)

; $_leveledit(#channel,levels[,new]) (leave off new to remove; #channel can be *)
_leveledit {
  if ($1 == *) return $puttok($2,$iif($3 == $null,$dlevel,$3),1,44)
  var %replace = = $+ $1ยฌ $+ $3,%match = = $+ $1ยฌ*
  if ($3 == $null) {
    if ($wildtok($2,%match,1,44)) return $remtok($2,$ifmatch,1,44)
    return $2
  }
  if ($wildtok($2,%match,1,44)) return $reptok($2,$ifmatch,%replace,1,44)
  return $addtok($2,%replace,44)
}

; $_stmask(n)
; standard masks 0-9 converted to A B C format for $_ppmask (or returns A B C if passed ABC)
; (this uses ban mask settings)
_stmask if ($len($1) > 1) return $left($1,1) $mid($1,2,1) $right($1,1) | else return $iif($1 < 5,0,1) $iif($1 isin 2468,0,$iif($1 isin 05,1,%`ban.id)) $iif($1 isin 012567,1,%`ban.dom)

; (this uses user mask settings)
_stmasku if ($len($1) > 1) return $left($1,1) $mid($1,2,1) $right($1,1) | else return $iif($1 < 5,0,1) $iif($1 isin 2468,0,$iif($1 isin 05,1,%`mask.id)) $iif($1 isin 012567,1,%`mask.dom)

; default user mask
_usermask return $_ppmask($1,0,%`mask.id,%`mask.dom)
; default ban mask
_banmask return $_ppmask($1,0,%`ban.id,%`ban.dom)

; $_fixmask(addr)
; Standardizes to *!*@* format
_fixmask {
  if ($1 == $null) return
  if (*!*@* iswm $1) return $1
  if (@ isin $1) return *! $+ $1
  if (! isin $1) return $1@*
  if (. isin $1) return *!*@ $+ $1
  return $1!*@*
}

; $_ppmask(nick/address,A,B,C[,x])
; returns formatted user address mask
; if nick is given, uses ial. (RETURNS NULL if ial doesn't have user)
; if asterisks are already present in nick or domain, mask is left UNTOUCHED. (except fixed to a!b@c form)
; if partial address given, returned in a!b@c form UNTOUCHED. (missing parts as *) Only works if nickname has wildcards or parts are missing
; type is in ABC - A is nick, B is identd, C is domain - 0 is *, 1 is full, 2 is *identd or *.domain.com; 3 is *identd if ~+-^=, identd otherwise
; example "pool044-max3.mpop2-ca-us.dialup.earthlink.net" (2 is "*.earthlink.net" and the minimum)
; domain 3 wildcards the first section only "*.mpop2-ca-us.dialup.earthlink.net"
; domain 4 wildcards everything until the last number "*-ca-us.dialup.earthlink.net"
; domain 5 wildcards everything until a section that contains a number "*.dialup.earthlink.net"
; domain 6 wildcards all numbers "pool*-max*.mpop*-ca-us.dialup.earthlink.net"
; numeric ips always produce #.#.#.*
; if x is present will return matching entry from userlist if fulladdress/nick given and match found
_ppmask {
  tokenize 32 $1-
  if ($3 == $null) tokenize 32 $1 $_stmask($2)
  if (* isin $1) {
    if ((*!*@* !iswm $1) || (* isin $gettok($1,1,33))) return $_fixmask($1)
    if ((* isin $gettok($gettok($1,2-,64),1-,42)) || ($remove($gettok($1,2-,64),*,?,.) == $null)) return $_fixmask($1)
    return $1
  }
  if (((! isin $1) || (. isin $1) || (@ isin $1)) && (*!*@* !iswm $1)) return $_fixmask($1)
  if (! isin $1) return $_ppmaskยฒ($1,$2,$3,$4,$5)
  if ($1 == $me) return $_ppmaskยฒ(%!myself,$2,$3,$4,$5)
  if ($address($1,5) == $null) return
  return $_ppmaskยฒ($address($1,5),$2,$3,$4,$5)
}
_ppmaskยฒ {
  if ($5) { if ($_fuser($1)) return $ifmatch }
  var %nick = $gettok($1,1,33),%dom = $gettok($1,$numtok($1,64),64),%ident = $mid($1,$calc($len(%nick) + 2),$calc($len($1) - $len(%dom) - $len(%nick) - 2))
  if ($2 == 0) %nick = *
  if ($4 == 0) %dom = *
  elseif (($4 > 1) && (($longip(%dom) != $null) || (($longip($gettok(%dom,1-3,46)) != $null) && ($gettok(%dom,4-,46) isin ***)))) %dom = $gettok(%dom,1-3,46) $+ .*
  elseif (($4 == 2) || ($4 == 3)) {
    var %dots = $count(%dom,.)
    if (*.us iswm %dom) dec %dots 2
    elseif (((. isin $right(%dom,3)) && (. isin $left($right(%dom,7),4))) || (*.mil iswm %dom) || (*.gov iswm %dom)) dec %dots
    if (%dots >= 2) %dom = *. $+ $iif($4 == 2,$gettok(%dom, [ %dots $+ ] -,46),$gettok(%dom,2-,46))
  }
  elseif ($4 > 3) {
    var %dots = 1- $+ $calc($count(%dom,.) - 1),%dots2 = $count(%dom,.) $+ -
    %dom = $replace($gettok(%dom,%dots,46),0,*,1,*,2,*,3,*,4,*,5,*,6,*,7,*,8,*,9,*) $+ . $+ $gettok(%dom,%dots2,46)
    if (* isin %dom) {
      if ($4 == 4) %dom = * $+ $gettok(%dom,$numtok(%dom,42),42)
      elseif ($4 == 5) %dom = *. $+ $gettok(~ [ $+ [ $gettok(%dom,$numtok(%dom,42),42) ] ] ,2-,46)
      else %dom = $iif($left(%dom,1) == *,*) $+ $gettok(%dom,1-,42)
    }
  }
  if ($3 == 0) %ident = *
  else {
    %ident = $replace(%ident,*,?)
    var %ident2 = %ident,%num = $len(%ident2)
    :loop
    if ($asc($mid(%ident2,%num,1)) !isnum 33-126) %ident2 = $replace(%ident2,$mid(%ident2,%num,1),?)
    if (%num > 1) { dec %num | goto loop }
    if (($3 > 1) && ($left(%ident2,1) isin -=+^~)) %ident2 = * $+ $mid(%ident2,2,$len(%ident2))
    elseif ($3 == 2) %ident2 = * $+ %ident2
    if ($len(%ident2) > 10) %ident2 = $left(%ident2,9) $+ *
    if ($4 == 0) %num = 4
    elseif ($calc($len(%dom) * 2) <= $gettok($1,$numtok($1,64),64)) %num = 3
    elseif (* isin %dom) %num = 2
    else %num = 1
    if ($len($remove(%ident2,*,?)) >= %num) %ident = %ident2
  }
  return %nick $+ ! $+ %ident $+ @ $+ %dom
}

;
; Filename identifiers
;

; $_add.ext(ext,filename)
; Adds . and extension to filename if it doesn't already have it
_add.ext if (. !isin $2-) return $2- $+ . $+ $1 | return $2-

; $_rel.fn(filename)
; If filename is relative to $mircdir, removes $mircdir
_rel.fn if ($mircdir isin $1-) return $remove($1-,$mircdir) | return $1-

; $_truename.fn(filename without quotes)
; Adds drive and/or mIRC directory to filename if missing
; Assumes c:blah is c:\blah
_truename.fn {
  if (?:* iswm $1) {
    if ($mid($1,3,1) != \) return $left($1,2) $+ \ $+ $right($1-,-2)
    return $1-
  }
  if (\* iswm $1) return $left($mircdir,2) $+ $1-
  return $mircdir $+ $1-
}

; $_cfg(filename)
; Returns filename in the config directory of the current user
_cfg return config\ $+ %!user $+ \ $+ $1-

; $_temp(ext)
; Returns filename in temp dir, in xxx.ext format
_temp return script\temp\ $+ %!ext $+ . $+ $1

; $_cfgi(item) $_dlgi(item) $_cfgx(sec,item)
; Returns item from config.ini of current user
_cfgi return $readini -n config\ $+ %!user $+ \config.ini cfg $1
_dlgi return $readini -n config\ $+ %!user $+ \config.ini dlg $1
_cfgx return $readini -n config\ $+ %!user $+ \config.ini $1 $2

; _cfgw|_dlgw item value _cfgxw sec item value
; Writes item to config.ini of current user
_cfgw if ($2 != $null) writeini config\ $+ %!user $+ \config.ini cfg $1 $2- | else remini config\ $+ %!user $+ \config.ini cfg $$1
_dlgw if ($2 != $null) writeini config\ $+ %!user $+ \config.ini dlg $1 $2- | else remini config\ $+ %!user $+ \config.ini dlg $$1
_cfgxw if ($3 != $null) writeini config\ $+ %!user $+ \config.ini $1 $2 $3- | else remini config\ $+ %!user $+ \config.ini $1 $$2

; $_renlogfile(window)
; Returns log file for window (without directory)
_renlogfile {
  if ($window($1).logfile) return $nopath($window($1).logfile)
  if ($os == Win3.x) {
    var %len = $len($1-),%rlf = $1-,%chr
    :loop
    %chr = $mid(%rlf,%len,1)
    if (%chr !isin abcdefghijklmnopqrstuvwxyz_0123456789) %rlf = $replace(%rlf,%chr,_)
    if (%len > 1) { dec %len | goto loop }
    if ($_ischan($1)) %rlf = $left($1,1) $+ $right(%rlf,-1)
    %rlf = $left(%rlf,8)
  }
  else {
    var %rlf = $_repl.fn($1-)
    if ($_optn(3,4)) %rlf = %rlf $+ $date(_yyyymmdd)
  }
  return %rlf $+ .log
}

; $_repl.fn(filename)
; Replaces \/:?"<>|*^ characters with _ (win95/NT standards)
_repl.fn return $replace($1-,\,_,/,_,:,_,?,_,",_,<,_,>,_,|,_,*,_,^,_)

; $_gen.id(string)
; Generates an id containing up to eight uppercase alphas; you need to ensure uniqueness for purpose
_gen.id {
  ; Generate profile id
  var %id = $remove($1-,$chr(32)),%num = $len(%id)
  :loop
  if ($mid(%id,%num,1) !isletter) %id = $replace(%id,$mid(%id,%num,1),_)
  if (%num > 1) { dec %num | goto loop }
  %id = $upper($left($remove(%id,_),8))
  if (%id == $null) return PNP
  return %id
}

;
; Misc startup
;

_mischash {
  .enable #^*
  .disable #_*
  %!pager = $_cfgi(back.pager)
  %!logging = 0
  %!title = $_cfgi(title.here)
  .ial on
  .ignore -r **!**@**
  _recclr dccget
  remini config\ $+ %!user $+ \config.ini e
  .serverlist
  if ($_cfgi(away.dq)) .dqwindow off
}

;
; Sync'd variable settings (reloading and sync'ing)
;

_rehash {
  unset %`*
  window -hl @.rehash
  loadbuf @.rehash $_cfg(cfgvar.dat)
  :loop | if ($line(@.rehash,1) != $null) { set %` $+ $ifmatch | dline @.rehash 1 | goto loop }
  window -c @.rehash
}
; `set varname [value]
; varname should not include the %`
`set {
  if (%` [ $+ [ $1 ] ] == $2-) return
  %` [ $+ [ $1 ] ] = $2-
  if ($2- != $null) write -s [ $+ [ $1 ] ] config\ $+ %!user $+ \cfgvar.dat $1-
  else write -ds [ $+ [ $1 ] ] config\ $+ %!user $+ \cfgvar.dat
  _broadcastp _`set $1
}
;;; workaround needed until such time that dde can be set to not reevaluate
_`set %` [ $+ [ $1 ] ] = $read -nts [ $+ [ $1 ] ] config\ [ $+ [ %!user ] $+ [ \cfgvar.dat ] ]
; `lset works like `set but doesn't propogate using DDE
`lset {
  if (%` [ $+ [ $1 ] ] == $2-) return
  %` [ $+ [ $1 ] ] = $2-
  if ($2- != $null) write -s [ $+ [ $1 ] ] config\ $+ %!user $+ \cfgvar.dat $1-
  else write -ds [ $+ [ $1 ] ] config\ $+ %!user $+ \cfgvar.dat
}

;
; Dynamic aliases/identifiers- used for colors, markup, display, fkey queue, version number+patches
; ($:ver is version with patches/etc, $:bver is base version number)
;

; The color/markup identifiers which don't (currently) change
:i if ($1) return  $+ $_cprep($colour(norm)) $+ $1- $+  | return  $+ $_cprep($colour(norm))
:ihn {
  var %tok,%str = $1-,%num = $numtok($1-,32)
  :loop
  if ($gettok(%str,%num,32) isnum) { %tok = $:s($gettok(%str,%num,32)) $+ $_cprep($colour(norm)) | %str = $puttok(%str,%tok,%num,32) }
  if (%num > 1) { dec %num | goto loop }
  return $:i(%str)
}
:mc return  $+ $_cprep($colour($1)) $+ $2- $+ 
; Update color/markup/display identifiers/cmds with current scheme (config\*\display.dat)
_upd.markup {
  window -hl @.markup
  loadbuf 1-22 @.markup $_cfg(display.dat)

  ; Color/markup identifiers
  alias :d return $_cprep($line(@.markup,3))
  alias :s return  $+ $_cprep($line(@.markup,4)) $!+ $!1- $!+ 
  alias :h return  $+ $_cprep($line(@.markup,5)) $!+ $!1- $!+ 
  alias :w if ($1) return  $+ $_cprep($line(@.markup,6)) $!+ $!1- $!+  $chr(124) return  $+ $_cprep($line(@.markup,6))
  alias :b return $line(@.markup,8) $!+ $!1- $!+ $line(@.markup,9)
  alias :t return  $+ $_cprep($line(@.markup,4)) $+ $line(@.markup,8) $!+ $!1- $!+  $+ $line(@.markup,9)
  alias :l var % $+ colcma $chr(124) % $+ colcma =  $+ $line(@.markup,9) $+ ,  $+ $_cprep($line(@.markup,4)) $+ $line(@.markup,8) $chr(124) return  $+ $_cprep($line(@.markup,4)) $+ $line(@.markup,8) $!+ $!replace($_s2c($1-),$chr(44),%colcma) $!+  $+ $line(@.markup,9)
  alias :c return $line(@.markup,12) $+  $+ $_cprep($line(@.markup,4)) $!+ $!1- $!+  $+ $line(@.markup,13)
  alias :cl return $line(@.markup,12) $+  $+ $_cprep($line(@.markup,4)) $!+ $!lower($1-) $!+  $+ $line(@.markup,13)
  alias :n return $line(@.markup,12) $+  $+ $_cprep($line(@.markup,4)) $+ $line(@.markup,8) $!+ $!1- $!+ $line(@.markup,9) $+  $+ $line(@.markup,13)
  alias :wq return $line(@.markup,10) $+  $+ $_cprep($line(@.markup,5)) $!+ $!replace($1-,, $+ $_cprep($line(@.markup,5)) $+ ) $!+  $+ $line(@.markup,11)
  alias :[ return $line(@.markup,14)
  alias :] return $line(@.markup,15)
  alias :q return  $+ $_cprep($line(@.markup,5)) $+ $line(@.markup,16) $!+ $!1- $!+ $line(@.markup,17) $+ 
  alias :x return $line(@.markup,19)
  alias :y return $line(@.markup,20)
  alias :z return $line(@.markup,21)
  alias :+ return $line(@.markup,22)
  alias :* return $line(@.markup,18)

  ; Line seperator
  _upd.line

  ; Display commands
  var %disp = if ((@* iswm $!active) && ($active != @Info)) disps $!1- $chr(124) else $chr(123) % $+ _last.disp = $!1- $chr(124) echo $line(@.markup,3)
  var %disp2 = $line(@.markup,18) $!1- $chr(125)
  alias disp %disp $_cfgi(eroute) $+ qt %disp2
  alias dispa %disp -qtai2 %disp2
  alias disps % $+ _last.disp = $!1- $chr(124) echo $line(@.markup,3) -qtsi2 $line(@.markup,18) $!1-
  %disp = if ($1 == -si2) disps $!2- $chr(124) elseif ($1 == -ai2) dispa $!2- $chr(124) elseif ($_isopen($1)) $chr(123) % $+ _last.disp = $!2- $chr(124) echo $line(@.markup,3) -qti2 $!1 $line(@.markup,18) $!2- $chr(125) $chr(124) else
  alias dispr %disp disp $!2-
  alias disprs %disp disps $!2-

  if ($::: == $null) {
    alias disp-div return
    alias dispa-div return
    alias disps-div return
    alias dispr-div return
    alias disprs-div return
  }
  else {
    if ($_cfgi(eroute) == -si2) alias disp-div return $!disps-div | else alias disp-div return $!dispa-div
    alias dispa-div if ((@* iswm $!active) && ($active != @Info)) return $!disps-div $chr(124) elseif ($::: !isin $!line($active,$line($active,0))) $chr(123) echo $line(@.markup,3) -qtai2 $line(@.markup,18) $!ifmatch $chr(124) return 1 $chr(125) $chr(124) return 0
    alias disps-div if ($::: !isin $!line(Status Window,$line(Status Window,0))) $chr(123) echo $line(@.markup,3) -qtsi2 $line(@.markup,18) $!ifmatch $chr(124) return 1 $chr(125) $chr(124) return 0
    %disp = if ($1 == -si2) return $!disps-div $chr(124) elseif ($1 == -ai2) return $!dispa-div $chr(124) elseif ($_isopen($1)) $chr(123) if ($::: !isin $!line($1,$line($1,0))) $chr(123) echo $line(@.markup,3) -qti2 $!1 $line(@.markup,18) $!ifmatch $chr(124) return 1 $chr(125) $chr(124) else return 0 $chr(125) $chr(124) else return
    alias dispr-div %disp $!disp-div
    alias disprs-div %disp $!disps-div
  }

  ; Cleanup
  window -c @.markup
}
; Update line seperator
_upd.line {
  var %dat = $read -ntl23 $_cfg(display.dat)
  if ($gettok(%dat,1,32) == a) alias ::: return $_cfade($replace($gettok(%dat,4-,32),$chr(32),.),$str($gettok(%dat,3,32),$gettok(%dat,2,32)))
  elseif (%dat == b) alias ::: return
  else alias ::: return $gettok(%dat,2-,32)
}

; Display commands that arent 'dynamic'
_alert {
  _title.note $_p2s($1)
  if ($1 == SELFLAG) _ssplay selflag
  elseif ($1 == FLOOD) _ssplay attacked
  else _ssplay otheralert
  echo $iif(((@* iswm $active) && ($active != @Info)),-si2,-ai2) $:i $+ , $+ [ $read -tl7 $_cfg(display.dat) ] $+ $timestamp *** $strip($2-,c) *** 
}
_pecho if (-* iswm $1) echo $:d $1qti2 $2- | else echo $:d -qti2 $1-
_cecho if (-* iswm $2) echo $1 $2qti2 $3- | else echo $1 -qti2 $2-

; Dynamic 'aliases'
;;; fix :ver in non beta
:bver return 4.00
:ver return 4.00 FINAL BETA
:d return 02
:s return 01 $+ $1- $+ 
:h return 14 $+ $1- $+ 
:w if ($1) return 05 $+ $1- $+  | return 05
:b return  $+ $1- $+ 
:t return 01 $+ $1- $+ 
:l var %colcma | %colcma = , 01 | return 01 $+ $replace($_s2c($1-),$chr(44),%colcma) $+ 
:c return [01 $+ $1- $+ ]
:cl return [01 $+ $lower($1-) $+ ]
:n return [01 $+ $1- $+ ]
:wq return ยซ14 $+ $replace($1-,,14) $+ ยป
:[ return -[
:] return ]-
:q return 14' $+ $1- $+ '
:x return ยข
:y return (w)
:z return (s)
:+ return ย  >
:* return 12โ€ข2โ€ข1โ€ข
::: return 12ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท2ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท1ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท14ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท15ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท
disp if ((@* iswm $active) && ($active != @Info)) disps $1- | else { %_last.disp = $1- | echo 02 -ai2qt 12โ€ข2โ€ข1โ€ข $1- }
dispa if ((@* iswm $active) && ($active != @Info)) disps $1- | else { %_last.disp = $1- | echo 02 -qtai2 12โ€ข2โ€ข1โ€ข $1- }
disps %_last.disp = $1- | echo 02 -qtsi2 12โ€ข2โ€ข1โ€ข $1-
dispr if ($1 == -si2) disps $2- | elseif ($1 == -ai2) dispa $2- | elseif ($_isopen($1)) { %_last.disp = $2- | echo 02 -qti2 $1 12โ€ข2โ€ข1โ€ข $2- } | else disp $2-
disprs if ($1 == -si2) disps $2- | elseif ($1 == -ai2) dispa $2- | elseif ($_isopen($1)) { %_last.disp = $2- | echo 02 -qti2 $1 12โ€ข2โ€ข1โ€ข $2- } | else disps $2-
disp-div return $dispa-div
dispa-div if ((@* iswm $active) && ($active != @Info)) return $disps-div | elseif ($::: !isin $line($active,$line($active,0))) { echo 02 -qtai2 12โ€ข2โ€ข1โ€ข $ifmatch | return 1 } | return 0
disps-div if ($::: !isin $line(Status Window,$line(Status Window,0))) { echo 02 -qtsi2 12โ€ข2โ€ข1โ€ข $ifmatch | return 1 } | return 0
dispr-div if ($1 == -si2) return $disps-div | elseif ($1 == -ai2) return $dispa-div | elseif ($_isopen($1)) { if ($::: !isin $line($1,$line($1,0))) { echo 02 -qti2 $1 12โ€ข2โ€ข1โ€ข $ifmatch | return 1 } | else return 0 } | else return $disp-div
disprs-div if ($1 == -si2) return $disps-div | elseif ($1 == -ai2) return $dispa-div | elseif ($_isopen($1)) { if ($::: !isin $line($1,$line($1,0))) { echo 02 -qti2 $1 12โ€ข2โ€ข1โ€ข $ifmatch | return 1 } | else return 0 } | else return $disps-div
f7 halt
sf7 halt
cf7 halt
sf10 halt
cf10 halt