Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2005-09

Turbo Pascal/legacy data file issue.

13 messages · 9 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Lowell C. Savage

Has anyone come up with a set of routines for converting between Turbo Pascal's 6-byte "real" format and FPC's real number format?

I am trying to use FPC to update a legacy TP 5.5 program. I've got most of the "major" issues solved and am now finding that I'm having trouble reading legacy data files. Many of these data file are "file of XXXRec" where "XXXRec" is a rather large and complex Record containing strings, integers, bytes, enumerated types, and reals.

My problem is that I am going to need to be able to read these existing files (without modification) into the new version of the program.

I've been able to use the "{$PACKRECORDS 1}" and "{$PACKENUMS 1}" directives to take care of everything else. But now I realize that Turbo Pascal used a 6-byte real representation while FPC uses either a 4 or 8-bit representation.

It appears that I'm going to need to make some kind of a special type, perhaps a packed record with a "byte", a "smallint" and a 4-byte "longword". Then, I read this value from the existing file and convert it into a "real". Then, when I want to write the file (or another file) I convert back to this record type when I fill the record I'm going to write.

Here's a simple program to demonstrate the issue. In Turbo Pascal 5.5 (Downloaded from http://bdn.borland.com/article/0,1410,20803,00.html) this code generates a 12-byte file. FPC generates a 16-byte file. (Actually, the preprocessor directives shown appear to have no effect on this code--not complaining since the docs don't make it appear that it should, just pointing it out.)

Program testrec;
{$IFDEF FPC}
{$MODE TP}
{$PACKRECORDS 1}
{$ENDIF}
type
      realrec = record
         t1 : real;
         t2 : real;
         end;
var
    realfile : file of realrec;
    r : realrec;
begin
    r.t1 := 1.0;
    r.t2 := 2.0;
    assign ( realfile, 'c:\r.rfl' );
    rewrite ( realfile );
    write ( realfile, r );
    close ( realfile );
end.

Any ideas appreciated!

Thanks,

Lowell C. Savage

505-667-6964 (office/msg)
360-961-8965 (cell/msg)
505-667-4341 (shared fax)

Reply by email

Florian Klaempfl
to Lowell C. Savage
Lowell C. Savage wrote
Has anyone come up with a set of routines for converting between Turbo Pascal's 6-byte "real" format and FPC's real number format?

http://www.freepascal.org/docs-html/rtl/system/real2double.html

Show quoted text 26 lines
I am trying to use FPC to update a legacy TP 5.5 program. I've got most of the "major" issues solved and am now finding that I'm having trouble reading legacy data files. Many of these data file are "file of XXXRec" where "XXXRec" is a rather large and complex Record containing strings, integers, bytes, enumerated types, and reals. My problem is that I am going to need to be able to read these existing files (without modification) into the new version of the program. I've been able to use the "{$PACKRECORDS 1}" and "{$PACKENUMS 1}" directives to take care of everything else. But now I realize that Turbo Pascal used a 6-byte real representation while FPC uses either a 4 or 8-bit representation. It appears that I'm going to need to make some kind of a special type, perhaps a packed record with a "byte", a "smallint" and a 4-byte "longword". Then, I read this value from the existing file and convert it into a "real". Then, when I want to write the file (or another file) I convert back to this record type when I fill the record I'm going to write. Here's a simple program to demonstrate the issue. In Turbo Pascal 5.5 (Downloaded from http://bdn.borland.com/article/0,1410,20803,00.html) this code generates a 12-byte file. FPC generates a 16-byte file. (Actually, the preprocessor directives shown appear to have no effect on

What effect should it have?

this code--not complaining since the docs don't make it appear that it should, just pointing it out.)

The 6 byte real isn't supported by fpc because it isn't handled by the fpu and thus deadly slow. For maybe 12 years, every new PC has an fpu.

Show quoted text 38 lines
Program testrec; {$IFDEF FPC} {$MODE TP} {$PACKRECORDS 1} {$ENDIF} type realrec = record t1 : real; t2 : real; end; var realfile : file of realrec; r : realrec; begin r.t1 := 1.0; r.t2 := 2.0; assign ( realfile, 'c:\r.rfl' ); rewrite ( realfile ); write ( realfile, r ); close ( realfile ); end. Any ideas appreciated! Thanks, Lowell C. Savage 505-667-6964 (office/msg) 360-961-8965 (cell/msg) 505-667-4341 (shared fax) _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Lowell C. Savage
to Lowell C. Savage: Has anyone come up with a set of routines for converting between Turbo Pascal's 6-byte…

Well, I found a "Real2Double" function in the System unit that converts from an old TP 6-byte "real" to an 8-byte double. (Guess I should have looked a little harder, there.) But I'm not seeing anything going the other way. Anyone?

Thanks,

Lowell

Lowell C. Savage wrote 62 lines
Has anyone come up with a set of routines for converting between Turbo Pascal's 6-byte "real" format and FPC's real number format? I am trying to use FPC to update a legacy TP 5.5 program. I've got most of the "major" issues solved and am now finding that I'm having trouble reading legacy data files. Many of these data file are "file of XXXRec" where "XXXRec" is a rather large and complex Record containing strings, integers, bytes, enumerated types, and reals. My problem is that I am going to need to be able to read these existing files (without modification) into the new version of the program. I've been able to use the "{$PACKRECORDS 1}" and "{$PACKENUMS 1}" directives to take care of everything else. But now I realize that Turbo Pascal used a 6-byte real representation while FPC uses either a 4 or 8-bit representation. It appears that I'm going to need to make some kind of a special type, perhaps a packed record with a "byte", a "smallint" and a 4-byte "longword". Then, I read this value from the existing file and convert it into a "real". Then, when I want to write the file (or another file) I convert back to this record type when I fill the record I'm going to write. Here's a simple program to demonstrate the issue. In Turbo Pascal 5.5 (Downloaded from http://bdn.borland.com/article/0,1410,20803,00.html) this code generates a 12-byte file. FPC generates a 16-byte file. (Actually, the preprocessor directives shown appear to have no effect on this code--not complaining since the docs don't make it appear that it should, just pointing it out.) Program testrec; {$IFDEF FPC} {$MODE TP} {$PACKRECORDS 1} {$ENDIF} type realrec = record t1 : real; t2 : real; end; var realfile : file of realrec; r : realrec; begin r.t1 := 1.0; r.t2 := 2.0; assign ( realfile, 'c:\r.rfl' ); rewrite ( realfile ); write ( realfile, r ); close ( realfile ); end. Any ideas appreciated! Thanks, Lowell C. Savage 505-667-6964 (office/msg) 360-961-8965 (cell/msg) 505-667-4341 (shared fax)

Lowell C. Savage

505-667-6964 (office/msg)
360-961-8965 (cell/msg)
505-667-4341 (shared fax)

Reply by email

Arne Hanssen
to Lowell C. Savage: Well, I found a "Real2Double" function in the System unit that converts from an old TP…

Thus spoke Lowell C. Savage ():

Show quoted text 8 lines
At 12:56 PM 9-19-05, Lowell C. Savage wrote: >Has anyone come up with a set of routines for converting between Turbo >Pascal's 6-byte "real" format and FPC's real number format? Well, I found a "Real2Double" function in the System unit that converts from an old TP 6-byte "real" to an 8-byte double. (Guess I should have looked a little harder, there.) But I'm not seeing anything going the other way. Anyone?

If this is Windows (or OS/2) you could use Virtual Pascal to build a conversion program. Even if VP is "dead" I think you still can get it from www.vpascal.com.

Vennlig hilsen / Best regards |\ ___,,--, _ Arne Hanssen, Senja, Norway /,`--'' \-,,__,'/ http://www.tuxic.net/ |,4 ) )_ ) /~-----' ---------------------------------'---^~(_/-_)--(_/_)-------

Reply by email

Alexey Pavluchenko
to Jose Pascual

Hello Jose,

Thursday, September 22, 2005, 1:20:48 PM, you wrote:

JP> How can avoid to run my program more than once?

I suppose you wanted to ask "how can I allow only one instance of my program running under Win32". Correct me if I'm wrong. If I'm right, then you may do it like this: check for named mutex with the name unique to your program, if it does not exist then create it, if it does then terminate the program. The following code is from APPINIT unit written by Marc Batchelor:

=== cut ===
procedure InitInstance;
begin
  { Check to see if the mutex is already there }
  InstanceMutexHandle := OpenMutex(MUTEX_ALL_ACCESS, false,
    @UniqueApplicationString[1]);
  if InstanceMutexHandle = 0 then
  begin
    { This is the first instance }
    InstanceMutexHandle := CreateMutex(nil, false,
      @UniqueApplicationString[1]);
    { Error checking to see if anyone beat us... }
    if InstanceMutexHandle = 0 then
      IsFirstInstance := false
    else
      IsFirstInstance := true;
  end
  else
    IsFirstInstance := false;
end;
=== cut ===

UniqueApplicationString in the above example is a shortstring, if you use ansistring then you don't need '@' operator and '[1]' index, just typecast it to pchar. The string should be unique system-wide so it is probably best to generate it based on some pseudo-random numbers.

Best regards, Alexey

Reply by email

Jose Pascual
to Alexey Pavluchenko

Hi Alexey,

thank you for your answer, I'm thinking about some portable solution for win32 and linux?
How can I also do it in linux?

tia!
best regards

Show quoted text 65 lines
-----Mensaje original----- De: En nombre de Alexey Pavluchenko Enviado el: viernes, 23 de septiembre de 2005 10:35 Para: FPC-Pascal users discussions Asunto: Re: [fpc-pascal] single application instance Hello Jose, Thursday, September 22, 2005, 1:20:48 PM, you wrote: JP> How can avoid to run my program more than once? I suppose you wanted to ask "how can I allow only one instance of my program running under Win32". Correct me if I'm wrong. If I'm right, then you may do it like this: check for named mutex with the name unique to your program, if it does not exist then create it, if it does then terminate the program. The following code is from APPINIT unit written by Marc Batchelor: === cut === procedure InitInstance; begin { Check to see if the mutex is already there } InstanceMutexHandle := OpenMutex(MUTEX_ALL_ACCESS, false, @UniqueApplicationString[1]); if InstanceMutexHandle = 0 then begin { This is the first instance } InstanceMutexHandle := CreateMutex(nil, false, @UniqueApplicationString[1]); { Error checking to see if anyone beat us... } if InstanceMutexHandle = 0 then IsFirstInstance := false else IsFirstInstance := true; end else IsFirstInstance := false; end; === cut === UniqueApplicationString in the above example is a shortstring, if you use ansistring then you don't need '@' operator and '[1]' index, just typecast it to pchar. The string should be unique system-wide so it is probably best to generate it based on some pseudo-random numbers. -- Best regards, Alexey _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fp> c-pascal __________ Información de NOD32, revisión 1.1230 (20050922) __________ Este mensaje ha sido analizado con NOD32 antivirus system

http://www.nod32.com

Reply by email

Matt Emson
to Jose Pascual
How can I also do it in linux?

Use semaphores. There is a semaphore implementation for LINUX, Windows, BeOS and probably most other Unices. Certainly, any platform that conforms to POSIX and/or PThreads will have a semaphore implementation.

The mechanics will be different - the idea will be universal.

M

Reply by email

Micha Nelissen
to Matt Emson
> How can I also do it in linux? Use semaphores. There is a semaphore implementation for LINUX, Windows, BeOS

Semaphores Mutexes. Semaphores do not always have names and are not system-wide.

Micha

Reply by email

Marco van de Voort
to Matt Emson: Use semaphores. There is a semaphore implementation for LINUX, Windows, BeOS and probably…
Show quoted text 7 lines
> How can I also do it in linux? Use semaphores. There is a semaphore implementation for LINUX, Windows, BeOS and probably most other Unices. Certainly, any platform that conforms to POSIX and/or PThreads will have a semaphore implementation. The mechanics will be different - the idea will be universal.

For *nix it is in unit ipc.

Reply by email

Jose Pascual
to Matt Emson

any example of implementation for semaphore in linux which I can use to know if there is
some instance of my program already running?

Show quoted text 26 lines
-----Mensaje original----- De: En nombre de Matt Emson Enviado el: viernes, 23 de septiembre de 2005 18:53 Para: FPC-Pascal users discussions Asunto: Re: [fpc-pascal] single application instance > Semaphores Mutexes. Semaphores do not always have names and are not > system-wide. In my experience, its the other way round. Semaphores are system wide/cross process. Admittedly, they are not always named though. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fp> c-pascal __________ Información de NOD32, revisión 1.1230 (20050922) __________ Este mensaje ha sido analizado con NOD32 antivirus system

http://www.nod32.com

Reply by email