Board index » delphi » Converting Turbo Pascal binary data files with C++

Converting Turbo Pascal binary data files with C++

I have a set of binary data files created with a Turbo Pascal 6.0
executable, and I even know the file formats.  These files (for the most
part) use variant records.

The data files use the pascal "real" type which I know is like C++'s
"double", but beyond that I don't know of anything else really weird
about the actual conversion of data types.

I now have a need to convert the data using C++.  Is there anything
special I have to know or do?

--
=========================================================
John Simmons - Redneck Techno-Biker (Zerex12)
http://www.members.home.net/jms1/index.html

John Simmons - Barbarian Diecast Collector
http://members.home.net/jsimm/diecast_index.html

If you want to send me email, go to either of the URL's
shown above & click "Send Me Mail" in the contents frame.
=========================================================

 

Re:Converting Turbo Pascal binary data files with C++


Quote
On Sat, 14 Nov 1998, John Simmons wrote:

JS> I have a set of binary data files created with a Turbo Pascal 6.0
JS> executable, and I even know the file formats.  These files (for
JS> the most part) use variant records.

JS> The data files use the pascal "real" type which I know is like
JS> C++'s "double", but beyond that I don't know of anything else
JS> really weird about the actual conversion of data types.

JS> I now have a need to convert the data using C++.  Is there
JS> anything special I have to know or do?

My general advice is to write a (hopefully) quick Pascal program to
dump the file contents into a text file (i.e. print out the reals
instead of saving them). Other than that, I've found the manuals to be
real good in describing how Turbo Pascal reals are stored in memory.
--
[e-mailed to individual user due to GTE.net being
down and broken]

Re:Converting Turbo Pascal binary data files with C++


Quote
On Sat, 14 Nov 1998, John Simmons wrote:

JS> I have a set of binary data files created with a Turbo Pascal 6.0
JS> executable, and I even know the file formats.  These files (for
JS> the most part) use variant records.

JS> The data files use the pascal "real" type which I know is like
JS> C++'s "double", but beyond that I don't know of anything else
JS> really weird about the actual conversion of data types.

JS> I now have a need to convert the data using C++.  Is there
JS> anything special I have to know or do?

My general advice is to write a (hopefully) quick Pascal program to
dump the file contents into a text file (i.e. print out the reals
instead of saving them). Other than that, I've found the manuals to be
real good in describing how Turbo Pascal reals are stored in memory.
--
[e-mailed to individual user due to GTE.net being
down and broken]

Re:Converting Turbo Pascal binary data files with C++


Quote
John Simmons wrote:
> I have a set of binary data files created with a Turbo Pascal 6.0
> executable, and I even know the file formats.  These files (for the most
> part) use variant records.

> The data files use the pascal "real" type which I know is like C++'s
> "double", but beyond that I don't know of anything else really weird
> about the actual conversion of data types.

> I now have a need to convert the data using C++.  Is there anything
> special I have to know or do?

As suggested in another method, you might want to dump the files into a human
readable form which you could parse in to new data files using C++ code.
However, that may be duplicating unnecessary work.

There *are* some considerations that need to be made though.  First, TP reals
are emulated 6-byte floating point values which are emulated in the Pascal
runtime code.  Search the web and you should be able to find C source for
converting these to IEEE floating point types that C will be able to digest.
Second, TP strings are not null-terminated.  The TP string is a character
array, with the [0] element of the string being a character value whose ASCII
value represents the length of the string, with no explicit terminator.
Third, enumerated values may be represented differently.  Fourth, I don't
think sets are implemented in C or C++.

This should get you a starting point of common sticking points.  Offhand, I
can't think of any more without having seen the data structure you're working
on.

Quote
> --
> =========================================================
> John Simmons - Redneck Techno-Biker (Zerex12)

--
Scott Earnest            | SPAM protection in effect. Remove  |
setech@_ix.netcom.com    | "_" as needed for true addresses.  |
earnests@_homenet.lm.com |    UIN:1136443  EFnet:pale_blue    |
sinykal@_{*word*104}space.org  | URL: http://www.netcom.com/~setech |

Re:Converting Turbo Pascal binary data files with C++


JRS:  In article <MPG.10b75d10d5d59f2b98981f@news> of Sat, 14 Nov 1998
17:23:45 in news:comp.lang.pascal.borland, John Simmons <j...@h.c> wrote:

Quote
>The data files use the pascal "real" type which I know is like C++'s
>"double", but beyond that I don't know of anything else really weird
>about the actual conversion of data types.

TP6 default real is 6 bytes; isn't C++ double an 8-bit type?

--
John Stockton, Surrey, UK.    j...@merlyn.demon.co.uk    Turnpike v4.00    MIME.
  Web <URL: http://www.merlyn.demon.co.uk/> - TP/BP/&c. FAQqish topics & links.
  Timo's TurboPascal <A HREF="ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip">FAQ</A>.
  <A HREF="http://www.merlyn.demon.co.uk/clpb-faq.txt">Mini-FAQ</A> of c.l.p.b.

Re:Converting Turbo Pascal binary data files with C++


Quote
Erik Anderson wrote in message <72kptj$84...@news-2.news.gte.net>...
>On Sat, 14 Nov 1998, John Simmons wrote:
>JS> I have a set of binary data files created with a Turbo Pascal 6.0
>...
>JS> I now have a need to convert the data using C++.  Is there
>JS> anything special I have to know or do?

>My general advice is to write a (hopefully) quick Pascal program to
>dump the file contents into a text file

Or to another file of record. TP since v4 handles the newer standard
floating point formats as well as its original Real type. Redefine the
original record types using type Double (or Single if appropriate)
instead of Real. Then, in Pascal, read from the old files and create
files of the new record type. C++ will then be able to handle the
floating point values directly. You could write C code to convert
6-byte Reals to 8-byte Doubles but would it be worth the effort?

FP

Other Threads