comp.lang.ada
 help / color / mirror / Atom feed
From: mcculley@greatwall.cctt.com (Gene McCulley)
Subject: Re: reading a file containing both text and binary data
Date: 8 Sep 1994 20:45:05 GMT
Date: 1994-09-08T20:45:05+00:00	[thread overview]
Message-ID: <34nt4h$evc@babyblue.cs.yale.edu> (raw)
In-Reply-To: 34njsu$17fu@watnews1.watson.ibm.com

|> In article <9409022042.aa16676@paris.ics.uci.edu>,
|> self@bordeaux.ICS.UCI.EDU (John Self) writes: 
|> 
|> |> At any point I can tell what the format of the next data item should
|> |> be, but I can't think of an Ada-like way to read different data types
|> |> (including text) from the same file.  I can use rep specs to read any
|> |> single data type by using Sequential_IO, but is there any Ada-like way
|> |> to read a file containing multiple types?  The only ideas I've had so
|> |> far involve instantiating Sequential_IO to read 8 bits at a time and
|> |> pack things into the appropriate data types manually with
|> |> UNCHECKED_CONVERSION.  In some sense I really am doing an "unchecked
|> |> conversion" since the files really are just sequences of bytes that
|> |> were generated by a piece of hardware, but I'd like to have take
|> |> advantage of any nice structuring ideas Ada can give me.
|> 
I am on a project where we are successfully using some Posix bindings to do
just this sort of thing.  The Posix bindings have Generic_Read and Generic_Write
functions that can be instantiated on any type (even unconstrained array types)
and work with a posix file descriptor.  This allows us to open a file, read
500 bytes of one type, then 1000 bytes of another type without playing any
games with Unchecked_Conversion or closing and reopening files.  We had to read
in some very large files generated by a C program.  It was not much fun at all
until we started using the bindings.  These can probably be found at wuarchive.




      reply	other threads:[~1994-09-08 20:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <9409022042.aa16676@paris.ics.uci.edu>
1994-09-08 18:07 ` reading a file containing both text and binary data Norman H. Cohen
1994-09-08 20:45   ` Gene McCulley [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox