Prev Previous Post   Next Post Next
Old 17th July 2008, 17: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
 
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