Error processing request
Parameters
CONTENT_LENGTH | 0 |
REQUEST_METHOD | GET |
REQUEST_URI | /revision/How+to+wrap+cell+contents+when+using+tcllib+struct%3A%3Amatrix+and+report?V=5 |
QUERY_STRING | V=5 |
CONTENT_TYPE | |
DOCUMENT_URI | /revision/How+to+wrap+cell+contents+when+using+tcllib+struct::matrix+and+report |
DOCUMENT_ROOT | /var/www/nikit/nikit/nginx/../docroot |
SCGI | 1 |
SERVER_PROTOCOL | HTTP/1.1 |
HTTPS | on |
REMOTE_ADDR | 172.70.34.152 |
REMOTE_PORT | 53426 |
SERVER_PORT | 4443 |
SERVER_NAME | wiki.tcl-lang.org |
HTTP_HOST | wiki.tcl-lang.org |
HTTP_CONNECTION | Keep-Alive |
HTTP_ACCEPT_ENCODING | gzip, br |
HTTP_X_FORWARDED_FOR | 3.235.180.245 |
HTTP_CF_RAY | 86c08230dfc759a3-IAD |
HTTP_X_FORWARDED_PROTO | https |
HTTP_CF_VISITOR | {"scheme":"https"} |
HTTP_ACCEPT | */* |
HTTP_USER_AGENT | claudebot |
HTTP_CF_CONNECTING_IP | 3.235.180.245 |
HTTP_CDN_LOOP | cloudflare |
HTTP_CF_IPCOUNTRY | US |
Body
Error
Unknow state transition: LINE -> END
-code
1
-level
0
-errorstack
INNER {returnImm {Unknow state transition: LINE -> END} {}} CALL {my render_wikit {How to wrap cell contents when using tcllib struct::matrix and report} {[Bezoar] 26 March 2008
I wanted to reformat a text table to reduce the width of each column and NOT truncate the
contents. I turned to tcllib's matrix and report packages to accomplish this as I mistakenly
thought that the report package would word wrap automatically. This unfortunately is not the
case. However by using textutils you can preprocess the cell data and get the result you want
this example script does that.
package require struct::matrix
package require report
package require textutil
# fill array with dummy data
set mytable(0,0) "Elements"
set mytable(0,1) "Element A"
set mytable(0,2) "Element B"
set mytable(0,3) "Element C"
set mytable(0,4) "Element D"
set mytable(1,0) "Description"
set mytable(1,1) "ABCDEFGHIJKLMENOP QRST UVW X YZ 1234 5676 9 10 11 12 13 141516"
set mytable(1,2) "ABCDEFGHIJKLMENOP QRST UVW X YZ 1234 5676 9 10 11 12 13 141516"
set mytable(1,3) "ABCDEFGHIJKLMENOP QRST UVW X YZ 1234 5676 9 10 11 12 13 141516"
set mytable(1,4) "ABCDEFGHIJKLMENOP QRST UVW X YZ 1234 5676 9 10 11 12 13 141516"
# define a style and create a report object with that style
proc getReport { name columns style args } {
::report::defstyle simpletable {} {
data set [split "[string repeat "| " [columns]]|"]
top set [split "[string repeat "+ - " [columns]]+"]
bottom set [top get]
top enable
bottom enable
}
set r [ report::report $name $columns style simpletable ]
return $r
}
# for report object named name take column list and set the
# width for each column. Also pass in the data to modify it
# to fit within the new column size.
proc setReportColumnSizes { name columnlist dataArray } {
upvar $dataArray a
r sizes $columnlist
for { set i 0 } { $i < [llength $columnlist] } { incr i } {
foreach index [ array names a $i,* ] {
set a($index) [ textutil::adjust $a($index) -length [lindex $columnlist $i ] -justify left -strictlength true ]
}
}
}
set columns 2
# calculate number of rows
set rows [ expr [ llength [ array names mytable ] ] / $columns ]
set r [ getReport r $columns simpletable ]
#make column one 15 characters wide make column 2 25 characters wide
set sizelist { 15 25 }
# set report column sizes and use textutil::adjust to modify cell data
setReportColumnSizes r $sizelist mytable
#create matrix
set m [ struct::matrix m ]
# create requisite rows and columns
m add columns $columns
m add rows $rows
# link array to matix ... filling in array fills matrix
m link tablex
# fill in matrix
array set tablex [array get mytable]
# output report
puts "[r printmatrix m ]"
Results in :
===
+---------------+-------------------------+
|Elements |Description |
|Element A |ABCDEFGHIJKLMENOP QRST |
| |UVW X YZ 1234 5676 9 10 |
| |11 12 13 141516 |
|Element B |ABCDEFGHIJKLMENOP QRST |
| |UVW X YZ 1234 5676 9 10 |
| |11 12 13 141516 |
|Element C |ABCDEFGHIJKLMENOP QRST |
| |UVW X YZ 1234 5676 9 10 |
| |11 12 13 141516 |
|Element D |ABCDEFGHIJKLMENOP QRST |
| |UVW X YZ 1234 5676 9 10 |
| |11 12 13 141516 |
+---------------+-------------------------+
======
if run without textutil pre-procesing the data is truncated :
======
+---------------+-------------------------+
|Elements |Description |
|Element A |676 9 10 11 12 13 141516|
|Element B |676 9 10 11 12 13 141516|
|Element C |676 9 10 11 12 13 141516|
|Element D |676 9 10 11 12 13 141516|
+---------------+-------------------------+
======
----
!!!!!!
%| [Category Package], subset [Tcllib]|%
!!!!!!} regexp2} CALL {my render {How to wrap cell contents when using tcllib struct::matrix and report} {[Bezoar] 26 March 2008
I wanted to reformat a text table to reduce the width of each column and NOT truncate the
contents. I turned to tcllib's matrix and report packages to accomplish this as I mistakenly
thought that the report package would word wrap automatically. This unfortunately is not the
case. However by using textutils you can preprocess the cell data and get the result you want
this example script does that.
package require struct::matrix
package require report
package require textutil
# fill array with dummy data
set mytable(0,0) "Elements"
set mytable(0,1) "Element A"
set mytable(0,2) "Element B"
set mytable(0,3) "Element C"
set mytable(0,4) "Element D"
set mytable(1,0) "Description"
set mytable(1,1) "ABCDEFGHIJKLMENOP QRST UVW X YZ 1234 5676 9 10 11 12 13 141516"
set mytable(1,2) "ABCDEFGHIJKLMENOP QRST UVW X YZ 1234 5676 9 10 11 12 13 141516"
set mytable(1,3) "ABCDEFGHIJKLMENOP QRST UVW X YZ 1234 5676 9 10 11 12 13 141516"
set mytable(1,4) "ABCDEFGHIJKLMENOP QRST UVW X YZ 1234 5676 9 10 11 12 13 141516"
# define a style and create a report object with that style
proc getReport { name columns style args } {
::report::defstyle simpletable {} {
data set [split "[string repeat "| " [columns]]|"]
top set [split "[string repeat "+ - " [columns]]+"]
bottom set [top get]
top enable
bottom enable
}
set r [ report::report $name $columns style simpletable ]
return $r
}
# for report object named name take column list and set the
# width for each column. Also pass in the data to modify it
# to fit within the new column size.
proc setReportColumnSizes { name columnlist dataArray } {
upvar $dataArray a
r sizes $columnlist
for { set i 0 } { $i < [llength $columnlist] } { incr i } {
foreach index [ array names a $i,* ] {
set a($index) [ textutil::adjust $a($index) -length [lindex $columnlist $i ] -justify left -strictlength true ]
}
}
}
set columns 2
# calculate number of rows
set rows [ expr [ llength [ array names mytable ] ] / $columns ]
set r [ getReport r $columns simpletable ]
#make column one 15 characters wide make column 2 25 characters wide
set sizelist { 15 25 }
# set report column sizes and use textutil::adjust to modify cell data
setReportColumnSizes r $sizelist mytable
#create matrix
set m [ struct::matrix m ]
# create requisite rows and columns
m add columns $columns
m add rows $rows
# link array to matix ... filling in array fills matrix
m link tablex
# fill in matrix
array set tablex [array get mytable]
# output report
puts "[r printmatrix m ]"
Results in :
===
+---------------+-------------------------+
|Elements |Description |
|Element A |ABCDEFGHIJKLMENOP QRST |
| |UVW X YZ 1234 5676 9 10 |
| |11 12 13 141516 |
|Element B |ABCDEFGHIJKLMENOP QRST |
| |UVW X YZ 1234 5676 9 10 |
| |11 12 13 141516 |
|Element C |ABCDEFGHIJKLMENOP QRST |
| |UVW X YZ 1234 5676 9 10 |
| |11 12 13 141516 |
|Element D |ABCDEFGHIJKLMENOP QRST |
| |UVW X YZ 1234 5676 9 10 |
| |11 12 13 141516 |
+---------------+-------------------------+
======
if run without textutil pre-procesing the data is truncated :
======
+---------------+-------------------------+
|Elements |Description |
|Element A |676 9 10 11 12 13 141516|
|Element B |676 9 10 11 12 13 141516|
|Element C |676 9 10 11 12 13 141516|
|Element D |676 9 10 11 12 13 141516|
+---------------+-------------------------+
======
----
!!!!!!
%| [Category Package], subset [Tcllib]|%
!!!!!!}} CALL {my revision {How to wrap cell contents when using tcllib struct::matrix and report}} CALL {::oo::Obj1475245 process revision/How+to+wrap+cell+contents+when+using+tcllib+struct%3A%3Amatrix+and+report} CALL {::oo::Obj1475243 process}
-errorcode
NONE
-errorinfo
Unknow state transition: LINE -> END
while executing
"error $msg"
(class "::Wiki" method "render_wikit" line 6)
invoked from within
"my render_$default_markup $N $C $mkup_rendering_engine"
(class "::Wiki" method "render" line 8)
invoked from within
"my render $name $C"
(class "::Wiki" method "revision" line 31)
invoked from within
"my revision $page"
(class "::Wiki" method "process" line 56)
invoked from within
"$server process [string trim $uri /]"
-errorline
4