Old 17th July 2008, 18:58   #1
stonkers
Senior Member
 
Join Date: Sep 2003
Posts: 192
Did I reinvent the wheel?

So I currently use the getparameters function to get the command line arguments. That's fine and dandy if I only have one argument, but if I have more I didn't know how to deal with it. Is there an easy way to split out the parameters? I didn't think there was, so I wrote the following function and then thought maybe that functionality already existed. Does it?

code:

; GetNextParameter
; input, $parameters
; output, puts first parameter on stack and replaces $parameters with the beginning of the next param to the end of params
; modifies no other variables.

Function GetNextParameter

Push $R0 ;Push all var's we're using onto the stack so we can get them back later
Push $R1
Push $R2
Push $R3

StrCpy $R2 1 ;Put 1 in $R2 because we'll start at Char 1
StrLen $R3 $parameters ;Put the length of parameters in $R3 for use
StrCmp $R3 "0" noParams ;If parameters was passed empty, we don't have any parameters left

killLeadingSpaces:
;Check for space at beginning - if so, remove it
StrCpy $R0 $parameters $R2 ;Put the first character of the parameters into $R0
StrCmp $R0 ' ' 0 loop ;If it starts with a space, remove it, if not, continue
StrCpy $parameters $parameters "" 1 ;Remove the space from the beginning
StrLen $R3 $parameters ;New length
StrCmp $R3 "0" 0 killLeadingSpaces ;If it's down to length 0, there aren't any params
noParams:
StrCpy $R0 "NoParams" ;Let 'em know
Goto finished

loop:
IntOp $R2 $R2 + 1 ;Add one to where we're searching
StrCpy $R0 $parameters 1 $R2 ;Get that character so we can check it out
StrCmp $R2 $R3 gotit ;If it's the last param, the length and where we're at will match up
StrCmp $R0 ' ' gotit loop ;If we're on a space, we've got this one - finish up

gotit:
StrCpy $R0 $parameters $R2 ;Put this parameter in $R0
StrCpy $parameters $parameters "" $R2 ;reset parameters var to what's left
Goto finished

finished:
Pop $R3
Pop $R2
Pop $R1
Exch $R0

FunctionEnd



Thanks,
Eric

Eric
stonkers is offline   Reply With Quote
Old 17th July 2008, 19:03   #2
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
See http://nsis.sourceforge.net/Get_comm...ameter_by_name

This can be used to get parameters in the "/PARAM=VALUE" format.
You specify which parameter you want to get and you set the default.
If the parameter is not set, the default is returned...

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 17th July 2008, 21:11   #3
stonkers
Senior Member
 
Join Date: Sep 2003
Posts: 192
Nice thanks! A little less error prone than mine...

Eric
stonkers is offline   Reply With Quote
Old 17th July 2008, 22:11   #4
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
What is wrong with GetOptions?

myfile.exe /arg=hello

${GetParameters} $0
${GetOptions} $0 `/arg=` $R0

$R0 = hello

It's in the NSIS doc under File functions header along with GetParameters. It also sets the error flag if the parameter is missing. For example you could use /arg without a value, in which case your code may be:

${GetParameters} $0
ClearErrors
${GetOptions} $0 `/arg` $R0
${Unless} ${Errors}
...
${EndUnless}

Stu
Afrow UK is offline   Reply With Quote
Old 18th July 2008, 21:51   #5
stonkers
Senior Member
 
Join Date: Sep 2003
Posts: 192
Looks even better. Guess the answer to the subject of this post is a resounding YES. I reinvented the wheel but didn't put enough spokes in it to support maintaining the original spherical shape...

Eric
stonkers is offline   Reply With Quote
Old 19th July 2008, 13:52   #6
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
I think there is a little syntax difference:

With ${GetOptions} you must pass it like this:
setup.exe /ARG1=C:\Program Files\My App /ARG2=C:\Program Files\My App 2

But with "GetParameterValue" you must pass it like this:
setup.exe /ARG1="C:\Program Files\My App" /ARG2="C:\Program Files\My App 2"

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 19th July 2008, 14:29   #7
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
You have to use quotes no matter what method you use when the value contains spaces. Otherwise your /ARG1 would have a value of "C:\Program"

Stu
Afrow UK is offline   Reply With Quote
Old 19th July 2008, 15:10   #8
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
From the NSIS User Manual:

Quote:
Example2:

code:
Section
${GetOptions} "-INSTDIR=C:\Program Files\Common Files -SILENT=yes" "-INSTDIR=" $R0
;$R0=C:\Program Files\Common Files
SectionEnd

Either the example is wrong or you are mistaken, Afrow

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 19th July 2008, 15:24   #9
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
My bad. GetOptions works with or without quotes.

Stu
Afrow UK is offline   Reply With Quote
Old 19th July 2008, 15:26   #10
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
Here is an example:
http://img411.imageshack.us/img411/6...optionsph0.png

So there is the difference between GetOptions and GetParameterValue.

The behavior of GetOptions is very unusual though

My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Old 14th August 2008, 23:24   #11
stonkers
Senior Member
 
Join Date: Sep 2003
Posts: 192
Say you have the following:

setup.exe doggie1 /ARG1="Jojo Likes Boxing"

Is there a way to grab doggie1 separate from Jojo Likes Boxing easily. In other words, I'm already grabbing one parameter with the getParameters function. It seems that if I continue to use the getParameters function with for doggie1, it will actually end up being 'doggie1 /ARG1="JojoLikesBoxing"' and I'll have to, instead, customize getParameters to only go to the first space. Am I making this harder than it really is?

Thanks,
Eric

Eric
stonkers is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump