comparison quotedb.tcl @ 293:42ba48d54324

quotedb: Use utillib string splitting.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 26 Jan 2015 14:03:41 +0200
parents 135e6c628164
children 141bb4a2b76f
comparison
equal deleted inserted replaced
292:9f90d6918626 293:42ba48d54324
11 ### The configuration should be in config.quotedb in same directory 11 ### The configuration should be in config.quotedb in same directory
12 ### as this script. Or change the line below to point where ever 12 ### as this script. Or change the line below to point where ever
13 ### you wish. See "config.quotedb.example" for an example config file. 13 ### you wish. See "config.quotedb.example" for an example config file.
14 source [file dirname [info script]]/config.quotedb 14 source [file dirname [info script]]/config.quotedb
15 15
16 ### Required utillib.tcl
17 source [file dirname [info script]]/utillib.tcl
18
16 19
17 ########################################################################## 20 ##########################################################################
18 # No need to look below this line 21 # No need to look below this line
19 ########################################################################## 22 ##########################################################################
20 set qdb_name "QuoteDB" 23 set qdb_name "QuoteDB"
83 qdb_log "$uerrmsg on SQL:\n$usql" 86 qdb_log "$uerrmsg on SQL:\n$usql"
84 qdb_msg $upublic $unick $uchan $qdb_msg_sql_error 87 qdb_msg $upublic $unick $uchan $qdb_msg_sql_error
85 return 0 88 return 0
86 } 89 }
87 return 1 90 return 1
88 }
89
90 proc qdb_split {str maxlen} {
91 set pos 0
92 set len [string length $str]
93 set ulen 0
94 set ustr ""
95 set result {}
96 while {$pos < $len} {
97 set end [string wordend $str $pos]
98 set new [expr $end - $pos + 1]
99 if {$ulen + $new < $maxlen} {
100 append ustr [string range $str $pos $end]
101 set ulen [expr $ulen + $new]
102 } else {
103 append ustr [string range $str $pos $end]
104 lappend result $ustr
105 set ustr ""
106 set ulen 0
107 }
108 set pos [expr $end + 1]
109 }
110 if {$ustr != ""} {
111 lappend result $ustr
112 }
113 return $result
114 } 91 }
115 92
116 proc qdb_valid_user {upublic unick uchan uhand} { 93 proc qdb_valid_user {upublic unick uchan uhand} {
117 global qdb_msg_invalid_user 94 global qdb_msg_invalid_user
118 if {$uhand == "" || $uhand == {}} { 95 if {$uhand == "" || $uhand == {}} {
332 append usql " GROUP BY ${utable}.id ORDER BY RANDOM() LIMIT 1" 309 append usql " GROUP BY ${utable}.id ORDER BY RANDOM() LIMIT 1"
333 qdb_log "$unick get random $utable" 310 qdb_log "$unick get random $utable"
334 } 311 }
335 312
336 qdb_handle eval $usql { 313 qdb_handle eval $usql {
337 set qtmp [qdb_split "#${quoteID}: $utext ($uuser@[qdb_ctime $utime], $uvote)" 450] 314 set qtmp [utl_str_split "#${quoteID}: $utext ($uuser@[qdb_ctime $utime], $uvote)" 450]
338 foreach qstr $qtmp { 315 foreach qstr $qtmp {
339 qdb_msg $upublic $unick $uchan $qstr 316 qdb_msg $upublic $unick $uchan $qstr
340 } 317 }
341 return 1 318 return 1
342 } 319 }