Posted to tcl by RiverRat at Fri Dec 07 23:38:17 GMT 2007view raw

  1. proc putlongbot {target header lst} {
  2. global max_line
  3. set tempstr ""
  4. set strlen 0
  5. set maxlines 5
  6. set templst $lst
  7. set linecount 0
  8. # set max_line 120
  9. set max_line [expr 420 - [string length $header]]
  10. # This should handle splitting of lists into many strings
  11. # It should limit itself to 3 such strings though.
  12.  
  13. # while {[string length $tempstr] > $max_line} {}
  14. while {1} {
  15. if {[llength $templst] <= 0} {
  16. if {$strlen} {
  17. putbot $target $tempstr
  18. # puthelp "PRIVMSG $target :$tempstr"
  19. }
  20. break
  21. }
  22. set tempele [lindex $templst 0]
  23. # TODO: Check for element too long
  24. set templst [lrange $templst 1 end]
  25. # puthelp "PRIVMSG $target :==> [expr $strlen + [string length $tempele] + 3] "
  26. if {[expr $strlen + [string length $tempele] + 10] > $max_line} {
  27. if {$linecount >= [expr $maxlines - 1]} {
  28. putbot $target "$tempstr (truncated)"
  29. return -1
  30. } else {
  31. putbot $target "$tempstr (cont)"
  32. }
  33. incr linecount
  34. set tempstr [concat $header " (more:)" "\{${tempele}\}"]
  35. set strlen [string length $tempstr]
  36. } else {
  37. # Perhaps without the ' ' on the first element
  38. if {![string length $tempstr]} {
  39. set tempstr [concat $header $tempstr "${tempele}"]
  40. } else {
  41. set tempstr [concat $tempstr " \{${tempele}\}"]
  42. }
  43. set strlen [string length $tempstr]
  44. }
  45. # check to see if adding another element to string exceeds maxlen
  46. # print tempstr and clear tempstr & strlen & inc linecount & continue
  47. # if linecount > maxlines then done
  48. # else
  49. # append element to tempstr & $strlen = new length
  50. # continue w/ next element
  51. # Check for empty $templst (removing elements as we go) if empty then finish
  52. # finish, print tempstr and break
  53. }
  54. return 0
  55. }
  56.