]> granicus.if.org Git - graphviz/commitdiff
moving stuff around
authorellson <devnull@localhost>
Fri, 3 Oct 2008 18:13:24 +0000 (18:13 +0000)
committerellson <devnull@localhost>
Fri, 3 Oct 2008 18:13:24 +0000 (18:13 +0000)
lib/inkpot/.cvsignore
lib/inkpot/Makefile.am
lib/inkpot/Makefile.old
lib/inkpot/inkpot_lib.tcl [new file with mode: 0755]
lib/inkpot/inkpot_lib_brewer.tcl [new file with mode: 0755]
lib/inkpot/inkpot_lib_procs.tcl [new file with mode: 0755]

index 9f3e49c13f97fe20e066c28ce3f7a415b7499b6b..3182bc03d73605102272086b827fa262cbe960e3 100644 (file)
@@ -11,4 +11,4 @@ inkpot
 inkpot_define.h
 inkpot_scheme_table.h
 inkpot_value_table.h
-*.lib
+*.dat
index d01d1cf7809f618e04ead3308defe46ad5df0959..7e3bd4c6ff6aba32cdfc73335cb11c7bf312f9da 100644 (file)
@@ -28,24 +28,28 @@ inkpot_value_table.h: $(builddir)/inkpot_define.h
 
 inkpot_scheme_table.h: $(builddir)/inkpot_define.h
 
-inkpot_define.h: scripts/lib-h.tcl \
-                       $(builddir)/tk.lib \
-                               $(builddir)/svg.lib \
-                       $(builddir)/x11.lib \
-                       $(builddir)/brewer.lib
-       $(TCLSH) scripts/lib-h.tcl tk.lib svg.lib x11.lib brewer.lib
+inkpot_define.h: inkpot_lib.tcl inkpot_lib_procs.tcl \
+                       $(builddir)/inkpot_lib_tk.dat \
+                               $(builddir)/inkpot_lib_svg.dat \
+                       $(builddir)/inkpot_lib_x11.dat \
+                       $(builddir)/inkpot_lib_brewer.dat
+       $(TCLSH) inkpot_lib.tcl \
+                       $(builddir)/inkpot_lib_tk.dat \
+                       $(builddir)/inkpot_lib_svg.dat \
+                       $(builddir)/inkpot_lib_x11.dat \
+                       $(builddir)/inkpot_lib_brewer.dat
 
-x11.lib: scripts/rgb.txt-x11.lib.tcl data/rgb.txt
-       $(TCLSH) scripts/rgb.txt-x11.lib.tcl data/rgb.txt
+inkpot_lib_x11.dat: inkpot_lib_x11.tcl data/rgb.txt
+       $(TCLSH) inkpot_lib_x11.tcl data/rgb.txt
 
-svg.lib: scripts/types.html-svg.lib.tcl data/types.html
-       $(TCLSH) scripts/types.html-svg.lib.tcl data/types.html
+inkpot_lib_svg.dat: inkpot_lib_svg.tcl data/types.html
+       $(TCLSH) inkpot_lib_svg.tcl data/types.html
 
-tk.lib: scripts/xcolors.c-tk.lib.tcl data/xcolors.c
-       $(TCLSH) scripts/xcolors.c-tk.lib.tcl data/xcolors.c
+inkpot_lib_tk.dat: inkpot_lib_tk.tcl data/xcolors.c
+       $(TCLSH) inkpot_lib_tk.tcl data/xcolors.c
 
-brewer.lib: scripts/brewer_colors-brewer.lib.tcl data/brewer_colors
-       $(TCLSH) scripts/brewer_colors-brewer.lib.tcl data/brewer_colors
+inkpot_lib_brewer.dat: inkpot_lib_brewer.tcl data/brewer_colors
+       $(TCLSH) inkpot_lib_brewer.tcl data/brewer_colors
 
 inkpot.1.pdf: inkpot.1
        - $(GROFF) -Tps -man inkpot.1 | $(PS2PDF) - - > inkpot.1.pdf
@@ -53,9 +57,9 @@ inkpot.1.pdf: inkpot.1
 inkpot.3.pdf: inkpot.3
        - $(GROFF) -Tps -man inkpot.3 | $(PS2PDF) - - > inkpot.3.pdf
 
-CLEANFILES = tk.lib svg.lib x11.lib  brewer.lib
+CLEANFILES = inkpot_lib_*.dat
 
-EXTRA_DIST = $(man_MANS) $(pdf_DATA) Makefile.old scripts/* data/* \
+EXTRA_DIST = $(man_MANS) $(pdf_DATA) Makefile.old *.tcl data/* \
        inkpot_define.h inkpot_value_table.h inkpot_scheme_table.h
 
 DISTCLEANFILES = $(pdf_DATA) \
index 8095854a9984e370902115b77eff7e725ce0fe51..f97c3d702668c976880ded0c2232ca51d2315893 100644 (file)
@@ -19,21 +19,30 @@ inkpot_value_table.h: inkpot_define.h
 
 inkpot_scheme_table.h: inkpot_define.h
 
-inkpot_define.h: scripts/lib-h.tcl       tk.lib svg.lib x11.lib brewer.lib
-       scripts/lib-h.tcl tk.lib svg.lib x11.lib brewer.lib
+inkpot_define.h: inkpot_lib.tcl inkpot_lib_procs.tcl \
+                       inkpot_lib_tk.dat \
+                               inkpot_lib_svg.dat \
+                       inkpot_lib_x11.dat \
+                       inkpot_lib_brewer.dat
+       tclsh inkpot_lib.tcl \
+                       inkpot_lib_tk.dat \
+                       inkpot_lib_svg.dat \
+                       inkpot_lib_x11.dat \
+                       inkpot_lib_brewer.dat
 
-x11.lib: scripts/rgb.txt-x11.lib.tcl     data/rgb.txt
-       scripts/rgb.txt-x11.lib.tcl data/rgb.txt
+inkpot_lib_x11.dat: inkpot_lib_x11.tcl data/rgb.txt
+       tclsh inkpot_lib_x11.tcl data/rgb.txt
 
-svg.lib: scripts/types.html-svg.lib.tcl  data/types.html
-       scripts/types.html-svg.lib.tcl data/types.html
+inkpot_lib_svg.dat: inkpot_lib_svg.tcl data/types.html
+       tclsh inkpot_lib_svg.tcl data/types.html
 
-tk.lib: scripts/xcolors.c-tk.lib.tcl     data/xcolors.c
-       scripts/xcolors.c-tk.lib.tcl data/xcolors.c
+inkpot_lib_tk.dat: inkpot_lib_tk.tcl data/xcolors.c
+       tclsh inkpot_lib_tk.tcl data/xcolors.c
 
-brewer.lib: scripts/brewer_colors-brewer.lib.tcl data/brewer_colors
-       scripts/brewer_colors-brewer.lib.tcl data/brewer_colors
+inkpot_lib_brewer.dat: inkpot_lib_brewer.tcl data/brewer_colors
+       tclsh inkpot_lib_brewer.tcl data/brewer_colors
 
 clean:
-       rm -rf *.o inkpot tk.lib svg.lib x11.lib brewer.lib \
+       rm -rf *.o inkpot *.dat \
                inkpot_value_table.h inkpot_scheme_table.h inkpot_define.h
+
diff --git a/lib/inkpot/inkpot_lib.tcl b/lib/inkpot/inkpot_lib.tcl
new file mode 100755 (executable)
index 0000000..d0b035e
--- /dev/null
@@ -0,0 +1,560 @@
+#!/usr/bin/tclsh
+
+set comments 1
+set target_line_length 60
+set indent "  "
+
+set preamble "/*\n * DO NOT EDIT !!\n *\n * The files:\n *\tinkpot_define.h\n *\tinkpot_value_table.h\n *\tinkpot_scheme_table.h\n * are generated as a matched set.\n */\n"
+
+if {! $argc} {exit}
+
+source inkpot_lib_procs.tcl
+
+#------------------------------------------------- set_up
+# merge input data
+foreach {lib} $argv {
+       set f [open $lib r]
+       array set COLORS [read $f [file size $lib]]
+       close $f
+
+       foreach {scheme coding} $COLORS() {break}
+       array unset COLORS {}
+       lappend ALL_STRINGS($scheme) scheme
+
+       foreach {color} [array names COLORS] {
+               set value $COLORS($color)
+
+               if {[llength $color] == 1
+               && [regexp -- {([a-z]+)([0-9]+)} $color . subscheme index] == 1} {
+                       unset COLORS($color)
+                       set color [list $subscheme $index]
+                       set COLORS($color) $value
+               }
+
+               switch [llength $color] {
+                       1 {
+                               lappend ALL_STRINGS($color) color
+                               set ALL_SCHEMES($scheme) {}
+                               lappend ALL_VALUES($value) $coding $scheme $color
+                       }
+                       2 {
+                               foreach {subscheme index} $color {break}
+                               lappend ALL_STRINGS($subscheme) subscheme
+                               lappend ALL_INDEX_SCHEMES([list $scheme $subscheme 0]) $index $value
+                               lappend ALL_INDEXES($value) $coding $scheme $subscheme 0 $index
+                       }
+                       3 {
+                               foreach {subscheme range index} $color {break}
+                               lappend ALL_STRINGS($subscheme) subscheme
+                               lappend ALL_INDEX_SCHEMES([list $scheme $subscheme $range]) $index $value
+                               lappend ALL_INDEXES($value) $coding $scheme $subscheme $range $index
+                       }
+                       default {
+                               puts stderr "wrong number of keys in: \"$color\""
+                       }
+               }
+       }
+}
+
+# crunch the data
+foreach {value} [array names ALL_VALUES] {
+       foreach {coding scheme color} $ALL_VALUES($value) {
+               lappend ALL_ALTS([list $color $value]) $scheme
+       }
+}
+foreach {color_value} [lsort -ascii [array names ALL_ALTS]] {
+       foreach {color value} $color_value {break}
+
+       # give preference to x11 scheme names, and hope that someone doesn't invent a z11 scheme
+       set schemeset [lsort -ascii -decreasing $ALL_ALTS($color_value)]
+
+       lappend ALL_ALTSETS($color) $value $schemeset
+       lappend ALL_MAPSETS($value) $color $schemeset
+}
+foreach {color} [lsort -ascii [array names ALL_ALTSETS]] {
+       set altset $ALL_ALTSETS($color)
+       lappend ALL_ALTSET_COLORS($altset) $color
+       foreach {value schemeset} $altset {
+               lappend ALL_VALUE_ALTSETS($value) $altset
+       }
+}
+foreach {value} [lsort -ascii [array names ALL_MAPSETS]] {
+       set mapset $ALL_MAPSETS($value)
+       lappend ALL_MAPSET_VALUES($mapset) $value
+       foreach {color schemeset} $mapset {
+               lappend ALL_COLOR_MAPSETS($color) $mapset
+       }
+}
+foreach {index_scheme} [lsort -ascii [array names ALL_INDEX_SCHEMES]] {
+       foreach {index value} $ALL_INDEX_SCHEMES($index_scheme) {
+               set indexes($index) $value
+       }
+       foreach {index} [lsort -dictionary [array names indexes]] {
+               lappend valueset $indexes($index)
+       }
+       lappend ALL_IDXSETS($valueset) $index_scheme
+       array unset indexes
+       unset valueset
+}
+
+# some support procs
+
+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]
+}
+
+
+# degug support
+proc print_first {a} {
+       upvar $a b
+       set size [llength [array names b]]
+       set first [lindex [array names b] 0]
+       set value $b($first)
+       set totelem 0
+       set maxelem 0
+       foreach {n} [array names b] {
+               set elems [llength $b($n)]
+               if {$elems > $maxelem} {set maxelem $elems}
+               incr totelem $elems
+       }
+       puts stderr [list $a size:$size maxelem:$maxelem totelem:$totelem first: $a\($first) $value]
+}
+       
+#------------------------------------------------- write inkpot_value_table.h
+set f [open inkpot_value_table.h w]
+puts $f $preamble
+
+# generate TAB_VALUES_24
+set SZT_VALUES 0
+tab_begin $f "unsigned char TAB_VALUES_24\[SZT_VALUES_24\] = {"
+foreach {value} [lsort -dictionary [array names ALL_VALUES]] {
+       tab_begin_block $f $SZT_VALUES
+
+       foreach {r g b} $value {break}
+       tab_elem $f [format "0x%02x,0x%02x,0x%02x," $r $g $b]
+
+       set ALL_VALUES_coded($value) $SZT_VALUES
+       incr SZT_VALUES
+       
+       tab_end_block $f $ALL_MAPSETS($value)
+}
+tab_end $f "};\n"
+
+# generate NONAME_VALUES_24
+set SZT_NONAME_VALUES 0
+tab_begin $f "unsigned char TAB_NONAME_VALUES_24\[SZT_NONAME_VALUES_24\] = {"
+foreach {value} [lsort -dictionary [array names ALL_INDEXES]] {
+       if {! [info exists ALL_VALUES($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]
+
+               set ALL_VALUES_coded($value) [expr $SZT_NONAME_VALUES + $SZT_VALUES]
+               incr SZT_NONAME_VALUES
+
+               foreach {coding scheme subscheme range index} $ALL_INDEXES($value) {
+                       set sri [list $subscheme $range $index]
+                       lappend SRI($sri) $scheme
+               }
+               set comment [list]
+               foreach {sri} [lsort -ascii [array names SRI]] {
+                       foreach {subscheme range index} $sri {break}
+                       foreach {scheme} $SRI($sri) {
+                               set schemes($scheme) {}
+                       }
+                       set schemes_s "\([join [lsort -ascii [array names schemes]] ,]\)"
+                       array unset schemes
+                       if {$range} {
+                               lappend comment "$schemes_s$subscheme$range<$index>"
+                       } {
+                               lappend comment "$schemes_s$subscheme<$index>"
+                       }
+               }
+               unset SRI
+       
+               tab_end_block $f $comment
+       }
+}
+tab_end $f "};\n"
+       
+close $f
+#------------------------------------------------- write inkpot_scheme_table.h
+set f [open inkpot_scheme_table.h w]
+puts $f $preamble
+
+# generate TAB_STRINGS
+set SZT_STRINGS 0
+set SZL_STRINGS 0
+set SZW_STRINGS 0
+
+tab_begin $f "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
+       
+       foreach {usage} $ALL_STRINGS($string) {
+               switch $usage {
+                       scheme {
+                               set ALL_SCHEME_STRINGS_coded($string) $SZT_STRINGS
+                       }
+                       subscheme {
+                               set ALL_SUBSCHEME_STRINGS_coded($string) $SZT_STRINGS
+                       }
+                       color {
+                               set ALL_COLOR_STRINGS_coded($string) $SZT_STRINGS
+                       }
+                       default {
+                               puts stderr "Unknown usage $usage for string \"$string\""
+                       }
+               }
+       }
+       incr SZW_STRINGS
+       if {$len > $SZL_STRINGS} {set SZL_STRINGS $len}
+       incr SZT_STRINGS $len
+}
+tab_end $f "};\n"
+# don't count the null in the length of the longest string
+incr SZL_STRINGS -1
+
+       
+# generate TAB_INDEXES
+set SZT_INDEXES 0
+tab_begin $f "IDX_VALUES TAB_INDEXES\[SZT_INDEXES\] = {"
+foreach {valueset} [lsort [array names ALL_IDXSETS]] {
+       set first_idx $SZT_INDEXES
+       tab_begin_block $f $SZT_INDEXES
+       foreach {value} $valueset {
+               tab_elem $f $ALL_VALUES_coded($value),
+               incr SZT_INDEXES
+       }
+       set comment [list]
+       foreach {index_scheme} $ALL_IDXSETS($valueset) {
+               set ALL_INDEX_RANGES_coded($index_scheme) [list $first_idx [expr $SZT_INDEXES - $first_idx]]
+               foreach {scheme subscheme range} $index_scheme {break}
+               if {$range} {
+                       lappend comment $scheme/$subscheme$range
+               } {
+                       lappend comment $scheme/$subscheme
+               }
+       }
+       tab_end_block $f $comment
+}
+tab_end $f "};\n"
+
+foreach {index_scheme} [lsort [array names ALL_INDEX_RANGES_coded]] {
+       foreach {scheme subscheme range} $index_scheme {break}
+       foreach {first_idx size} $ALL_INDEX_RANGES_coded($index_scheme) {break}
+       lappend ALL_INDEX_SUBSCHEME_map([list $subscheme $first_idx $size]) $scheme
+}
+foreach {subscheme_first_idx_size} [array names ALL_INDEX_SUBSCHEME_map] {
+       foreach {subscheme first_idx size} $subscheme_first_idx_size {break}
+       foreach {scheme} $ALL_INDEX_SUBSCHEME_map($subscheme_first_idx_size) {break}
+       lappend ALL_INDEX_SUBSCHEMES_coded([list $scheme $subscheme]) $first_idx $size
+}
+
+
+# generate TAB_SUBSCHEMES_INDEX
+set SZT_SUBSCHEMES_INDEX 0
+tab_begin $f "inkpot_scheme_index_t TAB_SUBSCHEMES_INDEX\[SZT_SUBSCHEMES_INDEX\] = {"
+foreach {scheme_subscheme} [lsort [array names ALL_INDEX_SUBSCHEMES_coded]] {
+       foreach {scheme subscheme} $scheme_subscheme {break}
+
+       tab_begin_block $f $SZT_SUBSCHEMES_INDEX
+
+       foreach {first_idx size} $ALL_INDEX_SUBSCHEMES_coded($scheme_subscheme) {break}
+       tab_elem $f "{$ALL_SUBSCHEME_STRINGS_coded($subscheme),$first_idx,$size},"
+
+       incr SZT_SUBSCHEMES_INDEX
+
+       tab_end_block $f "$scheme/$subscheme<1-$size>"
+}
+tab_end $f "};\n"
+
+# generate TAB_SCHEMES_INDEX
+set SZT_SCHEMES_INDEX 0
+tab_begin $f "inkpot_scheme_index_t TAB_SCHEMES_INDEX\[SZT_SCHEMES_INDEX\] = {"
+foreach {scheme_subscheme} [lsort [array names ALL_INDEX_SUBSCHEMES_coded]] {
+       foreach {scheme subscheme} $scheme_subscheme {break}
+
+       tab_begin_block $f $SZT_SCHEMES_INDEX
+       set ALL_INDEX_SCHEMES_coded($scheme) $SZT_SUBSCHEMES_INDEX
+
+       foreach {subschemes_idx} $ALL_INDEX_SUBSCHEMES_coded($scheme_subscheme) {
+               tab_elem $f $subschemes_idx,
+               incr SZT_SCHEMES_INDEX
+       }
+
+       if {$range} {
+               tab_end_block $f $scheme/$subscheme$range
+       } {
+               tab_end_block $f $scheme/$subscheme
+       }
+}
+tab_end $f "};\n"
+
+
+# generate TAB_SCHEMES
+set SZT_SCHEMES 0
+tab_begin $f "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
+       
+       set ALL_SCHEMES($scheme) [list $SZT_SCHEMES [expr 1 << $SZT_SCHEMES]]
+       incr SZT_SCHEMES
+}
+tab_end $f "};\n"
+       
+       
+# generate TAB_ALTS
+set SZT_ALTS 0
+tab_begin $f "inkpot_name_t TAB_ALTS\[SZT_ALTS\] = {"
+foreach {color} [lsort -ascii [array names ALL_ALTSETS]] {
+       set cnt 0
+       set altset $ALL_ALTSETS($color)
+       set aliases [lsort -ascii $ALL_ALTSET_COLORS($altset)]
+       foreach {value schemeset} $altset {
+               if {[info exists alts($value)]} {
+                       puts stderr "something weird going on"
+               }
+               lappend alts($value) $schemeset $aliases
+               incr cnt
+       }
+       foreach {value} [lsort -ascii [array names alts]] {
+               set scheme_bits 0
+               foreach {schemeset aliases} $alts($value) {break}
+               foreach {scheme} $schemeset {
+                       foreach {scheme_idx scheme_bit} $ALL_SCHEMES($scheme) {break}
+                       set scheme_bits [expr $scheme_bits | $scheme_bit]
+               }
+               lappend value_schemebits $value $scheme_bits $aliases
+       }
+       
+       set isneeded 0
+       if {$cnt == 0} {
+               puts stderr "shouldn't happen - zero alts: $color"
+       } elseif {$cnt == 1} {
+               foreach {value scheme_bits} $value_schemebits {break}
+               set ALL_ALTSETS_coded($color) "$ALL_VALUES_coded($value),[format {0x%x} $scheme_bits]"
+               # don't need entry in TAB_ALTS for this case
+       } else {
+               set first_idx $SZT_ALTS
+               foreach {value scheme_bits aliases} $value_schemebits {
+                       set firstcolor [lindex $aliases 0] 
+                       if {[string equal $color $firstcolor]} {
+                               tab_begin_block $f $first_idx
+                               incr isneeded
+                               
+                               tab_elem $f "{[incr cnt -1],$ALL_VALUES_coded($value),[format {0x%x} $scheme_bits]},"
+                               set ALL_ALTSETS_coded($color) "$SZT_ALTS,0"
+                               incr SZT_ALTS
+                       } {
+                               # the sorting means that this value has already been saved
+                               set ALL_ALTSETS_coded($color) $ALL_ALTSETS_coded($firstcolor)
+                               # don't need entry in TAB_ALTS for this case
+                       }
+               }
+       }
+       if {$isneeded} {tab_end_block $f $aliases}
+       
+       array unset alts
+       unset value_schemebits
+}
+tab_end $f "};\n"
+
+       
+# generate TAB_NAMES
+set SZT_NAMES 0
+tab_begin $f "inkpot_name_t TAB_NAMES\[SZT_NAMES\] = {"
+foreach {color} [lsort -ascii [array names ALL_ALTSETS]] {
+       tab_begin_block $f $SZT_NAMES
+       
+       tab_elem $f "{$ALL_COLOR_STRINGS_coded($color),$ALL_ALTSETS_coded($color)},"
+       
+       tab_end_block $f $color
+       
+       set ALL_NAMES_coded($color) $SZT_NAMES
+       incr SZT_NAMES
+}
+tab_end $f "};\n"
+       
+
+# generate TAB_TO_NAMES
+set SZT_TO_NAMES 0
+tab_begin $f "IDX_NAMES TAB_TO_NAMES\[SZT_TO_NAMES\] = {"
+foreach {value} [lsort -dictionary [array names ALL_VALUES]] {
+       tab_begin_block $f $SZT_TO_NAMES
+
+       set mapset $ALL_MAPSETS($value)
+       set ALL_TO_NAMES_coded($value) $SZT_TO_NAMES
+
+       set comment [list]
+       foreach {color schemeset} $mapset {
+
+               tab_elem $f $ALL_NAMES_coded($color),
+
+               lappend comment $color
+               incr SZT_TO_NAMES
+        }
+
+       tab_end_block $f $comment
+}
+tab_end $f "};\n"
+
+if {$SZT_TO_NAMES != $SZT_NAMES} {
+       puts stderr "That's weird! SZT_TO_NAMES $SZT_TO_NAMES != SZT_NAMES $SZT_NAMES"
+}
+
+
+# generate TAB_VALUE_TO
+set SZT_VALUE_TO 0
+tab_begin $f "IDX_TO_NAMES TAB_VALUE_TO\[SZT_VALUE_TO\] = {"
+# NB - this sort order must match TAB_VALUES
+foreach {value} [lsort -dictionary [array names ALL_VALUES]] {
+       tab_begin_block $f $SZT_VALUE_TO
+
+       set mapset $ALL_MAPSETS($value)
+       tab_elem $f $ALL_TO_NAMES_coded($value),
+       
+       tab_end_block $f $ALL_TO_NAMES_coded($value)
+       incr SZT_VALUE_TO
+}
+tab_end $f "};\n"
+       
+if {$SZT_VALUE_TO != $SZT_VALUES} {
+       puts stderr "That's weird! SZT_VALUE_TO $SZT_VALUE_TO != SZT_VALUES $SZT_VALUES"
+}
+
+
+close $f
+
+
+if {1} {
+       puts stderr ""
+       print_first ALL_STRINGS
+       print_first ALL_NAMES_coded
+       print_first ALL_ALTS
+       print_first ALL_VALUES
+       print_first ALL_ALTSETS
+       print_first ALL_MAPSETS
+       print_first ALL_ALTSET_COLORS
+       print_first ALL_MAPSET_VALUES
+       print_first ALL_VALUE_ALTSETS
+       print_first ALL_COLOR_MAPSETS
+       puts stderr ""
+}
+
+#------------------------------------------------- write inkpot_define.h
+set f [open inkpot_define.h w]
+puts $f $preamble
+
+set SZT_VALUES_24 [expr 3*$SZT_VALUES]
+set SZT_NONAME_VALUES_24 [expr 3*$SZT_NONAME_VALUES]
+incr SZT_VALUES $SZT_NONAME_VALUES
+
+puts $f "\#define SZL_STRINGS $SZL_STRINGS"
+puts $f "\#define SZW_STRINGS $SZW_STRINGS"
+puts $f ""
+foreach {i} {
+       STRINGS SCHEMES NAMES ALTS VALUES VALUE_TO TO_NAMES
+       SCHEMES_INDEX SUBSCHEMES_INDEX INDEXES NONAME_VALUES
+       VALUES_24 NONAME_VALUES_24
+} {
+       if {[set SZT_$i] < 256} {
+               set int "unsigned char"
+       } elseif {[set SZT_$i] < 65536} {
+               set int "unsigned short"
+       } elseif {[set SZT_$i] < 65536*65536} {
+               set int "unsigned int"
+       } else {
+               set int "unsigned long"
+       }
+       puts $f "\#define SZT_$i [set SZT_$i]"
+       puts $f "typedef $int IDX_$i\;"
+       puts $f ""
+}
+foreach {i} {SCHEMES} {
+       if {[set SZT_$i] < 8} {
+               set int "unsigned char"
+       } elseif {[set SZT_$i] < 16} {
+               set int "unsigned short"
+       } elseif {[set SZT_$i] < 32} {
+               set int "unsigned int"
+       } elseif {[set SZT_$i] < 64} {
+               set int "unsigned long"
+       } else {
+               puts stderr "more that 64 bits in MSK_$i"
+       }
+       puts $f "typedef $int MSK_$i\;"
+       puts $f ""
+}
+close $f
diff --git a/lib/inkpot/inkpot_lib_brewer.tcl b/lib/inkpot/inkpot_lib_brewer.tcl
new file mode 100755 (executable)
index 0000000..140c376
--- /dev/null
@@ -0,0 +1,88 @@
+#!/usr/bin/tclsh
+
+set fn $argv
+
+set f [open $fn r]
+set d [read $f [file size $fn]]
+close $f
+
+regsub -all -line -- {#.*$} $d {} d
+regsub -all -line -- {$} $d {:} d
+regsub -all -line -- {^} $d {:} d
+regsub -all -- {\"} $d {} d
+
+foreach {rec ColorName NumOfColors Type CritVal ix ixa r g b SchemeType} [regexp -all -inline -- {:(\w*),(\d*),(\w*),([.\d]*),(\d+),(\w+),(\d+),(\d+),(\d+),(\w*):} $d] {
+
+       if {[string length $ColorName]} {
+               set nam $ColorName
+               set n $NumOfColors
+               set typ $Type
+               set crit $CritVal
+               if {[string length $SchemeType]} {
+                       set styp $SchemeType
+               }
+               
+               set t $nam
+               set l [string length $t]
+               regsub -all -- {\d} $d {} d
+               set ll [string length $t]
+               if {$l != $ll} {
+                       puts stderr "scheme $nam contains digits!"
+               }
+       }
+
+       if {! [info exists nam]} {
+               puts stderr "ColorName was not set before use"
+       }
+
+if {1} {
+#
+# oranges/j is inconsistent
+#
+       set ixn [string first $ixa "abcdefghijklmnopqrstuvwxyz"]
+       if {$ixn < 0} {
+               puts stderr "Failed to convert alpha index \"$ixa\" to an integer"
+       }
+       incr ixn
+
+       set nam_ixn [list $nam $ixn]
+        if {[info exists COLORS($nam_ixn)]} {
+                foreach {rr gg bb} $COLORS($nam_ixn) {break}
+               if {$r != $rr || $g != $gg || $b != $bb} {
+                       puts stderr "\"$nam_ixn\" is not unique and rgb doesn't match: $r $g $b != $rr $gg $bb"
+                       puts stderr $rec
+               } {
+                       #                   puts "$nam_ixn is not unique"     
+               }
+       }
+       set COLORS($nam_ixn) [list $r $g $b]
+}
+
+if {1} {
+       set nam_n_ix [list $nam $n $ix]
+        if {[info exists COLORS($nam_n_ix)]} {
+                foreach {rr gg bb} $COLORS($nam_n_ix) {break}
+               if {$r != $rr || $g != $gg || $b != $bb} {
+                       puts stderr "\"$nam_n_ix\" is not unique and rgb doesn't match: $r $g $b != $rr $gg $bb"
+                       puts stderr $rec
+                       puts ":$nam,$n,$typ,$crit,$ix,$ixa,$r,$g,$b,$styp:"
+                       puts "\"$ixa\" = $ixn"
+
+                       puts stderr ""
+                       foreach {color} [lrange [lsort -ascii [array name COLORS]] end-5 end] {
+                               puts stderr "COLORS\($color\) = $COLORS($color)"
+                       }
+                       exit
+               } {
+                       #                   puts "$nam_n_ix is not unique"     
+               }
+       }
+       set COLORS($nam_n_ix) [list $r $g $b]
+}
+}
+
+set COLORS() [list brewer rgb]
+
+set f [open inkpot_lib_brewer.dat w]
+puts $f [array get COLORS]
+close $f
diff --git a/lib/inkpot/inkpot_lib_procs.tcl b/lib/inkpot/inkpot_lib_procs.tcl
new file mode 100755 (executable)
index 0000000..5301186
--- /dev/null
@@ -0,0 +1,147 @@
+# some support procs
+
+###########################################################
+# TAB  support formatting of outputput tables
+
+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]
+}
+
+###################################################################
+# DEBUG
+
+# print some summary information about an array
+proc print_first {a} {
+       upvar $a b
+       set size [llength [array names b]]
+       set first [lindex [array names b] 0]
+       set value $b($first)
+       set totelem 0
+       set maxelem 0
+       foreach {n} [array names b] {
+               set elems [llength $b($n)]
+               if {$elems > $maxelem} {set maxelem $elems}
+               incr totelem $elems
+       }
+       puts stderr [list $a size:$size maxelem:$maxelem totelem:$totelem first: $a\($first) $value]
+}
+
+####################################################################
+#  MAP  --mapping m:n relationships between elemenets of 2 sets
+
+#populate the map
+proc mapw {XY x y r} {
+       upvar MAP_[set XY] MAP_XY
+       lappend MAP_XY([list $x $y]) $r
+}
+
+#crunch the map
+proc maps {XY} {
+       foreach {X Y} [split $XY {}] {break}
+       upvar MAP_[set XY] MAP_XY
+       upvar MAP_2[set X] MAP_2X
+       upvar MAP_2[set Y] MAP_2Y
+       upvar MAP_[set X]2 MAP_X2
+       upvar MAP_[set Y]2 MAP_Y2
+       #obtain sorted r_sets and use them as keys to the map
+       foreach {xy} [array names MAP_XY] {
+               foreach {x y} $xy {break}
+               set r_set [lsort -ascii $MAP_XY($xy)]
+               # set up for finding X and Y from r_sets        
+               #using arrays removes duplicate r_sets
+               lappend MAP_2X($r_set) $x
+               lappend MAP_2Y($r_set) $y
+       }
+       #set up for finding rsets from X
+       set MAP_X2() $Y
+       foreach {r_set} [lsort -ascii [array names MAP_2X]] {
+               foreach {x} $MAP_2X($r_set) {
+                       lappend MAP_X2($x) $r_set
+               }
+       }
+       #set up for finding rsets from Y
+       set MAP_Y2() $X
+       foreach {r_set} [lsort -ascii [array names MAP_2Y]] {
+               foreach {y} $MAP_2Y($r_set) {
+                       lappend MAP_Y2($y) $r_set
+               }
+       }
+if {1} {
+       foreach {map up} [list  MAP_XY [set XY]
+                               MAP_2X 2[set X]
+                               MAP_2Y 2[set Y] 
+                               MAP_X2 [set X]2
+                               MAP_Y2 [set Y]2] {
+               puts "size MAP_$up = [llength [array names $map]]"
+       }
+}
+}
+
+#use the map
+proc mapr {K {k {}}} {
+       upvar MAP_[set K]2 MAP_K2
+       set J $MAP_K2()
+       upvar MAP_2[set J] MAP_2J
+       set res [list]
+       foreach {r_set} $MAP_K2($k) {
+               lappend res $MAP_2J($r_set)
+       }
+       set res
+}