rtfm — File Browser

rtfmv1.0 / rtfmv1.0 / rtfm.mrc

rtfm.mrc — 6.14 KB — Download this file

on *:LOAD:if ($version < 6.16) echo $color(info) -a NOTE: your mIRC version is not up to date | rtfm
on *:UNLOAD:if ($input(Unset $+(%,c.*) variables?,y,Confirm cleanup)) unset %c.*
alias -l print {
  ; set colors
  if (%c.main == $null) set %c.main 2
  if (%c.switch == $null) set %c.switch 3
  if (%c.syntax == $null) set %c.syntax 4
  if (%c.id == $null) set %c.id 5
  if (%c.cmd == $null) set %c.cmd 6
  if (%c.prop == $null) set %c.prop 7
  ; different types of output
  if ($1 == +s) echo %c.main $target syntax: $+($chr(3),%c.syntax,$2-,$chr(3))
  elseif ($1 == +c) echo %c.main $target /rtfm: $2-
  elseif ($1 == +p) echo %c.main $target Properties: $+($chr(3),%c.prop,$replace($3-,$chr(44),$+($chr(3),%c.main,$chr(44),$chr(3),%c.prop)),$chr(3))
  ; add syntax highlight to /commands, <parms> [parms], $identifiers, .props, and -switches. 
  else {
    var %str = $1-, %exp = /(\$[a-z0-9!_]+(\([^()]*\))?)/gi
    .echo -q $regsub(%str,%exp,$chr(3) $+ %c.id $+ \1 $+ $chr(3),%str)
    %exp = /([^a-z]|^)(\.[a-z]+)/gi
    .echo -q $regsub(%str,%exp,\1 $+ $chr(3) $+ %c.prop $+ \2 $+ $chr(3),%str)
    .echo -q $regsub(%str,/((\s|^)\/\S+|<[^<>]+>|\[[^\[\]]+\])/g,$chr(3) $+ %c.cmd $+ \1 $+ $chr(3),%str)
    .echo -q $regsub(%str,/((\s|^)-[a-z0-9\[\]#]+\s)/gi,$chr(3) $+ %c.switch $+ \1 $+ $chr(3),%str)
    %exp = / $+ $chr(3) $+ \d{0,2}(,\d{0,2})? $+ $chr(3) $+ /g
    .echo -q $regsub(%str,%exp,$chr(3),%str)
    .echo -q $regsub(%str,/ $+ $chr(3) $+ 7(\.(bmp|txt|ini|host))/g,\1,%str)
    echo %c.main $target %str
  }
}
alias rtfm {
  var %type = $iif($left($1,1) == /,cmd,$iif($left($1,1) == $,id,$iif($left($1,2) == on,event,*)))
  tokenize 32 $remove($1-,$,/)
  if (%type == event) && ($1 == on) tokenize 32 $2-
  if ($isid) return $null
  if ($2 isalpha) tokenize 32 $1 1 $2
  ; initial information.
  if ($1 == $null) {
    print explanation for dummies
    print +s /rtfm <query> [N] [group]
    print parameter: $+($chr(2),query,$chr(2)) - search string (wildcards allowed).
    print parameter: $+($chr(2),N,$chr(2)) - optional, display the Nth match.
    print parameter: $+($chr(2),group,$chr(2)) - optional, search within this group only.
    print example: /rtfm *tok 3 tokens
    print -
    return 1
  }
  ; fails if rtfm.db is not found.
  var %db = $+($scriptdir,rtfm.db), %group = $iif($3,$3,*)
  if (!$isfile(%db)) { print +c unable to locate %db | return 0 }
  ; process switches
  if ($regex($1,/-([lceduh])/i)) {
    ; list groups
    if ($regml(1) === l) {
      .echo -q $read(%db,s,#GROUPS)
      var %i = $readn + 1, %n, %m
      while ($read(%db, %i) != -EOF-) {
        %m = $ifmatch
        if (%m != $null) { inc %n | print $+($chr(35),$base(%n,10,10,2),:) %m }
        inc %i
      }
      print -
    }
    ; color dialog, enable/disable popup, unload
    elseif ($regml(1) === c) dialog -m rtfm rtfm
    elseif ($regml(1) === d) if ($group(#rtfm_menu) == on) .disable #rtfm_menu
    elseif ($regml(1) === e) if ($group(#rtfm_menu) == off) .enable #rtfm_menu
    elseif ($regml(1) === u && $input(Unload rtfm.mrc?,y,Confirm removal) == $true) unload -rs $script
    return 1
  }
  ; calculate N and were to read from the db.
  var %n = $iif($2 isnum 1-,$2,1), %t, %i = 1, %a = 1
  while ($read(%db, wn, $+(%type,:,$1,:,%group,:*), %i)) {
    inc %t
    var %i = $readn + 1
    if (%t == %n) %a = $readn
  }
  if (%n > %t) var %a = %i - 1
  ; start reading and output information + syntax.
  if ($read(%db, wn, $+(%type,:,$1,:,%group,:*), %a)) {
    var %i = $readn + 1
    tokenize 58 $ifmatch
    var %type = $replace($1,cmd,command,id,identifier,pre,prefix,suf,suffix)
    print $iif(%t > 1,match $+($chr(35),$iif(%n > %t,%t,%n),/,%t,:),match:) $+($chr(2),$2,$chr(2),$chr(32),$chr(40),%type,$chr(44),$chr(32),$3,$chr(41))
    print +s $iif($istok(event prefix suffix,%type,32),$replace($4-,;,:),$4-)
    ; keep reading until 'end' is returned.
    while ($true) {
      var %data = $read(%db, n, %i)
      if (%data == end) break
      if (%data) print $iif($gettok(%data,1,32) == Properties:,+p) %data
      else print $chr(160)
      inc %i
    }
    print -
  }
  else print +c no matches found on: $1 $iif($3 isalpha,in group $+(",$3,"))
  print -
}
; dialog table
dialog rtfm {
  title "/rtfm - Colors"
  size -1 -1 122 89
  option dbu
  box "", 1, 3 1 116 85
  list 2, 10 11 52 50, size
  combo 3, 67 11 45 49, size drop
  button "OK", 4, 10 67 30 12, ok
  button "Default", 5, 46 67 30 12
  button "Cancel", 6, 82 67 30 12, cancel
}
; dialog event
on *:DIALOG:rtfm:*:*:{
  if ($devent == init) {
    did -a $dname 2 main = $iif(%c.main == $null,2,%c.main)
    did -a $dname 2 switches = $iif(%c.switch == $null,3,%c.switch)
    did -a $dname 2 syntax = $iif(%c.syntax == $null,4,%c.syntax)
    did -a $dname 2 identifiers = $iif(%c.id == $null,5,%c.id)
    did -a $dname 2 commands = $iif(%c.cmd == $null,6,%c.cmd)
    did -a $dname 2 properties = $iif(%c.prop == $null,7,%c.prop)
    var %i = 0
    while (%i <= 15) {
      did -a $dname 3 color: %i
      inc %i
    }
  }
  if ($devent == sclick) {
    if ($did == 2) did -c $dname 3 $calc($gettok($did(2).seltext,3,32) + 1)
    elseif ($did == 3 && $did(2).seltext != $null) {
      did -o $dname 2 $did(2).sel $gettok($did(2).seltext,1,32) = $gettok($did(3).seltext,2,32)
    }
    elseif ($did == 4) {
      set %c.main $gettok($did(2,1),3,32)
      set %c.switch $gettok($did(2,2),3,32)
      set %c.syntax $gettok($did(2,3),3,32)
      set %c.id $gettok($did(2,4),3,32)
      set %c.cmd $gettok($did(2,5),3,32)
      set %c.prop $gettok($did(2,6),3,32)
    }
    elseif ($did == 5) {
      did -r $dname 2
      did -u $dname 3
      did -a $dname 2 main = 2
      did -a $dname 2 switches = 3
      did -a $dname 2 syntax = 4
      did -a $dname 2 identifiers = 5
      did -a $dname 2 commands = 6
      did -a $dname 2 properties = 7
    }
  }
}
; popups
#rtfm_menu on
menu menubar,channel,query,status {
  -
  /rtfm
  .<execute /rtfm>:if ($input(Enter search:,e,/rtfm)) rtfm $!
  .<list groups>:rtfm -l
  .<set colors>:rtfm -c
  .-
  .<disable popup>:rtfm -d
  .<unload rtfm.mrc>:rtfm -u
}
#rtfm_menu end
; eof