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.

adding \

Old posts that have not been replied to for several years.
Locked
s
simonbell
Halfop
Posts: 68
Joined: Mon Aug 05, 2002 8:07 pm
Location: Washington, England
Contact:

adding \

Post by simonbell »

Ive written a script which effecitvely safes user nicks and some information about them to a file. Ive encountered a problem that when nicks contain { and [ the script gets confused. How would i go about checking each time a nick is to be added to the database and adding a \ infront of each character such as { and [ so that the script takes them as normal characters.

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

Post by ppslim »

The trick is to handle them correctly in the first place.

The simplest way to extract information, is using list commands, however, most users pass stings too them.

This causes incorrectly escaped charcters within variables or return values.

It would be wise to post the code that is causing trouble, and we should be able to help more.
s
simonbell
Halfop
Posts: 68
Joined: Mon Aug 05, 2002 8:07 pm
Location: Washington, England
Contact:

Post by simonbell »

The script which adds information to the database is this:
putlog "NickHost: Join check on $nick: Adding new host $host"
set filewrite [open $nickdb a]
puts $filewrite "$nick $host"
close $filewrite
$nick being the nick of the person who just joined the channel, etc

Then, a user submits a request to view certain information, and this part of the script is used:
putnotc $nick "Nicks in the database matching the host: \002$whoishost\002"
set showopen [open $nickdb r]
set show [read $showopen]
close $showopen
foreach listnick [split $show \n] {
if { [lindex $listnick 1] == $whoishost } {
putnotc $nick "\002ø\002 [lindex $listnick 0]"
}
}
This just lists the nicks matching a certain host which are in the file.

It was working fine. Now, when a user with { in there nick joined and was registered by the bot, whenever anyone requests information, the script *can* still work, although sometimes it does, but the error message
<InfinitY> [15:30] Tcl error [savehost-whois]: unmatched open brace in list
Simon
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Change this line

Code: Select all

foreach listnick [split $show \n] {
To

Code: Select all

foreach listnick [split [split $show \n]] {
s
simonbell
Halfop
Posts: 68
Joined: Mon Aug 05, 2002 8:07 pm
Location: Washington, England
Contact:

Post by simonbell »

to narrow this down slightly ive been looking at the string map command.

Im not exactly how i would get this to work, but using
putlog "[string map "\{" "\\{"]"
creates 'unmatched open brace in list ' errors...

Simon
e
egghead
Master
Posts: 481
Joined: Mon Oct 29, 2001 8:00 pm
Contact:

Post by egghead »

simonbell wrote:to narrow this down slightly ive been looking at the string map command.
[snip]
Simon
This is not needed. ppslim already pointed at a weakness in your script.

Let me review it step by step.

Step 1. You save the $nick and $host to file. By the way you save it, each line is now a string in the datafile.

Step 2. "set show [read $showopen]". This will read the whole file, as is, into the variable "show".

Step 3. "close $showopen".

Step 4. "foreach listnick [split $show \n] {" The variable $show is splitted around the newline character into a list. Note that each list element of $show is a string by itself i.e. the variable $listnick contains a string (a single line from the file) and not a list.

Step 5. "if { [lindex $listnick 1] == $whoishost } {" And this is where things go wrong. The variable $listnick contains a string and not a list. You are performing the listcommand [lindex] on the string $listnick.
s
simonbell
Halfop
Posts: 68
Joined: Mon Aug 05, 2002 8:07 pm
Location: Washington, England
Contact:

Post by simonbell »

Sorry, ive removed the script above as the person i was writing it for changed his mind about what he wanted. I would just like to know for knowledges sake how i would actually add a \ infront of a character in a string which is }

Would it be via the string map command? or would i use something else?

thanks
Simon
Locked