From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,919012a7fc17ce29 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-09-08 23:20:42 PST Path: nntp.gmd.de!xlink.net!howland.reston.ans.net!europa.eng.gtefsd.com!MathWorks.Com!news2.near.net!yale!yale!mcculley From: mcculley@greatwall.cctt.com (Gene McCulley) Newsgroups: comp.lang.ada Subject: Re: reading a file containing both text and binary data Date: 8 Sep 1994 20:45:05 GMT Organization: CCTT, Orlando, FL Distribution: world Message-ID: <34nt4h$evc@babyblue.cs.yale.edu> References: <9409022042.aa16676@paris.ics.uci.edu> <34njsu$17fu@watnews1.watson.ibm.com> NNTP-Posting-Host: greatwall.cctt.com Date: 1994-09-08T20:45:05+00:00 List-Id: |> 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.