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.

irc control char to html generator

Old posts that have not been replied to for several years.
Locked
s
scarface
Voice
Posts: 12
Joined: Mon Jul 11, 2005 3:49 pm

irc control char to html generator

Post by scarface »

Hi

Could anyone make a irc control char to html generator for me?
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

what is "irc control char"? mIRC's color escape codes? ANSI color escapes? ^B for bold, ^U for underline?
s
scarface
Voice
Posts: 12
Joined: Mon Jul 11, 2005 3:49 pm

Post by scarface »

The 'normal' chars:
Like \002 for bold \003xx,yy for color and underline/reverse and such.

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

Post by demond »

this can't be done correctly, at least not without representing your input string as HTML table, since you can change text's background color only within BODY/TABLE/TR/TD tags (attribute bgcolor)

and representing the string as table will mess up your page layout

or maybe it could be done with CSS, but that would require rather complex parsing and building the stylesheet, i.e. can't be done on-the-fly

anyway, I'm neither that good with HTML/CSS, nor that interested in writing code for complex handling of mIRC's lame colors
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

oops, wait... it seems that still could be done on-the-fly with SPAN tag and inline styling

stay tuned hehe
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

here you go:

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
	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" {
				set tag "<span style=\"font-weight:bold\">" 
				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
}
it's not 100% correct, but at least 99% hehe (tested!)
s
scarface
Voice
Posts: 12
Joined: Mon Jul 11, 2005 3:49 pm

Post by scarface »

thank you very much :D
s
scarface
Voice
Posts: 12
Joined: Mon Jul 11, 2005 3:49 pm

Post by scarface »

hm, the bold closing didnt seem to work

if it was \002hi\002 there it would be hi there
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

fixed:

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