1 | /* $Id: string_odin.cpp,v 1.8 2002-06-07 08:02:20 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Win32 Lightweight SHELL32 for OS/2
|
---|
5 | *
|
---|
6 | * Copyright 1997 Marcus Meissner
|
---|
7 | * Copyright 1999 Patrick Haller (haller@zebra.fh-weingarten.de)
|
---|
8 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
9 | *
|
---|
10 | * Path Functions
|
---|
11 | *
|
---|
12 | * Many of this functions are in SHLWAPI.DLL also
|
---|
13 | *
|
---|
14 | * Corel WINE 20000324 level (without CRTDLL_* calls)
|
---|
15 | */
|
---|
16 |
|
---|
17 | /*****************************************************************************
|
---|
18 | * Remark *
|
---|
19 | *****************************************************************************
|
---|
20 |
|
---|
21 | */
|
---|
22 |
|
---|
23 |
|
---|
24 | /*****************************************************************************
|
---|
25 | * Includes *
|
---|
26 | *****************************************************************************/
|
---|
27 |
|
---|
28 | #include <odin.h>
|
---|
29 | #include <odinwrap.h>
|
---|
30 | #include <os2sel.h>
|
---|
31 |
|
---|
32 | #include <string.h>
|
---|
33 | #include <ctype.h>
|
---|
34 | #include <wctype.h>
|
---|
35 | #ifndef __GNUC__
|
---|
36 | #include <wcstr.h>
|
---|
37 | #else
|
---|
38 | #include <wchar.h>
|
---|
39 | #endif
|
---|
40 | #define HAVE_WCTYPE_H
|
---|
41 |
|
---|
42 | #include "debugtools.h"
|
---|
43 |
|
---|
44 | #include <winreg.h>
|
---|
45 |
|
---|
46 | #include <heapstring.h>
|
---|
47 | #include <misc.h>
|
---|
48 | #include <win/shell.h>
|
---|
49 | #include <win/winerror.h>
|
---|
50 | #include <winversion.h>
|
---|
51 | #include <winuser.h>
|
---|
52 |
|
---|
53 | #define CINTERFACE
|
---|
54 |
|
---|
55 | #include "winerror.h"
|
---|
56 | #include "winnls.h"
|
---|
57 | #include "winversion.h"
|
---|
58 | #include "heap.h"
|
---|
59 |
|
---|
60 | #include "shellapi.h"
|
---|
61 | #include "shlobj.h"
|
---|
62 |
|
---|
63 | #include "shlwapi_odin.h"
|
---|
64 | #include "shlwapi.h"
|
---|
65 |
|
---|
66 | /*****************************************************************************
|
---|
67 | * Local Variables *
|
---|
68 | *****************************************************************************/
|
---|
69 |
|
---|
70 | ODINDEBUGCHANNEL(SHLWAPI-STRING)
|
---|
71 |
|
---|
72 |
|
---|
73 |
|
---|
74 |
|
---|
75 | /*****************************************************************************
|
---|
76 | * Name : StrChrIA
|
---|
77 | * Purpose : Searches a string for the first occurrence of a character that
|
---|
78 | * matches the specified character. The comparison is not case sensitive.
|
---|
79 | * Parameters: LPCSTR lpStart Address of the string to be searched.
|
---|
80 | * TCHAR wMatch Character to be used for comparison.
|
---|
81 | * Variables :
|
---|
82 | * Result : Returns the address of the first occurrence of the character in
|
---|
83 | * the string if successful, or NULL otherwise.
|
---|
84 | * Remark : SHELL32.
|
---|
85 | * Status : COMPLETELY IMPLEMENTED UNTESTED UNKNOWN
|
---|
86 | *
|
---|
87 | * Author : Patrick Haller [Wed, 1999/12/29 09:00]
|
---|
88 | *****************************************************************************/
|
---|
89 |
|
---|
90 | ODINFUNCTION2(LPSTR, StrChrIA,
|
---|
91 | LPCSTR, lpStart,
|
---|
92 | char, cMatch)
|
---|
93 | {
|
---|
94 | LPSTR lpRes;
|
---|
95 |
|
---|
96 | cMatch = tolower(cMatch);
|
---|
97 | lpRes = strchr(lpStart, cMatch); // lower case comparsion
|
---|
98 | if (NULL == lpRes)
|
---|
99 | {
|
---|
100 | cMatch = toupper(cMatch);
|
---|
101 | lpRes = strchr(lpStart, cMatch); // upper case comparsion
|
---|
102 | }
|
---|
103 |
|
---|
104 | return lpRes;
|
---|
105 | }
|
---|
106 |
|
---|
107 |
|
---|
108 | /*****************************************************************************
|
---|
109 | * Name : StrChrIW
|
---|
110 | * Purpose : Searches a string for the first occurrence of a character that
|
---|
111 | * matches the specified character. The comparison is not case sensitive.
|
---|
112 | * Parameters: LPCSTR lpStart Address of the string to be searched.
|
---|
113 | * TCHAR wMatch Character to be used for comparison.
|
---|
114 | * Variables :
|
---|
115 | * Result : Returns the address of the first occurrence of the character in
|
---|
116 | * the string if successful, or NULL otherwise.
|
---|
117 | * Remark : SHELL32.
|
---|
118 | * Status : COMPLETELY IMPLEMENTED UNTESTED UNKNOWN
|
---|
119 | *
|
---|
120 | * Author : Patrick Haller [Wed, 1999/12/29 09:00]
|
---|
121 | *****************************************************************************/
|
---|
122 |
|
---|
123 | ODINFUNCTION2(LPWSTR, StrChrIW,
|
---|
124 | LPCWSTR, lpStart,
|
---|
125 | WCHAR, wMatch)
|
---|
126 | {
|
---|
127 | LPWSTR lpRes;
|
---|
128 |
|
---|
129 | wMatch = towlower(wMatch);
|
---|
130 | lpRes = (WCHAR*)wcschr((const wchar_t*)lpStart, wMatch); // lower case comparsion
|
---|
131 | if (NULL == lpRes)
|
---|
132 | {
|
---|
133 | wMatch = towupper(wMatch);
|
---|
134 | lpRes = (WCHAR*)wcschr((const wchar_t*)lpStart, wMatch); // upper case comparsion
|
---|
135 | }
|
---|
136 |
|
---|
137 | return lpRes;
|
---|
138 | }
|
---|
139 |
|
---|
140 | #if 0
|
---|
141 | /*****************************************************************************
|
---|
142 | * Name : StrCpyA
|
---|
143 | * Purpose : copy a string
|
---|
144 | * Parameters:
|
---|
145 | * Variables :
|
---|
146 | * Result :
|
---|
147 | * Remark : not exported ?
|
---|
148 | * Status : UNTESTED
|
---|
149 | *
|
---|
150 | * Author :
|
---|
151 | *****************************************************************************/
|
---|
152 |
|
---|
153 | ODINFUNCTIONNODBG2(LPSTR, StrCpyA,
|
---|
154 | LPSTR, lpDest,
|
---|
155 | LPCSTR, lpSource)
|
---|
156 | {
|
---|
157 | return lstrcpyA(lpDest,
|
---|
158 | lpSource);
|
---|
159 | }
|
---|
160 | #endif
|
---|
161 |
|
---|
162 | /*****************************************************************************
|
---|
163 | * Name : StrSpnA
|
---|
164 | * Purpose : find the first occurence of a character in string1
|
---|
165 | * that is not contained in the set of characters specified by
|
---|
166 | * string2.
|
---|
167 | * Parameters:
|
---|
168 | * Variables :
|
---|
169 | * Result :
|
---|
170 | * Remark : COMCTL32undoc.StrSpnW, CRTDLL.strspn
|
---|
171 | * Status : UNTESTED
|
---|
172 | *
|
---|
173 | * Author :
|
---|
174 | *****************************************************************************/
|
---|
175 |
|
---|
176 | ODINFUNCTION2(INT, StrSpnA,
|
---|
177 | LPCSTR, lpString1,
|
---|
178 | LPCSTR, lpString2)
|
---|
179 | {
|
---|
180 | // 2001-08-30 PH
|
---|
181 | // copied from implementation in COMCTL32
|
---|
182 | if ( (lpString1 == NULL) ||
|
---|
183 | (lpString2 == NULL) )
|
---|
184 | return 0;
|
---|
185 |
|
---|
186 | LPSTR lpLoop = (LPSTR)lpString1;
|
---|
187 |
|
---|
188 | for (; (*lpLoop != 0); lpLoop++ )
|
---|
189 | if ( StrChrA( lpString2, *lpLoop ) )
|
---|
190 | return (INT) (lpLoop - lpString1);
|
---|
191 |
|
---|
192 | return (INT) (lpLoop - lpString1);
|
---|
193 | }
|
---|
194 |
|
---|
195 |
|
---|
196 | /*****************************************************************************
|
---|
197 | * Name : StrSpnW
|
---|
198 | * Purpose : find the first occurence of a character in string1
|
---|
199 | * that is not contained in the set of characters specified by
|
---|
200 | * string2.
|
---|
201 | * Parameters:
|
---|
202 | * Variables :
|
---|
203 | * Result :
|
---|
204 | * Remark : COMCTL32undoc.StrSpnW, CRTDLL.strspn
|
---|
205 | * Status : UNTESTED
|
---|
206 | *
|
---|
207 | * Author :
|
---|
208 | *****************************************************************************/
|
---|
209 |
|
---|
210 | ODINFUNCTION2(INT, StrSpnW,
|
---|
211 | LPCWSTR, lpString1,
|
---|
212 | LPCWSTR, lpString2)
|
---|
213 | {
|
---|
214 | // 2001-08-30 PH
|
---|
215 | // copied from implementation in COMCTL32
|
---|
216 | if ( (lpString1 == NULL) ||
|
---|
217 | (lpString2 == NULL) )
|
---|
218 | return 0;
|
---|
219 |
|
---|
220 | LPWSTR lpLoop = (LPWSTR)lpString1;
|
---|
221 |
|
---|
222 | for (; (*lpLoop != 0); lpLoop++ )
|
---|
223 | if ( StrChrW( lpString2, *lpLoop ) )
|
---|
224 | return (INT) (lpLoop - lpString1);
|
---|
225 |
|
---|
226 | return (INT) (lpLoop - lpString1);
|
---|
227 | }
|
---|
228 |
|
---|
229 |
|
---|
230 | /*****************************************************************************
|
---|
231 | * Name : StrPBrkA
|
---|
232 | * Purpose : find the first occurence in string1 of any character from string2
|
---|
233 | * Parameters:
|
---|
234 | * Variables :
|
---|
235 | * Result :
|
---|
236 | * Remark :
|
---|
237 | * Status : UNTESTED
|
---|
238 | *
|
---|
239 | * Author :
|
---|
240 | *****************************************************************************/
|
---|
241 |
|
---|
242 | ODINFUNCTION2(LPSTR, StrPBrkA,
|
---|
243 | LPCSTR, lpString1,
|
---|
244 | LPCSTR, lpString2)
|
---|
245 | {
|
---|
246 | register LPSTR s1;
|
---|
247 |
|
---|
248 | while (*lpString1)
|
---|
249 | {
|
---|
250 | for (s1 = (LPSTR)lpString2;
|
---|
251 | *s1 && *s1 != *lpString1;
|
---|
252 | s1++)
|
---|
253 | /* empty */
|
---|
254 | ;
|
---|
255 |
|
---|
256 | if (*s1)
|
---|
257 | return (LPSTR)lpString1;
|
---|
258 |
|
---|
259 | lpString1++;
|
---|
260 | }
|
---|
261 |
|
---|
262 | return (LPSTR)NULL;
|
---|
263 | }
|
---|
264 |
|
---|
265 |
|
---|
266 | /*****************************************************************************
|
---|
267 | * Name : StrPBrkW
|
---|
268 | * Purpose : find the first occurence in string1 of any character from string2
|
---|
269 | * Parameters:
|
---|
270 | * Variables :
|
---|
271 | * Result :
|
---|
272 | * Remark :
|
---|
273 | * Status : UNTESTED
|
---|
274 | *
|
---|
275 | * Author :
|
---|
276 | *****************************************************************************/
|
---|
277 |
|
---|
278 | ODINFUNCTION2(LPWSTR, StrPBrkW,
|
---|
279 | LPCWSTR, lpString1,
|
---|
280 | LPCWSTR, lpString2)
|
---|
281 | {
|
---|
282 | register LPWSTR s1;
|
---|
283 |
|
---|
284 | while (*lpString1)
|
---|
285 | {
|
---|
286 | for (s1 = (LPWSTR)lpString2;
|
---|
287 | *s1 && *s1 != *lpString1;
|
---|
288 | s1++)
|
---|
289 | /* empty */
|
---|
290 | ;
|
---|
291 |
|
---|
292 | if (*s1)
|
---|
293 | return (LPWSTR)lpString1;
|
---|
294 |
|
---|
295 | lpString1++;
|
---|
296 | }
|
---|
297 |
|
---|
298 | return (LPWSTR)NULL;
|
---|
299 | }
|
---|
300 |
|
---|
301 |
|
---|
302 | /*************************************************************************
|
---|
303 | * StrRStrIA [SHLWAPI]
|
---|
304 | */
|
---|
305 | LPSTR WINAPI StrRStrIA(LPCSTR lpFirst, LPCSTR lpSrch, LPCSTR unknown)
|
---|
306 | {
|
---|
307 | INT iLen = lstrlenA(lpFirst) - lstrlenA(lpSrch);
|
---|
308 |
|
---|
309 | dprintf(("StrRStrIA %x %x %x NOT IMPLEMENTED correctly", lpFirst, lpSrch, unknown));
|
---|
310 |
|
---|
311 | // lpSrch cannot fit into lpFirst
|
---|
312 | if (iLen < 0)
|
---|
313 | return (LPSTR)NULL;
|
---|
314 |
|
---|
315 | LPSTR lpThis = (LPSTR)lpFirst + iLen;
|
---|
316 |
|
---|
317 | while (lpThis >= lpFirst)
|
---|
318 | {
|
---|
319 | LPCSTR p1 = lpThis, p2 = lpSrch;
|
---|
320 | while (*p1 && *p2 && toupper(*p1) == toupper(*p2)) { p1++; p2++; }
|
---|
321 | if (!*p2) return (LPSTR)lpThis;
|
---|
322 | lpThis--;
|
---|
323 | }
|
---|
324 |
|
---|
325 | return NULL;
|
---|
326 | }
|
---|
327 |
|
---|
328 |
|
---|
329 | /*************************************************************************
|
---|
330 | * StrRStrIW [SHLWAPI]
|
---|
331 | */
|
---|
332 | LPWSTR WINAPI StrRStrIW(LPCWSTR lpFirst, LPCWSTR lpSrch, LPCWSTR unknown)
|
---|
333 | {
|
---|
334 | INT iLen = lstrlenW(lpFirst) - lstrlenW(lpSrch);
|
---|
335 |
|
---|
336 | dprintf(("StrRStrIA %x %x %x NOT IMPLEMENTED correctly", lpFirst, lpSrch, unknown));
|
---|
337 |
|
---|
338 | // lpSrch cannot fit into lpFirst
|
---|
339 | if (iLen < 0)
|
---|
340 | return (LPWSTR)NULL;
|
---|
341 |
|
---|
342 | LPWSTR lpThis = (LPWSTR)lpFirst + iLen;
|
---|
343 |
|
---|
344 | while (lpThis >= lpFirst)
|
---|
345 | {
|
---|
346 | LPCWSTR p1 = lpThis, p2 = lpSrch;
|
---|
347 | while (*p1 && *p2 && toupperW(*p1) == toupperW(*p2)) { p1++; p2++; }
|
---|
348 | if (!*p2) return (LPWSTR)lpThis;
|
---|
349 | lpThis--;
|
---|
350 | }
|
---|
351 |
|
---|
352 | return NULL;
|
---|
353 | }
|
---|