Posted to tcl by RiverRat at Fri Dec 07 23:38:17 GMT 2007view raw
- proc putlongbot {target header lst} {
- global max_line
- set tempstr ""
- set strlen 0
- set maxlines 5
- set templst $lst
- set linecount 0
- # set max_line 120
- set max_line [expr 420 - [string length $header]]
- # This should handle splitting of lists into many strings
- # It should limit itself to 3 such strings though.
-
- # while {[string length $tempstr] > $max_line} {}
- while {1} {
- if {[llength $templst] <= 0} {
- if {$strlen} {
- putbot $target $tempstr
- # puthelp "PRIVMSG $target :$tempstr"
- }
- break
- }
- set tempele [lindex $templst 0]
- # TODO: Check for element too long
- set templst [lrange $templst 1 end]
- # puthelp "PRIVMSG $target :==> [expr $strlen + [string length $tempele] + 3] "
- if {[expr $strlen + [string length $tempele] + 10] > $max_line} {
- if {$linecount >= [expr $maxlines - 1]} {
- putbot $target "$tempstr (truncated)"
- return -1
- } else {
- putbot $target "$tempstr (cont)"
- }
- incr linecount
- set tempstr [concat $header " (more:)" "\{${tempele}\}"]
- set strlen [string length $tempstr]
- } else {
- # Perhaps without the ' ' on the first element
- if {![string length $tempstr]} {
- set tempstr [concat $header $tempstr "${tempele}"]
- } else {
- set tempstr [concat $tempstr " \{${tempele}\}"]
- }
- set strlen [string length $tempstr]
- }
- # check to see if adding another element to string exceeds maxlen
- # print tempstr and clear tempstr & strlen & inc linecount & continue
- # if linecount > maxlines then done
- # else
- # append element to tempstr & $strlen = new length
- # continue w/ next element
- # Check for empty $templst (removing elements as we go) if empty then finish
- # finish, print tempstr and break
- }
- return 0
- }
-