udfParseCmdLineToArray
arr udfParseCmdLineToArray (str)
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfParseCmdLineToArray (strCmdLine)
intParams = ParseData (strCmdLine)
arrParam = ArrDimension (intParams, 4)
ArrInitialize (arrParam, "")
intObject = 0
intOption = 0
For intParam = 1 To intParams
   intElem = intParam - 1
   strParam = Param%intParam%
   If 1 == StrScan (strParam, "-/", 1, @FWDSCAN)
      ; Parameter type 1=Option.
      arrParam [intElem, 0] = 1
      intOption = intOption + 1
      arrParam [intElem, 1] = intOption
      strParam = StrSub (strParam, 2, -1)
      intPos = StrScan (strParam, ":=", 1, @FWDSCAN)
      If !!intPos
         ; Name of option.
         arrParam [intElem, 2] = StrSub (strParam, 1, intPos - 1)
         ; Value of option.
         arrParam [intElem, 3] = StrSub (strParam, intPos + 1, -1)
         strParam = StrLower (arrParam [intElem, 3])
         Switch @TRUE
         Case !!ItemLocate (strParam, "1,on,true,yes,+", ",")
            arrParam [intElem, 3] = @TRUE
            Break
         Case !!ItemLocate (strParam, "0,off,false,no,-", ",")
            arrParam [intElem, 3] = @FALSE
            Break
         EndSwitch
      Else
         ; Option without specific value.
         arrParam [intElem, 2] = strParam
         ; Set value to @TRUE, that means, Option exists.
         arrParam [intElem, 3] = @TRUE
      EndIf
   Else
      ; Parameter type 0=Object.
      arrParam [intElem, 0] = 0
      intObject = intObject + 1
      arrParam [intElem, 1] = intObject
      arrParam [intElem, 3] = strParam
   EndIf
Next

Return arrParam
;..........................................................................................................................................
; This UDF "udfParseCmdLineToArray" returns a dim-2 array of (n, 4).
; Array cells are populated with parameters parsed from the given commandline string.
; One array row holds four properties for one parameter.
;..........................................................................................................................................
; arrParam [n, 0] = Type of parameter: 0=Object, 1=Option.
; arrParam [n, 1] = Ordinal number 1..n of parameter type.
; arrParam [n, 2] = Name of option, if any.
; arrParam [n, 3] = Value of parameter resp. option.
;..........................................................................................................................................
; Idea adapted from: Kevin van Haaren.
; Topic: Command line parser
; Conf:  WinBatch Script Exchange
; From:  kvanhaaren kvanhaaren@hntb.com
; Date:  Saturday, June 16, 2001 07:52 PM
;..........................................................................................................................................
; Detlev Dalitz.20040329.20090506.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


; Test.

strMsgTitle = "Demo: udfParseCmdLineToArray (strCmdLine)"

strCmdLine = `WBApp.exe TheFileIn /lower -OEM:- TheFileOut -AppFolder:"C:\Program Files\" -Loop=forever /count=221` ; 8 parameters.
arrParam = udfParseCmdLineToArray (strCmdLine)

GoSub DisplayResult

Exit

;------------------------------------------------------------------------------------------------------------------------------------------
:DisplayResult

intDims = ArrInfo (arrParam, 0) ; Number of dimensions in the array.

strMsgText = "intDims = " : intDims : @LF
For intDim = 1 To intDims
   intDim%intDim% = ArrInfo (arrParam, intDim) ; Number of elements in dimension x.
   strMsgText = strMsgText : "intDim%intDim% = " : intDim%intDim% : @LF
Next
strMsgText = strMsgText : @LF

strResult = "[No array elements]"
If intDims > 0
   If intDim1 > 0
      intDim1High = intDim1 - 1
      strResult = ""
      For intDim1 = 0 To intDim1High
         strRow = ""
         intDim2High = intDim2 - 1
         For intDim2 = 0 To intDim2High
            strRow = ItemInsert (arrParam [intDim1, intDim2], -1, strRow, @TAB)
         Next
         strResult = strResult : strRow : @LF
      Next
   EndIf
EndIf

IntControl (63, 200, 200, 800, 700) ; Sets coordinates for AskFileText, AskItemList and AskTextBox windows.
IntControl (28, 1, 0, 0, 0)         ; Selects system font used in list boxes. p1=1=fixed pitch font.
AskItemlist ("Demo: udfParseCmdLineToArray (strCmdLine)", strMsgText : strResult, @LF, @UNSORTED, @SINGLE)

Return ; from GoSub DisplayResult.
;------------------------------------------------------------------------------------------------------------------------------------------

;------------------------------------------------------------------------------------------------------------------------------------------
; Display output.
;
;   +----+------------+-----------+--------------+--------------------+
;   | A0 | B0         | B1        | B2           | B3                 |
;   +----+------------+-----------+--------------+--------------------+
;   | A0 | Param Type | Ord. Nr.  | Option Name  | Param Value        |
;   +----+------------+-----------+--------------+--------------------+
;   |  0 |     0      |     1     |              | WBApp.exe          |
;   |  1 |     0      |     2     |              | TheFileIn          |
;   |  2 |     1      |     1     | lower        | 1                  |
;   |  3 |     1      |     2     | OEM          | 0                  |
;   |  4 |     0      |     3     |              | TheFileOut         |
;   |  5 |     1      |     3     | AppFolder    | C:\Program Files\  |
;   |  6 |     1      |     4     | Loop         | forever            |
;   |  7 |     1      |     5     | count        | 221                |
;   +----+------------+-----------+--------------+--------------------+
;------------------------------------------------------------------------------------------------------------------------------------------