some small stuff for chopping up command line parameters etc. nothing special for the experts but it might save you some typing
Code: Select all
Procedure x_parsenext()
Global x_parseflags, x_parsed.s, x_parse.s, x_eol, x_retval, x_parsesearch.s
;
; *** get next section, see x_parse() and x_parsestring()
;
If x_parseflags & %010 = 0 ; trim
x_parse = Trim(x_parse)
EndIf
;
If Len(x_parse) = 0 ; empty string
x_retval = #False
x_eol = #True
x_parsed = ""
x_parse = ""
Else
;
If parseflags & %001 <> 0 ; case doesn't matter
p = FindString(UCase(x_parse.s),UCase(x_parsesearch.s),1)
Else ; case matters
p = FindString(x_parse.s,x_parsesearch.s,1)
EndIf
;
If p = 0 ; didn't find the search string
x_parsed = x_parse
x_parse = ""
x_eol = #True
If x_parseflags & %100 = 0 ; eol is considered a match
x_retval = #True
Else
x_retval = #False
EndIf
Else ; x_retval
x_parsed = Left(x_parse,p-1)
x_parse = Mid(x_parse,p+Len(x_parsesearch),Len(x_parse))
x_retval = #True
If Len(x_parse) = 0 ; the match just came before the eol
x_eol = #True
Else
x_eol = #False
EndIf
EndIf
;
If x_parseflags & %010 = 0
x_parse = Trim(x_parse)
x_parsed = Trim(x_parsed)
EndIf
EndIf
;
ProcedureReturn x_retval
EndProcedure
Procedure x_parsestring(search.s)
Global x_parsesearch.s
;
x_parsesearch.s = search
ProcedureReturn x_parsenext()
EndProcedure
Procedure x_parse(string.s,search.s,flags)
Global x_parseflags, x_parsed.s, x_parse.s, x_parsesearch.s
;
; *** parse a string (retrieve parameters etc.)
;
; in: string.s - string to parse
; search.s - string or seperator to find
; flags = 0 - trim and slice
; flags = %001 (1) - no case check
; flags = %010 (2) - don't trim
; flags = %100 (3) - when NOT set eol is considered a matching search
; retval: 0 (#False) - not found
; 1 (#True) - found
; out: x_parsed.s - part of string BEFORE the x_retval searchstring
; x_parse.s - part of string AFTER the x_retval searchstring (can be reparsed)
; x_eol = 1 (#True) - flag to indicate end of line was reached
; x_retval = 1 (#true) - as retval
;
x_parse = string
x_parseflags = flags
x_parsesearch = search
x_parsed = ""
;
ProcedureReturn x_parsenext()
;
EndProcedure

