;-- TIME_STAMP 2019-07-17 19:28:05 Opt('MustDeclareVars', 1) ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CmdLine_Parse ; Description ...: Splits a command line into its elements. Standard separator between parts is the space. ; If this character is part of path or arguments, they must be enclosed in string delimiters. ; The first part of command line is a executable file path. The function recognise this also with spaces in it and none ; string marker encapsulation. ; Syntax ........: _CmdLine_Parse($_sLine[, $_sDelimParam = ' ']) ; Parameters ....: $_sLine - The command line to be parsed. ; $_sDelimParam - [optional] Separator between parts. Default is ' '. ; Return values .: Array, each part of command line in one entry. ; Author ........: BugFix ; =============================================================================================================================== Func _CmdLine_Parse($_sLine, $_sDelimParam=' ') Return StringSplit(StringTrimRight(__ParseRecursive($_sLine, $_sDelimParam), 1), Chr(1), 2) EndFunc ;==> _CmdLine_Parse Func __ParseRecursive($_sLine, $_sDelimParam, $_iCall=1) Local $sDelimResult = Chr(1), $sResult = '', $sTmp, $sOut Local $sDelimString = '' Local $s1st = StringMid($_sLine, 1, 1) If $s1st = "'" Or $s1st = '"' Then $sDelimString = $s1st Local $sPart, $sPattExe, $aMatch If $sDelimString <> '' Then $sPart = StringFormat('%s[^%s]+%s', $sDelimString, $sDelimString, $sDelimString) Else ; Check if executable file path has spaces in it -- only for 1st call If $_iCall = 1 Then Local $aExec[] = ['.exe','.com','.bat','.cmd','.scr'] Local $iMatch, $iPos = 1024, $sExt = '' For $i = 0 To 4 $iMatch = StringInStr($_sLine, $aExec[$i]) If $iMatch > 0 And $iMatch < $iPos Then $iPos = $iMatch $sExt = $aExec[$i] EndIf Next If $sExt = '' Then ; none executable in line, use part to first space $sPart = StringFormat('[^%s]+', $_sDelimParam) Else Local $sRes = '\.', $sChar For $i = 2 To 4 $sChar = StringMid($sExt, $i, 1) $sRes &= StringFormat('[%s%s]', StringUpper($sChar), StringLower($sChar)) Next $sPart = StringFormat('.+%s', $sRes) EndIf Else $sPart = StringFormat('[^%s]+', $_sDelimParam) EndIf EndIf $aMatch = StringRegExp($_sLine, $sPart, 1) $sResult &= $aMatch[0] & $sDelimResult $sTmp = StringTrimLeft($_sLine, StringLen($sResult)) If StringLen($sTmp) > 0 Then $_iCall += 1 $sOut = $sResult & __ParseRecursive($sTmp, $_sDelimParam, $_iCall) Else $sOut = $sResult EndIf Return $sOut EndFunc