8 Function ${__PREFIX__}StrStr
10 ------------------------------------------
11 $R0 = SubString (input)
13 $R2 = SubStringLen (temp)
15 $R4 = StartCharPos (temp)
16 $R5 = TempStr (temp)*/
27 ;Get "String" and "SubString" length
30 ;Start "StartCharPos" counter
33 ;Loop until "SubString" is found or "String" reaches its end
35 ;Remove everything before and after the searched part ("TempStr")
36 StrCpy $R5 $R1 $R2 $R4
38 ;Compare "TempStr" with "SubString"
40 ;If not "SubString", this could be "String"'s end
41 IntCmp $R4 $R3 done 0 done
42 ;If not, continue the loop
48 ------------------------------------------
49 $R0 = ResultVar (output)*/
51 ;Remove part before "SubString" on "String" (if there has one)
54 ;Return output to user
66 ; output, top of stack (replaces, with e.g. whatever)
67 ; modifies no other variables.
69 Function ${__PREFIX__}GetParameters
78 ;Check for quote or space
79 StrCpy $R0 $CMDLINE $R2
87 StrCpy $R0 $CMDLINE 1 $R2
94 StrCpy $R0 $CMDLINE 1 $R2
96 StrCpy $R0 $CMDLINE "" $R2
106 ; Chris Morgan<cmorgan@alum.wpi.edu> 5/10/2004
107 ; -Updated 4/7/2005 to add support for retrieving a command line switch
108 ; and additional documentation
110 ; Searches the command line input, retrieved using GetParameters, for the
111 ; value of an option given the option name. If no option is found the
112 ; default value is placed on the top of the stack upon function return.
114 ; This function can also be used to detect the existence of just a
115 ; command line switch like /OUTPUT Pass the default and "OUTPUT"
116 ; on the stack like normal. An empty return string "" will indicate
117 ; that the switch was found, the default value indicates that
118 ; neither a parameter or switch was found.
120 ; Inputs - Top of stack is default if parameter isn't found,
121 ; second in stack is parameter to search for, ex. "OUTPUT"
122 ; Outputs - Top of the stack contains the value of this parameter
123 ; So if the command line contained /OUTPUT=somedirectory, "somedirectory"
124 ; will be on the top of the stack when this function returns
127 ;$R0 - default return value if the parameter isn't found
128 ;$R1 - input parameter, for example OUTPUT from the above example
129 ;$R2 - the length of the search, this is the search parameter+2
130 ; as we have '/OUTPUT='
131 ;$R3 - the command line string
132 ;$R4 - result from StrStr calls
133 ;$R5 - search for ' ' or '"'
135 Function ${__PREFIX__}GetParameterValue
136 Exch $R0 ; get the top of the stack(default parameter) into R0
137 Exch ; exchange the top of the stack(default) with
138 ; the second in the stack(parameter to search for)
139 Exch $R1 ; get the top of the stack(search parameter) into $R1
141 ;Preserve on the stack the registers used in this function
147 Strlen $R2 $R1+2 ; store the length of the search string into R2
149 Call ${__PREFIX__}GetParameters ; get the command line parameters
150 Pop $R3 ; store the command line string in R3
152 # search for quoted search string
153 StrCpy $R5 '"' ; later on we want to search for a open quote
154 Push $R3 ; push the 'search in' string onto the stack
155 Push '"/$R1=' ; push the 'search for'
156 Call ${__PREFIX__}StrStr ; search for the quoted parameter value
158 StrCpy $R4 $R4 "" 1 ; skip over open quote character, "" means no maxlen
159 StrCmp $R4 "" "" next ; if we didn't find an empty string go to next
161 # search for non-quoted search string
162 StrCpy $R5 ' ' ; later on we want to search for a space since we
163 ; didn't start with an open quote '"' we shouldn't
164 ; look for a close quote '"'
165 Push $R3 ; push the command line back on the stack for searching
166 Push '/$R1=' ; search for the non-quoted search string
167 Call ${__PREFIX__}StrStr
170 ; $R4 now contains the parameter string starting at the search string,
173 StrCmp $R4 "" check_for_switch ; if we didn't find anything then look for
174 ; usage as a command line switch
175 # copy the value after /$R1= by using StrCpy with an offset of $R2,
176 # the length of '/OUTPUT='
177 StrCpy $R0 $R4 "" $R2 ; copy commandline text beyond parameter into $R0
178 # search for the next parameter so we can trim this extra text off
180 Push $R5 ; search for either the first space ' ', or the first
182 ; if we found '"/output' then we want to find the
183 ; ending ", as in '"/output=somevalue"'
184 ; if we found '/output' then we want to find the first
185 ; space after '/output=somevalue'
186 Call ${__PREFIX__}StrStr ; search for the next parameter
188 StrCmp $R4 "" done ; if 'somevalue' is missing, we are done
189 StrLen $R4 $R4 ; get the length of 'somevalue' so we can copy this
190 ; text into our output buffer
191 StrCpy $R0 $R0 -$R4 ; using the length of the string beyond the value,
192 ; copy only the value into $R0
193 goto done ; if we are in the parameter retrieval path skip over
194 ; the check for a command line switch
196 ; See if the parameter was specified as a command line switch, like '/output'
198 Push $R3 ; push the command line back on the stack for searching
199 Push '/$R1' ; search for the non-quoted search string
200 Call ${__PREFIX__}StrStr
202 StrCmp $R4 "" done ; if we didn't find anything then use the default
203 StrCpy $R0 "" ; otherwise copy in an empty string since we found the
204 ; parameter, just didn't find a value
212 Exch $R0 ; put the value in $R0 at the top of the stack
218 !if "${__PREFIX__}" != "un."
219 !macro GetCommandlineParameter param default var
220 Push "${param}" ; push the search string onto the stack
221 Push "${default}" ; push a default value onto the stack
222 Call GetParameterValue
226 !macro un.GetCommandlineParameter param default var
227 Push "${param}" ; push the search string onto the stack
228 Push "${default}" ; push a default value onto the stack
229 Call un.GetParameterValue