Oxygen Basic
Programming => Problems & Solutions => Topic started by: Emil_halim on March 31, 2013, 11:47:40 AM
-
Hi all,
I have a function from BCX that i want to convert to work with Oxygen
here it is
char *AppExePath (void)
{
static char strtmp[ 2048 ];
register int i;
i=GetModuleFileName(GetModuleHandle(0),strtmp, 2048);
while(i && strtmp[i] != 0x5C)
i--;
strtmp[i+1] = 0;
return strtmp;
}
-
i was think that , Oxygen will understand c function , so what is the minimal changes to make the previous
function to work with Oxygen basic?
-
Close. (Stand-alone example)
extern lib kernel32.dll
! GetModuleHandle alias "GetModuleHandleA"
! GetModuleFileName alias "GetModuleFileNameA"
end extern
sys x 'workaround for strange glitch
char* AppExePath(void)
{
static char strtmp[2048]
sys i
i=GetModuleFileName(GetModuleHandle(0), strptr strtmp, 2048)
while asc(strtmp,i) != 0x5c
i--
wend
mid strtmp,i+1,chr 0
return strtmp
}
print AppExePath
-
Closer:
extern lib kernel32.dll
! GetModuleHandle alias "GetModuleHandleA"
! GetModuleFileName alias "GetModuleFileNameA"
end extern
sys x 'workaround for strange glitch
char* AppExePath(void)
{
indexbase 1
static byte b[512]
sys i=GetModuleFileName(GetModuleHandle(0), @b, 512)
while b[ i ] != 0x5c
i--
wend
b[ i+1 ]=0
= @b 'low level
return
}
print AppExePath
I have corrected the glitch, so I will post an update to Oxygen.
-
very nice work Charles,
this example works very well , but when i put this function "AppExePath" in my code , it compiled okay but did not run.
when comment it , every thing is okay , that drive my crazy >:(
any help please
-
to be more specific
this work okay
print AppExePath()
string cmd,File,AppPath
sys ii
cmd = GetCommandLine()
ii=instr(cmd," ")
if ii
ii++
File=mid(cmd,ii,len(cmd)-ii+1)
end if
but this ont
string cmd,File,AppPath
sys ii
cmd = GetCommandLine()
ii=instr(cmd," ")
if ii
ii++
File=mid(cmd,ii,len(cmd)-ii+1)
end if
print AppExePath()
-
after many tries i successefly it worked.
there was two things
first , when using this , it did not work
extern lib kernel32.dll
! GetModuleHandle alias "GetModuleHandleA"
! GetModuleFileName alias "GetModuleFileNameA"
end extern
but this work
! GetCommandLine lib "kernel32.dll" alias "GetCommandLineA" () as char*
! GetModuleFileName lib "kernel32.dll" alias "GetModuleFileNameA" (sys a,char* b,sys c) as int
second ,this not work
sys i=GetModuleFileName(GetModuleHandle(0), @b, 512)
but this works
push 512 : addr eax , b : push eax : GetModuleHandle(0) : push eax
call GetModuleFileName
mov i , eax
i think @b did not return the correct address in long code , but do wrok with shourt code , strange things
is'nt it?
Charles is there a BUG
-
Hi Emil,
Try the latest update. Should be clear of the declarations bug.
This works, but you will need to do some parsing work on the CmmandLine file: (stripping quote marks)
extern lib kernel32.dll
! GetCommandLine alias "GetCommandLineA"
! GetModuleFileName alias "GetModuleFileNameA"
! GetModuleHandle alias "GetModuleHandleA"
end extern
'includepath "$\inc\"
'include "minwin.inc"
char* AppExePath()
{
static byte b[256]
sys i
a=GetModuleHandle(0)
i=GetModuleFileName(a, @b, 256)
while b[ i ] != 0x5c
i--
wend
b[ i+1 ]=0
= @b
return
}
print AppExePath
string cmd,File,AppPath
sys ii
cmd = cast zstring GetCommandLine()
ii=instr(cmd," ")
if ii
ii++
File=mid(cmd,ii,len(cmd)-ii+1)
end if
print file
-
Hi Charles,
no luck , after updating has the same error.
-
okay , it works now , do not ask me why , because i really do not know.
Does Oxygen unstable ?
-
Sometimes, I think the OS picks up the wrong DLL.
And don't forget, this is alpha software. There are more permutations than many languages have. Error trapping is not very tight at this stage of its development, so you have to code defensively, and test your program as you grow it.
The other extreme would be to have a very strict language with only one coding style. IronJawBasic ? :)
Charles
-
IronJawBasic
There is a Blunt-Axe Basic to ASM translator Steve wrote so I think that base is covered. Please continue on with the O2 destiny as you see it.
-
Okay , i was playing with your getword function that split the line code into tokens.
so i start a new one , getline , based on getword , but it does not act like i want
here it is ,
function getline(s as string, b as sys) as string
'================================================
sys c,bb
bb=b
do
c=asc(s,b)
if c=0 then exit do
if c=13 and asc(s,b+1)=10 then exit do
b+=1
end do
if b>bb then return mid(s,bb,b-bb)
end function
sys i = 1
string lin
do
lin = getline(src,i)
if not lin then exit do
print lin
end do
so what code be wrong here?
-
Emil,
You just need to skip the crlf
function getline(s as string, b as sys) as string
'
sys c,bb
bb=b
do
c=asc(s,b)
if c=0 then exit do
if c=13 and asc(s,b+1)=10 then exit do
b+=1
end do
if b>bb
function=mid(s,bb,b-bb)
b+=2
end if
end function
string src=
"1 one
2 two
3 three"
sys i = 1
string lin
do
lin = getline(src,i)
if not lin then exit do
print lin
end do
-
Hi Charles ,
when getline function find a blank line the loop end ignoring the rest of string , so i changed it like this
function getline(s as string, b as sys) as string
=================================================
sys c,bb
bb=b
do
c=asc(s,b)
if c=0 then exit do
if c=13 then b+=1 : exit do
b+=1
end do
if asc(s,b)=10 then b+=1
return mid(s,bb,b-bb)
end function
so it works well but when using it with my next function the program end in the middel and execution did
not reach to end end of function , any help please?
void processAllLayer(string file)
{
sys i = 1
string src , lin
for i = 1 to LayerNo
print "processing... " file chr(10) "by" chr(10) LayName[i]
src = getfile(file)
do
lin = getline(src,i)
if not lin then exit do
print lin
end do
'<------------------------------- program end here????????
if ActiveLayer[i] then
addr eax , src
push eax
call procProcess[i]
push eax : push eax
putfile file, cast bstring eax
call freememory
end if
next
}
-
Hi Emil,
your returned lines will always include the terminators, therefore you will never get an empty line to terminate with. This is why I captured the line string before skipping the termination chars.
-
yes Charles ,
my source code may contain an empty line and that does not mean the end of string (source code) , so i need
an other way to terminate the loop.
-
I am thinking in c language , char* is a pointer to the buffer of returned string and if is null that will end the loop ,
what is your opinion ?
-
You can record the ascii value of the terminating character, as a global state variable possibly, and test for zero to exit the line-reading loop.
I use global state variables in the compiler to hold parsing data like word-position word-ascii, next- word-position, word-length.