Re: [Haskell-cafe] busting up a structured binary file

2005-12-09 Thread Bulat Ziganshin
Hello Brian,

Thursday, December 08, 2005, 10:54:29 PM, you wrote:

BM> I need to extract text from a structed binary file.  Its a local
BM> database for a commercial app of proprietary structure, though the
BM> structure has been determined.  So I need to move along a number of
BM> bytes, take a few chunks of so many more bytes and grab the string and
BM> move on to the next record, dumping the contents - ultimately dumping

compile with "ghc --make a.hs"

import Foreign.C.String
import Foreign.C.Types
import Foreign.Marshal.Alloc
import Foreign.Ptr
import Foreign.Storable
import System.IO

main = do
  h <- openBinaryFile "database" ReadMode
  hSeek h AbsoluteSeek 137
  buf <- mallocBytes 10
  hGetBuf h buf 10
  str <- peekCStringLen (buf,10)
  print str
  hClose h


-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] busting up a structured binary file

2005-12-08 Thread Brian McQueen
Can someone point me to a sample so I can get started?  This will be
my first Haskkel project, after reading about it for some months now. 
I need to extract text from a structed binary file.  Its a local
database for a commercial app of proprietary structure, though the
structure has been determined.  So I need to move along a number of
bytes, take a few chunks of so many more bytes and grab the string and
move on to the next record, dumping the contents - ultimately dumping
it to XML.  It'll need to run on windows so I guess I had better use
Hugs.

So a sample and any advice would be an excellent start for me, and
would be greatly appreciated.

Thanks

Brian McQueen
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe