Skip to content
⌘ NSIS Forum Archive

Bug in GetNextParm?

7 posts

aadya#

Bug in GetNextParm?

Hi Guys,
I am using GetNextParm to parse commandline switches.
However, for a value below, the function fails. I would like to know what could be an appropriate fix.

Usage:

setup.exe /S /INSTALLDIR="C:\Program Files\Mydir" /TEMP=c:\temp

Code:

...
Call GetNextParm
Pop $0 ;$0 = /INSTALLDIR="C:\Program

Call GetNextParm
Pop $0 ;$0 = Files\Mydir"

Looks like once a space is encountered, function assumes that it has copied the entire value.

.....................

Function GetNextParm
Exch $0
Push $1
Push $9
Push $8
StrCpy $1 ""

; Trim leading space
TrimLeading:
StrCpy $9 $0 1
StrCmp $9 "" Done
StrCmp $9 '"' DelimitQuote
StrCmp $9 " " "" DelimitSpace
StrCpy $0 $0 "" 1
Goto TrimLeading

; Begin a quote-delimited parameter
DelimitQuote:
StrCpy $0 $0 "" 1
Goto CopyParm

; Begin a space-delimited parameter
DelimitSpace:
StrCpy $9 " "

; Extract the parameter
CopyParm:
StrCpy $8 $0 1
StrCmp $8 "" Done
StrCpy $0 $0 "" 1
StrCmp $8 $9 Done
StrCpy $1 $1$8
Goto CopyParm

Done:
Pop $8
Pop $9
Exch $1
Exch
Exch $0
Exch
FunctionEnd
pengyou#
If you use quotes, GetNextParm expects the _entire_ parameter to be enclosed in quotes.

So if you use this command:

setup.exe /S "/INSTALLDIR=C:\Program Files\Mydir" /TEMP=c:\temp

you will find that GetNextParm will return this

/INSTALLDIR=C:\Program Files\Mydir
aadya#
Thanks for the replies.

pengyou: I will try it and get back if this works.

Afrow UK: I ended up using this option but is it true that it only works if used as the last option. If I use it earlier, then the entire command line is treated as the directory for installation. Any thoughts?
Instructor#
#Use " /" to separate the parameters

!include "WordFunc.nsh"
!insertmacro WordFind

Section
StrCpy $0 1

loop:
IntOp $0 $0 + 1
${WordFind} 'setup.exe /S /INSTALLDIR="C:\Program Files\Mydir" /TEMP=c:\temp' ' /' 'E+$0' $R0
IfErrors end

MessageBox MB_YESNO '$$R0=[$R0]$\nNext parameter?' IDYES loop

end:
SectionEnd
Script used Header
Comperio#
Here's one of my own creations that might help: