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.

covert codes to html

Help for those learning Tcl or writing their own scripts.
Post Reply
S
Savage_Garden
Voice
Posts: 1
Joined: Wed Aug 23, 2006 3:53 pm

covert codes to html

Post by Savage_Garden »

Hello, sorry if this has been asked before but i didnt meet such a topic. My problem is that i am writing a tcl for online stats and i am logging whats going on in the channel in chat.txt. Next i write a html using that file, but the problem is in the .txt file where there are lines with bold, reverse, underline or color, such as:
1156356695 quit LaM3r43t0 admin@84.238.171.248 Quit: 4? 9Club Xtazy ? 11Script ? 4Download ? w15ww.15styni.HiT.9bG ?
on the .html file they dont appear colored, underlined, etc.
I hope you understand what my problem is and you can help me. I need a procedure that would fix that effect.

Thanks in advantage.
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Try regsub.
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

I already wrote mirc-colors-to-html converter for some guy a while ago, you could have found it with a simple forum search for "color html"

anyway, here it is again:

Code: Select all

proc mirc2html str {
   set re {([\002\017\026\037]|[\003]{1}[0-9]{0,2}[\,]{0,1}[0-9]{0,2})}
array   set colors { 0 white   1 black    2 navy    3 green
                4 red     5 maroon   6 purple  7 olive
                8 yellow  9 lime    10 teal   11 aqua
               12 blue   13 fuchsia 14 gray   15 silver}
   set numtags 0; set bold 0
   while {[regexp -indices $re $str -> idxs]} {
      set b [lindex $idxs 0]
      set e [lindex $idxs 1]
      set sub [string range $str $b $e]
      switch [string index $sub 0] {
         "\002" {
            if !$bold {
               set tag "<span style=\"font-weight:bold\">"
               set bold 1
            } {
               set tag "<span style=\"font-weight:normal\">"
               set bold 0
            }
            incr numtags
         }
         "\017" {
            set tag [string repeat "</span>" $numtags]
            set numtags 0
         }
         "\026" {
            set tag [string repeat "</span>" $numtags]            
            append tag "<span style=\"color:white;background-color:black\">"
            set numtags 1
         }
         "\037" {
            set tag "<span style=\"text-decoration:underline\">"
            incr numtags
         }
         "\003" {
            set fg [lindex [split [string range $sub 1 e] ,] 0]
            set bg [lindex [split [string range $sub 1 e] ,] 1]
            if {$fg != "" || $bg != ""} {
               if {$fg > 15 || $bg > 15} {
                  set tag "<span>"
               } elseif {$fg != "" && $bg != ""} {
                  set tag "<span style=\"color:$colors($fg);background-color:$colors($bg)\">"
               } elseif {$fg != "" && $bg == ""} {
                  set tag "<span style=\"color:$colors($fg)\">"
               } else {
                  set tag "<span style=\"background-color:$colors($bg)\">"
               }
               incr numtags
            } {
               set tag [string repeat "</span>" $numtags]
               set numtags 0
            }
         }
      }
      set str [string replace $str $b $e $tag]
   }
   append str [string repeat "</span>" $numtags]
   return $str
} 
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
Post Reply