* binding to C: popen
@ 2006-02-21 14:37 Poul-Erik Andreasen
2006-02-21 15:25 ` jimmaureenrogers
2006-02-22 13:50 ` Marc A. Criley
0 siblings, 2 replies; 9+ messages in thread
From: Poul-Erik Andreasen @ 2006-02-21 14:37 UTC (permalink / raw)
Hi
i am trying to make a biding to the C function popen, it goes like this:
with System.Address_To_Access_Conversions;
with Interfaces.C_Streams;
package Pipe_Pkg is
subtype Command_Pipe is Interfaces.C_Streams.FILEs;
procedure Pipe_Open (Pipe : in out Command_Pipe;
Command : in String);
private
function To_C (Input : in String) return Interfaces.C_Streams.Chars;
end Pipe_Pkg;
package body Pipe_Pkg is
procedure Pipe_Open
(Pipe : in out Command_Pipe;
Command : in String)
is
use Interfaces.C_Streams;
function C_Popen (C_Command : Chars;
C_Type : Chars) return Command_Pipe;
pragma Import (C, C_Popen, "popen");
begin
Pipe := C_Popen ((To_C (Command)), To_C ("w"));
end Pipe_Open;
function To_C (Input : in String) return Interfaces.C_Streams.Chars
is
package String_Conversion is
new System.Address_To_Access_Conversions (String);
String_Pointer : String_Conversion.Object_Pointer :=
new String'(Input & ascii.nul);
begin
return String_Conversion.To_Address (String_Pointer);
end;
end Pipe_Pkg;
This ictually going as it is suppose to, but i would like set in an
exception if the piping dosn't have succes. Acording to the C manual
popen returns null if it fails. But how do i test on that in the FILEs type?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: binding to C: popen
2006-02-21 14:37 binding to C: popen Poul-Erik Andreasen
@ 2006-02-21 15:25 ` jimmaureenrogers
2006-02-21 15:45 ` Poul-Erik Andreasen
2006-02-22 13:50 ` Marc A. Criley
1 sibling, 1 reply; 9+ messages in thread
From: jimmaureenrogers @ 2006-02-21 15:25 UTC (permalink / raw)
Poul-Erik Andreasen wrote:
> This ictually going as it is suppose to, but i would like set in an
> exception if the piping dosn't have succes. Acording to the C manual
> popen returns null if it fails. But how do i test on that in the FILEs type?
The popen man page describes the command as:
FILE *popen(const char *command, const char *mode);
Note that popen returns a file pointer. Upon failure it returns a null
pointer.
It seems that you might be able to test if the return value is null.
Jim Rogers
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: binding to C: popen
2006-02-21 15:25 ` jimmaureenrogers
@ 2006-02-21 15:45 ` Poul-Erik Andreasen
2006-02-21 15:52 ` Georg Bauhaus
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Poul-Erik Andreasen @ 2006-02-21 15:45 UTC (permalink / raw)
jimmaureenrogers@worldnet.att.net wrote:
> Poul-Erik Andreasen wrote:
>
>>This ictually going as it is suppose to, but i would like set in an
>>exception if the piping dosn't have succes. Acording to the C manual
>>popen returns null if it fails. But how do i test on that in the FILEs type?
>
>
> The popen man page describes the command as:
> FILE *popen(const char *command, const char *mode);
>
> Note that popen returns a file pointer. Upon failure it returns a null
> pointer.
>
> It seems that you might be able to test if the return value is null.
>
> Jim Rogers
>
Yes but a C pointer is in Ada represented as system.address and i can
not test that for O the the systems.address_image gives 0804C060 and if
that is a stadart c value for a null-pointer things are fine, but that
seems to be a hack.
Poul-Erik
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: binding to C: popen
2006-02-21 15:45 ` Poul-Erik Andreasen
@ 2006-02-21 15:52 ` Georg Bauhaus
2006-02-21 16:16 ` Poul-Erik Andreasen
2006-02-21 16:12 ` Alex R. Mosteo
2006-02-21 23:51 ` Jeffrey R. Carter
2 siblings, 1 reply; 9+ messages in thread
From: Georg Bauhaus @ 2006-02-21 15:52 UTC (permalink / raw)
Poul-Erik Andreasen wrote:
> Yes but a C pointer is in Ada represented as system.address and i can
> not test that for O the the systems.address_image gives 0804C060 and if
> that is a stadart c value for a null-pointer things are fine, but that
> seems to be a hack.
System.Null_Address, or Interfaces.C.Strings.Null_Ptr perhaps?
You could consider writing a predicate like
fucntion is_null(p: System.Address) return Boolean;
in order to have the comparison in one place only.
HTH,
Georg
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: binding to C: popen
2006-02-21 15:45 ` Poul-Erik Andreasen
2006-02-21 15:52 ` Georg Bauhaus
@ 2006-02-21 16:12 ` Alex R. Mosteo
2006-02-21 23:51 ` Jeffrey R. Carter
2 siblings, 0 replies; 9+ messages in thread
From: Alex R. Mosteo @ 2006-02-21 16:12 UTC (permalink / raw)
Poul-Erik Andreasen wrote:
> jimmaureenrogers@worldnet.att.net wrote:
>
>> Poul-Erik Andreasen wrote:
>>
>>> This ictually going as it is suppose to, but i would like set in an
>>> exception if the piping dosn't have succes. Acording to the C manual
>>> popen returns null if it fails. But how do i test on that in the
>>> FILEs type?
>>
>>
>>
>> The popen man page describes the command as:
>> FILE *popen(const char *command, const char *mode);
>>
>> Note that popen returns a file pointer. Upon failure it returns a null
>> pointer.
>>
>> It seems that you might be able to test if the return value is null.
>>
>> Jim Rogers
>>
>
> Yes but a C pointer is in Ada represented as system.address (...)
Not necessarily. Have a look at Interfaces.C, Interfaces.C.Pointers and
Interfaces.C.Strings.
Also with Gnat an access type with pragma Convention (C, ...) can do the
trick. You can easily check for null pointers that way.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: binding to C: popen
2006-02-21 15:52 ` Georg Bauhaus
@ 2006-02-21 16:16 ` Poul-Erik Andreasen
0 siblings, 0 replies; 9+ messages in thread
From: Poul-Erik Andreasen @ 2006-02-21 16:16 UTC (permalink / raw)
Georg Bauhaus wrote:
> Poul-Erik Andreasen wrote:
>
>
>>Yes but a C pointer is in Ada represented as system.address and i can
>>not test that for O the the systems.address_image gives 0804C060 and if
>>that is a stadart c value for a null-pointer things are fine, but that
>>seems to be a hack.
>
>
> System.Null_Address, or Interfaces.C.Strings.Null_Ptr perhaps?
>
> You could consider writing a predicate like
>
> fucntion is_null(p: System.Address) return Boolean;
>
> in order to have the comparison in one place only.
>
> HTH,
> Georg
In the meantime i have found out that i will not help much. The
null-pointer return will only occur if there is a internal error, and
since sh normaly will succed even if the command fails it somthing that
rarely occurs. I can not even find out a way to test it.
Poul-Erik
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: binding to C: popen
2006-02-21 15:45 ` Poul-Erik Andreasen
2006-02-21 15:52 ` Georg Bauhaus
2006-02-21 16:12 ` Alex R. Mosteo
@ 2006-02-21 23:51 ` Jeffrey R. Carter
2 siblings, 0 replies; 9+ messages in thread
From: Jeffrey R. Carter @ 2006-02-21 23:51 UTC (permalink / raw)
Poul-Erik Andreasen wrote:
> Yes but a C pointer is in Ada represented as system.address
No, it's not. A C pointer in Ada is a C-convention access type. A C-convention
access type must correspond to a C pointer. System.Address need not.
--
Jeff Carter
"Death awaits you all, with nasty, big, pointy teeth!"
Monty Python & the Holy Grail
20
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: binding to C: popen
2006-02-21 14:37 binding to C: popen Poul-Erik Andreasen
2006-02-21 15:25 ` jimmaureenrogers
@ 2006-02-22 13:50 ` Marc A. Criley
2006-02-23 1:10 ` poulerik
1 sibling, 1 reply; 9+ messages in thread
From: Marc A. Criley @ 2006-02-22 13:50 UTC (permalink / raw)
Poul-Erik Andreasen wrote:
> Hi
>
> i am trying to make a biding to the C function popen, it goes like this:
If your goal is just to get a binding to pipes, and you're less
interested in writing it yourself, you could get Jim Roger's "pipes"
package at
http://www.adapower.com/index.php?Command=Class&ClassID=Bindings&CID=181
I've used this on a number of projects over the years, and it's been a
terrific utility.
-- Marc A. Criley
-- McKae Technologies
-- www.mckae.com
-- DTraq - XPath In Ada - XML EZ Out
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: binding to C: popen
2006-02-22 13:50 ` Marc A. Criley
@ 2006-02-23 1:10 ` poulerik
0 siblings, 0 replies; 9+ messages in thread
From: poulerik @ 2006-02-23 1:10 UTC (permalink / raw)
Marc A. Criley wrote:
> Poul-Erik Andreasen wrote:
>
>> Hi
>>
>> i am trying to make a biding to the C function popen, it goes like this:
>
>
> If your goal is just to get a binding to pipes, and you're less
> interested in writing it yourself, you could get Jim Roger's "pipes"
> package at
> http://www.adapower.com/index.php?Command=Class&ClassID=Bindings&CID=181
>
> I've used this on a number of projects over the years, and it's been a
> terrific utility.
Thanks , it is allways nice to see how other poeple do stuff. To answer
your question, i have never been witing a C binding before( i am awfully
in C), i thought i was nice litle thing to start with, and as i have
mentioned before my binding actually works fine. Jim Rogers package dos
either catch any errors in the opening, and as i mention elsewhere it is
rather useles to do so.
Poul-Erik
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2006-02-23 1:10 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-21 14:37 binding to C: popen Poul-Erik Andreasen
2006-02-21 15:25 ` jimmaureenrogers
2006-02-21 15:45 ` Poul-Erik Andreasen
2006-02-21 15:52 ` Georg Bauhaus
2006-02-21 16:16 ` Poul-Erik Andreasen
2006-02-21 16:12 ` Alex R. Mosteo
2006-02-21 23:51 ` Jeffrey R. Carter
2006-02-22 13:50 ` Marc A. Criley
2006-02-23 1:10 ` poulerik
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox