GetOptions: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Created by user: Instructor.)
 
m (Updated by user: Instructor.)
Line 17: Line 17:


Syntax:
Syntax:
${GetOptions} "[Parameters]" "[Delimiter]" "[Option]" $var
${GetOptions} "[Parameters]" "[Option]" $var


"[Parameters]"    ; command line parameters
"[Parameters]"    ; command line parameters
                  ;
"[Delimiter]"      ; delimiter (one symbol)
                   ;
                   ;
"[Option]"        ; option name
"[Option]"        ; option name
                   ;
                   ;
$var              ; Result: option string
$var              ; Result: option string
Note:
-First option symbol it is delimiter




Example1:
Example1:
Section
Section
${GetOptions} "/INSTDIR=Temp /SILENT=yes /ADMIN=qwerty" "/" "ADMIN="  $R0
${GetOptions} "/INSTDIR=Temp /SILENT=yes /ADMIN=qwerty" "/ADMIN="  $R0
;$R0=qwerty
;$R0=qwerty
SectionEnd
SectionEnd
Line 36: Line 39:
Example2:
Example2:
Section
Section
${GetOptions} "/INSTDIR=C:\Program Files\ /SILENT=yes"\
${GetOptions} "-INSTDIR=C:\Program Files\Common Files -SILENT=yes"\
          "/" "INSTDIR="  $R0
  "-INSTDIR="  $R0
;$R0=C:\Program Files\
;$R0=C:\Program Files\Common Files
SectionEnd
SectionEnd


Example3:
Example3:
Section
Section
${GetOptions} '/SILENT=yes /INSTDIR="C:/Program Files/" /ADMIN=qwerty'\
${GetOptions} '/INSTDIR="C:/Program Files/Common Files" /ADMIN=qwerty'\
          "/" "INSTDIR="  $R0
  "/INSTDIR="  $R0
;$R0=C:/Program Files/
;$R0=C:/Program Files/Common Files
SectionEnd
SectionEnd


Example4:
Example4:
Section
Section
${GetOptions} `-SILENT=yes -INSTDIR='"C:/Program Files/"' -ADMIN=qwerty`\
${GetOptions} `-SILENT=yes -INSTDIR='"C:/Program Files/Common Files"'`\
          "-" "INSTDIR="  $R0
  "-INSTDIR="  $R0
;$R0="C:/Program Files/"
;$R0="C:/Program Files/Common Files"
SectionEnd*/
SectionEnd*/


Line 61: Line 64:
!define GetOptions `!insertmacro GetOptionsCall`
!define GetOptions `!insertmacro GetOptionsCall`


!macro GetOptionsCall _PARAMETERS _DELIMITER _OPTION _RESULT
!macro GetOptionsCall _PARAMETERS _OPTION _RESULT
Push `${_PARAMETERS}`
Push `${_PARAMETERS}`
Push `${_DELIMITER}`
Push `${_OPTION}`
Push `${_OPTION}`
Call GetOptions
Call GetOptions
Line 69: Line 71:
!macroend
!macroend


Exch $2
Exch
Exch $1
Exch $1
Exch
Exch
Exch 2
Exch $0
Exch $0
Exch 2
Exch
Push $2
Push $3
Push $3
Push $4
Push $4
Push $5
Push $5


StrCmp $1 '' notfound
StrCpy $2 $1 '' 1
StrCpy $1 $1 1
StrLen $3 '$1$2'
StrLen $3 '$1$2'
StrCpy $4 -1
StrCpy $4 -1

Revision as of 09:25, 19 April 2005

Links

Latest version of headers "nsh.zip"
http://forums.winamp.com/showthread.php?s=&threadid=203228&goto=lastpost

If function used without header then put function in script before call it

The Function

/*
____________________________________________________________________________
 
                            GetOptions
____________________________________________________________________________
 
 
Get options from command line parameters.
 
 
Syntax:
${GetOptions} "[Parameters]" "[Option]" $var
 
"[Parameters]"     ; command line parameters
                   ;
"[Option]"         ; option name
                   ;
$var               ; Result: option string
 
 
Note:
-First option symbol it is delimiter
 
 
 
Example1:
Section
	${GetOptions} "/INSTDIR=Temp /SILENT=yes /ADMIN=qwerty" "/ADMIN="  $R0
	;$R0=qwerty
SectionEnd
 
Example2:
Section
	${GetOptions} "-INSTDIR=C:\Program Files\Common Files -SILENT=yes"\
	  "-INSTDIR="  $R0
	;$R0=C:\Program Files\Common Files
SectionEnd
 
Example3:
Section
	${GetOptions} '/INSTDIR="C:/Program Files/Common Files" /ADMIN=qwerty'\
	  "/INSTDIR="  $R0
	;$R0=C:/Program Files/Common Files
SectionEnd
 
Example4:
Section
	${GetOptions} `-SILENT=yes -INSTDIR='"C:/Program Files/Common Files"'`\
	  "-INSTDIR="  $R0
	;$R0="C:/Program Files/Common Files"
SectionEnd*/
 
 
;---------------------------------------------------------------------------
 
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
 
	StrCpy $2 $1 '' 1
	StrCpy $1 $1 1
	StrLen $3 '$1$2'
	StrCpy $4 -1
 
	trimleft:
	IntOp $4 $4 + 1
	StrCpy $5 $0 $3 $4
	StrCmp $5 '' notfound
	StrCmp $5 '$1$2' 0 trimleft
	IntOp $4 $4 + $3
	StrCpy $0 $0 '' $4
	StrCpy $4 $0 1
	StrCmp $4 ' ' 0 +3
	StrCpy $0 $0 '' 1
	goto -3
 
	StrCpy $3 ''
	StrCpy $4 -1
 
	trimright:
	IntOp $4 $4 + 1
	StrCpy $5 $0 1 $4
	StrCmp $5 '' found
	StrCmp $5 '"' 0 +7
	StrCmp $3 '' 0 +3
	StrCpy $3 '"'
	goto trimright
	StrCmp $3 '"' 0 +3
	StrCpy $3 ''
	goto trimright
	StrCmp $5 `'` 0 +7
	StrCmp $3 `` 0 +3
	StrCpy $3 `'`
	goto trimright
	StrCmp $3 `'` 0 +3
	StrCpy $3 ``
	goto trimright
	StrCmp $5 '`' 0 +7
	StrCmp $3 '' 0 +3
	StrCpy $3 '`'
	goto trimright
	StrCmp $3 '`' 0 +3
	StrCpy $3 ''
	goto trimright
	StrCmp $3 '"' trimright
	StrCmp $3 `'` trimright
	StrCmp $3 '`' trimright
	StrCmp $5 $1 0 trimright
 
	found:
	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:
	StrCpy $0 ''
 
	end:
	Pop $5
	Pop $4
	Pop $3
	Pop $2
	Pop $1
	Exch $0
FunctionEnd

Page author: Instructor