comp.lang.ada
 help / color / mirror / Atom feed
* Providing C function With Argv
@ 2002-07-22 15:26 Jeff
  2002-07-23  8:14 ` Ken Thomas
  2002-07-23 13:43 ` Robert Dewar
  0 siblings, 2 replies; 4+ messages in thread
From: Jeff @ 2002-07-22 15:26 UTC (permalink / raw)


I'm in the process of extending/porting a C program to Ada.  I have an
Ada main program that needs to call a C function with the parameters
int argc, char **argv.  With Ada.Command_Line, I've been able to pass
the C function with int argc.  Using Interfaces.C.Strings, I have even
been successful supplying a modified version of the C function with a
Interfaces.C.Strings.chars_ptr to provide the function with a single
string Argument.  However, I can't seem to figure out how to construct
and pass the equivalent of a C char ** in order to pass all the
arguments at once.  My guess is that I need to use
Interfaces.C.Pointers to construct a Pointer to chars_ptr.  But I've
had no luck with this approach.

How does one pass a C function the eqivalent of char **?  Is there any
easier way to accomplish this than to construct the char **argv from
Ada.Command_Line.Argument?  Working code would be much appreciated
since I'm rather new to Ada.



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

* Re: Providing C function With Argv
  2002-07-22 15:26 Providing C function With Argv Jeff
@ 2002-07-23  8:14 ` Ken Thomas
  2002-07-24  6:18   ` Jeff
  2002-07-23 13:43 ` Robert Dewar
  1 sibling, 1 reply; 4+ messages in thread
From: Ken Thomas @ 2002-07-23  8:14 UTC (permalink / raw)


Take a look at the interface to TCL (tash802), there is a package "Cargv"
that does the job.
http://unicoi.kennesaw.edu/ase/ase02_02/bindings/tash/

Ken Thomas

"Jeff" <jeff.huter@bigfoot.com> wrote in message
news:fe4bb2c2.0207220726.7502e4bd@posting.google.com...
> I'm in the process of extending/porting a C program to Ada.  I have an
> Ada main program that needs to call a C function with the parameters
> int argc, char **argv.  With Ada.Command_Line, I've been able to pass
> the C function with int argc.  Using Interfaces.C.Strings, I have even
> been successful supplying a modified version of the C function with a
> Interfaces.C.Strings.chars_ptr to provide the function with a single
> string Argument.  However, I can't seem to figure out how to construct
> and pass the equivalent of a C char ** in order to pass all the
> arguments at once.  My guess is that I need to use
> Interfaces.C.Pointers to construct a Pointer to chars_ptr.  But I've
> had no luck with this approach.
>
> How does one pass a C function the eqivalent of char **?  Is there any
> easier way to accomplish this than to construct the char **argv from
> Ada.Command_Line.Argument?  Working code would be much appreciated
> since I'm rather new to Ada.





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

* Re: Providing C function With Argv
  2002-07-22 15:26 Providing C function With Argv Jeff
  2002-07-23  8:14 ` Ken Thomas
@ 2002-07-23 13:43 ` Robert Dewar
  1 sibling, 0 replies; 4+ messages in thread
From: Robert Dewar @ 2002-07-23 13:43 UTC (permalink / raw)


jeff.huter@bigfoot.com (Jeff) wrote in message news:<fe4bb2c2.0207220726.7502e4bd@posting.google.com>...
> How does one pass a C function the eqivalent of char **?  Is there any
> easier way to accomplish this than to construct the char **argv from
> Ada.Command_Line.Argument?  Working code would be much appreciated
> since I'm rather new to Ada.


To do this in portable Ada is a real pain, because you
would have to reconstruct the data in the form expected
by a C program.

In practice, most implementations will save argc and argv
somewhere. Read the GNAT documentation to find out how
this is done in GNAT (it is fully documented).

I trust that if you are using GNAT, you do indeed have
the documentation?



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

* Re: Providing C function With Argv
  2002-07-23  8:14 ` Ken Thomas
@ 2002-07-24  6:18   ` Jeff
  0 siblings, 0 replies; 4+ messages in thread
From: Jeff @ 2002-07-24  6:18 UTC (permalink / raw)


Thanks Ken,

The CArgv and CHelper packages of TASH did the trick.  I only wish I
found them sooner.  It would have saved many hours of hacking in my
feeble attempt to accomplish what I thought should be an "easy" task.
Oh well.  Live and learn.

One bright spot is that I wasn't too far off.  While CArgv and CHelper
are much more elegant, my approach was similar and probably would have
worked with some minor corrections.  However, I decided to use the
CArgv and CHelper packages because they provide functions which should
be helpful in accomplishing my thin port.

Thanks again,

Jeff

"Ken Thomas" <kst@ecs.soton.ac.uk> wrote in message news:<3d3d0fdd@news.ecs.soton.ac.uk>...
> Take a look at the interface to TCL (tash802), there is a package "Cargv"
> that does the job.
> http://unicoi.kennesaw.edu/ase/ase02_02/bindings/tash/
> 
> Ken Thomas
> 
> "Jeff" <jeff.huter@bigfoot.com> wrote in message
> news:fe4bb2c2.0207220726.7502e4bd@posting.google.com...
> > I'm in the process of extending/porting a C program to Ada.  I have an
> > Ada main program that needs to call a C function with the parameters
> > int argc, char **argv.  With Ada.Command_Line, I've been able to pass
> > the C function with int argc.  Using Interfaces.C.Strings, I have even
> > been successful supplying a modified version of the C function with a
> > Interfaces.C.Strings.chars_ptr to provide the function with a single
> > string Argument.  However, I can't seem to figure out how to construct
> > and pass the equivalent of a C char ** in order to pass all the
> > arguments at once.  My guess is that I need to use
> > Interfaces.C.Pointers to construct a Pointer to chars_ptr.  But I've
> > had no luck with this approach.
> >
> > How does one pass a C function the eqivalent of char **?  Is there any
> > easier way to accomplish this than to construct the char **argv from
> > Ada.Command_Line.Argument?  Working code would be much appreciated
> > since I'm rather new to Ada.



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

end of thread, other threads:[~2002-07-24  6:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-22 15:26 Providing C function With Argv Jeff
2002-07-23  8:14 ` Ken Thomas
2002-07-24  6:18   ` Jeff
2002-07-23 13:43 ` Robert Dewar

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