Recent Posts

Pages: 1 2 3 4 5 6 7 8 9 10
1
OxygenBasic / Re: Trim function will GPF if given string is a null string
« Last post by Brian Alvarez on November 16, 2018, 10:13:17 PM »
These are the ones i made, support for ANY switch and trimming words:

Code: [Select]
// returns a trimed string
FUNCTION LTRIM(string src, long a = 0, string ch = " ") as string

    byte srcchar at strptr(src)
    byte trichar at strptr(ch)
    long p1 = 1
    long index   
    long cha   
       
    if a then
        for index = 1 to len(src)       
            for cha = 1 to len(ch)       
                if srcchar[index] = trichar[cha] then
                    goto checknextchar                     
                end if
            next
            p1 = index
            exit for
            checknextchar:
        next
        return mid(src, p1)
    else       
        for index = 1 to len(src)
            for cha = 1 to len(ch)       
                if srcchar[index+cha-1] <> trichar[cha] then
                    goto nomorematches
                end if               
            next
            p1 += len(ch)             
        next
        nomorematches:       
        return mid(src, p1)
    end if
   
END FUNCTION


// returns a trimed string   
FUNCTION RTRIM(string src, long a = 0, string ch = " ") as string

    byte srcchar at strptr(src)
    byte trichar at strptr(ch)
    long p1 = len(src)
    long index   
    long cha   
       
    if a then
        for index = len(src) TO 1 step -1       
            for cha = 1 to len(ch)       
                if srcchar[index] = trichar[cha] then
                    goto checknextchar                     
                end if
            next
            p1 = index
            exit for
            checknextchar:
        next
        return mid(src, 1, p1)
    else       
        for index = len(src)-len(ch) TO 1 step -1
            for cha = 1 to len(ch)       
                if srcchar[index+cha-1] <> trichar[cha] then
                    goto nomorematches
                end if               
            next
            p1 = index-1             
        next
        nomorematches:       
        return mid(src, 1, p1)
    end if
   
END FUNCTION

// returns a trimed string
FUNCTION TRIM(string inp, long a = 0, string chrs = " ") as string
    RETURN RTRIM(LTRIM(inp, a, chrs), a, chrs)     
END FUNCTION

2
OxygenBasic / Re: Trim function will GPF if given string is a null string
« Last post by Chris Chancellor on November 16, 2018, 05:35:26 PM »
Thanxx a lot Charles

i did a lot of tests and the new Trim function will be very useful
you are a meastro
3
OxygenBasic / Re: Trim function will GPF if given string is a null string
« Last post by Charles Pegge on November 16, 2018, 06:41:47 AM »
Hi Chris,

It works okay on the new system.

But try this trim function. It is quite efficient, and you can derive other useful string functions from it.

Code: [Select]
$filename "c.exe"
'uses rtl64

function trim(string s) as string
=================================
int i,j
int ls=len s
if ls=0 then return ""
byte bb at strptr(s)
indexbase 1
for i=1 to ls
   if bb[i]>32 then exit for
next
if i>ls then return ""
for j=ls to 1 step -1
   if bb[j]>32 then exit for
next
return mid(s,i,j-i+1)
end function

string s,t
t=trim(s)
print ">" t "<"
s=""
t=trim(s)
print ">" t "<"
s=" "
t=trim(s)
print ">" t "<"
s="  ABCDEF   "
t=trim(s)
print ">" t "<"
4
OxygenBasic / Trim function will GPF if given string is a null string
« Last post by Chris Chancellor on November 16, 2018, 05:41:44 AM »
Hello Charles

previosly you suggested that the PB Trim function can be replaced
by a macro as below

Code: [Select]
' Trim function
 def Trim ltrim(rtrim(%1))


but i tested this code with a null string, the program just GPF
Code: [Select]
' TestGPF.o2bas

$ filename "TestGPF.exe"
uses rtl64

' Trim function
 def Trim ltrim(rtrim(%1))


' This will GPF
string  tty = ""
string  tgy
tgy =  Trim(tty)    ' this will GPF

print tgy

it means that its string argument cannot be a blank string ""


and if i use the following code it will not GPF
Code: [Select]
' TestGPF.o2bas

$ filename "TestGPF.exe"
uses rtl64

' Trim function
 def Trim ltrim(rtrim(%1))



' This will not GPF
string  tty = " you are most welcome           "
string  tgy
tgy =  Trim(tty)   
print tgy

so we need to protect this macro from GPF by blocking any blank argument
from accessing Trim()

how to do this ?  how to write this macro ?

5
OxygenBasic / Re: Equivalent of PB MAK function
« Last post by Chris Chancellor on November 16, 2018, 05:34:00 AM »
Thanxx a lot Charles

i will test it out against PB to see if they work out

6
OxygenBasic / Re: Equivalent of PB MAK function
« Last post by Charles Pegge on November 16, 2018, 04:58:13 AM »
Hi Chris,

Something like this:

Code: [Select]
function makword(byte lower,upper) as word
  return upper*0x100+lower
end function

function makdword(word lower,upper) as dword
  return upper*0x10000+lower
end function

'masking tests
int a,b
a=0x30101
b=0x30202
print hex makword a,b '201
print hex makdword a,b '2020101

7
OxygenBasic / Re: Floating point issue
« Last post by Charles Pegge on November 16, 2018, 04:19:19 AM »
Thanks, Mike.

I wonder what other variations there are in the C99 / C++ standard.
8
OxygenBasic / Re: Floating point issue
« Last post by Mike Lobanovsky on November 16, 2018, 03:45:57 AM »
...............

  sprintf(odata,"%lli", quad 9/5)

...............

Charles,

IIRC %lli is an originally Linuxoid formatter not recognized by MS Windows native msvcrt.dll's formatted IO functions. You are supposed to use %I64 instead. %lli may be used in later MS VC++ builds but the latter links against MS VC++ -specific libraries rather than msvcrt.dll.

If nonetheless you can still use %lli in OxygenBasic, it means you're substituting it with its Windows-legit counterpart somewhere in the O2 internals. In other words, IMHO you're making O2 non-conformant with your own hands... Or am I missing something?
9
OxygenBasic / Equivalent of PB MAK function
« Last post by Chris Chancellor on November 15, 2018, 04:34:40 PM »
Hello Charles

what is the equivalent of  PB  MAK function ? 

see http://www.manmrk.net/tutorials/basic/PowerBASIC/PBWINH/MAK_function.html

from PB Manual it is
Quote
MAK function
Purpose
 Create an integral class value of a specified data type.
 
Syntax
 resultvar = MAK(datatype, loworderval, highorderval)
 
Remarks
 Create an integral class value of a specified data type (WORD, DWORD, PTR, INTEGER, LONG, QUAD) from a low-order and a high-order part.

The complements to this function are the HI and LO  functions, which may be used to split a single 32-bit value into two 16-bit components.
 
Restrictions
 MAK supercedes the MAKWRD, MAKDWD, and MAKPTR functions. Those functions are no longer supported, so update your code to use the new syntax.
 
See also
 HI, LO
 
Example
 dwResult = MAK(DWORD, x??, y??)
 

 




10
OxygenBasic / Re: Floating point issue
« Last post by Charles Pegge on November 15, 2018, 09:17:59 AM »
mscvrt.inc is included in corewin

sprintf requires a char buffer, a formatting string, and 0 or more variadic data.

http://www.cplusplus.com/reference/cstdio/printf/

This is a very simple format example:

Code: [Select]
'msvcrt val/str/format$ equivalent
'nb: msvcrt downgrades extended precision to double.

  uses msvcrt 'or corewin
  char odata[64]
  sprintf(odata,"%g", double 1/3)
  print odata '0.333333
  sprintf(odata,"%lli", quad 9/5)
  print odata '2
Pages: 1 2 3 4 5 6 7 8 9 10