This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

TCl Woes

Old posts that have not been replied to for several years.
Locked
D
Del^

TCl Woes

Post by Del^ »

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
}
}
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

The first 2 things that stood out.

1: you didn't include what you used to try and automaticaly send the file.

2: Have you tried making sure that the $data variable is in lowercase too, just like the line of text int he file./
D
Del^

Post by Del^ »

PPSlim - Thanks for the reply.

I removed the dccsend part (it was purely 'dccsend scripts/sites/output.txt $nick' after the 'puthelp "PRIVMSG $nick :Found some matches - Preparing URL file. Please wait....."' line

and yes $data is in lowercase as I convert it and pull it through from another procedure. 'set datat [string tolower $datat]'

The procedures that I am having problems with are matching correctly, but they are doing the if statements and outputting both the true and false statements if they are true.

Del^
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

As for the dccsend issue, it does sound like more than what should hapen, is going on.

When it comes to the matching, it sounds less serious.

Because you are using a "string match" command, and the match pattern is "*$data*", it could be a simple fact that $data is empty.

Use some putlog lines, to test for this.
D
Del^

Post by Del^ »

Hmmm - intreging. The script is loading several text files at once to do the string match on. Could be that it outputs the 'cannot find' statement if one of the files returns nothing.

Thanks

Del^
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

In your original post you gave 2 pieces of code.

From looking at them, they are not the only pieces, as there is a part missing from the begining.

The fact it opens several files at a time, shows the searchserials proc is being called more than once, this applies to the dccsend issue too.

You may think that it can't be so, as messages are only displayed once. This can be explained too. Eggdrop will drop repeated messages, to conserve uneeded traffic.

You are getting different sized files from dccsend, because you opened the file using the "a" mode, which will append to a file, rather than overwrite it.

It may help to see / revise the first part of the code.
Locked