comp.lang.ada
 help / color / mirror / Atom feed
* Interfacing Ada to Unix/execl var. arg. list function?
@ 1994-10-13  7:44 Dale Stanbrough
  1994-10-13  9:21 ` David Emery
                   ` (5 more replies)
  0 siblings, 6 replies; 13+ messages in thread
From: Dale Stanbrough @ 1994-10-13  7:44 UTC (permalink / raw)


I am currently trying to develop a simple Ada/Unix binding (not Posix!)
that will allow students to use the packages with a minimum of fuss.
(i.e. reading the Unix man page/Unix programming text would give them
a fair idea of how to use the Ada version).

I've got stuck on how to implement Ada calls to the corresponding
variable parameter list C functions, specifically execl.

Also the solutions I have written currently look clunky. I was wondering if 
there was a better way to implement these features.



Problem #1.
-----------
Passing in a list of variable length strings...

The possible options for passing in strings would be...

type string_ptr is access all string;
type string_array is array(natural range <>) of string_ptr;

then...

#1 ...execv(pathname, strings'("a","bb","cccc"));
#2 ...execv(pathname, strings_array'("a"'access, "bb"'access, "ccc"'access));
#3 ...execv(pathname, strings_array'(a'access,b'access,c'access));
#4 ...execv(pathname, ?);

#1 won't work because arrays elements have to be the same size
#2 won't work because I don't know why ?:-/ (I wish Gnat gave me LRM ref's!).
#3 seems awfully clunky, esp. as you have to alias all the strings before hand.
#4 is there a better one?



Problem #2.
-----------
Defining a constant null array seems to require the declaration of a
superfluous variable just to make the compiler happy...

------------------------------------------------------------
package unix is
        type string_ptr is access all string;
        type string_array is array(natural range <>) of string_ptr;

        null_arg_list   :constant string_array;

        function execl( path    :string;
                        arg_list:string_array := null_arg_list)
                        return integer;

private

        dummy   :aliased constant string := "";   --?? superfluous?
        null_arg_list   :constant string_array := (1..0 => dummy'access);
end unix.process;
------------------------------------------------------------




Problem #3.
-----------
How to specify and pass in a variable list of pointers to a C program.
(Yes, I know we've been down this path before, but generally w.r.t.
printf, which has varying types of parameters, as well as number).

-----------------------------------------------------------
-- Calling profile for execl in C.
--
--      int execl(path, arg0 [ , arg1,...  , argn ] (char *)0)
--      char *path, *arg0, *arg1, ..., *argn;
--

function execl( path            :string;
                arg_list        :string_array) return integer is

        ---------------------------------------------
        function C_execl( path      :system.address;
                          C_arg_list:               --?? What type here?
                          return interfaces.c.int;
        pragma import(C, C_execl, "execl");

begin
      -- how to do this?
end;
-----------------------------------------------------------
Thanks for any help you can give...

Dale
-------------------------------------------------------------
Dale Stanbrough, RMIT, Melbourne, Australia, dale@rmit.edu.au
GNU Ada 94 (GNAT) => the best $0 you'll ever spend.
Available for DOS, Linux, OS/2, Sun Sparc, Sun Solaris, ...
Coming to a GNU supported platform near you soon...



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

end of thread, other threads:[~1994-10-20 12:42 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1994-10-13  7:44 Interfacing Ada to Unix/execl var. arg. list function? Dale Stanbrough
1994-10-13  9:21 ` David Emery
1994-10-13 12:22 ` Robert Dewar
1994-10-13 17:37   ` Mark A Biggar
1994-10-13 18:46     ` Robert Dewar
1994-10-14 13:55   ` Norman H. Cohen
1994-10-13 13:31 ` Nicolas Courtel
1994-10-13 19:28 ` Tucker Taft
1994-10-14 13:55 ` Interfacing Ada to Unix/execl var ncohen
1994-10-17 18:18 ` Interfacing Ada to Unix/execl var. arg. li Bob Gilbert
1994-10-19  3:30   ` Interfacing Ada to Unix/execl var. arg. list function? Dale Stanbrough
1994-10-20 12:42     ` Interfacing Ada to Unix/execl var. arg Bob Gilbert
1994-10-20  4:18   ` Interfacing Ada to Unix/execl var. arg. li S M Ryan

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