comp.lang.ada
 help / color / mirror / Atom feed
* Re: In GNAT/Ada95(main) use a C-Program
  1999-06-09  0:00 ` David C. Hoos, Sr.
@ 1999-06-09  0:00   ` Gerhard Griessnig
  1999-06-09  0:00     ` Robert Dewar
  1999-06-09  0:00     ` David C. Hoos, Sr.
  1999-06-09  0:00   ` Samuel Mize
  1 sibling, 2 replies; 10+ messages in thread
From: Gerhard Griessnig @ 1999-06-09  0:00 UTC (permalink / raw)
  To: David C. Hoos, Sr.

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 ).

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





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: In GNAT/Ada95(main) use a C-Program
  1999-06-09  0:00   ` Gerhard Griessnig
@ 1999-06-09  0:00     ` Robert Dewar
  1999-06-09  0:00     ` David C. Hoos, Sr.
  1 sibling, 0 replies; 10+ messages in thread
From: Robert Dewar @ 1999-06-09  0:00 UTC (permalink / raw)


In article <375EB748.2ABAAC25@sbox.tu-graz.ac.at>,
  Gerhard Griessnig <grie@sbox.tu-graz.ac.at> wrote:
> 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 ).

This is completely covered in the Ada RM, GNAT follows all the
RM recommendations for passing parameters to C convention
subprograms.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: In GNAT/Ada95(main) use a C-Program
  1999-06-09  0:00   ` Gerhard Griessnig
  1999-06-09  0:00     ` Robert Dewar
@ 1999-06-09  0:00     ` David C. Hoos, Sr.
  1999-06-10  0:00       ` Robert Dewar
  1 sibling, 1 reply; 10+ messages in thread
From: David C. Hoos, Sr. @ 1999-06-09  0:00 UTC (permalink / raw)


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
>





^ permalink raw reply	[flat|nested] 10+ messages in thread

* In GNAT/Ada95(main) use a C-Program
@ 1999-06-09  0:00 Gerhard Griessnig
  1999-06-09  0:00 ` dennison
  1999-06-09  0:00 ` David C. Hoos, Sr.
  0 siblings, 2 replies; 10+ messages in thread
From: Gerhard Griessnig @ 1999-06-09  0:00 UTC (permalink / raw)


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).

Thanks,
    Gerhard, Peter

(grie@sbox.tu-graz.ac.at)





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: In GNAT/Ada95(main) use a C-Program
  1999-06-09  0:00 In GNAT/Ada95(main) use a C-Program Gerhard Griessnig
  1999-06-09  0:00 ` dennison
@ 1999-06-09  0:00 ` David C. Hoos, Sr.
  1999-06-09  0:00   ` Gerhard Griessnig
  1999-06-09  0:00   ` Samuel Mize
  1 sibling, 2 replies; 10+ messages in thread
From: David C. Hoos, Sr. @ 1999-06-09  0:00 UTC (permalink / raw)



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








^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: In GNAT/Ada95(main) use a C-Program
  1999-06-09  0:00 In GNAT/Ada95(main) use a C-Program Gerhard Griessnig
@ 1999-06-09  0:00 ` dennison
  1999-06-09  0:00 ` David C. Hoos, Sr.
  1 sibling, 0 replies; 10+ messages in thread
From: dennison @ 1999-06-09  0:00 UTC (permalink / raw)


In article <375E60AD.C56EAE59@sbox.tu-graz.ac.at>,
  Gerhard Griessnig <grie@sbox.tu-graz.ac.at> wrote:
> 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.

Don't tell anyone that I told you this: There's a secret source
of documentation that comes with every Gnat installation that goes into
how to do this in detail. On a win95 system it is cleverly hidden in
your start menu, in the "Gnat Ada95 Compiler" group, with the name "GNAT
Users Guide". If you took the default installation for version 3.11p,
you can just surf to the following URL:

file:///C|/GNAT/Documentation/gnat_ug.html#SEC24

--
T.E.D.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: In GNAT/Ada95(main) use a C-Program
  1999-06-09  0:00 ` David C. Hoos, Sr.
  1999-06-09  0:00   ` Gerhard Griessnig
@ 1999-06-09  0:00   ` Samuel Mize
  1 sibling, 0 replies; 10+ messages in thread
From: Samuel Mize @ 1999-06-09  0:00 UTC (permalink / raw)


David C. Hoos, Sr. <david.c.hoos.sr@ada95.com> wrote:
> 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.
...
> For the binding of C to Ada, how about reading the
> Gnat User's Guide, especially the section titled
> Mixed Language Programming

That's pretty brief, and has no examples (at least in my 3.10 version).
Is there a tutorial we can point him to?

Also, the Ada Reference Manual, Appendix B, sections 1 through 3,
are where the interfacing capabilities are defined -- but again,
this is a reference, not a tutorial.

Best,
Sam Mize

-- 
Samuel Mize -- smize@imagin.net (home email) -- Team Ada
Fight Spam: see http://www.cauce.org/ \\\ Smert Spamonam




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: In GNAT/Ada95(main) use a C-Program
  1999-06-09  0:00     ` David C. Hoos, Sr.
@ 1999-06-10  0:00       ` Robert Dewar
  1999-06-10  0:00         ` Keith Thompson
  0 siblings, 1 reply; 10+ messages in thread
From: Robert Dewar @ 1999-06-10  0:00 UTC (permalink / raw)


In article <XbNsYkus#GA.203@newstoo.hiwaay.net>,
  "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com> wrote:
> one way to provide this interface is with the following
> library function:

(interface to System snipped)

If you are using GNAT, a preferable method is to use the
higher level routines in GNAT.OS_Lib, since they are portable
across all platforms, including those that do not support
the Unix system call.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: In GNAT/Ada95(main) use a C-Program
  1999-06-10  0:00       ` Robert Dewar
@ 1999-06-10  0:00         ` Keith Thompson
  1999-06-11  0:00           ` Robert Dewar
  0 siblings, 1 reply; 10+ messages in thread
From: Keith Thompson @ 1999-06-10  0:00 UTC (permalink / raw)


Robert Dewar <robert_dewar@my-deja.com> writes:
[...]
> If you are using GNAT, a preferable method is to use the
> higher level routines in GNAT.OS_Lib, since they are portable
> across all platforms, including those that do not support
> the Unix system call.

One minor correction: the system() function is part of the C language
definition, so it should exist on any system that supports C,
not just Unix.

On the other hand, the form of the argument to system() is extremely
system-specific.  On Unix, it's usually passed to /bin/sh, on
DOS/Windows, I think it's usually interpreted as a DOS command,
and so on.

-- 
Keith Thompson (The_Other_Keith) kst@cts.com  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center  <http://www.sdsc.edu>                 <*>
One of the great tragedies of ancient history is that Helen of Troy
lived before the invention of the champagne bottle.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: In GNAT/Ada95(main) use a C-Program
  1999-06-10  0:00         ` Keith Thompson
@ 1999-06-11  0:00           ` Robert Dewar
  0 siblings, 0 replies; 10+ messages in thread
From: Robert Dewar @ 1999-06-11  0:00 UTC (permalink / raw)


In article <yecyahrz2sa.fsf@king.cts.com>,
  Keith Thompson <kst@cts.com> wrote:
> Robert Dewar <robert_dewar@my-deja.com> writes:
> [...]
> > If you are using GNAT, a preferable method is to use the
> > higher level routines in GNAT.OS_Lib, since they are
portable
> > across all platforms, including those that do not support
> > the Unix system call.
>
> One minor correction: the system() function is part of the C
language
> definition, so it should exist on any system that supports C,
> not just Unix.

I meant *EXACTLY* what I said, I was talking about platforms
that do not support the *UNIX* system call, i.e. the version
of system typically accepted by Unix. As Keith points out, the
use of system varies significantly from one system to another.



Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~1999-06-11  0:00 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-06-09  0:00 In GNAT/Ada95(main) use a C-Program Gerhard Griessnig
1999-06-09  0:00 ` dennison
1999-06-09  0:00 ` David C. Hoos, Sr.
1999-06-09  0:00   ` Gerhard Griessnig
1999-06-09  0:00     ` Robert Dewar
1999-06-09  0:00     ` David C. Hoos, Sr.
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   ` Samuel Mize

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox