Function match%(o:obj,text$)
text=Upper(text)
If Not Instr(text,"*") Then 'Easy! No wildcard involved.
If o.kind+":"+o.name=text Return 1
If "OBJECT:"+o.kind=text Return 1
For Local t$=EachIn o.tokens
readtoken t
If "TOKEN:"+t=text Return 1
If "TOKEN:"+token=text Return 1
Next
ElseIf text="*" 'Aha. Only wildcard!
Return 1
Else 'has a wildcard and normal text. this'll be a little harder, eh?
If Left(text,1)="*" 'can be in string
If Right(text,1)="*" 'beginning and end, both
Else
If Instr(o.kind+":"+o.name,text) Return 1
For Local t$=EachIn o.tokens
readtoken t
If Instr("TOKEN:"+t,text) Return 1
If Instr("TOKEN:"+token,text) Return 1
Next
EndIf
ElseIf Right(text,1)="*" 'has to start with string
If Instr(o.kind+":"+o.name,text)=1 Return 1
For Local t$=EachIn o.tokens
readtoken t
If Instr("TOKEN:"+t,text)=1 Return 1
If Instr("TOKEN:"+token,text)=1 Return 1
Next
ElseIf Instr(text,"#") 'the wildcard specifically indicates a missing character
If wild(o.kind+":"+o.name,text) Return 1
For Local t$=EachIn o.tokens
readtoken t
If wild("TOKEN:"+t,text) Return 1
If wild("TOKEN:"+token,text) Return 1
Next
EndIf
EndIf
Return 0
End Function
Function wild%(str$,sub$)
For Local k@=1 To Len(str)
If Not(Mid(str,k,1)=Mid(sub,k,1) Or Mid(sub,k,1)="#") Then Return 0
If k>Len(sub) Return 1
Next
Return 1
End Function
Global cmd$,arg$,arg2$
Function Parse(line$)
line=Replace(line,Chr(9)," ")
cmd="";arg=""
Local on%=0
For Local readit%=1 To Len(line)
Local char$=Mid(line,readit,1)
If char=" " And on=0
on=1
ElseIf char="/" ' comment!
Exit
ElseIf char="|"
on=2
Else
If on=0 cmd:+char
If on=1 arg:+char
If on=2 arg2:+char
EndIf
Next
cmd=Trim(cmd)
arg=Trim(arg)
arg2=Trim(arg2)
End Function
Function getraws(dir$)
Local files$[]=LoadDir(dir)
For Local x$=EachIn files$
If ExtractExt(x)="txt" Then
If FileType(dir+"\"+x)=1 raws.addlast dir+"\"+x
EndIf
If Trim(Replace(x,".",""))<>""
If FileType(dir+"\"+x)=2 getraws dir+"\"+x
EndIf
Next
End Function
Global token$,args$[64],numparams@
Function ReadToken(text$)
numparams=0
args[0]=""
CleanString text
text=Replace(text,"[","")
text=Replace(text,"]","")
Local onparam@=0
For Local p@@=1 To Len(text)
Local char$=Mid(text,p,1)
If char=":"
onparam:+1
If onparam<64 args[onparam]=""
ElseIf onparam<64
args[onparam]:+char
EndIf
Next
token=args[0]
numparams=onparam
End Function
Function CleanParams()
CleanString token
For Local x@=0 To numparams
CleanString args
Next
End Function
Function CleanString(text$ Var)
text=Trim(Replace(text,Chr(9)," "))
If Left(text,1)="'" And Right(text,1)="'" text=Mid(text,1,Len(text)-2)
End Function
Global tokens:TList=CreateList(),numtokens@
Function GrabTokens(text$)
numtokens=0
ClearList tokens
CleanString text
Local ontoken@=0
Local started@=0
Local grabbed$=""
For Local p@@=1 To Len(text)
Local char$=Mid(text,p,1)
If char="]"
tokens.addlast grabbed
ontoken:+1
ElseIf char<>"["
grabbed:+char
EndIf
Next
numtokens=ontoken+1
End Function
Function uarg$(index@)
Return Upper(args[index])
End Function
Function LeftIs@(str$,sub$)
If Len(sub)>Len(str) Return 0
If Instr(str,sub)=0 Return 1
Return 0
End Function