mIRC Home    About    Download    Register    News    Help

Print Thread
#216922 22/12/09 11:29 PM
Joined: Mar 2009
Posts: 74
K
Babel fish
OP Offline
Babel fish
K
Joined: Mar 2009
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)?

KageNoOni #216925 23/12/09 03:22 AM
Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
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.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #216926 23/12/09 06:36 PM
Joined: Mar 2009
Posts: 74
K
Babel fish
OP Offline
Babel fish
K
Joined: Mar 2009
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.
}

KageNoOni #216927 23/12/09 07:36 PM
Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
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.

Last edited by Wims; 23/12/09 07:39 PM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #216928 23/12/09 09:14 PM
Joined: Mar 2009
Posts: 74
K
Babel fish
OP Offline
Babel fish
K
Joined: Mar 2009
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.

Last edited by KageNoOni; 23/12/09 09:46 PM.
KageNoOni #216929 23/12/09 09:53 PM
Joined: Mar 2009
Posts: 74
K
Babel fish
OP Offline
Babel fish
K
Joined: Mar 2009
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.

KageNoOni #216930 24/12/09 01:44 AM
Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
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


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #216931 24/12/09 04:11 AM
Joined: Mar 2009
Posts: 74
K
Babel fish
OP Offline
Babel fish
K
Joined: Mar 2009
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.

Last edited by KageNoOni; 24/12/09 04:18 AM.
KageNoOni #216941 24/12/09 06:55 PM
Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
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.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #216942 24/12/09 07:15 PM
Joined: Mar 2009
Posts: 74
K
Babel fish
OP Offline
Babel fish
K
Joined: Mar 2009
Posts: 74
That's what I needed. Thank you very much. smile

KageNoOni #216945 24/12/09 08:13 PM
Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
You welcome, hope you won't disconnect now, at least I'm sure you won a lots of seconds of execution


#mircscripting @ irc.swiftirc.net == the best mIRC help channel

Link Copied to Clipboard