--- loging-old.tcl 2007-12-23 20:23:30.000000000 +1100 +++ loging.tcl 2007-12-23 21:39:24.000000000 +1100 @@ -1383,12 +1383,28 @@ #/////////////////////////////////////////////////////////////////////////////// # ParseToFile (logvar filepath) - # Decodes the log file and writes to file + # Calls ParseToTextFile or ParseToHTMLFile, depending on what file type we want to save. # - # wname : Log window # logvar : variable containing the whole log file (sure need to setup log file limits) + # filepath : Input box containing file path to save to ?? proc ParseToFile { logvar filepath } { + + # Are we writing a HTML file? + if {[file extension [${filepath} get]] == ".htm"} { + ParseToHTMLFile $logvar $filepath + } else { + ParseToTextFile $logvar $filepath + } + } + + #/////////////////////////////////////////////////////////////////////////////// + # ParseToTextFile (logvar filepath) + # Decodes the log file and writes to file + # + # logvar : variable containing the whole log file (sure need to setup log file limits) + # filepath : Input box containing file path to save to ?? + proc ParseToTextFile { logvar filepath } { global langenc @@ -1432,6 +1448,113 @@ close $fileid } } + + #/////////////////////////////////////////////////////////////////////////////// + # ParseToHTMLFile (logvar filepath) + # Decodes the log file and writes to a HTML file + # + # logvar : variable containing the whole log file (sure need to setup log file limits) + # filepath : Input box containing file path to save to ?? + proc ParseToHTMLFile { logvar filepath } { + + global langenc + + set fileid [open [${filepath} get] w+] + fconfigure $fileid -encoding utf-8 + if { $fileid != 0 } { + + # Write the HTML header and stuff + puts $fileid { + + + + + aMSN Log File + + + + + } + + set nbline 0 + + set loglines [split $logvar "\n"] + set result [list] + foreach line $loglines { + incr nbline + set aidx 0 + while {$aidx != -1} { + # Checks if the line begins by |"L (it happens when we go to the line in the chat window). + # If not, use the tags of the previous line + if { $aidx == 0 & [string range $line 0 2] != "\|\"L" } { + set bidx -1 + } else { + # If the portion of the line begins by |"LC, there is a color information. + # The color is indicated by the 6 fingers after it + if {[string index $line [expr {$aidx + 3}]] == "C"} { + set color "#[string range $line [expr {$aidx + 4}] [expr {$aidx + 9}]]" + incr aidx 10 + # Else, it is the system with LNOR, LGRA... + } else { + if {[string range $line $aidx [expr {$aidx + 6}]] == "\|\"LTIME" } { + #it is a time in [clock seconds] + incr aidx 7 + #add formated date/time stamp to the log output + #search a non digit character since on older version, there wasn't always a space after the timestamp + regexp -start $aidx -indices {\D} $line sidx + set sidx [lindex $sidx 0] + incr sidx -1 + puts -nonewline $fileid "[ LogDateConvert [string range $line $aidx $sidx ]]" + set aidx $sidx + incr aidx 1 + } else { + switch [string range $line [expr {$aidx + 3}] [expr {$aidx + 5}]] { + RED { + set color "red" + } + GRA { + set color "gray" + } + NOR { + set color "black" + } + ITA { + set color "blue" + } + GRE { + set color "darkgreen" + } + } + incr aidx 6 + } + } + set bidx [string first "\|\"L" $line $aidx] + } + if { [string first "\|\"L" $line] == -1 } { + set string [string range $line 0 end] + } elseif { $bidx != -1 } { + set string [string range $line $aidx [expr {$bidx - 1}]] + } else { + set string [string range $line $aidx end] + } + puts -nonewline $fileid "$string" + set aidx $bidx + } + puts -nonewline $fileid "
\n\t" + + } + + puts $fileid { + +} + close $fileid + } + } #///////////////////////////////////////////////////////////////////////////////