chiark / gitweb /
show-thing database interaction improved
authorIan Jackson <ian@liberator.(none)>
Wed, 3 Jun 2009 16:59:24 +0000 (17:59 +0100)
committerIan Jackson <ian@liberator.(none)>
Wed, 3 Jun 2009 16:59:24 +0000 (17:59 +0100)
pctb/show-thing.tcl
pctb/text.xpm [moved from pctb/stuff/text.xpm with 100% similarity]

index 4537e6af63b8242cd7afca15aebd1cad341f4e69..1c55fcdcb8c0d75a441994c91abc998c63fb9b80 100755 (executable)
@@ -1,4 +1,10 @@
-#!/usr/bin/tk
+#!/usr/bin/wish
+
+# usage:
+#  run show-thing without args
+#  then on stdin write
+#     one line which is a Tcl list for foolist
+#     the xpm in the format expected
 
 proc manyset {list args} {
     foreach val $list var $args {
@@ -287,11 +293,10 @@ proc read_database {} {
     global database
     set f [open database r]
     while {[gets $f l] >= 0} {
-       if {![regexp {^(\w+) (\d+) ([0-9a-f]{2}+)$} $l \
+       if {![regexp {^(\w+) (\d+) ((?:[0-9a-f]{2})+)$} $l \
                  dummy context strl strh]} {
            error "bad syntax"
        }
-        binary scan $strw h* strh
        if {[string length $strh] != $strl*2} { error "$strh $strl" }
        gets $f l; set width [format %d $l]
        set bm $context
@@ -300,6 +305,7 @@ proc read_database {} {
        }
        set database($bm) $strh
     }
+    close $f
 }
 
 proc write_database {} {
@@ -314,9 +320,12 @@ proc write_database {} {
        foreach x [lrange $bm 1 end] { append o "$x\n" }
        lappend ol $o
     }
+    set f [open database.new w]
     foreach o [lsort $ol] {
-       puts -nonewline $o
+       puts -nonewline $f $o
     }
+    close $f
+    file rename -force database.new database
 }
 
 proc update_database/DEFINE {c0 c1 strh} {
similarity index 100%
rename from pctb/stuff/text.xpm
rename to pctb/text.xpm