Board index » delphi » Converting Turbo Pascal to ANSI Pascal

Converting Turbo Pascal to ANSI Pascal

I was wondering whether anyone has produced a program which will
replace references to TPUs and their procedures with references to
standard ANSI libraries.  If so, can I download it from somewhere?  I
am trying to port some TP code to another platform and I would rather
not have to rewrite the whole thing!

--
 x^      ( )      _________         //     Email:  mailto:c...@crok.demon.co.uk
<       U O      |_|_|_|_|_|    O  ||       WWW:   http://www.crok.demon.co.uk
 \,     |/|\      _________       [  ]            
     .  |/^\  .       2       .   /__\
... If I save the whales, where do I keep them?

 

Re:Converting Turbo Pascal to ANSI Pascal


In <19980503.095214...@crok.demon.co.uk>,

Quote
Stephen Crocker <c...@crok.demon.co.uk> wrote:
> I was wondering whether anyone has produced a program which will
> replace references to TPUs and their procedures with references to
> standard ANSI libraries.  If so, can I download it from somewhere?  I
> am trying to port some TP code to another platform and I would rather
> not have to rewrite the whole thing!

The main problem is not the library functions, but already the
language used by TP differs vastly from the standards. Therefore
I guess that an automatic translation is not possible to a
satisfying degree.

One solution to your problem seems to be using a compiler that
supports (some of the) TP extensions. There are two free compilers:

GNU Pascal, http://home.pages.de/~GNU-Pascal/
FPK Pascal, http://home.pages.de/~FPK-Pascal/

GNU Pascal runs on almost any platform and supports almost all of
Standard Pascal and most of the TP extensions. FPK Pascal runs of
some platforms (Dos, Linux, OS/2 or so -- I don't know exactly),
supports most of TP, but (I think) less of Standard Pascard.

Frank

PS: replaced the outdated c.l.p by c.l.p.ansi-iso in the newsgroups line.

--
Frank Heckenbach, frank@[NOSPAM.REMOVE.THIS]pascal.gnu.de
Internet links:  http://fjf.gnu.de/
Pascal programs: http://fjf.gnu.de/programs.html (including BP Crt.Delay fix)
PGP keys: http://pgp5.ai.mit.edu/pks/lookup?op=index&search=Frank+Heckenbach

Re:Converting Turbo Pascal to ANSI Pascal


Before being shot for writing article <fjf.19980503200...@gnu.de>, Frank Heckenbach wrote:

Quote
> In <19980503.095214...@crok.demon.co.uk>,
> Stephen Crocker <c...@crok.demon.co.uk> wrote:

> > I was wondering whether anyone has produced a program which will
> > replace references to TPUs and their procedures with references to
> > standard ANSI libraries.  If so, can I download it from somewhere?  I
> > am trying to port some TP code to another platform and I would rather
> > not have to rewrite the whole thing!

> The main problem is not the library functions, but already the
> language used by TP differs vastly from the standards. Therefore
> I guess that an automatic translation is not possible to a
> satisfying degree.

> One solution to your problem seems to be using a compiler that
> supports (some of the) TP extensions. There are two free compilers:

> GNU Pascal, http://home.pages.de/~GNU-Pascal/
> FPK Pascal, http://home.pages.de/~FPK-Pascal/

> GNU Pascal runs on almost any platform and supports almost all of
> Standard Pascal and most of the TP extensions. FPK Pascal runs of
> some platforms (Dos, Linux, OS/2 or so -- I don't know exactly),
> supports most of TP, but (I think) less of Standard Pascard.

Hmmm...  The problem is that I have a program which uses the Graph,
DOS, CRT and Mouse units quite heavily.  I would rather not rewrite it
by hand, so I was wondering if there was a program which would
substitute calls to procedures in these units with calls to ANSI
procedures.

--
 x^      ( )      _________         //     Email:  mailto:c...@crok.demon.co.uk
<       U O      |_|_|_|_|_|    O  ||       WWW:   http://www.crok.demon.co.uk
 \,     |/|\      _________       [  ]            
     .  |/^\  .       2       .   /__\
... Don't like these tags?? Steal your own.....

Re:Converting Turbo Pascal to ANSI Pascal


In article <19980503.221140...@crok.demon.co.uk>,

Quote
Stephen Crocker <c...@crok.demon.co.uk> wrote:

>Hmmm...  The problem is that I have a program which uses the Graph,
>DOS, CRT and Mouse units quite heavily.  I would rather not rewrite it
>by hand, so I was wondering if there was a program which would
>substitute calls to procedures in these units with calls to ANSI
>procedures.

Why not just create wrapper procedures that convert the calls?

Osmo

Re:Converting Turbo Pascal to ANSI Pascal


Quote
Stephen Crocker <c...@crok.demon.co.uk> wrote:

> Hmmm...  The problem is that I have a program which uses the Graph,
> DOS, CRT and Mouse units quite heavily.  I would rather not rewrite it
> by hand, so I was wondering if there was a program which would
> substitute calls to procedures in these units with calls to ANSI
> procedures.

There are no ANSI procedures replacing DOS, CRT, Graph, and Mouse.
(`Mouse'?  That's not a standard BP unit, is it?)  You need replacements
for their functionality anyway, so if FPK Pascal runs on your system,
it is probably the best choice for you.  Otherwise, try GNU Pascal which
is closer to ANSI-ISO Pascal, runs on almost any existing system (it is
just as portable as GNU C), comes with a portable, Graph-compatible
Graphics unit (`GRX') and can use all of the portable libraries
(e.g. `ncurses') written for C for getting the functionality of CRT
and such.

Good luck,

    Peter

--
Peter Gerwinski, Essen, Germany, http://home.pages.de/~Peter.Gerwinski/
Maintainer GNU Pascal - http://home.pages.de/~GNU-Pascal/ - gpc-980420
  PGP: see homepage - 6C 94 45 BE 28 A4 96 - 0E CC E9 12 47 25 82 75
Fight the SPAM and UBE! - http://spam.abuse.net/ - http://maps.vix.com/

Re:Converting Turbo Pascal to ANSI Pascal


Before being shot for writing article <6iji8f$...@kruuna.Helsinki.FI>, Osmo Ronkanen wrote:

Quote
> In article <19980503.221140...@crok.demon.co.uk>,
> Stephen Crocker <c...@crok.demon.co.uk> wrote:

> >Hmmm...  The problem is that I have a program which uses the Graph,
> >DOS, CRT and Mouse units quite heavily.  I would rather not rewrite it
> >by hand, so I was wondering if there was a program which would
> >substitute calls to procedures in these units with calls to ANSI
> >procedures.

> Why not just create wrapper procedures that convert the calls?

Hmmm... That's an option.  Has anyone doen this already?  Presumably
it's a matter of creating a library of procedures which just call other
procedures from the standard libraries.  I have Gnu Pascal with a
UNIX C library so it shouldn't be TOO hard to do.  Just three
questions:-

How do I create a library?
What are the ANSI equivalents?
How do I tell the compiler to add these libraries (Is it just "Uses" as
in TP?)

--
 x^      ( )      _________         //     Email:  mailto:c...@crok.demon.co.uk
<       U O      |_|_|_|_|_|    O  ||       WWW:   http://www.crok.demon.co.uk
 \,     |/|\      _________       [  ]            
     .  |/^\  .       2       .   /__\
... The universe is laughing behind your back

Re:Converting Turbo Pascal to ANSI Pascal


In article <6ik17p$h...@mx2.hrz.uni-essen.de>,
pe...@agnes.dida.physik.uni-essen.de says...

Quote

>Stephen Crocker <c...@crok.demon.co.uk> wrote:

>> Hmmm...  The problem is that I have a program which uses the Graph,
>> DOS, CRT and Mouse units quite heavily.  I would rather not rewrite it
>> by hand, so I was wondering if there was a program which would
>> substitute calls to procedures in these units with calls to ANSI
>> procedures.

>There are no ANSI procedures replacing DOS, CRT, Graph, and Mouse.
>(`Mouse'?  That's not a standard BP unit, is it?)  You need replacements
>for their functionality anyway, so if FPK Pascal runs on your system,
>it is probably the best choice for you.  Otherwise, try GNU Pascal which
>is closer to ANSI-ISO Pascal, runs on almost any existing system (it is
>just as portable as GNU C), comes with a portable, Graph-compatible
>Graphics unit (`GRX') and can use all of the portable libraries
>(e.g. `ncurses') written for C for getting the functionality of CRT
>and such.

I converted a couple of TP programs to the system at hand, an
ANSI compatible compiler. The biggest problem was strings.

Your problem is that graphics and special device functions, like the
mouse, are not discussed (I think properly) in the language standard.
To write a really independent program, you need to either use or
create a standard procedures libary. Ie, a standard method of
using those features. You have actually been using such a library -
the DOS, CRT, etc. modules. The problem is that they were never
ported off the PC/MSDOS platform, and you don't have the source
for them to change it.

Now comes the advice that no one ever takes. You are going to
write a set of adaption code. You either write a general purpose
library of functions, such as the Borland folks did, or you
create a porting library just for that program. In the latter
case, all you really have to do is isolate the lower level
functions, such as graphics or mouse, into a support section.
Then, you rewrite that as required to port it. Ie., your program
will be portable because it is designed that way.

                                     [sam]

Re:Converting Turbo Pascal to ANSI Pascal


Quote
Stephen Crocker <c...@crok.demon.co.uk> wrote:
> [...] Presumably
> it's a matter of creating a library of procedures which just call other
> procedures from the standard libraries.  I have Gnu Pascal with a
> UNIX C library so it shouldn't be TOO hard to do.

Indeed.

See the GPC FAQ list (http://home.pages.de/~GNU-Pascal/gpc-faq.html)
for instructions how to use C library functions from GNU Pascal
programs.

Quote
> Just three questions:-
> How do I create a library?

What do you mean?
A Unit? --> Like in BP.
A library (.a file)? --> Like in GNU C.

Quote
> What are the ANSI equivalents?

For Units? --> Modules.  See the GPC documentation.
               But GPC also supports Units.

For DOS, CRT, Graph? --> Nothing. :-(

Quote
> How do I tell the compiler to add these libraries (Is it just "Uses" as
> in TP?)

To use a Unit:  Yes: "Uses".
To use a Module:  Essentially use "Import" instead of "Uses".
                  (See the doc for details.)

But now for my guess of what you are *really* looking for:  ;-)

On ftp://agnes.dida.physik.uni-essen.de/gnu-pascal/contrib/, you can
find a BP compatibility package "BPcompat" for GNU Pascal.  While it
is written for the DOS (DJGPP) platform, large parts of it should be
easily ported to other platforms.

In the DJGPP distribution (subdirectory gnu/djgpp/ on any SimTel
mirror) you can find a library called GRX (file v2tk/grx22.zip).
Although it has originally been written for DOS, it is portable to
other platforms such as Linux/SVGAlib or Linux/X11.  It comes with
a file `graph.pas' which does exactly what you would expect from
this name. :-)

You will need a more recent (alpha or beta) version of GPC in order
to take full advantage of the above.  You can download one from
http://agnes.dida.physik.uni-essen.de/gnu-pascal/alpha/ .

If you need further help, be invited to join the GNU Pascal mailing
list.  See http://home.pages.de/~GNU-Pascal/support.html .

Hope this helps,

    Peter

--
Peter Gerwinski, Essen, Germany, http://home.pages.de/~Peter.Gerwinski/
Maintainer GNU Pascal - http://home.pages.de/~GNU-Pascal/ - gpc-980420
  PGP: see homepage - 6C 94 45 BE 28 A4 96 - 0E CC E9 12 47 25 82 75
Fight the SPAM and UBE! - http://spam.abuse.net/ - http://maps.vix.com/

Re:Converting Turbo Pascal to ANSI Pascal


Before being shot for writing article <6ilhul$o5...@news-sj-3.cisco.com>, Scott A. Moore wrote:

Quote
> In article <6ik17p$h...@mx2.hrz.uni-essen.de>,
> pe...@agnes.dida.physik.uni-essen.de says...

> >Stephen Crocker <c...@crok.demon.co.uk> wrote:

> >> Hmmm...  The problem is that I have a program which uses the Graph,
> >> DOS, CRT and Mouse units quite heavily.  I would rather not rewrite it
> >> by hand, so I was wondering if there was a program which would
> >> substitute calls to procedures in these units with calls to ANSI
> >> procedures.

> >There are no ANSI procedures replacing DOS, CRT, Graph, and Mouse.
> >(`Mouse'?  That's not a standard BP unit, is it?)  You need replacements
> >for their functionality anyway, so if FPK Pascal runs on your system,
> >it is probably the best choice for you.  Otherwise, try GNU Pascal which
> >is closer to ANSI-ISO Pascal, runs on almost any existing system (it is
> >just as portable as GNU C), comes with a portable, Graph-compatible
> >Graphics unit (`GRX') and can use all of the portable libraries
> >(e.g. `ncurses') written for C for getting the functionality of CRT
> >and such.

> I converted a couple of TP programs to the system at hand, an
> ANSI compatible compiler. The biggest problem was strings.

> Your problem is that graphics and special device functions, like the
> mouse, are not discussed (I think properly) in the language standard.
> To write a really independent program, you need to either use or
> create a standard procedures libary. Ie, a standard method of
> using those features. You have actually been using such a library -
> the DOS, CRT, etc. modules. The problem is that they were never
> ported off the PC/MSDOS platform, and you don't have the source
> for them to change it.

> Now comes the advice that no one ever takes. You are going to
> write a set of adaption code. You either write a general purpose
> library of functions, such as the Borland folks did, or you
> create a porting library just for that program. In the latter
> case, all you really have to do is isolate the lower level
> functions, such as graphics or mouse, into a support section.
> Then, you rewrite that as required to port it. Ie., your program
> will be portable because it is designed that way.

Well, I'd like to write a library but I don't know where to begin!

--
 x^      ( )      _________         //     Email:  mailto:c...@crok.demon.co.uk
<       U O      |_|_|_|_|_|    O  ||       WWW:   http://www.crok.demon.co.uk
 \,     |/|\      _________       [  ]            
     .  |/^\  .       2       .   /__\
... ((((((((HYPNOTIC))))))))((((((TAGLINE))))))))

Re:Converting Turbo Pascal to ANSI Pascal


Before being shot for writing article <6inf5q$9...@mx2.hrz.uni-essen.de>, Peter Gerwinski wrote:

Quote
> Stephen Crocker <c...@crok.demon.co.uk> wrote:
> > [...] Presumably
> > it's a matter of creating a library of procedures which just call other
> > procedures from the standard libraries.  I have Gnu Pascal with a
> > UNIX C library so it shouldn't be TOO hard to do.

> Indeed.

> See the GPC FAQ list (http://home.pages.de/~GNU-Pascal/gpc-faq.html)
> for instructions how to use C library functions from GNU Pascal
> programs.

That should help.

Quote
> > Just three questions:-
> > How do I create a library?

> What do you mean?
> A Unit? --> Like in BP.
> A library (.a file)? --> Like in GNU C.

A library in C for use with GPC.

Quote
> > What are the ANSI equivalents?

> For Units? --> Modules.  See the GPC documentation.
>                But GPC also supports Units.

> For DOS, CRT, Graph? --> Nothing. :-(

No, I meant the commands from the units, and their corresponding ANSI
functions.

Quote
> > How do I tell the compiler to add these libraries (Is it just "Uses" as
> > in TP?)

> To use a Unit:  Yes: "Uses".
> To use a Module:  Essentially use "Import" instead of "Uses".
>                   (See the doc for details.)

Right...

Quote
> But now for my guess of what you are *really* looking for:  ;-)

> On ftp://agnes.dida.physik.uni-essen.de/gnu-pascal/contrib/, you can
> find a BP compatibility package "BPcompat" for GNU Pascal.  While it
> is written for the DOS (DJGPP) platform, large parts of it should be
> easily ported to other platforms.

Ah, that sounds REALLY handy!

Quote
> In the DJGPP distribution (subdirectory gnu/djgpp/ on any SimTel
> mirror) you can find a library called GRX (file v2tk/grx22.zip).
> Although it has originally been written for DOS, it is portable to
> other platforms such as Linux/SVGAlib or Linux/X11.  It comes with
> a file `graph.pas' which does exactly what you would expect from
> this name. :-)

Right.  I'll look into it.

Quote
> You will need a more recent (alpha or beta) version of GPC in order
> to take full advantage of the above.  You can download one from
> http://agnes.dida.physik.uni-essen.de/gnu-pascal/alpha/ .

Hmmm...  I'm not sure how recent mine is.

Quote
> If you need further help, be invited to join the GNU Pascal mailing
> list.  See http://home.pages.de/~GNU-Pascal/support.html .

I'll keep that in mind.

--
 x^      ( )      _________         //     Email:  mailto:c...@crok.demon.co.uk
<       U O      |_|_|_|_|_|    O  ||       WWW:   http://www.crok.demon.co.uk
 \,     |/|\      _________       [  ]            
     .  |/^\  .       2       .   /__\
... My hard disk is full! Maybe I'll try this message section thing.

Re:Converting Turbo Pascal to ANSI Pascal


Quote
Stephen Crocker (c...@crok.demon.co.uk) wrote:

: Before being shot for writing article <6ilhul$o5...@news-sj-3.cisco.com>, Scott A. Moore wrote:

: > In article <6ik17p$h...@mx2.hrz.uni-essen.de>,
: > pe...@agnes.dida.physik.uni-essen.de says...
: > >
: > >Stephen Crocker <c...@crok.demon.co.uk> wrote:
: > >>
: > >> Hmmm...  The problem is that I have a program which uses the Graph,
: > >> DOS, CRT and Mouse units quite heavily.  I would rather not rewrite it
: > >> by hand, so I was wondering if there was a program which would
: > >> substitute calls to procedures in these units with calls to ANSI
: > >> procedures.
: > >
: > >There are no ANSI procedures replacing DOS, CRT, Graph, and Mouse.
: > >(`Mouse'?  That's not a standard BP unit, is it?)  You need replacements
: > >for their functionality anyway, so if FPK Pascal runs on your system,
: > >it is probably the best choice for you.  Otherwise, try GNU Pascal which
: > >is closer to ANSI-ISO Pascal, runs on almost any existing system (it is
: > >just as portable as GNU C), comes with a portable, Graph-compatible
: > >Graphics unit (`GRX') and can use all of the portable libraries
: > >(e.g. `ncurses') written for C for getting the functionality of CRT
: > >and such.
: >
: > I converted a couple of TP programs to the system at hand, an
: > ANSI compatible compiler. The biggest problem was strings.
: >
: > Your problem is that graphics and special device functions, like the
: > mouse, are not discussed (I think properly) in the language standard.
: > To write a really independent program, you need to either use or
: > create a standard procedures libary. Ie, a standard method of
: > using those features. You have actually been using such a library -
: > the DOS, CRT, etc. modules. The problem is that they were never
: > ported off the PC/MSDOS platform, and you don't have the source
: > for them to change it.
: >
: > Now comes the advice that no one ever takes. You are going to
: > write a set of adaption code. You either write a general purpose
: > library of functions, such as the Borland folks did, or you
: > create a porting library just for that program. In the latter
: > case, all you really have to do is isolate the lower level
: > functions, such as graphics or mouse, into a support section.
: > Then, you rewrite that as required to port it. Ie., your program
: > will be portable because it is designed that way.

: Well, I'd like to write a library but I don't know where to begin!

Some versions of Borland Pascal 7.0 (not Turbo) come with a "bonus disk"
which contains the source code for most of the RTL. The only source not
provided is the OVERLAY assembler source (name one other compiler that
uses and overlay format and does not have appropriate units for them). If
you were to port the borland RTL into another compiler/platform, this
might be where to begin.
--
  Peter Mac Millan    | Get the new, improved, wounderfully enhanced, and
zero....@bitsmart.com | graphically stunnging: MS-PetRock. Only $99.99

Re:Converting Turbo Pascal to ANSI Pascal


In article <fjf.19980503200...@gnu.de>,

Quote
  frank@[NOSPAM.REMOVE.THIS]pascal.gnu.de wrote:

> In <19980503.095214...@crok.demon.co.uk>,
> Stephen Crocker <c...@crok.demon.co.uk> wrote:

> > I was wondering whether anyone has produced a program which will
> > replace references to TPUs and their procedures with references to
> > standard ANSI libraries.  If so, can I download it from somewhere?  I
> > am trying to port some TP code to another platform and I would rather
> > not have to rewrite the whole thing!

> The main problem is not the library functions, but already the
> language used by TP differs vastly from the standards. Therefore
> I guess that an automatic translation is not possible to a
> satisfying degree.

The major problem with Turbo Pascal is that the semantics are different,
especially for i/o.  For example, the get/put and f^ constructs are totally
missing, and the rules for numerical input (e.g. read(f, integervar) are also
different.  WITH clauses are another bane (WITH recordtype.variant will not
allocate the correct space), writes do not format correctly (write(f,
ARRAY[1..n] OF char : field) will not truncate the chararray at field), and so
on.

About ten years ago I prepared some TPUs to fix these problems.  I could not
use the original names (for example f^ was replaced by fptr(f)) which allowed
most ISO programs to port.

I have been out of the game for some years, but if someone will advise me of a
suitable place to post these TPUs and their source, I am willing to attempt to
do so.

I do not have newsgroup access here, only via this DEJA-VUE system, and I am
not familiar with it so far.  Thus between work & other things I am very
likely to miss responses on the newsgroup.  I can be emailed directly as:

          Charles_Falco...@apsnet.com

in addition to the DEJA-Vue system.

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading

Other Threads