TclBin package

TclBin is an extension of Tcl to allow direct access and manipulation of binary data and structures from Tcl.

Lets take a simple exemple, imagine you have a C function that use a

struct point_data {
  double  x;   /* X coord */
  double  y;   /* Y coord */
  int     n;   /* value */
}

With my package, you can for instance

# define an object 'pt'
bin_new pt point_data [bin_sizeof double]*2+[bin_sizeof int] ;
# define fields inside
bin_def pt x double 0;
bin_def pt y double [bin_sizeof double];
bin_def pt n int    2*[bin_sizeof double];

Then, either you add to you interpreter C function that works on directly on point_data structure and 'talk' with Tcl, or you can read/write on file/pipes/sockets,... these binary data and modify them at will from Tcl, like in :

set file [open "tst.out" RDWR]
# read binary data
bin_read $file pt  ;
# manipulate from tcl binary structure
puts "X is $pt(x), Y is $pt(y) and n is $pt(n)";
set pt(n) [expr int($pt(x)+$pt(y))];
seek $file 0;
# write binary data
bin_write $file pt ;
close $file;

You can also make arrays, pointers, use network ordered numbers transparently, etc ... and more... You can have a look at the news post announce for other examples.

NEW Fetch a more complete documentation Intro (DVI format) or Intro (PostScript format) and Reference (Man page format) or Reference (PostScript format).

I intend to improve this web page in the near future, meanwhile, you can look at the files in the distribution directly (see end of this page for realese infos)

It's been used for more than two year now (since oct 1994), as one of the library for the Adonis instrument control software I wrote here at Observatory as well as by a number of people worldwide. It is very stable and I think quite bug free.

You can find the latest release hereafter : tclbin-1.2.tar.gz (dated Jan 1997 (!), eigth public release, second non beta).

This release now includes an example shell and tcl code to make an efficient (anonymous) WWW proxy httpd server (btclsh and http_proxy.tcl). It includes MD5 checksums/ digests support.

If you are interested in binary data access/... in Tcl in general or by the tclbin package, you can subsribe to my mailing list, by sending a mail with ``SUB tclbin YourFirstName YourLastName'' in a mail body sent to listserv@hplyot.obspm.fr (this may not work anymore...)

If you just need to read write a couple of binary integers, you want use this Tcl Bin Read/Write hack in plain tcl7.5 instead.


demailly.com © 1994-2009 Laurent Demailly, Last update: Wed Oct 20 1999