Thanks. I've worked out a few of the basics of how bitstreams works but I'm
not sure about the whole thing.. I do have another bit of code that I'd be
very grateful if folks could look at and tell me if it could be done
better, because I'm really not used to this language at all!

Also, is there somewhere in the UI library the prefabs for the neat rounded
coloured buttons that the Factor UI uses?

Mark


USING: kernel locals accessors math sequences math.bitwise bitstreams
io.files io xml io.encodings.binary xml.traversal strings
  assocs math.parser combinators ;
FROM: io => read ;

IN: fr8x

TUPLE: chunkinfo
{ name string }
{ size integer }
{ count integer }
{ offset integer } ;

TUPLE: chunkdata name data ;

: get-header ( -- bin ) "\x8d" read-until drop ;

: chop-junk ( bin -- slice ) 4 tail-slice ;

: get-chunk-tags ( head -- vector ) children>> 1 swap nth children-tags ;

: get-int-attr ( attrs name -- int ) swap at* drop string>number ;

: parse-chunk-tag ( tag -- chunkspec )
    [ name>> main>> ] keep
    attrs>>
    [ "size" get-int-attr ] [ "number" get-int-attr ] [ "offset"
get-int-attr ] tri
    chunkinfo boa ;

: parse-chunk-tags ( vector -- chunks ) [ parse-chunk-tag ] map ;

: parse-header ( -- chunks ) get-header chop-junk bytes>xml get-chunk-tags
parse-chunk-tags ;

: load-chunk ( chunkinfo offset -- chunkdata )
  swap
  [ offset>> + seek-absolute seek-input ] keep
  [ name>> V{ } ] [ size>> ] [ count>> ] tri
  [ [ read suffix ] keep ] times
  drop chunkdata boa ;

: load-chunks ( chunkinfos -- chunkdatas ) tell-input [ load-chunk ] curry
map ;

: parse-set-file ( -- head ) parse-header load-chunks ;

: load-set-file ( fn --  head ) binary [ parse-set-file ] with-file-reader ;

: test ( -- head ) "FR-8X_SET_001.ST8" load-set-file ;
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to