1. comparison troubles...
		
		
Hiyas,
 I need to compare two atoms which one is a value
from a return C_POINTER from a DLL routine, and the
other is an atom has a allocate_string value.
I need to do something like:
atom a1, a2
a1=c_func(Get_Description,{NULL}) -- Ex: a1 = "Stop"
a2=allocate_string("Text")        -- Ex: a2 = "Stop"
If a1=a2 then stop=1 end if
I know that both atoms hold the address loaction of the text.
Is there anyway to actually compare the text within the atoms?
Any help will be much appreiciated...
- Todd Riggins
		
	 
	
		
		2. Re: comparison troubles...
		
		
I meant to type in the last email:
a2=allocate_string("Stop")        -- Ex: a2 = "Stop"
Sorry about that... and for this wasted email addition to your
hardrive... ;)
-- Todd Riggins
		
	 
	
		
		3. Re: comparison troubles...
		
			- Posted by Brian Broker <bkb at CNW.COM>
			Oct 04, 1999
- 
				Last edited Oct 05, 1999			
On Mon, 4 Oct 1999 19:02:00 -0500, Todd Riggins <triggins at AIRMAIL.NET>
wrote:
>Hiyas,
>
> I need to compare two atoms which one is a value
>from a return C_POINTER from a DLL routine, and the
>other is an atom has a allocate_string value.
>
>I need to do something like:
>
>atom a1, a2
>
>a1=c_func(Get_Description,{NULL}) -- Ex: a1 = "Stop"
>a2=allocate_string("Text")        -- Ex: a2 = "Stop"
>
>If a1=a2 then stop=1 end if
>
>I know that both atoms hold the address loaction of the text.
>Is there anyway to actually compare the text within the atoms?
>
>Any help will be much appreiciated...
>
>- Todd Riggins
Since what you have are pointers to memory locations, you need to 'peek' at
the contents and compare them.  Strings should be null terminated so just
peek until you hit a 0 in memory.
Looking at what 'allocate_string' actually does should help:
global function allocate_string(sequence s)
-- create a C-style null-terminated string in memory
    atom mem
    mem = allocate(length(s) + 1)
    if mem then
 poke(mem, s & 0)
    end if
    return mem
end function
There may be an easier way to do it with a library that I don't know about
but I would probably just code up my own routines anyway...
		
	 
	
		
		4. Re: comparison troubles...
		
			- Posted by Pete Eberlein <xseal at HARBORSIDE.COM>
			Oct 04, 1999
- 
				Last edited Oct 05, 1999			
On Mon, 4 Oct 1999 19:02:00 -0500, Todd Riggins <triggins at AIRMAIL.NET>
wrote:
>Hiyas,
>
> I need to compare two atoms which one is a value
>from a return C_POINTER from a DLL routine, and the
>other is an atom has a allocate_string value.
>
>I need to do something like:
>
>atom a1, a2
>
>a1=c_func(Get_Description,{NULL}) -- Ex: a1 = "Stop"
>a2=allocate_string("Text")        -- Ex: a2 = "Stop"
>
>If a1=a2 then stop=1 end if
>
>I know that both atoms hold the address loaction of the text.
>Is there anyway to actually compare the text within the atoms?
>
>Any help will be much appreiciated...
>
>- Todd Riggins
Hi Todd,
Brian Broker gave a insight to how this is done, and peek is the right way
to do it.  But let me expound a little:
If you know for absolutely certain that the lengths of the strings pointed
to are both 4, then you can do something like:
if equal(peek({a1,4}), peek({a2,4})) then stop=1 end if
But if you have no way of knowing the length of the strings, you need a
peek_string function which looks for the null terminating character:
function peek_string(atom astr)   -- coded off the cuff
   integer len                    -- may contain syntax errors  len = 0
   while peek(astr + len) do len += 1 end while
   return peek({astr, len})
end function
Then,
if equal(peek_string(a1), peek_string(a2)) then stop=1 end if
Should do what you want.
Regards,
 _______  ______  _______  ______
[    _  \[    _ ][ _   _ ][    _ ]
[/| [_] |[/| [_\][/ | | \][/| [_\]
  |  ___/  |  _]    | |     |  _]
[\| [/]  [\| [_/] [\| |/] [\| [_/]
[_____]  [______] [_____] [______]
xseal at harborside.com  ICQ:13466657
http://www.harborside.com/home/x/xseal/euphoria/
   len = 0
   while peek(astr + len) do len += 1 end while
   return peek({astr, len})
end function
Then,
if equal(peek_string(a1), peek_string(a2)) then stop=1 end if
Should do what you want.
Regards,
 _______  ______  _______  ______
[    _  \[    _ ][ _   _ ][    _ ]
[/| [_] |[/| [_\][/ | | \][/| [_\]
  |  ___/  |  _]    | |     |  _]
[\| [/]  [\| [_/] [\| |/] [\| [_/]
[_____]  [______] [_____] [______]
xseal at harborside.com  ICQ:13466657
http://www.harborside.com/home/x/xseal/euphoria/
		
	 
	
		
		5. Re: comparison troubles...
		
		
Thanks for helping me Brian and Pete.
I keep forgetting about the peek routine...
Pete, your function worked perfectly! ;)
-- Todd Riggins
		
	 
	
		
		6. Re: comparison troubles...
		
			- Posted by Lewis Townsend <keroltarr at HOTMAIL.COM>
			Oct 12, 1999
- 
				Last edited Oct 13, 1999			
Hello Todd,
>Hiyas,
>
>  I need to compare two atoms which one is a value
>from a return C_POINTER from a DLL routine, and the
>other is an atom has a allocate_string value.
>
>I need to do something like:
>
>atom a1, a2
>
>a1=c_func(Get_Description,{NULL}) -- Ex: a1 = "Stop"
>a2=allocate_string("Text")        -- Ex: a2 = "Stop"
>
>If a1=a2 then stop=1 end if
>
>I know that both atoms hold the address loaction of the text.
>Is there anyway to actually compare the text within the atoms?
>
>Any help will be much appreiciated...
>
>- Todd Riggins
Well, actually the text isn't IN the atoms. "a1" is kind
of like a routineID for the C function that will return
the string "Stop" to another variable. "a2" is the location
in memory that the letter 'S' of the word stop is stored in
memory. I guess you knew that but anyway, here's what I
would do:
-- START OF UNTESTED CODE --
atom a1, a2, stop
sequence text, aa1, aa2
a1 = c_func (Get_Description, {NULL})
text = "Stop"
a2 = allocate_string (text)
aa1 = call_func (a1, {}) -- I'm not sure exactly how to use
                         -- call_func myself but I think this
                         -- is right.
aa2 = ""
for i = 0 to length (text) -1 do
  aa2 &= peek (a2 +i)
end for
if equal (aa1, aa2) then
  stop = 1
end if
-- END OF UNTESTED CODE --
I hope this helps,
Lewis Townsend
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com