Re: [GEN] Re: multiple pointers
On Sun, 15 Oct 2000 12:36:08 -0600, cense <cense at MAIL.RU> wrote:
cense :
This code is untested but it just to give an idea of what
you need to do. Add the procedure below to mixedlib.e to
make working with structure pointers easier.
Bernie
-----------------------------------------------------------------<>---------
--
-- Associates pointer to a structure that was returned by a "C"
--
global
procedure AssociatePtr( pointer address, sequence structure )
-- declare
pointer ptr
---| ptr | ST | name | offset | type | size | ... | total bytes |---
ptr = struc(structure,HIGH)
MastList[length(MastList)][1] = address
free(ptr)
--
end procedure -- end of AssociatePtr procedure
-----------------------------------------------------------------<>---------
I am assuming that you are using Linux.
Add the above procedure to the mixedlib.e at the end of the code.
-- "C" structure definition
-- struct hostent {
-- char *h_name; // official name of host
-- char **h_aliases; // alias list
-- int h_addrtype; // host address type
-- int h_length; // length of address
-- char **h_addr_list; // list of addresses
--};
-- stuct hostent *gethostbyname( const char *name );
When "C" returns the pointer to hostent structure use the above
procedure to associate the pointer to the hostent structure
like this.
AssociatePtr(hostent_ptr, " h_name : pointer : 1 "&
" h_aliases : pointer : 1 "&
" h_addrtype : int : 1 "&
" h_length : int : 200 "&
" h_addr_list : pointer : 1 ",
HIGH) -- allocate in high memory
Now the hostent_ptr can be used to access the structure that
"C" placed in memory.
pointer host_name_ptr
-- this would return the host name
host_name_ptr = Gets( hostent_ptr, "h_name" )
-- this would return the host name but as a sequence
pointer host_name_str
sequence host_name_seq
host_name_str = string(255) -- create an empty string
-- copy out the string
host_name_str = strcpy(host_name_str, host_name_ptr)
-- you can convert to sequence for euphoria use
host_name_seq = str2seq(host_name_str)
-- or you can use the "C" string functions to manipulate it.
-- heres how to get the pointer to a pointer
pointer h_aliases_ptr_2_ptr
h_aliases_ptr_2_ptr = peek4u(Gets( hostent_ptr, "h_aliases" ))
pointer h_addr_list_ptr_2_ptr
h_addr_list_ptr_2_ptr = peek4u(Gets( hostent_ptr, "h_addr_list" ))
|
Not Categorized, Please Help
|
|