Fsearch

By Zmodem on Oct 27, 2003

Fsearch utilizes a custom identifier, $fsearch(), which gives you the ability to search for a certain string of text through 'non-binary' files; the snippet itself describes exactly what it does and how to do it. This file is well-commented, so it should be easy for scripters to understand. Enjoy!

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; $fsearch() - Allows you to search a NON-BINARY file
; for a certain string of text.
;
; Useage: $fsearch(<filename>,<search string>,<N>)
;
; (Note: All three parameters are required.)
;
; filename - Must be a valid filename for proper
; execution
;
; search string - This is the string that you want the
; search to look for in the file.
;
; N - If you specify N as 0 the total matches is displayed
; to you.
; Else it displays the Nth matching result.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

fsearch {

; First we declare all of the 'temporary' variables we are going to
; use in order to achieve fast and proper search results
;
; Note: If you specify variables for 'lengthy' functions, mIRC takes
; less time to perform certain return values.

  var %w = @FsearchWindow, %f = " $+ $1 $+ ", %s = $2, %g = $3, %t = 0, %r = 0, %e = return

; This next line checks to make sure that the user has specified all
; of the required information:
;
; %f = filename specified
; %s = string to search for
; %g = the flag value (N) (isnum makes sure that %g is a number and
; nothing more)

  if ((%f) && (%s) && (%g >= 0) && (%g isnum) && ($isfile(%f))) {

; Here we will create a 'temporary' window that is (-h) hidden so
; that it does not show up when the search begins. The line after
; this also clears this new window in case the window already
; existed. We do not want invalid search results in our window.

    window -h %w

    clear %w

; The /loadbuf command we have used here loads to the window %w all
; of the information from the user-specified %f file. If you take a
; look at the temporary variables at the top of this alias, you will
; notice that we have set %w as @FsearchWindow. This saves a bit of
; space in our alias and quickens our procedure.

; You might be asking yourself: "Why not just use $read(%f,N) to get
; the line of a file instead of loading it into a custom window?". The
; answer for this is simple: mIRC is MUCH quicker searching through
; it's customized @Windows rather than a straight file. You will
; find that it is almost 4x's faster.

    loadbuf %w %f

; The %m is now initialized to the amount of lines in the window,
; which are exactly identical to the amount of lines in the file %f.
; %i is set to 1, because we want %i to be our 'no-infinite-loop-
; watching' variable. This will make it so that we know how many
; lines we've checked so far. As long as %i is less-than or equal-to
; %m, the total amount of lines, then we can read the next line in the
; window because we have not reached the end yet.

    var %i = 1, %m = $line(%w,0), %z

    while (%i <= %m) {

; We now have to set %z to the %i line being read. If %i is 2 and line
; 2 reads: this is some stupid line, then %z now equals: this is some
; stupid line.

      %z = $line(%w,%i)

; This line checks to see if the search string %s appears ANYWHERE
; within the line %z that has just been read.

      if ($+(*,%s,*) iswm %z) {

; We have to increase the %r (our total results variable) by 1. This
; variable is the key in returning how many results were found.

        inc %r

; The next line checks to see if %g is the same as the currently matching
; line. If it is, we will close the search buffer window and return the
; results using %e, because as you can see in our temporary variable
; initialization, %e was set to the word 'return', which allows it to
; perform the /return command.

        if (%g == %r) { window -c %w | %e %z }

      }

; Increase our %i variable just to let the alias know we've went through
; the while loop again.

      inc %i

    }

; The while loop has ended. If the user specified '0' for the value of
; their N, then this is where it will end up. 'window -c %w' now closes
; our buffer window.

    window -c %w

; If the user-specified N (%g) is greater-than the amount of results found
; then there is no such result match and the user gets no return value. If
; not, the user will now receive the total amount of matches found instead.

    $iif(%g > %r,%e,%e %r)

  }

}

Comments

Sign in to comment.
Hawkee   -  Oct 27, 2003

I use a program called Windows Grep which can be found at www.wingrep.com - it\'s very handy and also has a feature to search and replace some text within an entire directory. Good when you don\'t want to open up several documents to make a change.

 Respond  
Hawkee   -  Oct 27, 2003

I\'d just do something like $mircgrep(\'$directory\', \'search terms\') and it\'ll search that directory recursively for all the files with \'search terms\' written in them or as the title. It\'s very useful and much better than Window\'s find feature

 Respond  
Zmodem   -  Oct 27, 2003

I\'ll probably say no because windows has one that\'s much better and it\'s just reinventing the wheel of something that\'s already there. lol

 Respond  
Zmodem   -  Oct 27, 2003

Because of the way that you\'re describing Grep to work, it won\'t work as a single $identifier ;-) Oh well, maybe a find file addon in mIRC is a little useless because we have one for windows? What do you think? Worth it? It would be so simple.

 Respond  
Zmodem   -  Oct 27, 2003

I\'ll probably make that an addon then, or maybe I\'ll just make a findfile for mIRC with a \'search for text string\' included in it.

 Respond  
Zmodem   -  Oct 27, 2003

OH, killer! I should add that directory search to this snippet. I never heard of it, but thanks for the info and the unintended suggestion! :-D

 Respond  
Hawkee   -  Oct 27, 2003

I\'m surprised you haven\'t heard of it.. it\'s a unix program that will search a directory or directory tree for text within all of the text files in the tree. It returns a list of the filename and the line of content the word was found in.

 Respond  
Zmodem   -  Oct 27, 2003

Grep?

 Respond  
Hawkee   -  Oct 27, 2003

This sounds just like grep for mIRC

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.