From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: In GNAT/Ada95(main) use a C-Program
Date: 1999/06/09
Date: 1999-06-09T00:00:00+00:00 [thread overview]
Message-ID: <XbNsYkus#GA.203@newstoo.hiwaay.net> (raw)
In-Reply-To: 375EB748.2ABAAC25@sbox.tu-graz.ac.at
Gerhard Griessnig <grie@sbox.tu-graz.ac.at> wrote in message
news:375EB748.2ABAAC25@sbox.tu-graz.ac.at...
> Thanks for your response,
> we have also read the GNAT-Users Guide.
> We know how to compile-bind and link C-Programes, but we do not know the
Syntax
> how
> to call a C-Program in an Ada-Main-Program and deliver some Parameters.
> We would need some examples ( Syntax ).
>
If by calling a C-Program, you mean invoking a sepaate executable process,
then the answer doesn't depend at all on the language in which it is
written.
To invoke another process in a subshell, one can use an Ada interface to
the library function "system", exactly as is done in a C program.
one way to provide this interface is with the following library
function:
with Interfaces.C;
function Execute_Shell_Command (The_Command_String : String)
return Interfaces.C.Int is
package C renames Interfaces.C;
function System (S : C.Char_Array) return C.Int;
pragma Import (C, System, "system");
begin
return System (C.To_C (The_Command_String));
end Execute_Shell_Command;
Then, for example, to display the contents of the current directory,
you would have the following:
with Execute_Shell_Command;
.
.
.
.
Execute_Shell_command ("ls -l");
.
.
.
Read the man page for system, to get additional details such as
what values is returned by the function, etc.
If, instead of executing in a subshell, and waiting for the shell to
terminate, you want your program to spawn a child process, then
for the Sun platform I would recommend using the Posix Ada bindings
from Florida State University, called Florist, available from
http://www.cs.fsu.edu/~baker/ftp/pub/PART/FLORIST/florist990327.tar.gz
ftp://ftp.cs.fsu.edu/pub/PART/FLORIST/florist990327.tar.gz
Look at the services provided by the packaghe POSIX.Process_Primitives.
> About our platform: We use a Sun-Workstation, more details follow.
>
> Bye,
> Gerhard, Peter
>
>
>
>
> David C. Hoos, Sr. schrieb:
>
> > Gerhard Griessnig wrote in message
<375E60AD.C56EAE59@sbox.tu-graz.ac.at>...
> > >Hello,
> > >we want to bind C-Programs in a GNAT-Ada95 Mainprogram.
> > >How is it possible, and who is able to send us some examples.
> > >
> > >We need this
> > > - to communicate with a RS232
> > > ( are protocols in GNAT-Ada available ? )
> > > - to communicate with radar
> > >to our roboter (Khepera on Unix).
> > >
> > The RS-232 portion of your question is dependent of the OS/hardware
> > platform. Can you provide more details? I have written some
> > serial port communication stuff for Linux/PC and Win32.
> >
> > For the binding of C to Ada, how about reading the
> > Gnat User's Guide, especially the section titled
> > Mixed Language Programming
>
next prev parent reply other threads:[~1999-06-09 0:00 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-06-09 0:00 In GNAT/Ada95(main) use a C-Program Gerhard Griessnig
1999-06-09 0:00 ` David C. Hoos, Sr.
1999-06-09 0:00 ` Gerhard Griessnig
1999-06-09 0:00 ` David C. Hoos, Sr. [this message]
1999-06-10 0:00 ` Robert Dewar
1999-06-10 0:00 ` Keith Thompson
1999-06-11 0:00 ` Robert Dewar
1999-06-09 0:00 ` Robert Dewar
1999-06-09 0:00 ` Samuel Mize
1999-06-09 0:00 ` dennison
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox