Hi there - I'm very new to tcl scripting. While I can work out the basics - this script that I am working on is really got me baffled.
There are two procedures that i'm working on that do a simple search against a flat text file. (Script below).
There are 2 problems I have that I've tried to sort but to no avail.
Problem 1. If there are no matches on the text file - I want the script to tell the user that there are no matches - which it does fine. But even if there are matches - it still says that there are no matches and continues processing. Have I got my if & else statements wrong?
Problem 2. Ideally after the script has found all of the matches in the flat text file and written them to the output.txt file - i want it to automatically dccsend to the user thats requested the search, but when I try to do this, the script seems to initiate 3 or 4 dccsends of files all different sizes (sometimes sending the correct one). I'm assuming that somehow the script hasnt finished matching and writing the file. Is there a way to pause the script until the matching and writing the file is complete?
You're help is greatly greatly appreciated. If you dont want to reply on here - could you please message me on windows messenger (hezbag@hotmail.com). Thanks
Del^
Script below here:
------------------------------------------------------------------------------------
proc searchserials {nick database data chan} {
global maxsearch results outputf
set in [open $database r]
set totfound 0
set resu [open scripts/sites/output.txt a]
while {![eof $in]} {
set line [gets $in]
if {[string match "*$data*" [string tolower $line]]} {
puts $resu "$line"
if {$totfound > $maxsearch} {
puthelp "PRIVMSG $nick :There are over $maxsearch matches. Please narrow your search."
close $in
close $resu
return 0
}
set totfound [expr $totfound + 1]
}
}
close $in
close $resu
sendoutput $nick $data $chan
return 0
}
proc sendoutput {nick data chan} {
set size [file size scripts/sites/output.txt]
if {$size > 0} {
puthelp "PRIVMSG $nick :Found some matches - Preparing URL file. Please wait....."
puthelp "PRIVMSG $nick :File is now ready. Type !geturlfile in the channel."
return 0
} else {
puthelp "PRIVMSG $nick :No matches found for $data - Try another search"
puthelp "PRIVMSG $chan :0,4 Search process now completed - !filename trigger now available again."
return 0
}
}