## fairly simple wraping proc...never breaks a word
## usage:  foreach line [wrapit $text 20] {puts $line}
## example:
## % set text "According to Finnish security researcher Jouko Pynnonen, who discovered the problem, the risk is not limited ## to IE users but also affects Mozilla Firefox both on Windows and Linux systems. Opera users also at risk."
## According to Finnish security researcher Jouko Pynnonen, who discovered the problem, the risk is not limited to IE users ## but also affects Mozilla Firefox both on Windows and Linux systems. Opera users also at risk.
## % foreach line [wrapit $text 20] {puts $line}
## According to Finnish
## security researcher
## Jouko Pynnonen, who
## discovered the problem,
## the risk is not limited
## to IE users but also
## affects Mozilla Firefox
## both on Windows and
## Linux systems. Opera
## users also at risk.
## %
##
proc wrapit {text length} {
	if {[string length [set tmp $text]] > $length} {
		set len 0
		while {$len < [string length $tmp]} {
			if {![string equal {} [set tmpline [string range $tmp $len \
			[string wordend $tmp [expr {$len + ($length - 2)}]]]]]} {
				lappend outs [string trim $tmpline]
			}
			incr len [string length $tmpline]
		}
		if {[info exists outs]} {return $outs}
	} else {return [list $text]}
}