;This is changed only for testing reasons
If $CmdLine[0] = 0 Then $CmdLineRaw = '/File: "C:\File.txt" /Line: "Some_Line"'
_CmdLineSetEvent("File", "_Show_CmdLine_Proc", "Call #1")
_CmdLineSetEvent("Line", "_Show_CmdLine_Proc", "Call #2")
;Event function
Func _Show_CmdLine_Proc($sArgument, $sParams)
Return MsgBox(64, $sParams, "Command Line: " & $sArgument)
EndFunc
; #FUNCTION# ====================================================================================================
; Name...........: _CmdLineSetEvent
; Description....: Sets an event for passed command line parameters
; Syntax.........: _CmdLineSetEvent($sArguments, $sFuncName, $sParams="")
; Parameters.....: $sArguments - The argument that will be checked and passed to the event function.
; $sFuncName - Event function to call when command line is recieved.
; $sParams - [Optional] Additional parameters to pass to the event function.
;
; Return values..: Success - Executes the $sFuncName function and returns it's value.
; Failure - Returns 0 and sets @error as following:
; 1 - Unable to extract the command line argument.
; 2 - Error to call the $sFuncName function.
; Author.........: G.Sandler (a.k.a CreatoR), creator-lab.ucoz.ru, autoit-script.ru
; Modified.......:
; Remarks........:
; Related........:
; Link...........:
; Example........:
; ;This is changed only for testing reasons
; If $CmdLine[0] = 0 Then $CmdLineRaw = '/File "C:\File.txt" /Line "Some_Line"'
; _CmdLineSetEvent("File", "_Show_CmdLine_Proc", "Call #1")
; _CmdLineSetEvent("Line", "_Show_CmdLine_Proc", "Call #2")
;
; Func _Show_CmdLine_Proc($sArgument, $sParams)
; Return MsgBox(64, $sParams, "Command Line: " & $sArgument)
; EndFunc
; ===============================================================================================================
Func _CmdLineSetEvent($sArguments, $sFuncName, $sParams="")
Local $sRegExp, $sArgs, $sRet
Local $iStripQuotes = 1, $sPar = "-/", $sVal = "=:"
$sPar = "[" & StringRegExpReplace($sPar, "([-^\\])", "\\\1") & "]"
$sVal = "[" & StringRegExpReplace($sVal, "([-^\\])", "\\\1") & " ]"
$sArguments = "\Q" & $sArguments & "\E"
$sRegExp = '(?i)^(?:|.*?\s)'&$sPar&$sArguments&$sVal&'+(?:$|'&$sPar&'|((?:"[^"]*"|[^"])+?)(?:$|\s'&$sPar&'\w)).*'
$sArgs = StringRegExpReplace($CmdLineRaw, $sRegExp, '\1')
If @extended = 0 Or $sArgs = "" Then Return SetError(1, 0, 0)
If $iStripQuotes Then $sArgs = StringRegExpReplace($sArgs, '\A"+|"+\z', '')
$sRet = Call($sFuncName, $sArgs, $sParams)
If @error Then $sRet = Call($sFuncName, $sArgs)
If @error Then Return SetError(2, 0, 0)
Return $sRet
EndFunc