mIRC Home    About    Download    Register    News    Help

Topic Options
#216922 - 22/12/09 11:29 PM Searching
KageNoOni Offline
Babel fish

Registered: 23/03/09
Posts: 74
I made a script for searching a variety of files (the code for a game I play) that, due to the amount of information in the search, it takes a while to find what I'm looking for. Now, when I do the search, mIRC locks up until the search is complete, and the result is that I disconnect from all servers I'm connected to. Is there a way to get it to do a search in the background so that other functions will run normally (including server ping replies)?

Top
#216925 - 23/12/09 03:22 AM Re: Searching [Re: KageNoOni]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3515
Loc: France
No, when mirc is busy with something, nothing else is performed.
But one thing could be to show here your code, often people use $findfile in a very bad way that make it so slow.
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#216926 - 23/12/09 06:36 PM Re: Searching [Re: Wims]
KageNoOni Offline
Babel fish

Registered: 23/03/09
Posts: 74
When I do the search, it looks through a few hundred files for a wildcard text match, and finds every match there is, so it isn't a surprise that it's slow. If you can speed it up how ever, I'll be more than happy to add any optimizations you can come up with.

Code:
Search-Code {
  if ($1 == $null) { halt }
  if (!$window(@code_search)) { window @code_search }
  else { dline @code_search 1- }
  var %a 1
  var %max $findfile(C:\MoMEditor\,*.py,0)
  while (%a <= %max) {
    var %file $findfile(C:\MoMEditor\,*.py,%a)
    var %result $read(%file,wn,$1-,1)
    var %line $readn
    while ((%result != $null) && (%line > 0)) {
      aline -p @code_search %file Line %line $+ : %result
      var %line %line + 1
      var %result $read(%file,wn,$1-,%line)
      var %line $readn
    }
    var %a %a + 1
  }
  aline -p @code_search 4Search finished.
}

Top
#216927 - 23/12/09 07:36 PM Re: Searching [Re: KageNoOni]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3515
Loc: France
As I guessed, you're not using $findfile correctly, try :

Code:
Search-Code {
  if ($1) {
  if (!$window(@code_search)) window @code_search
  else clear @code_search
  var %1 $1-
  noop $findfile(C:\momeditor\,*.py,0,noop $check_pyfile(%1,$1-))
  aline -p @code_search 4Search finished.
}
}
check_pyfile if ($read($2-,wn,$1-)) filter -fwr $readn $+ - $lines($2-) $qt($2-) @code_search *
This is untested but it's how you should do it, this will make a big big difference.


Edited by Wims (23/12/09 07:39 PM)
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#216928 - 23/12/09 09:14 PM Re: Searching [Re: Wims]
KageNoOni Offline
Babel fish

Registered: 23/03/09
Posts: 74
While the search is much faster now, unfortunately the search turned up no results, using a previous wildcard search that turned up around 100 results when used.

Since I'm not at all familiar with /noop or /filter, I have no way of trying to figure out what it's doing wrong.

Thanks for helping though.

Edit: I think I figured it out. You use $1- and $2- in the $check_pyfile alias. $1- in the alias ends up being the search term followed by the file name. As a result, the filter looks for a match to the search term followed by the file name, and no line in these files include the file name itself. As a result, the search ends up finding nothing. I removed the hyphens so that the search term and file name would only find what is being looked for, but now I'm getting an error saying it can't open a file it shouldn't even be looking at.

* /filter: unable to open file 'C:\Users\ben\AppData\Roaming\mIRC\219'

There isn't a filename of "219" anywhere, and I'm not sure what is causing it to try to open this file, or why the filter is looking in my AppData folder instead of the MoMEditor folder.

Edit Again: Ok, I used /echo to debug, and found that the line numbers it was searching have a space between the the second line number, and the first line number + hyphen. Just adding a $+ should solve that.


Edited by KageNoOni (23/12/09 09:46 PM)

Top
#216929 - 23/12/09 09:53 PM Re: Searching [Re: KageNoOni]
KageNoOni Offline
Babel fish

Registered: 23/03/09
Posts: 74
A few problems with this. When I do the search, it's to find areas with in the files for me to look at. This means I need file name and line number of the relevant results, and this method doesn't give me either of them. Also, I'm getting lines put into the window that don't include the search term. Doing a search for *resist* pulled up (among other things) the following.

Code:
    def getDBSpawn(name):
        return DBDict.getDBDict('Spawn','name',name)
    
    getDBSpawn = staticmethod(getDBSpawn)

    def addSpell(self,spellname):
        self.spawnSpells.append(spellname)
        
    def addFaction(self,faction):
        self.factions.append(faction)

Is there a way to use filter to include the information I'm after, and skip the lines I'm not interested in? I don't need every line from what ever file it finds a mention of the search term in, just enough to let me know if the line is what I'm after, the file it's in, and what line to begin looking at.

Top
#216930 - 24/12/09 01:44 AM Re: Searching [Re: KageNoOni]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3515
Loc: France
Yeah sorry, made some mistakes, here is a new try :
Code:
Search-Code {
  if ($1) {
  if (!$window(@code_search)) window @code_search
  else clear @code_search
  var %1 $1-
  noop $findfile(C:\momeditor\,*.py,0,noop $check_pyfile(%1,$1-))
  aline -p @code_search 4Search finished.
}
}
check_pyfile filter -fwr $qt($2-) @code_search $1
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#216931 - 24/12/09 04:11 AM Re: Searching [Re: Wims]
KageNoOni Offline
Babel fish

Registered: 23/03/09
Posts: 74
Well, I had to remove the -r switch, because the program was assuming that $qt($2) was the line numbers to be returned, and as a result thought that the window name was a file name. Now the search works very well, and thanks for that, but it still doesn't show me what file the information came from, or give me a line number. I've altered it to give me the file name, but with out the line numbers it'll be harder to find what I'm after due to the fact some of these files can be more than 4000 lines long. Often times the same line can be used multiple times, making it even harder to find what I'm after. Can you find a way to return the line numbers the matched text is found at?

Here's the current check_pyfile alias.

Code:
check_pyfile {
  if ($read($2,wn,$1) != $null) { aline @code_search  $+ $2 $+  }
  filter -fw $qt($2-) @code_search $1
}


Also, one thing I haven't figured out is what the /noop command is for. The information in the help file was not the least bit clear.

Edit: I think I understand it now. It just allows the use of identifiers with out an actual command being performed. In this alias, $findfile and $check_pyfile.


Edited by KageNoOni (24/12/09 04:18 AM)

Top
#216941 - 24/12/09 06:55 PM Re: Searching [Re: KageNoOni]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3515
Loc: France
Again, sorry about the -r, and use -n to have the line number.
And yes, noop means no-operation, mIRC will not do anything with the parameters but evaluate them.
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#216942 - 24/12/09 07:15 PM Re: Searching [Re: Wims]
KageNoOni Offline
Babel fish

Registered: 23/03/09
Posts: 74
That's what I needed. Thank you very much. smile

Top
#216945 - 24/12/09 08:13 PM Re: Searching [Re: KageNoOni]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3515
Loc: France
You welcome, hope you won't disconnect now, at least I'm sure you won a lots of seconds of execution
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top