07-19-2022, 01:14 AM
LibC stuff:
Code: (Select All)
proc SYSTEM_BUS_T.k_min(v1 as SYSTEM_TYPE,v2 as SYSTEM_TYPE) as SYSTEM_TYPE
if (v1<v2) then return v1
return v2
end proc
proc SYSTEM_BUS_T.k_max(v1 as SYSTEM_TYPE,v2 as SYSTEM_TYPE) as SYSTEM_TYPE
if (v1>v2) then return v1
return v2
end proc
proc SYSTEM_BUS_T.k_strlen(s as ubyte ptr) as SYSTEM_TYPE
dim retval as SYSTEM_TYPE
retval=0
while s[retval]<>0
retval+=1
wend
return retval
end proc
proc SYSTEM_BUS_T.k_strtrim(s as ubyte ptr) as ubyte ptr
dim retval as ubyte ptr=@(Result(0))
retval[0]=0
dim i as integer=0
dim j as integer=0
while (s[i]<>0 and s[i]=32 and s[i]<>9 and s[i]<>10 and s[i]<>13)
i+=1
wend
while(s[i]<>0)
retval[j]=s[i]
i+=1
j+=1
wend
retval[j]=0
k_strrev(retval)
i=0
j=0
while (retval[i]<>0 and retval[i]=32 and retval[i]=9 and retval[i]=10 and retval[i]=13)
i+=1
wend
while(retval[i]<>0)
retval[j]=retval[i]
i+=1
j+=1
wend
retval[j]=0
k_strrev(retval)
return retval
end proc
proc SYSTEM_BUS_T.k_strtoupper(s as ubyte ptr) as ubyte ptr
dim i as SYSTEM_TYPE
dim dst as ubyte ptr=@(Result(0))
i=0
while s[i]<>0 and i<1022
if (s[i]>=97 and s[i]<=122) then
dst[i]=s[i]-32
else
dst[i]=s[i]
end if
i+=1
wend
dst[i]=0
return dst
end proc
proc SYSTEM_BUS_T.k_strtolower(s as ubyte ptr) as ubyte ptr
dim i as SYSTEM_TYPE
dim dst as ubyte ptr=@(Result(0))
i=0
while s[i]<>0 and i<1022
if (s[i]>=65 and s[i]<=90) then
dst[i]=s[i]+32
else
dst[i]=s[i]
end if
i+=1
wend
dst[i]=0
return dst
end proc
proc SYSTEM_BUS_T.k_substring(s as ubyte ptr,index as SYSTEM_TYPE, count as SYSTEM_TYPE) as ubyte ptr
dim i as SYSTEM_TYPE
dim dst as ubyte ptr=@(Result(0))
dim l as SYSTEM_TYPE=k_strlen(s)
i=0
while s[i+index]<>0 and i+index<1022 and i+index<l and (i<count or count=-1)
dst[i]=s[i+index]
i+=1
wend
dst[i]=0
return dst
end proc
proc SYSTEM_BUS_T.k_strlastindexof(s as ubyte ptr,s2 as ubyte ptr) as SYSTEM_TYPE
var l1=k_strlen(s)
var l2=k_strlen(s2)
dim i as SYSTEM_TYPE
dim j as SYSTEM_TYPE
var ok=0
for i=l1-l2 to 0 step -1
if s[i]=s2[0] then
ok=1
for j=0 to l2-1
if s[i+j]<>s2[j] then
ok=0
exit for
end if
next j
if ok<>0 then return i
end if
next i
return -1
end proc
proc SYSTEM_BUS_T.k_strendswith(src as ubyte ptr,search as ubyte ptr) as SYSTEM_TYPE
if (k_strlastindexof(src,search) = k_strlen(src)-k_strlen(search)) then
return 1
else
return 0
end if
end proc