puts $f $preamble
# generate TAB_VALUES_24
+tab_initialize $f {set SZT_VALUES} {map2m1 CV $value} \
+ "unsigned char TAB_VALUES_24\[SZT_VALUES_24\] = {"
set SZT_VALUES 0
-tab_begin $f "unsigned char TAB_VALUES_24\[SZT_VALUES_24\] = {"
-foreach {value} [map2 CV] {
- tab_begin_block $f $SZT_VALUES
-
+foreach {value} [lsort -dictionary [map2 CV]] {
foreach {r g b} $value {break}
- tab_elem $f [format "0x%02x,0x%02x,0x%02x," $r $g $b]
-
+ tab_elem [format "0x%02x,0x%02x,0x%02x," $r $g $b]
+ tab_row
set ALL_VALUES_coded($value) $SZT_VALUES
incr SZT_VALUES
-
- # comment shows {{color {scheme...}}...}
- tab_end_block $f [map2m1 CV $value]
}
-tab_end $f "};\n"
-
+tab_finalize "};\n"
# generate NONAME_VALUES_24
+tab_initialize $f {set SZT_NONAME_VALUES} {map2m1 ICRIV $range_index_value} \
+ "unsigned char TAB_NONAME_VALUES_24\[SZT_NONAME_VALUES_24\] = {"
set SZT_NONAME_VALUES 0
-tab_begin $f "unsigned char TAB_NONAME_VALUES_24\[SZT_NONAME_VALUES_24\] = {"
foreach {range_index_value} [lsort -dictionary [map2 ICRIV]] {
foreach {range index value} $range_index_value {break}
if {! [info exists ALL_VALUES_coded($value)]} {
- tab_begin_block $f $SZT_NONAME_VALUES
-
foreach {r g b} $value {break}
- tab_elem $f [format "0x%02x,0x%02x,0x%02x," $r $g $b]
-
+ tab_elem [format "0x%02x,0x%02x,0x%02x," $r $g $b]
+ tab_row
set ALL_VALUES_coded($value) [expr $SZT_NONAME_VALUES + $SZT_VALUES]
incr SZT_NONAME_VALUES
-
- # comment shows {{icolor {scheme...}}...}
- tab_end_block $f [map2m1 ICRIV $range_index_value]
}
}
-tab_end $f "};\n"
+tab_finalize "};\n"
close $f
+
#------------------------------------------------- write inkpot_scheme_table.h
set f [open inkpot_scheme_table.h w]
puts $f $preamble
set SZT_STRINGS 0
set SZL_STRINGS 0
set SZW_STRINGS 0
-tab_begin $f "const char TAB_STRINGS\[SZT_STRINGS\] = {"
+tab_initialize $f {set SZT_STRINGS} {set len} \
+ "const char TAB_STRINGS\[SZT_STRINGS\] = {"
foreach {string} [lsort -ascii [array names ALL_STRINGS]] {
- tab_begin_block $f $SZT_STRINGS
-
- tab_elem $f "\"$string\\0\""
-
set len [string length $string]
# include the null
incr len
-
- tab_end_block $f $len
-
+ tab_elem "\"$string\\0\""
+ tab_row
foreach {usage} $ALL_STRINGS($string) {
switch $usage {
scheme {
if {$len > $SZL_STRINGS} {set SZL_STRINGS $len}
incr SZT_STRINGS $len
}
-tab_end $f "};\n"
+tab_finalize "};\n"
# don't count the null in the length of the longest string
incr SZL_STRINGS -1
# generate TAB_INDEXES
set SZT_INDEXES 0
set index -1
-tab_begin $f "IDX_VALUES TAB_INDEXES\[SZT_INDEXES\] = {"
+tab_initialize $f {set SZT_INDEXES} {list [map2m1 ICRIV $RIV] $size} \
+ "IDX_VALUES TAB_INDEXES\[SZT_INDEXES\] = {"
foreach {icolor_range_schemes} [lsort -ascii [array names ALL_RANGES]] {
- tab_begin_block $f $SZT_INDEXES
+ tab_row
foreach {m2} $ALL_RANGES($icolor_range_schemes) {
foreach {RIV schemes} $m2 {break}
foreach {range index value} $RIV {break}
- tab_elem $f $ALL_VALUES_coded($value),
+ tab_elem $ALL_VALUES_coded($value),
incr SZT_INDEXES
}
set size [llength $ALL_RANGES($icolor_range_schemes)]
set ALL_RANGES_coded($icolor_range_schemes) [list $SZT_INDEXES $size]
- tab_end_block $f "[map2m1 ICRIV $RIV] $size"
}
-tab_end $f "};\n"
+tab_finalize "};\n"
# generate TAB_RANGES
set SZT_RANGES 0
set last_icolor ""
-tab_begin $f "inkpot_range_t TAB_RANGES\[SZT_RANGES\] = {"
+tab_initialize $f {set SZT_RANGES} {list $icolor $schemes $cnt} \
+ "inkpot_range_t TAB_RANGES\[SZT_RANGES\] = {"
foreach {icolor_range_schemes} [lsort -dictionary [array names ALL_RANGES_coded]] {
foreach {icolor range schemes} $icolor_range_schemes {break}
foreach {first_idx size} $ALL_RANGES_coded($icolor_range_schemes) {break}
if {! [string equal $last_icolor $icolor]} {
- if {! [string equal $last_icolor ""]} {
- tab_end_block $f [list $icolor $schemes $cnt]
- }
- tab_begin_block $f $SZT_RANGES
+ tab_row
set cnt 0
set last_icolor $icolor
}
set size [llength $ALL_RANGES($icolor_range_schemes)]
- tab_elem $f "{$size,$first_idx},"
+ tab_elem "{$size,$first_idx},"
incr SZT_RANGES
incr cnt
}
-tab_end_block $f [list $icolor $schemes $cnt]
-tab_end $f "};\n"
+tab_finalize "};\n"
# generate TAB_ICOLORS
set SZT_ICOLORS 0
set last_icolor ""
-tab_begin $f "inkpot_scheme_index_t TAB_ICOLORS\[SZT_ICOLORS\] = {"
+tab_initialize $f {set SZT_ICOLORS} {list $icolor $schemes} \
+ "inkpot_scheme_index_t TAB_ICOLORS\[SZT_ICOLORS\] = {"
foreach {icolor_range_schemes} [lsort -dictionary [array names ALL_RANGES_coded]] {
foreach {icolor range schemes} $icolor_range_schemes {break}
foreach {first_idx size} $ALL_RANGES_coded($icolor_range_schemes) {break}
if {! [string equal $last_icolor $icolor]} {
- if {! [string equal $last_icolor ""]} {tab_end_block $f [list $icolor $schemes]}
- tab_begin_block $f $SZT_ICOLORS
- tab_elem $f "{$ALL_ICOLOR_STRINGS_coded($icolor),$first_idx},"
+ tab_elem "{$ALL_ICOLOR_STRINGS_coded($icolor),$first_idx},"
+ tab_row
set last_icolor $icolor
}
set ALL_ICOLORS_coded($color) $SZT_ICOLORS
incr SZT_ICOLORS
}
-tab_end_block $f [list $icolor $schemes]
-tab_end $f "};\n"
+tab_finalize "};\n"
# generate TAB_SCHEMES
set SZT_SCHEMES 0
-tab_begin $f "inkpot_scheme_name_t TAB_SCHEMES\[SZT_SCHEMES\] = {"
+tab_initialize $f {set SZT_SCHEMES} {set scheme} \
+ "inkpot_scheme_name_t TAB_SCHEMES\[SZT_SCHEMES\] = {"
foreach {scheme} [lsort -ascii [array names ALL_SCHEMES]] {
- tab_begin_block $f $SZT_SCHEMES
-
# tab_elem $f "{$ALL_SCHEME_STRINGS_coded($scheme),$ALL_INDEX_SCHEMES_coded($scheme)},"
- tab_elem $f "{$ALL_SCHEME_STRINGS_coded($scheme)},"
-
- tab_end_block $f $scheme
-
+ tab_elem "{$ALL_SCHEME_STRINGS_coded($scheme)},"
+ tab_row
set ALL_SCHEMES_coded($scheme) [list $SZT_SCHEMES [expr 1 << $SZT_SCHEMES]]
incr SZT_SCHEMES
}
-tab_end $f "};\n"
+tab_finalize "};\n"
if {0} {
# generate TAB_ALTS
set SZT_ALTS 0
-tab_begin $f "inkpot_name_t TAB_ALTS\[SZT_ALTS\] = {"
+tab_initialize $f {set first_idx} {set aliases} \
+ "inkpot_name_t TAB_ALTS\[SZT_ALTS\] = {"
#foreach {m1} [lsort -ascii [array names ALL_ALIASES]] {
# foreach {color schemes} $m1 {break}
foreach {r_set} [map3 CV] {
foreach {scheme_idx scheme_bit} $ALL_SCHEMES_coded($scheme) {break}
set scheme_bits [expr $scheme_bits | $scheme_bit]
}
- set isneeded 0
set m2s [map3m2 CV $r_set]
# set m2s $ALL_ALIASES($m1)
set cnt [llength $m2s]
set first_idx $SZT_ALTS
foreach {m2} $m2s {
foreach {value schemeset} $m2 {break}
- tab_begin_block $f $first_idx
- incr isneeded
- tab_elem $f "{[incr cnt -1],$ALL_VALUES_coded($value),[format {0x%x} $scheme_bits]},"
+ tab_elem "{[incr cnt -1],$ALL_VALUES_coded($value),[format {0x%x} $scheme_bits]},"
incr SZT_ALTS
set aliases [mapm21 CV $m2]
foreach {color} $aliases {
}
}
}
- if {$isneeded} {tab_end_block $f $aliases}
+ tab_row
#}
-tab_end $f "};\n"
+tab_finalize "};\n"
# generate TAB_NAMES
set SZT_NAMES 0
-tab_begin $f "inkpot_name_t TAB_NAMES\[SZT_NAMES\] = {"
+tab_initialize $f {set SZT_NAMES} {set color} \
+ "inkpot_name_t TAB_NAMES\[SZT_NAMES\] = {"
foreach {color} [map1 CV] {
- tab_begin_block $f $SZT_NAMES
-
- tab_elem $f "{$ALL_COLOR_STRINGS_coded($color),$ALL_ALTSETS_coded($color)},"
-
- tab_end_block $f $color
-
+ tab_elem "{$ALL_COLOR_STRINGS_coded($color),$ALL_ALTSETS_coded($color)},"
+ tab_row
set ALL_NAMES_coded($color) $SZT_NAMES
incr SZT_NAMES
}
-tab_end $f "};\n"
+tab_finalize "};\n"
# generate TAB_TO_NAMES
set SZT_TO_NAMES 0
-tab_begin $f "IDX_NAMES TAB_TO_NAMES\[SZT_TO_NAMES\] = {"
+tab_initialize $f {set SZT_TO_NAMES} {set alias_set} \
+ "IDX_NAMES TAB_TO_NAMES\[SZT_TO_NAMES\] = {"
foreach {m2} [mapm2 CV] {
set alias_set [mapm21 CV $m2]
- tab_begin_block $f $SZT_TO_NAMES
foreach {value schemeset} $m2 {break}
set ALL_TO_NAMES_coded($value) $SZT_TO_NAMES
- switch [llength $alias_set] {
- 0 {
- puts stderr "shouldn't happen - zero maps: $value"
- }
- default {
- set first_idx $SZT_TO_NAMES
- foreach {color} $alias_set {
- tab_elem $f $ALL_NAMES_coded($color),
- lappend comment $color
- incr SZT_TO_NAMES
- }
- }
+ set first_idx $SZT_TO_NAMES
+ foreach {color} $alias_set {
+ tab_elem $ALL_NAMES_coded($color),
+ lappend comment $color
+ incr SZT_TO_NAMES
}
- if {$isneeded} {tab_end_block $f $alias_set}
+ tab_row
}
-tab_end $f "};\n"
+tab_finalize "};\n"
# generate TAB_VALUE_TO
set SZT_VALUE_TO 0
-tab_begin $f "IDX_TO_NAMES TAB_VALUE_TO\[SZT_VALUE_TO\] = {"
+tab_initialize $f {set SZT_VALUE_TO} {set ALL_TO_NAMES_coded($value)} \
+ "IDX_TO_NAMES TAB_VALUE_TO\[SZT_VALUE_TO\] = {"
# NB - this sort order must match TAB_VALUES
-foreach {value} [map2 CV] {
- tab_begin_block $f $SZT_VALUE_TO
-
- tab_elem $f $ALL_TO_NAMES_coded($value),
-
- tab_end_block $f $ALL_TO_NAMES_coded($value)
+foreach {value} [lsort -dictionary [map2 CV]] {
+ tab_elem $ALL_TO_NAMES_coded($value),
+ tab_row
incr SZT_VALUE_TO
}
-tab_end $f "};\n"
+tab_finalize "};\n"
close $f
puts $ch $table_end
}
-proc tab_first_elem {data} {
+proc tab_elem {data} {
upvar TAB_pos pos
upvar TAB_chan ch
- if {$pos} { tab_end_row }
- tab_start_row
- puts -nonewline $ch $data
- incr pos [string length $data]
-}
-
-proc tab_last_elem {data} {
- upvar TAB_pos pos
- upvar TAB_chan ch
- puts -nonewline $ch $data
- incr pos [string length $data]
- tab_end_row
-}
-
-proc tab_next_elem {data} {
- upvar TAB_pos pos
- upvar TAB_chan ch
- if {$pos > 64} { tab_end_row }
+ if {$pos > 64} {
+ puts $ch ""
+ set pos 0
+ }
if {$pos == 0} { tab_start_row }
puts -nonewline $ch $data
incr pos [string length $data]
}
-
-proc tab_begin {f s} {
- upvar pos pos
-
- puts $f $s
- set pos 0
-}
-
-proc tab_end {f s} {
- upvar pos pos
-
- if {$pos} { puts $f "" }
- puts $f $s
- set pos 0
-}
-
-# $comment_list needs to be 8 char or less
-proc tab_begin_block {f {comment_list {}}} {
- upvar pos pos
- upvar comments comments
- upvar indent indent
-
- if {$pos == 0} {
- incr pos [string length $indent]
- if {$comments && [llength $comment_list]} {
- set s [concat "/*" $comment_list "*/"]
- incr pos [string length $s]
- set w [expr 16 - $pos]
- puts -nonewline $f $indent$s[format "%.[set w]s" " "]
- set pos 16
- } {
- puts -nonewline $f $indent
- }
- }
-}
-
-proc tab_end_block {f {comment_list {}}} {
- upvar pos pos
- upvar comments comments
- upvar target_line_length target_line_length
-
- if {$comments && [llength $comment_list]} {
- set w [expr 5 - $pos / 8]
- if {$w < 0} {set w 0}
- set s [concat "/*" $comment_list "*/"]
- puts $f [format "%.[set w]s" "\t\t\t\t\t"]$s
- set pos 0
- } {
- if {$pos >= $target_line_length} {
- puts $f ""
- set pos 0
- }
- }
-}
-
-proc tab_elem {f s} {
- upvar pos pos
-
- puts -nonewline $f $s
- incr pos [string length $s]
+proc tab_row { } {
+ upvar TAB_pos pos
+ if {$pos} { tab_end_row }
}
###################################################################