[Tkabber-dev] r1871 - in trunk/tkabber: . plugins/general

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sat Jan 16 03:41:55 MSK 2010


Author: sergei
Date: 2010-01-16 03:41:55 +0300 (Sat, 16 Jan 2010)
New Revision: 1871

Modified:
   trunk/tkabber/ChangeLog
   trunk/tkabber/plugins/general/rawxml.tcl
Log:
	* plugins/general/rawxml.tcl: Moved timestamp and comments generation
	  to separate procedures. Ensure that commented line doesn't contain
	  two dashes -- (thanks to Konstantin Khomoutov).


Modified: trunk/tkabber/ChangeLog
===================================================================
--- trunk/tkabber/ChangeLog	2010-01-15 13:12:59 UTC (rev 1870)
+++ trunk/tkabber/ChangeLog	2010-01-16 00:41:55 UTC (rev 1871)
@@ -1,3 +1,9 @@
+2010-01-16  Sergei Golovan  <sgolovan at nes.ru>
+
+	* plugins/general/rawxml.tcl: Moved timestamp and comments generation
+	  to separate procedures. Ensure that commented line doesn't contain
+	  two dashes -- (thanks to Konstantin Khomoutov).
+
 2010-01-15  Sergei Golovan  <sgolovan at nes.ru>
 
 	* privacy.tcl: Added IQ to blocked stanzas for JIDs in invisible list

Modified: trunk/tkabber/plugins/general/rawxml.tcl
===================================================================
--- trunk/tkabber/plugins/general/rawxml.tcl	2010-01-15 13:12:59 UTC (rev 1870)
+++ trunk/tkabber/plugins/general/rawxml.tcl	2010-01-16 00:41:55 UTC (rev 1871)
@@ -39,6 +39,29 @@
 }
 
 
+if {![catch {clock milliseconds}]} {
+    proc rawxml::timestamp {} {
+	set ms [clock milliseconds]
+	set seconds [expr {$ms/1000}]
+	set fraction [format %03d [expr {$ms%1000}]]
+	return [clock format $seconds -format %T].$fraction
+    }
+} else {
+    proc rawxml::timestamp {} {
+	clock format [clock seconds] -format %T
+    }
+}
+
+
+proc rawxml::format_comment {xlib prefix} {
+    set id "($xlib)"
+    catch {set id "($xlib, [connection_jid $xlib])"}
+    set safe_id [string map { -- -&#0045; } $id]
+
+    return "<-- [timestamp] $prefix $safe_id -->"
+}
+
+
 proc rawxml::handle_inout {xlib dir type msg} {
     variable options
 
@@ -63,25 +86,14 @@
 	}
     }
 
-    if {![catch {clock milliseconds} ms]} {
-	set seconds [expr {$ms/1000}]
-	set fraction [format %03d [expr {$ms%1000}]]
-	set prefix "[clock format $seconds -format %T].$fraction $prefix"
-    } else {
-	set prefix "[clock format [clock seconds] -format %T] $prefix"
-    }
-
     set dump $w.dump
     $dump configure -state normal
 
     set scroll [expr {[lindex [$dump yview] 1] == 1}]
 
-    set id "($xlib)"
-    catch {set id "($xlib, [connection_jid $xlib])"}
-
     $dump insert end \
-	"<!-- $prefix $id -->\n" [list xlib$xlib] \
-	"$msg" [list $tag xlib$xlib]
+	[format_comment $xlib $prefix]\n [list xlib$xlib] \
+	$msg [list $tag xlib$xlib]
 
     if {![$dump compare "end -1 chars linestart" == "end -1 chars"]} {
 	$dump insert end "\n" [list xlib$xlib]
@@ -112,24 +124,13 @@
 	}
     }
 
-    if {![catch {clock milliseconds} ms]} {
-	set seconds [expr {$ms/1000}]
-	set fraction [format %03d [expr {$ms%1000}]]
-	set prefix "[clock format $seconds -format %T].$fraction $prefix"
-    } else {
-	set prefix "[clock format [clock seconds] -format %T] $prefix"
-    }
-
     set dump $w.dump
     $dump configure -state normal
 
     set scroll [expr {[lindex [$dump yview] 1] == 1}]
 
-    set id "($xlib)"
-    catch {set id "($xlib, [connection_jid $xlib])"}
+    $dump insert end [format_comment $xlib $prefix]\n [list xlib$xlib]
 
-    $dump insert end "<!-- $prefix $id -->\n" [list xlib$xlib]
-
     pretty_print $dump $xml "" $tag $xlib
 
     if {![$dump compare "end -1 chars linestart" == "end -1 chars"]} {



More information about the Tkabber-dev mailing list