Code:
;----------------------------------------------------------------------
IgnoreCase var bit
Xs var byte
Ys var byte
Zs var byte
Js var byte
Ws var byte
Cmd var byte
Length1 var word
Length2 var word
MaxSearchLen var byte
Str1ArrayLength CON 30
Str2ArrayLength con 30
MaxCompareLength var byte
Str1 var byte[Str1ArrayLength]
Str2 var byte[Str2ArrayLength]
;---------------------------------------------------------------------------
; Zero out the strings
arraywrite Str1,[rep 0\Str1ArrayLength]
arraywrite Str2,[rep 0\Str2ArrayLength]
;--------------------------------------------------
; Fill input arrays with some test stuff
ARRAYWRITE Str1,["0123456789ABCDEF"]
arraywrite Str2,["345"]
;-------------------------------------------------
'LeftString: ; Str2 contains the leftmost chars of Str1
; Ys = Number of Chars to separate off from Str1
YS = 6 ; for testing only
If Ys != 0 then
For Js = 0 to YS-1
Str2[Js] = Str1[Js]
next Js
Str2[Js] = 0 ; make certain we always end with a nul
endif
return
;----------------------------------------------------
;----------------------------------------------------
MidString: ; Str2 contains a string of Ys chars derived from Str1 starting at position Zs (zero based)
ys = 2 :Zs = 4 ; for testing only
If Ys !=0 then
For Xs = Zs to ((Zs + Ys)-1)
Str2[Xs-Zs] = Str1[Xs]
next Xs
Str2[xs] = 0 ; terminate with a nul
Endif
return
;-------------------------------------------------------------------------------------
RightString: ; Str2 contains a string consisting of the right-most chars (number defined by Ys) of Str1
Ys = 4 ; for testing only
Js = Ys - 1
for xs = Str1ArrayLength to 0 step - 1
If Str1[xs] != 0 then
Str2 [Js] = Str1[Xs]
if Js = 0 then DoneRS
Js = Js-1
endif
next xs
DoneRS:
; return
;---------------------------------------------------------------------------------------
LenSTring: ; Ys contains the length of STR1
Js= 0
While Str1[JS] != 0
JS = Js + 1
wend
if Js > 1 then
Ys = Js - 2
else
YS = 0
endif
; return
;----------------------------------------------------------------------------------------
InString: ; Ws contains the position in STR1 where the match with STR2 started
; if there is no match, Ws contains 255
; if Ignore Case is set to '1', it will, of course, ignore the case.
MaxCompareLength = Str1ArrayLength Min Str2ArrayLength
for Xs = 0 to Str1ArrayLength
If IgnoreCase then
Str2[0] = Str2[0] & %11011111
Str1[Xs] = Str1[XS] & %11011111
endif
If Str2[0] = Str1[Xs] then ; Found a match on 1st char of Str2
Ws = Xs
Js = 1
for Ys = Xs + 1 to MaxCompareLength
if Str2[Js] = 0 then FoundMatch ; hit the end of Str2
If IgnoreCase then
Str2[Js] = Str2[JS] & %11011111
Str1[Ys] = Str1[Ys] & %11011111
endif
if Str2[Js] != Str1[Ys] then NoMatch
Js = Js + 1
next Ys
goto FoundMatch
endif
next Xs
NoMatch:
WS = 255
return
FoundMatch:
return
;-----------------------------------------------------------------------------------
CommandParser:
; Fast searcher! Case sensitive. Closely based on info provided by Darrel Taylor.
; Searches through Str1. If it finds the strings listed in the quotes, it returns which one it found.
; the max length of STR1 that will be searched is in MaxSearchLen
Cmd = 255 ; In case of no match
MaxSearchLen = 20
Parse01: Cmd=01 : ARRAYREAD Str1,MaxSearchLen,Parse02,[WAIT("Command1")] : GOTO Foundit
Parse02: Cmd=02 : ARRAYREAD Str1,MaxSearchLen,Parse03,[WAIT("Age")] : GOTO Foundit
Parse03: Cmd=03 : ARRAYREAD Str1,MaxSearchLen,Parse04,[WAIT("Weight")] : GOTO Foundit
Parse04: Cmd=04 : ARRAYREAD Str1,MaxSearchLen,Parse05,[WAIT("Address")] : GOTO Foundit
Parse05: Cmd=05 : ARRAYREAD Str1,MaxSearchLen,Parse06,[WAIT("Command5")] : GOTO Foundit
Parse06: Cmd=06 : ARRAYREAD Str1,MaxSearchLen,Parse07,[WAIT("Command6")] : GOTO Foundit
Parse07: Cmd=07 : ARRAYREAD Str1,MaxSearchLen,Parse08,[WAIT("Command7")] : GOTO Foundit
Parse08: Cmd=08 : ARRAYREAD Str1,MaxSearchLen,Parse09,[WAIT("Command8")] : GOTO Foundit
Parse09: Cmd=09 : ARRAYREAD Str1,MaxSearchLen,Parse10,[WAIT("Command9")] : GOTO Foundit
Parse10: Cmd=10 : ARRAYREAD Str1,MaxSearchLen,Parse11,[WAIT("Command10")] : GOTO Foundit
Parse11: Cmd=11 : ARRAYREAD Str1,MaxSearchLen,Parse12,[WAIT("Command11")] : GOTO Foundit
Parse12: Cmd=12 : ARRAYREAD Str1,MaxSearchLen,Parse13,[WAIT("Command12")] : GOTO Foundit
Parse13: Cmd=13 : ARRAYREAD Str1,MaxSearchLen,Parse14,[WAIT("Command13")] : GOTO Foundit
Parse14: Cmd=14 : ARRAYREAD Str1,MaxSearchLen,Parse15,[WAIT("Command14")] : GOTO Foundit
Parse15: Cmd=15 : ARRAYREAD Str1,MaxSearchLen,Foundit,[WAIT("Command15")] : GOTO Foundit
Foundit:
return
;-------------------------------------------------------------------------------------------
Bookmarks