VirtualBox

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

Last change on this file was 96694, checked in by vboxsync, 20 months ago

Add/Nt/Installer: Reduce the number of warnings to almost none.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use