From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.7 required=5.0 tests=BAYES_00,INVALID_DATE, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,130283ad9c6c2e69 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-10-18 13:08:31 PST Path: bga.com!news.sprintlink.net!sundog.tiac.net!wizard.pn.com!Germany.EU.net!EU.net!howland.reston.ans.net!math.ohio-state.edu!magnus.acs.ohio-state.edu!csn!boulder!news.coop.net!news.den.mmc.com!iplmail.orl.mmc.com!alcyone!rgilbert From: rgilbert@orl.mmc.com (Bob Gilbert) Newsgroups: comp.lang.ada Subject: Re: Interfacing Ada to Unix/execl var. arg. li Date: 17 Oct 1994 18:18:54 GMT Organization: Martin Marietta Orlando Distribution: world Message-ID: <37uf6e$7ik@theopolis.orl.mmc.com> References: <37ioh5$h9v@goanna.cs.rmit.oz.au> Reply-To: rgilbert@orl.mmc.com NNTP-Posting-Host: alcyone.orl.mmc.com Date: 1994-10-17T18:18:54+00:00 List-Id: In article h9v@goanna.cs.rmit.oz.au, Dale Stanbrough () writes: ->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 #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; I don't know all (any of) the details involved with C_execl but... If it is desired for the arg_list to contain a list of values of possibly different types, and you would like to protect the procedure/function from invalid (wrong type) arguments (maybe better than just passing an array of addresses to who knows what), and you don't want to have to overload the function with all the possible argument lengths, then how about something like: -- enumerate all possible argument types type ARG is (Arg_1, Arg_2, Arg_3, ... Arg_n, Null_Arg); type ARG_RECORD is (Arg_Name : ARG := Null_Arg) is record case Arg_Name is when Arg _1 => Arg_1 : ARG_1_TYPE; when Arg_2 => Arg_2 : ARG_2_TYPE; . . when Arg_n => Arg_n : ARG_N_TYPE; when Null_Arg => null; end record; type ARG_LIST is array (NATURAL range <>) of ARG_RECORD; Null_Arg_List : constant ARG_LIST(1..0); --------------------------------------------------------- -- The following procedure (or function) can be invoked as: -- -- C_Excel(My_Path, ARG_LIST'((Arg_1, Data_1), -- (Arg_3, Data_2), -- ... -- (Arg_n, Data_n))); --------------------------------------------------------- function C_Excel(Path : System.ADDRESS; Arg_List : ARG_LIST := Null_Arg_List) return Interfaces.c.int is type ADDRESS_ARRAY is array (NATURAL range Arg_List'range) of System.ADDRESS; Arg_Address_List : ADDRESS_ARRAY; begin for i in Arg_List'range loop -- Build Arg_Address_List for C call case Arg_List is Arg_List(i) := Arg_List(i).Arg_1'address; when Arg_2 => Arg_List(i) := Arg_List(i).Arg_2'address; . . when Arg_n => Arg_List(i) := Arg_List(i).Arg_n'address; when Null_Arg => null; end case; end loop; . . . return {whatever}; end C_Excel; pragma (Disclaimer_On); Hope I didn't make too many errors in the above example, I didn't get a chance to see if it actually compiles. If their are any problems that I didn't account for (like maybe the Arg_Address_List does not have a valid lifetime or something), or if I'm just completely off base, I'm sure others will correct me. -Bob