mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Sep 2006
Posts: 43
M
Ameglian cow
OP Offline
Ameglian cow
M
Joined: Sep 2006
Posts: 43
First Thank you Horstl for the script
I would like to chang a thing or 2 about the script (well prob not change the script but mor like have a aliases) I tried but failed many times to do it.
Here is how I would like to change or have an aliases for I want to be able to right click on status(or anywhere) and click searchlogs a prompt will come up and i type name ie peter and it will automatically make the file name peter too so i don't need to type peter as the name and peter as the file name right now I type /logsearch peter peter I did ask for this cause i may need a different File name at some point but for now i just need the name i put in to be the file name.


I hope i explained it right


Thank you

Code:
alias logsearch {
  if (!$2) { echo -a Insufficient parameters. Syntax: /logsearch matchword filename(without .txt) }
  else {
    var %matchword = $1, %lognum = $findfile($logdir,*.*,0)
    echo -ga Looking up %lognum logfiles for $qt($1) ....
    window -h @logfilter
    window -h @logbuffer
    noop $findfile($logdir,*.*,0,logfilter $shortfn($1-) %matchword)
    window -c @logbuffer
    if ($line(@logfilter,1)) {
      if (!$isdir($qt($+($mircdir,logsearch)))) { mkdir $qt($+($mircdir,logsearch))) }
      filter -wfc @logfilter $qt($+($mircdir,logsearch\,$2,.txt))
      run $qt($+($mircdir,logsearch\,$2,.txt))
    }
    else { echo -ga Sorry, found no matches of $qt(%matchword) in your %lognum logfiles. }
    window -c @logfilter
  }
}

alias -l logfilter {
  filter -fwn $1 @logbuffer $+(*,$2 ,*)
  if ($filtered) {
    aline @logfilter $str(-,20) File $longfn($1) : $v1 $iif(($v1 == 1),match,matches) of $qt($2) $+ : $str(-,20)
    filter -ww @logbuffer @logfilter
    aline @logfilter $chr(9)
    clear @logbuffer
  }
}

Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Code:
menu status {
  -
  searchlogs : logsearch $gettok($$input(Enter word to search for:,eog,Search logfiles for a word (wildcard search)),1,32) $mkfn($gettok($!,1,32))
}


A more basic command would be { logsearch $$?=prompt1 $$?=prompt2 }. You get the prompt via $input or $?, the double $$ skips the whole process if you don't enter anything in the input box, or click the close box.
I added a gettok to play safe, cause the script was made for a single search word and single filename, but the input box allows you to enter more words.
The $! used at the end simply repeats the previous input, thus it's passing the same paramter twice to the alias: first for "searchword" and second for "filename".
$mkfn replaces chars that may not be part of filenames (like " or /) with an underscore.


Here's a more complex (and first of all: chunky), altered draft of the search script, pulled out of the basement, which I left for a while. It has many flaws and it's ignoring the whole "different output filenames" thingie (writing to a search_results.txt over and over), thus useless to you, I suppose smile
Anyway:
Code:
Logsearch 0.3  --- Horstl ---

alias logsearch {
  ; • no parameters given: echo help •
  if (!$1) {
    if (!$isid) {
      echo -gi5a LOGSEARCH
      echo -gi5a Command syntax: /logsearch [-acpq] <matchword or -term> [target]
      echo -gi5a The -c switch makes the search case sensitive.
      echo -gi5a The -p switch will result in a plain text search for matchword / -term. If you don't use the switch, $&
        a normal wildcard search for *word* or "*the term*" will be performed. 
      echo -gi5a $str($chr(160),4) Note: The matchword / -term may contain wildcards (? or *) in itself. $&
        Using the -p switch will result in a literal search for these chars.
      echo -gi5a Instead of a single matchword, the -q switch allows to specify a (complex) term (use quotation marks arround the expression).
      echo -gi5a $str($chr(160),4) Note: The Wildcard * will not exceed word boundaries if applied to a matchword. $&
        But it will do, if applied to a term (which may again be a single word)
      echo -gi5a To check all logs, use "all" for target or the -a switch.
      echo -gi5a If you dont specify a target, the active window is taken as target. The Target may contain wildcards.
    }
    return 
  }

  ; • switches •
  elseif ($regex($1,/(^-[acqp])/i)) {
    var %ls.switch = $regsubex($1,/([^acqp])/gi,$null)
    tokenize 32 $2-
    if (c isletter %ls.switch) { set -e %ls.cs true }
    if (p isletter %ls.switch)  { set -e %ls.plain true }
    if (q isletter %ls.switch) { 
      set -e %ls.quote true
      ; check term range (leading/trailing quotation marks)
      if ($left($1,1) != $chr(34)) { 
        if (!$isid) {
          echo -ga Logsearch: No starging quotation mark found. $&
            (If using the -q flag, you have to enclose the search term in double quotation marks.)
        }
        return
      }
      if ($right($gettok($1-,-1,32),1) == $chr(34)) {
        set %ls.target $active
        set -e %ls.term $noqt($1-)
      }
      elseif ($right($gettok($1-,-2,32),1) == $chr(34)) {
        set %ls.target $gettok($1-,-1,32)
        set -e %ls.term $noqt($gettok($1-,1- $calc($0 -1),32))
      }
      else { 
        if (!$isid) {
          echo -ga Logsearch: No final quotation mark found. $&
            (If using the -q flag, you have to enclose the search term in double quotation marks.)
        }
        unset %ls.*
        return
      }
    }
  }

  if (!%ls.term) { set -e %ls.term $1 }
  if (a isletter %ls.switch) { set %ls.target all }
  if (!%ls.target) { set %ls.target $iif(($2),$v1,$active) }
  ; status window compatiblility (the only $target with spaces, doh)
  set -e %ls.target $gettok(%ls.target,1,32)

  ; search init message
  var %reg = $iif((%ls.target != all),$+(/\W[?:,$chantypes,]?\Q,$replacexcs($regsubex(%ls.target,$+(^,$chr(40),$chantypes,$chr(41)),$null),*,\E.*\Q,?,\E.\Q,\E,\E\\E\Q),\E\..*log/i))
  var %wild = $+($iif((%ls.target != all),$+(*,%ls.target)),*.log)
  var %lognum = $findfile($logdir,*.log,0), %loopnum = $findfile($logdir,%wild,0)
  if (%loopnum > 0) {
    if (!$isid) {
      echo -ga Looking up $iif((%ls.target == all),all %lognum logfiles,aprox. %loopnum logfiles $&
        $iif((%ls.target != $gettok($active,1,32)),matching target $qt(%ls.target),of $active) (total: %lognum logs)) for the $iif((%ls.quote),term,word) $qt(%ls.term) $&
        $+($chr(40),$iif((%ls.cs),$+(case sensitive,$chr(32))),$iif((!%ls.plain),wildcard,plaintext) search,$chr(41))
    }
  }
  else {
    if (!$isid) {
      if (%ls.target == all) { echo -ga No logfile found! }
      else { echo -ga No logfile $iif((%ls.target != $gettok($active,1,32)),of $qt(%ls.target),for $active) found! }
    }
    unset %ls.*
    return 0,0,0 no target
  }

  ; • search routine •
  set %ls.checkfiles 0
  window -h @logfilter
  window -h @logbuffer
  noop $findfile($logdir,%wild,0,logfilter $shortfn($1-) %ls.term %reg)
  window -c @logbuffer

  ; • matches •
  if ($line(@logfilter,1)) {
    if (!$isid) {
      ; • file output •
      var %file = $qt($+($scriptdir,search_results.txt))
      iline @logfilter 1 $chr(9)
      iline @logfilter 1 $str(=,65)
      iline @logfilter 1 Total found: %ls.matches $iif((%ls.matches == 1),match,matches) in %ls.matchfiles $iif((%ls.matchfiles == 1),file,files)
      iline @logfilter 1 $+($iif((%ls.cs),$+(case sensitive,$chr(32))),$iif((!%ls.plain),wildcard,plaintext)) search $&
        for the $iif((%ls.quote),term,word) $qt(%ls.term) in $iif((%ls.target == all),all %lognum logfiles,the %ls.checkfiles logfiles $&
        $iif((%ls.target != $gettok($active,1,32)),matching target $qt(%ls.target),of $active) (total: %lognum logs)) 
      iline @logfilter 1 $str(=,25) $upper(search result) $str(=,25) 
      filter -wfc @logfilter %file

      ; window output
      echo -ga Found %ls.matches $iif((%ls.matches == 1),match,matches) of the $iif((%ls.quote),term,word) $qt(%ls.term) $&
        $+($chr(40),$iif((%ls.cs),$+(case sensitive,$chr(32))),$iif((!%ls.plain),wildcard,plaintext) search,$chr(41)) in $&
        %ls.matchfiles $iif((%ls.matchfiles == 1),file,files) of $iif((%ls.target == all),all %lognum logs,the %ls.checkfiles logfiles $&
        $iif((%ls.target != $gettok($active,1,32)),matching target $qt(%ls.target),of $active) (total: %lognum logs)) $+ .

      .timer 1 1 run %file
    }
    ; • id output •
    else {
      var %return = $+(%ls.checkfiles,$chr(44),%ls.matchfiles,$chr(44),%ls.matches)
      window -c @logfilter
      unset %ls.*
      return %return
    }
  }
  ; • no matches •
  else {
    if (!$isid) {
      echo -ga Found no matches of the $iif((%ls.quote),term,word) $qt(%ls.term) $&
        $+($chr(40),$iif((%ls.cs),$+(case sensitive,$chr(32))),$iif((!%ls.plain),wildcard,plaintext) search,$chr(41)) in $&
        $iif((%ls.target == all),all %lognum logfiles,the %ls.checkfiles logfiles $&
        $iif((%ls.target != $gettok($active,1,32)),matching target $qt(%ls.target),of $active) (total: %lognum logs)) $+ .
    }
    else {
      window -c @logfilter
      var %return = $+(%ls.checkfiles,$chr(44),0,$chr(44),0) no match
      unset %ls.*
      return %return
    }
  }
  window -c @logfilter
  unset %ls.*
}

alias -l logfilter {
  if ((%ls.target == all) || ($regex($nopath($longfn($1)),$gettok($3-,-1,32)))) {
    inc %ls.checkfiles
    if (%ls.plain) { filter -fwng $1 @logbuffer $+(/,(?:\s|^)\Q,$replacexcs(%ls.term,\E,\E\\E\Q),\E(?:\s|$),/,$iif((!%ls.cs),i)) }
    else { filter -fwng $1 @logbuffer $+(/,\Q,$replacexcs(%ls.term,*,$+(\E,$iif((%ls.quote),.*,\S*),\Q),?,\E.\Q,\E,\E\\E\Q),\E,/,$iif((!%ls.cs),i)) }
    if ($filtered) {
      inc %ls.matchfiles
      inc %ls.matches $v1
      aline @logfilter $str(-,20) File $longfn($1) : $v1 $iif(($v1 == 1),match,matches) of $qt(%ls.term) $+ : $str(-,12)
      filter -ww @logbuffer @logfilter
      aline @logfilter $chr(9)
      clear @logbuffer
    }
  }
}

/*
Notes:
Findfile loop cycles all files with a wildcard match "%wild" of target, the reg "%reg" is checking these files for a more consistant match.
Thus, the initial echo (=findfile) returns an aprox. file number, the second (= regexcheck and filtering the looped files) the exact number of logs matching.
Example, looking for "target":
- findfile loop will find all *target*.log files     
- inside the loop, the reg-check proceeds, passing: target.log, #target.log, <somestamp>.#target.log, traget.<somestamp>.log etc while
- not passing the reg: target<moretext>.log, ##target.log, OLD.#target.log etc
Note: if using wildcards for the target, e.g. "*target*", the logs "skipped" in the example above will be evaluated, of course :)

Known issue of the target reg:
"test" and ".test" and "test." etc count as "same" target, due to the dot used as the token separator in logfile-names

$logsearch Identifier feature ( order of parameters = parameters of the alias: $logsearch([switches,]word/term[,target]) ), returning: 
- nothing if an error occurs
- "0,0,0 no target" if no file matching the target was found
- "A,0,0 no match" if no matches for the search expression in the targetfile(s) found (A being matching target files)
- "A,B,C" for matches (MatchingTargetFiles,TargetfilesWithMatches,TotalNumberOfMatches). 

Todo:
- Fix status window behaviour
- Replace "target" acc. to $mklogfn - atm you won't search appropriate logs of nicks like "\".
- Hard coded escape for [$chantypes]? if active windows logs are processed:
-- by design, target "test" will check logs for "test" (nick in query) and "#test" (channel); "#test" will check logs for "#test" (channel)
-- for sure, it will never find "2test" or "##test" or "#2test" 
- Switch for regex search; for windowed output incl. highlights of matches, for "search all queries" (wonder how), for "show count only" (that is, no file popping up)
- Plaintext search counts chars like | word boundary in the literal sense, thus it melts these occurances with surrounding chars/words and no search for | ^ * etc too
- Age-sensitive search: $file .ctime/.mtime
- Anti-freeze via "pause" (fiberoptics snippet)
- Popups and Dialog Box, to apply switches on the fly; check for number of matches first using $logsearch, extended output properties
*/

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Code:
menu * {
  Log Search : logsearch $$input(Enter word to search for,e)) $$input(NOTE: No extension (eg: .txt) required,e,Enter file name to search,$!)
}


While this will still require the double entry like Peter Peter, the second Peter will be auto-filled, so all you need to do is press the Enter key (unless you want to change it.)

Additionally note that using this method means that the code you're currently using could be altered to allow for a phrase to be searched, rather than just a single word.


Link Copied to Clipboard