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)
}
}