alias asciiview {
  if ($window(@Logviewer) == $null) { window -moabel15 @asciiview 30 50 500 300 @asciiview Courier New 10 }
  else { clear -l @asciiview }
  window -nls @Loglist Courier New 10
  aline -l @asciiview ASCII :
  set %logview.num 1
  :loop
  set %logview.log $findfile(ascii ,*.txt,%logview.num)
  if (%logview.log == $null) { goto part2 }
  aline -l @Loglist $nopath(%logview.log)
  inc %logview.num 1
  goto loop
  :part2
  set %logview.total $line(@Loglist,0,0)
  set %logview.num 1
  :loop2
  if (%logview.num > %logview.total) { goto end }
  aline -l @asciiview $line(@Loglist,%logview.num)
  inc %logview.num 1
  goto loop2
  :end
  aline @asciiview End log listing.
  window -c @Loglist
  unset %logview.num %logview.log $logview.total
}
alias logview.viewlog {
  if ($1 != $null) {
    set %logview.temp $1 $+ .txt
    set %logview.file $logdir $+ %logview.temp
    if ($exists(%logview.file)) {
      set %nameof.currentlog %logview.temp
      asciiview
      clear @asciiview
      aline @asciiview Viewing %logview.temp ( $+ $file(%logview.file).size bytes):
      titlebar @asciiview ( $+ %logview.temp $+ )
      loadbuf -p @asciiview %logview.file
      sline @asciiview 20
      halt
    }
  }
  if (($sline(@asciiview,1).ln == 1) || ($sline(@asciiview,1) == $null)) { halt }
  set %logview.file Ascii\ $+ $sline(@asciiview,1)
  set %nameof.currentlog $sline(@asciiview,1)
  clear @asciiview
  aline @asciiview Viewing  $+ $sline(@asciiview,1) ( $+ $file(%logview.file).size bytes):
  titlebar @asciiview ( $+ $sline(@asciiview,1) $+ )
  loadbuf -p @asciiview %logview.file
  sline @asciiview 20
  unset %logview.file
}
alias -l logview.search {
  if (%nameof.currentlog == $null) { aline @asciiview 4Error!  You must view a log first. | halt }
  if ($window(@IDTLogsearch) == $null) { window -moabel @IDTLogsearch 150 150 450 300 @IDTLogsearch Verdana 12 }
  else { /clear @IDTLogsearch }
  set %logview.file $logdir $+ %nameof.currentlog
  titlebar @IDTLogsearch ( $+ %nameof.currentlog $+ )
  set %logview.searchstring * [ $+ [ $$?="Text to search for?" ] $+ ] *
  aline @IDTLogsearch Searching %nameof.currentlog for %logview.searchstring 
  aline @IDTLogsearch [#]____________[Text]________________________________________
  filter -fwnp %logview.file @IDTLogsearch %logview.searchstring
  unset %logview.*
}
alias -l logview.gotoline {
  if (($sline(@IDTLogsearch,1).ln == 1) || ($sline(@IDTLogsearch,1).ln == 2) || ($sline(@IDTLogsearch,1).ln == $null)) { halt }
  sline @asciiview $calc($gettok($sline(@IDTLogsearch,1),1,32) + 2)
  window -a @asciiview
}
alias -l logview.delete {
  if (($sline(@asciiview,1).ln == 1) || ($sline(@asciiview,1) == $null)) { halt }
  set %logview.total $sline(@asciiview,0)
  set %logview.num 1
  :loop
  if (%logview.num > %logview.total) { goto mid }
  set %logview.files %logview.files $sline(@asciiview,%logview.num) $+ ,
  inc %logview.num | goto loop
  :mid
  set %logview.filen $calc($len(%logview.files) - 1)
  set %logview.files $left(%logview.files,%logview.filen)
  set %logview.yesno $$?!="Do you want to delete these files ( $+ %logview.files $+ )?"
  if (%logview.yesno) {
    set %logview.num 1
    :loop2
    if (%logview.num > %logview.total) { goto end }
    set %logview.file $logdir $+ $sline(@asciiview,%logview.num)
    if (%nameof.currentlog == $sline(@asciiview,%logview.num)) { clear @asciiview | unset %nameof.currentlog }
    .remove %logview.file
    inc %logview.num 1 | goto loop2
  }
  :end
  unset %logview.*
  asciiview
}
alias -l logview.copy {
  if (($sline(@asciiview,1).ln == 1) || ($sline(@asciiview,1) == $null)) { halt }
  set %logview.total $sline(@asciiview,0)
  set %logview.num 1
  :loop
  if (%logview.num > %logview.total) { goto mid }
  set %logview.files %logview.files $sline(@asciiview,%logview.num) $+ ,
  inc %logview.num | goto loop
  :mid
  set %logview.filen $calc($len(%logview.files) - 1)
  set %logview.files $left(%logview.files,%logview.filen)
  set %logview.yesno $$?!="Do you want to copy these files ( $+ %logview.files $+ )?"
  if (%logview.yesno) {
    set %logview.dir $$sdir="Select a directory to copy to:"
    set %logview.num 1
    :loop2
    if (%logview.num > %logview.total) { goto end }
    set %logview.file $logdir $+ $sline(@asciiview,%logview.num)
    if (%nameof.currentlog == $sline(@asciiview,%logview.num)) { clear @asciiview | unset %nameof.currentlog }
    copy %logview.file [ %logview.dir ] $+ $sline(@asciiview,%logview.num)
    inc %logview.num 1 | goto loop2
  }
  :end
  unset %logview.*
  asciiview
}
alias -l logview.rename {
  if (($sline(@asciiview,1).ln == 1) || ($sline(@asciiview,1) == $null)) { halt }
  set %logview.total $sline(@asciiview,0)
  set %logview.num 1
  :loop
  if (%logview.num > %logview.total) { goto mid }
  set %logview.files %logview.files $sline(@asciiview,%logview.num) $+ ,
  inc %logview.num | goto loop
  :mid
  set %logview.filen $calc($len(%logview.files) - 1)
  set %logview.files $left(%logview.files,%logview.filen)
  set %logview.yesno $$?!="Do you want to rename these files ( $+ %logview.files $+ )?"
  if (%logview.yesno) {
    set %logview.num 1
    :loop2
    if (%logview.num > %logview.total) { goto end }
    set %logview.file Ascii\ $+ $sline(@asciiview,%logview.num)
    if (%nameof.currentlog == $sline(@asciiview,%logview.num)) { clear @asciiview | unset %nameof.currentlog }
    rename Ascii\ $+ $sline(@asciiview,%logview.num) Ascii\ $+ $$?="Please enter a new file name for $sline(@asciiview,%logview.num) $+ :"
    inc %logview.num 1 | goto loop2
  }
  :end
  unset %logview.*
  asciiview
}
alias -l logview.notepad {
  if (($sline(@asciiview,1).ln == 1) || ($sline(@asciiview,1) == $null)) { halt }
  set %logview.total $sline(@asciiview,0)
  set %logview.num 1
  :loop
  if (%logview.num > %logview.total) { goto end }
  set %logview.file Ascii\ $+ $sline(@asciiview,%logview.num)
  run notepad.exe %logview.file
  inc %logview.num
  goto loop
  :end
  unset %logview.*
  asciiview
}
alias logview.diffus {
  if ($1 != $null) {
    set %logview.temp $1 $+ .txt
    set %logview.file $logdir $+ %logview.temp
    if ($exists(%logview.file)) {
      set %nameof.currentlog %logview.temp
      play logview.file
      halt
    }
  }
  if (($sline(@asciiview,1).ln == 1) || ($sline(@asciiview,1) == $null)) { halt }
  set %logview.file Ascii\ $+ $sline(@asciiview,1)
  set %nameof.currentlog $sline(@asciiview,1)
  /play %diffascii  %logview.file 1500
  unset %logview.file
}
menu @asciiview {
  dclick logview.viewlog $sline(@asciiview,1)
  Diffuser au channel ou au pseudo : {
    logview.diffus
  }  
  List des ascii:/asciiview
  Voir:/logview.viewlog $sline(@asciiview,1)
  Copier:/logview.copy
  Effacer:/logview.delete
  Renommer:/logview.rename
  Ouvrir l'ascii dans notepad:/logview.notepad
  Remettre à zero:/clear @asciiview
  Fermer:/window -c @asciiview
}
menu @IDTLogsearch {
  dclick /logview.gotoline
  Goto line:/logview.gotoline
  Close:/window -c @IDTLogsearch
  ReSearch:/logview.search
}

on *:CLOSE:@asciiview: { unset %nameof.currentlog }
on 1:UNLOAD: { unset %nameof.currentlog %logview.* }
