comp.lang.ada
 help / color / mirror / Atom feed
From: "Eric G. Miller" <egm2@Jay-Pee-eSs.net>
Subject: Re: [Spark] Arrays of Strings
Date: Wed, 09 Apr 2003 07:50:16 GMT
Date: 2003-04-09T07:50:16+00:00	[thread overview]
Message-ID: <pan.2003.04.09.07.50.03.727731@Jay-Pee-eSs.net> (raw)
In-Reply-To: slrnb95ehu.ob.lutz@taranis.iks-jena.de

In <slrnb95ehu.ob.lutz@taranis.iks-jena.de>, Lutz Donnerhacke wrote:

> In order to implement thin an execve binding, I wonder how to emulate the
> C-Type "char const * const x []". Any bright ideas?

Errm, my local definition of execve looks like:

int execve(const char *filename, 
           char *const argv [], char *const envp[]);

What'd the const pointer be for?  Even if your definition had such, that'd
be a burden upon the C function, but shouldn't much affect the Ada side of
things.

Try the following out (rename "/tmp/hello" as appropriate)...

-- executor.ads
with Interfaces.C.Strings;

package Executor is

   package C renames Interfaces.C;

   function Execve (Filename : C.Strings.Chars_Ptr;
                    Argv     : C.Strings.Chars_Ptr_Array;
                    Envp     : C.Strings.Chars_Ptr_Array) return C.Int;

   pragma Import (Convention => C,
                  Entity => Execve,
                  External_Name => "execve");

end Executor;


-- try_exec.adb
with Ada.Text_Io;
use Ada.Text_Io;
with Executor;
with Interfaces.C.Strings;

procedure Try_Exec
is
   package C renames Interfaces.C;

   Argv : C.Strings.Chars_Ptr_Array :=
     (C.Strings.New_String("John"),
      C.Strings.New_String("Bill"),
      C.Strings.New_String("Bob"),
      C.Strings.Null_Ptr);

   -- GNAT says there can't only be one??
   Envp : C.Strings.Chars_Ptr_Array :=
     (C.Strings.Null_Ptr, C.Strings.Null_Ptr);

   FileName : C.Strings.Chars_Ptr :=
     C.Strings.New_String("/tmp/hello");

   Status : C.Int;

begin

   Status := Executor.Execve(FileName => FileName,
                    Argv => Argv, Envp => Envp);

   -- Got here?
   Put_Line ("That didn't work! Got " & C.Int'Image(Status));

end Try_Exec;

-- hello.c
#include <stdio.h>

int main (int argc, char *argv[])
{
  int i;

  for (i = 0; i < argc; ++i) {
    printf ("Hello %s!\n", argv[i]);
  }

  return 0;
}

-- 
echo ">gra.fcw@2ztr< eryyvZ .T pveR" | rot13 | reverse




  parent reply	other threads:[~2003-04-09  7:50 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-08 12:02 [Spark] Arrays of Strings Lutz Donnerhacke
2003-04-08 18:08 ` Martin Krischik
2003-04-09  9:23   ` Lutz Donnerhacke
2003-04-09 12:38     ` Hyman Rosen
2003-04-09 12:47       ` Vinzent Hoefler
2003-04-09 14:27         ` Hyman Rosen
2003-04-09 15:13           ` Vinzent Hoefler
2003-04-09 17:21         ` Hyman Rosen
2003-04-09 18:41           ` Vinzent Hoefler
2003-04-09 21:04           ` Randy Brukardt
2003-04-10 23:21           ` John R. Strohm
2003-04-11 12:19             ` Hyman Rosen
2003-04-11 13:14               ` John R. Strohm
2003-04-09  7:50 ` Eric G. Miller [this message]
2003-04-09  8:10   ` Lutz Donnerhacke
2003-04-09 18:23   ` Matthew Heaney
2003-04-09 17:42 ` Matthew Heaney
2003-04-09 21:06   ` Randy Brukardt
2003-04-10  8:23   ` Lutz Donnerhacke
2003-04-10 14:09     ` Matthew Heaney
2003-04-10 14:48       ` Hyman Rosen
2003-04-11  6:20         ` Chad R. Meiners
2003-04-11 12:31           ` Hyman Rosen
2003-04-11 18:27             ` Chad R. Meiners
2003-04-11  7:35         ` Phil Thornley
2003-04-11 12:05           ` Marin David Condic
2003-04-11 13:19             ` John R. Strohm
2003-04-12 23:09               ` Robert A Duff
2003-04-11 18:47             ` Chad R. Meiners
2003-04-12 23:51         ` Robert A Duff
2003-04-13  5:47           ` Hyman Rosen
2003-04-14  8:05             ` Lutz Donnerhacke
2003-04-10 15:02       ` Lutz Donnerhacke
2003-04-10 15:50         ` Hyman Rosen
2003-04-10 18:32           ` Randy Brukardt
2003-04-11  6:28         ` Chad R. Meiners
2003-04-11  8:11           ` Lutz Donnerhacke
2003-04-11 12:32 ` Rod Chapman
2003-04-11 14:50   ` Peter Amey
2003-04-11 18:41   ` Matthew Heaney
2003-04-11 21:25     ` Chad R. Meiners
2003-04-12 10:08     ` Peter Amey
replies disabled

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