VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Installer/strstr.nsh@ 40257

Last change on this file since 40257 was 33540, checked in by vboxsync, 14 years ago

*: spelling fixes, thanks Timeless!

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.5 KB
Line 
1; StrStr
2 ; input, top of stack = string to search for
3 ; top of stack-1 = string to search in
4 ; output, top of stack (replaces with the portion of the string remaining)
5 ; modifies no other variables.
6 ;
7 ; Usage:
8 ; Push "this is a long ass string"
9 ; Push "ass"
10 ; Call StrStr
11 ; Pop $R0
12 ; ($R0 at this point is "ass string")
13
14
15!macro StrStr un
16 Function ${un}StrStr
17 Exch $R1 ; st=haystack,old$R1, $R1=needle
18 Exch ; st=old$R1,haystack
19 Exch $R2 ; st=old$R1,old$R2, $R2=haystack
20 Push $R3
21 Push $R4
22 Push $R5
23 StrLen $R3 $R1
24 StrCpy $R4 0
25 ; $R1=needle
26 ; $R2=haystack
27 ; $R3=len(needle)
28 ; $R4=cnt
29 ; $R5=tmp
30 loop:
31 StrCpy $R5 $R2 $R3 $R4
32 StrCmp $R5 $R1 done
33 StrCmp $R5 "" done
34 IntOp $R4 $R4 + 1
35 Goto loop
36 done:
37 StrCpy $R1 $R2 "" $R4
38 Pop $R5
39 Pop $R4
40 Pop $R3
41 Pop $R2
42 Exch $R1
43 FunctionEnd
44!macroend
45!insertmacro StrStr ""
46!insertmacro StrStr "un."
47
48!macro StrStrAdv un
49Function ${un}StrStrAdv
50
51 ; After this point:
52 ; $0 = String (input)
53 ; $1 = SubString (input)
54 ; $2 = SearchDirection (input)
55 ; $3 = StrInclusionDirection (input)
56 ; $4 = IncludeSubString (input)
57 ; $5 = Loops (input)
58 ; $6 = CaseSensitive (input)
59 ; $7 = StringLength (temp)
60 ; $8 = StrToSearchLength (temp)
61 ; $9 = CurrentLoop (temp)
62 ; $R0 = EndCharPos (temp)
63 ; $R1 = StartCharPos (temp)
64 ; $R2 = ResultVar (output)
65 ; $R3 = Temp (temp)
66
67 ; Get input from user
68
69 Exch $6
70 Exch
71 Exch $5
72 Exch
73 Exch 2
74 Exch $4
75 Exch 2
76 Exch 3
77 Exch $3
78 Exch 3
79 Exch 4
80 Exch $2
81 Exch 4
82 Exch 5
83 Exch $1
84 Exch 5
85 Exch 6
86 Exch $0
87 Exch 6
88 Push $7
89 Push $8
90 Push $9
91 Push $R3
92 Push $R2
93 Push $R1
94 Push $R0
95
96 ; Clean $R0-$R3 variables
97 StrCpy $R0 ""
98 StrCpy $R1 ""
99 StrCpy $R2 ""
100 StrCpy $R3 ""
101
102 ; Verify if we have the correct values on the variables
103 ${If} $0 == ``
104 SetErrors ;AdvStrStr_StrToSearch not found
105 Goto AdvStrStr_End
106 ${EndIf}
107
108 ${If} $1 == ``
109 SetErrors ;No text to search
110 Goto AdvStrStr_End
111 ${EndIf}
112
113 ${If} $2 != <
114 StrCpy $2 >
115 ${EndIf}
116
117 ${If} $3 != <
118 StrCpy $3 >
119 ${EndIf}
120
121 ${If} $4 <> 0
122 StrCpy $4 1
123 ${EndIf}
124
125 ${If} $5 <= 0
126 StrCpy $5 0
127 ${EndIf}
128
129 ${If} $6 <> 1
130 StrCpy $6 0
131 ${EndIf}
132
133 ; Find "AdvStrStr_String" length
134 StrLen $7 $0
135
136 ; Then find "AdvStrStr_SubString" length
137 StrLen $8 $1
138
139 ; Now set up basic variables
140
141 ${If} $2 == <
142 IntOp $R1 $7 - $8
143 StrCpy $R2 $7
144 ${Else}
145 StrCpy $R1 0
146 StrCpy $R2 $8
147 ${EndIf}
148
149 StrCpy $9 0 ; First loop
150
151 ;Let's begin the search
152
153 ${Do}
154 ; Step 1: If the starting or ending numbers are negative
155 ; or more than AdvStrStr_StringLen, we return
156 ; error
157
158 ${If} $R1 < 0
159 StrCpy $R1 ``
160 StrCpy $R2 ``
161 StrCpy $R3 ``
162 SetErrors ;AdvStrStr_SubString not found
163 Goto AdvStrStr_End
164 ${ElseIf} $R2 > $7
165 StrCpy $R1 ``
166 StrCpy $R2 ``
167 StrCpy $R3 ``
168 SetErrors ;AdvStrStr_SubString not found
169 Goto AdvStrStr_End
170 ${EndIf}
171
172 ; Step 2: Start the search depending on
173 ; AdvStrStr_SearchDirection. Chop down not needed
174 ; characters.
175
176 ${If} $R1 <> 0
177 StrCpy $R3 $0 `` $R1
178 ${EndIf}
179
180 ${If} $R2 <> $7
181 ${If} $R1 = 0
182 StrCpy $R3 $0 $8
183 ${Else}
184 StrCpy $R3 $R3 $8
185 ${EndIf}
186 ${EndIf}
187
188 ; Step 3: Make sure that's the string we want
189
190 ; Case-Sensitive Support <- Use "AdvStrStr_Temp"
191 ; variable because it won't be used anymore
192
193 ${If} $6 == 1
194 System::Call `kernel32::lstrcmpA(ts, ts) i.s` `$R3` `$1`
195 Pop $R3
196 ${If} $R3 = 0
197 StrCpy $R3 1 ; Continue
198 ${Else}
199 StrCpy $R3 0 ; Break
200 ${EndIf}
201 ${Else}
202 ${If} $R3 == $1
203 StrCpy $R3 1 ; Continue
204 ${Else}
205 StrCpy $R3 0 ; Break
206 ${EndIf}
207 ${EndIf}
208
209 ; After the comparison, confirm that it is the
210 ; value we want.
211
212 ${If} $R3 = 1
213
214 ;We found it, return except if the user has set up to
215 ;search for another one:
216 ${If} $9 >= $5
217
218 ;Now, let's see if the user wants
219 ;AdvStrStr_SubString to appear:
220 ${If} $4 == 0
221 ;Return depends on AdvStrStr_StrInclusionDirection
222 ${If} $3 == <
223 ; RTL
224 StrCpy $R0 $0 $R1
225 ${Else}
226 ; LTR
227 StrCpy $R0 $0 `` $R2
228 ${EndIf}
229 ${Break}
230 ${Else}
231 ;Return depends on AdvStrStr_StrInclusionDirection
232 ${If} $3 == <
233 ; RTL
234 StrCpy $R0 $0 $R2
235 ${Else}
236 ; LTR
237 StrCpy $R0 $0 `` $R1
238 ${EndIf}
239 ${Break}
240 ${EndIf}
241 ${Else}
242 ;If the user wants to have more loops, let's do it so!
243 IntOp $9 $9 + 1
244
245 ${If} $2 == <
246 IntOp $R1 $R1 - 1
247 IntOp $R2 $R2 - 1
248 ${Else}
249 IntOp $R1 $R1 + 1
250 IntOp $R2 $R2 + 1
251 ${EndIf}
252 ${EndIf}
253 ${Else}
254 ; Step 4: We didn't find it, so do steps 1 thru 3 again
255
256 ${If} $2 == <
257 IntOp $R1 $R1 - 1
258 IntOp $R2 $R2 - 1
259 ${Else}
260 IntOp $R1 $R1 + 1
261 IntOp $R2 $R2 + 1
262 ${EndIf}
263 ${EndIf}
264 ${Loop}
265
266 AdvStrStr_End:
267
268 ;Add 1 to AdvStrStr_EndCharPos to be supportable
269 ;by "StrCpy"
270
271 IntOp $R2 $R2 - 1
272
273 ;Return output to user
274
275 Exch $R0
276 Exch
277 Pop $R1
278 Exch
279 Pop $R2
280 Exch
281 Pop $R3
282 Exch
283 Pop $9
284 Exch
285 Pop $8
286 Exch
287 Pop $7
288 Exch
289 Pop $6
290 Exch
291 Pop $5
292 Exch
293 Pop $4
294 Exch
295 Pop $3
296 Exch
297 Pop $2
298 Exch
299 Pop $1
300 Exch
301 Pop $0
302
303FunctionEnd
304!macroend
305!insertmacro StrStrAdv ""
306!insertmacro StrStrAdv "un."
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette