comparison utillib.tcl @ 432:124b97f5a19d

utillib: Add some comments, bump copyright.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 09 Jan 2017 03:55:53 +0200
parents 04021e2e26c3
children cd53828bb724
comparison
equal deleted inserted replaced
431:5763716060a0 432:124b97f5a19d
1 ########################################################################## 1 ##########################################################################
2 # 2 #
3 # TCL functions library by Matti 'ccr' Hamalainen <ccr@tnsp.org> 3 # TCL functions library by Matti 'ccr' Hamalainen <ccr@tnsp.org>
4 # (C) Copyright 2015 Tecnic Software productions (TNSP) 4 # (C) Copyright 2015-2017 Tecnic Software productions (TNSP)
5 # 5 #
6 # This script is freely distributable under GNU GPL (version 2) license. 6 # This script is freely distributable under GNU GPL (version 2) license.
7 # 7 #
8 ########################################################################## 8 ##########################################################################
9 9
18 append utl_html_ent_str "|&#x2026;|...|&hellip;|...|&#34;|\"|&#xad;||&#064;|#" 18 append utl_html_ent_str "|&#x2026;|...|&hellip;|...|&#34;|\"|&#xad;||&#064;|#"
19 append utl_html_ent_str "|&#xa0;| " 19 append utl_html_ent_str "|&#xa0;| "
20 set utl_html_ent_list [split [encoding convertfrom "utf-8" $utl_html_ent_str] "|"] 20 set utl_html_ent_list [split [encoding convertfrom "utf-8" $utl_html_ent_str] "|"]
21 21
22 22
23 # Convert given string, containing HTML/XML style entities into a normal
24 # UTF-8 Unicode string, using the above entity->character mapping
23 proc utl_convert_html_ent {udata} { 25 proc utl_convert_html_ent {udata} {
24 global utl_html_ent_list 26 global utl_html_ent_list
25 return [string map -nocase $utl_html_ent_list [string map $utl_html_ent_list $udata]] 27 return [string map -nocase $utl_html_ent_list [string map $utl_html_ent_list $udata]]
26 } 28 }
27 29
28 30
31 # Split given string "str" into a list of sub-strings of maximum length
32 # "maxlen", by attempting to split at "words", if possible.
29 proc utl_str_split {str maxlen} { 33 proc utl_str_split {str maxlen} {
30 set pos 0 34 set pos 0
31 set len [string length $str] 35 set len [string length $str]
32 set ulen 0 36 set ulen 0
33 set ustr "" 37 set ustr ""
61 } 65 }
62 return 0 66 return 0
63 } 67 }
64 68
65 69
70 # Send IRC message with given message type, splitting the
71 # string to fit to IRCNet (etc.) max message length.
66 proc utl_msg_do {upreferredmsg upublic unick uchan umsg} { 72 proc utl_msg_do {upreferredmsg upublic unick uchan umsg} {
67 foreach uline [utl_str_split $umsg 450] { 73 foreach uline [utl_str_split $umsg 450] {
68 if {$upublic == 1} { 74 if {$upublic == 1} {
69 putserv "$upreferredmsg $uchan :$uline" 75 putserv "$upreferredmsg $uchan :$uline"
70 } else { 76 } else {
72 } 78 }
73 } 79 }
74 } 80 }
75 81
76 82
83 # Return formatted time for given UNIX timestamp
77 proc utl_ctime {utime} { 84 proc utl_ctime {utime} {
78 if {$utime == "" || $utime == "*"} { 85 if {$utime == "" || $utime == "*"} {
79 set utime 0 86 set utime 0
80 } 87 }
81 return [clock format $utime -format "%d.%m.%Y %H:%M"] 88 return [clock format $utime -format "%d.%m.%Y %H:%M"]