GetOptions: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (Created by user: Instructor.) |
Instructor (talk | contribs) No edit summary |
||
(9 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{PageAuthor|Instructor}} | |||
{{User:Instructor/Headers/Template}} | |||
== | == Function Description == | ||
<highlight-nsis> | |||
<highlight-nsis> | |||
____________________________________________________________________________ | ____________________________________________________________________________ | ||
Line 17: | Line 16: | ||
Syntax: | Syntax: | ||
${GetOptions} "[Parameters | ${GetOptions} "[Parameters]" "[Option]" $var | ||
"[Parameters]" ; command line parameters | "[Parameters]" ; command line parameters | ||
; | ; | ||
"[Option]" ; option name | "[Option]" ; option name | ||
Line 28: | Line 25: | ||
Example1: | Note: | ||
Section | -Error flag if option not found | ||
${GetOptions} "/ | -First option symbol it is delimiter | ||
</highlight-nsis> | |||
<b>Example1:</b> | |||
<highlight-nsis>Section | |||
${GetOptions} "/S /T" "/T" $R0 | |||
IfErrors 0 +2 | |||
MessageBox MB_OK "Not found" IDOK +2 | |||
MessageBox MB_OK "Found" | |||
SectionEnd | SectionEnd | ||
</highlight-nsis> | |||
Example2: | <b>Example2:</b> | ||
Section | <highlight-nsis>Section | ||
${GetOptions} " | ${GetOptions} "-INSTDIR=C:\Program Files\Common Files -SILENT=yes" "-INSTDIR=" $R0 | ||
;$R0=C:\Program Files\Common Files | |||
;$R0=C:\Program Files\ | |||
SectionEnd | SectionEnd | ||
</highlight-nsis> | |||
Example3: | <b>Example3:</b> | ||
Section | <highlight-nsis>Section | ||
${GetOptions} '/SILENT=yes /INSTDIR="C:/Program Files/" /ADMIN= | ${GetOptions} '/SILENT=yes /INSTDIR="C:/Program Files/Common Files" /ADMIN=password' "/INSTDIR=" $R0 | ||
;$R0=C:/Program Files/Common Files | |||
;$R0=C:/Program Files/ | |||
SectionEnd | SectionEnd | ||
</highlight-nsis> | |||
Example4: | <b>Example4:</b> | ||
Section | <highlight-nsis>Section | ||
${GetOptions} `-SILENT=yes -INSTDIR='"C:/Program Files/"' -ADMIN= | ${GetOptions} `-SILENT=yes -INSTDIR='"C:/Program Files/Common Files"' -ADMIN=password` "-INSTDIR=" $R0 | ||
;$R0="C:/Program Files/Common Files" | |||
;$R0="C:/Program Files/" | SectionEnd | ||
SectionEnd | </highlight-nsis> | ||
== Function Code == | |||
<highlight-nsis> | |||
Function GetOptions | Function GetOptions | ||
!define GetOptions `!insertmacro GetOptionsCall` | !define GetOptions `!insertmacro GetOptionsCall` | ||
!macro GetOptionsCall _PARAMETERS | !macro GetOptionsCall _PARAMETERS _OPTION _RESULT | ||
Push `${_PARAMETERS}` | Push `${_PARAMETERS}` | ||
Push `${_OPTION}` | Push `${_OPTION}` | ||
Call GetOptions | Call GetOptions | ||
Line 69: | Line 76: | ||
!macroend | !macroend | ||
Exch $1 | Exch $1 | ||
Exch | Exch | ||
Exch $0 | Exch $0 | ||
Exch 2 | Exch | ||
Push $2 | |||
Push $3 | Push $3 | ||
Push $4 | Push $4 | ||
Push $5 | Push $5 | ||
Push $6 | |||
Push $7 | |||
ClearErrors | |||
StrCpy $2 $1 '' 1 | |||
StrCpy $1 $1 1 | |||
StrLen $3 $2 | |||
StrCpy $7 0 | |||
begin: | |||
StrCpy $4 -1 | StrCpy $4 -1 | ||
StrCpy $6 '' | |||
quote: | |||
IntOp $4 $4 + 1 | |||
StrCpy $5 $0 1 $4 | |||
StrCmp $5$7 '0' notfound | |||
StrCmp $5 '' trimright | |||
StrCmp $5 '"' 0 +7 | |||
StrCmp $6 '' 0 +3 | |||
StrCpy $6 '"' | |||
goto quote | |||
StrCmp $6 '"' 0 +3 | |||
StrCpy $6 '' | |||
goto quote | |||
StrCmp $5 `'` 0 +7 | |||
StrCmp $6 `` 0 +3 | |||
StrCpy $6 `'` | |||
goto quote | |||
StrCmp $6 `'` 0 +3 | |||
StrCpy $6 `` | |||
goto quote | |||
StrCmp $5 '`' 0 +7 | |||
StrCmp $6 '' 0 +3 | |||
StrCpy $6 '`' | |||
goto quote | |||
StrCmp $6 '`' 0 +3 | |||
StrCpy $6 '' | |||
goto quote | |||
StrCmp $6 '"' quote | |||
StrCmp $6 `'` quote | |||
StrCmp $6 '`' quote | |||
StrCmp $5 $1 0 quote | |||
StrCmp $7 0 trimleft trimright | |||
trimleft: | trimleft: | ||
Line 88: | Line 133: | ||
StrCpy $5 $0 $3 $4 | StrCpy $5 $0 $3 $4 | ||
StrCmp $5 '' notfound | StrCmp $5 '' notfound | ||
StrCmp $5 | StrCmp $5 $2 0 quote | ||
IntOp $4 $4 + $3 | IntOp $4 $4 + $3 | ||
StrCpy $0 $0 '' $4 | StrCpy $0 $0 '' $4 | ||
Line 95: | Line 140: | ||
StrCpy $0 $0 '' 1 | StrCpy $0 $0 '' 1 | ||
goto -3 | goto -3 | ||
StrCpy $7 1 | |||
StrCpy $ | goto begin | ||
trimright: | trimright: | ||
StrCpy $0 $0 $4 | StrCpy $0 $0 $4 | ||
StrCpy $4 $0 1 -1 | StrCpy $4 $0 1 -1 | ||
Line 145: | Line 159: | ||
notfound: | notfound: | ||
SetErrors | |||
StrCpy $0 '' | StrCpy $0 '' | ||
end: | end: | ||
Pop $7 | |||
Pop $6 | |||
Pop $5 | Pop $5 | ||
Pop $4 | Pop $4 | ||
Line 157: | Line 174: | ||
</highlight-nsis> | </highlight-nsis> | ||
[[Category:Command Line Functions]] |
Latest revision as of 07:26, 7 February 2006
Author: Instructor (talk, contrib) |
Page for NSIS 2.07 and below users
You can use the latest version of headers (recommended) or the following function code (put the function code in your script before calling it)
Function Description
____________________________________________________________________________ GetOptions ____________________________________________________________________________ Get options from command line parameters. Syntax: ${GetOptions} "[Parameters]" "[Option]" $var "[Parameters]" ; command line parameters ; "[Option]" ; option name ; $var ; Result: option string Note: -Error flag if option not found -First option symbol it is delimiter
Example1:
Section ${GetOptions} "/S /T" "/T" $R0 IfErrors 0 +2 MessageBox MB_OK "Not found" IDOK +2 MessageBox MB_OK "Found" SectionEnd
Example2:
Section ${GetOptions} "-INSTDIR=C:\Program Files\Common Files -SILENT=yes" "-INSTDIR=" $R0 ;$R0=C:\Program Files\Common Files SectionEnd
Example3:
Section ${GetOptions} '/SILENT=yes /INSTDIR="C:/Program Files/Common Files" /ADMIN=password' "/INSTDIR=" $R0 ;$R0=C:/Program Files/Common Files SectionEnd
Example4:
Section ${GetOptions} `-SILENT=yes -INSTDIR='"C:/Program Files/Common Files"' -ADMIN=password` "-INSTDIR=" $R0 ;$R0="C:/Program Files/Common Files" SectionEnd
Function Code
Function GetOptions !define GetOptions `!insertmacro GetOptionsCall` !macro GetOptionsCall _PARAMETERS _OPTION _RESULT Push `${_PARAMETERS}` Push `${_OPTION}` Call GetOptions Pop ${_RESULT} !macroend Exch $1 Exch Exch $0 Exch Push $2 Push $3 Push $4 Push $5 Push $6 Push $7 ClearErrors StrCpy $2 $1 '' 1 StrCpy $1 $1 1 StrLen $3 $2 StrCpy $7 0 begin: StrCpy $4 -1 StrCpy $6 '' quote: IntOp $4 $4 + 1 StrCpy $5 $0 1 $4 StrCmp $5$7 '0' notfound StrCmp $5 '' trimright StrCmp $5 '"' 0 +7 StrCmp $6 '' 0 +3 StrCpy $6 '"' goto quote StrCmp $6 '"' 0 +3 StrCpy $6 '' goto quote StrCmp $5 `'` 0 +7 StrCmp $6 `` 0 +3 StrCpy $6 `'` goto quote StrCmp $6 `'` 0 +3 StrCpy $6 `` goto quote StrCmp $5 '`' 0 +7 StrCmp $6 '' 0 +3 StrCpy $6 '`' goto quote StrCmp $6 '`' 0 +3 StrCpy $6 '' goto quote StrCmp $6 '"' quote StrCmp $6 `'` quote StrCmp $6 '`' quote StrCmp $5 $1 0 quote StrCmp $7 0 trimleft trimright trimleft: IntOp $4 $4 + 1 StrCpy $5 $0 $3 $4 StrCmp $5 '' notfound StrCmp $5 $2 0 quote IntOp $4 $4 + $3 StrCpy $0 $0 '' $4 StrCpy $4 $0 1 StrCmp $4 ' ' 0 +3 StrCpy $0 $0 '' 1 goto -3 StrCpy $7 1 goto begin trimright: StrCpy $0 $0 $4 StrCpy $4 $0 1 -1 StrCmp $4 ' ' 0 +3 StrCpy $0 $0 -1 goto -3 StrCpy $3 $0 1 StrCpy $4 $0 1 -1 StrCmp $3 $4 0 end StrCmp $3 '"' +3 StrCmp $3 `'` +2 StrCmp $3 '`' 0 end StrCpy $0 $0 -1 1 goto end notfound: SetErrors StrCpy $0 '' end: Pop $7 Pop $6 Pop $5 Pop $4 Pop $3 Pop $2 Pop $1 Exch $0 FunctionEnd