From 7715bdc10f8ea8a0b26715bddb3fb5b973f0d404 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 3 Jun 2009 17:59:24 +0100 Subject: [PATCH] show-thing database interaction improved --- pctb/show-thing.tcl | 17 +++++++++++++---- pctb/{stuff => }/text.xpm | 0 2 files changed, 13 insertions(+), 4 deletions(-) rename pctb/{stuff => }/text.xpm (100%) diff --git a/pctb/show-thing.tcl b/pctb/show-thing.tcl index 4537e6a..1c55fcd 100755 --- a/pctb/show-thing.tcl +++ b/pctb/show-thing.tcl @@ -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} { diff --git a/pctb/stuff/text.xpm b/pctb/text.xpm similarity index 100% rename from pctb/stuff/text.xpm rename to pctb/text.xpm -- 2.30.2