1 | /* $Id: string_odin.cpp,v 1.4 2001-08-30 19:19:59 phaller 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 | #include <wcstr.h>
|
---|
36 | #define HAVE_WCTYPE_H
|
---|
37 |
|
---|
38 | #include "debugtools.h"
|
---|
39 |
|
---|
40 | #include <winreg.h>
|
---|
41 |
|
---|
42 | #include <heapstring.h>
|
---|
43 | #include <misc.h>
|
---|
44 | #include <win\shell.h>
|
---|
45 | #include <win\winerror.h>
|
---|
46 | #include <winversion.h>
|
---|
47 | #include <winuser.h>
|
---|
48 |
|
---|
49 |
|
---|
50 | #define ICOM_CINTERFACE 1
|
---|
51 | #define CINTERFACE 1
|
---|
52 |
|
---|
53 | #include "winerror.h"
|
---|
54 | #include "winnls.h"
|
---|
55 | #include "winversion.h"
|
---|
56 | #include "heap.h"
|
---|
57 |
|
---|
58 | #include "shellapi.h"
|
---|
59 | #include "shlobj.h"
|
---|
60 | #include "wine/undocshell.h"
|
---|
61 |
|
---|
62 | #include "shlwapi_odin.h"
|
---|
63 | #include "shlwapi.h"
|
---|
64 |
|
---|
65 | /*****************************************************************************
|
---|
66 | * Local Variables *
|
---|
67 | *****************************************************************************/
|
---|
68 |
|
---|
69 | ODINDEBUGCHANNEL(SHLWAPI-STRING)
|
---|
70 |
|
---|
71 |
|
---|
72 | /*****************************************************************************
|
---|
73 | * Name : ChrCmpIA
|
---|
74 | * Purpose :
|
---|
75 | * Parameters:
|
---|
76 | * Variables :
|
---|
77 | * Result :
|
---|
78 | * Remark :
|
---|
79 | * Status : PARTIALLY IMPLEMENTED UNTESTED
|
---|
80 | *
|
---|
81 | * Author : Patrick Haller [Wed, 1999/12/29 09:00]
|
---|
82 | *****************************************************************************/
|
---|
83 |
|
---|
84 | ODINFUNCTION2(INT, ChrCmpIA,
|
---|
85 | INT, ch1,
|
---|
86 | INT, ch2)
|
---|
87 | {
|
---|
88 | // Note: IsDBCSLeadByte ignored !
|
---|
89 |
|
---|
90 | if ( (ch1 >= 'A') && (ch1 <= 'Z') ) ch1 |= 0x20;
|
---|
91 | if ( (ch2 >= 'A') && (ch2 <= 'Z') ) ch2 |= 0x20;
|
---|
92 |
|
---|
93 | return ch1 - ch2;
|
---|
94 | }
|
---|
95 |
|
---|
96 |
|
---|
97 | #if 0
|
---|
98 | /*************************************************************************
|
---|
99 | * OleStrToStrN [SHELL32.78]
|
---|
100 | */
|
---|
101 | BOOL WINAPI OleStrToStrNA (LPSTR lpStr, INT nStr, LPCWSTR lpOle, INT nOle)
|
---|
102 | {
|
---|
103 | TRACE("%p %x %s %x\n", lpStr, nStr, debugstr_w(lpOle), nOle);
|
---|
104 | return WideCharToMultiByte (0, 0, lpOle, nOle, lpStr, nStr, NULL, NULL);
|
---|
105 | }
|
---|
106 |
|
---|
107 | BOOL WINAPI OleStrToStrNW (LPWSTR lpwStr, INT nwStr, LPCWSTR lpOle, INT nOle)
|
---|
108 | {
|
---|
109 | TRACE("%p %x %s %x\n", lpwStr, nwStr, debugstr_w(lpOle), nOle);
|
---|
110 |
|
---|
111 | if (lstrcpynW ( lpwStr, lpOle, nwStr))
|
---|
112 | { return lstrlenW (lpwStr);
|
---|
113 | }
|
---|
114 | return 0;
|
---|
115 | }
|
---|
116 |
|
---|
117 | BOOL WINAPI OleStrToStrNAW (LPVOID lpOut, INT nOut, LPCVOID lpIn, INT nIn)
|
---|
118 | {
|
---|
119 | if (VERSION_OsIsUnicode())
|
---|
120 | return OleStrToStrNW ((LPWSTR)lpOut, nOut, (LPCWSTR)lpIn, nIn);
|
---|
121 | return OleStrToStrNA ((LPSTR)lpOut, nOut, (LPCWSTR)lpIn, nIn);
|
---|
122 | }
|
---|
123 |
|
---|
124 | /*************************************************************************
|
---|
125 | * StrToOleStrN [SHELL32.79]
|
---|
126 | * lpMulti, nMulti, nWide [IN]
|
---|
127 | * lpWide [OUT]
|
---|
128 | */
|
---|
129 | BOOL WINAPI StrToOleStrNA (LPWSTR lpWide, INT nWide, LPCSTR lpStrA, INT nStr)
|
---|
130 | {
|
---|
131 | TRACE("%p %x %s %x\n", lpWide, nWide, lpStrA, nStr);
|
---|
132 | return MultiByteToWideChar (0, 0, lpStrA, nStr, lpWide, nWide);
|
---|
133 | }
|
---|
134 | BOOL WINAPI StrToOleStrNW (LPWSTR lpWide, INT nWide, LPCWSTR lpStrW, INT nStr)
|
---|
135 | {
|
---|
136 | TRACE("%p %x %s %x\n", lpWide, nWide, debugstr_w(lpStrW), nStr);
|
---|
137 |
|
---|
138 | if (lstrcpynW (lpWide, lpStrW, nWide))
|
---|
139 | { return lstrlenW (lpWide);
|
---|
140 | }
|
---|
141 | return 0;
|
---|
142 | }
|
---|
143 |
|
---|
144 | BOOL WINAPI StrToOleStrNAW (LPWSTR lpWide, INT nWide, LPCVOID lpStr, INT nStr)
|
---|
145 | {
|
---|
146 | if (VERSION_OsIsUnicode())
|
---|
147 | return StrToOleStrNW (lpWide, nWide, (LPWSTR)lpStr, nStr);
|
---|
148 | return StrToOleStrNA (lpWide, nWide, (LPSTR)lpStr, nStr);
|
---|
149 | }
|
---|
150 |
|
---|
151 |
|
---|
152 |
|
---|
153 |
|
---|
154 | /************************************************************************
|
---|
155 | * StrToOleStr [SHELL32.163]
|
---|
156 | *
|
---|
157 | */
|
---|
158 | int WINAPI StrToOleStrA (LPWSTR lpWideCharStr, LPCSTR lpMultiByteString)
|
---|
159 | {
|
---|
160 | TRACE("%p %p(%s)\n",
|
---|
161 | lpWideCharStr, lpMultiByteString, lpMultiByteString);
|
---|
162 |
|
---|
163 | return MultiByteToWideChar(0, 0, lpMultiByteString, -1, lpWideCharStr, MAX_PATH);
|
---|
164 |
|
---|
165 | }
|
---|
166 | int WINAPI StrToOleStrW (LPWSTR lpWideCharStr, LPCWSTR lpWString)
|
---|
167 | {
|
---|
168 | TRACE("%p %p(%s)\n",
|
---|
169 | lpWideCharStr, lpWString, debugstr_w(lpWString));
|
---|
170 |
|
---|
171 | if (lstrcpyW (lpWideCharStr, lpWString ))
|
---|
172 | { return lstrlenW (lpWideCharStr);
|
---|
173 | }
|
---|
174 | return 0;
|
---|
175 | }
|
---|
176 |
|
---|
177 | BOOL WINAPI StrToOleStrAW (LPWSTR lpWideCharStr, LPCVOID lpString)
|
---|
178 | {
|
---|
179 | if (VERSION_OsIsUnicode())
|
---|
180 | return StrToOleStrW (lpWideCharStr, (LPCWSTR)lpString);
|
---|
181 | return StrToOleStrA (lpWideCharStr, (LPCSTR)lpString);
|
---|
182 | }
|
---|
183 | #endif
|
---|
184 |
|
---|
185 |
|
---|
186 | /*****************************************************************************
|
---|
187 | * Name : StrChrIA
|
---|
188 | * Purpose : Searches a string for the first occurrence of a character that
|
---|
189 | * matches the specified character. The comparison is not case sensitive.
|
---|
190 | * Parameters: LPCSTR lpStart Address of the string to be searched.
|
---|
191 | * TCHAR wMatch Character to be used for comparison.
|
---|
192 | * Variables :
|
---|
193 | * Result : Returns the address of the first occurrence of the character in
|
---|
194 | * the string if successful, or NULL otherwise.
|
---|
195 | * Remark : SHELL32.
|
---|
196 | * Status : COMPLETELY IMPLEMENTED UNTESTED UNKNOWN
|
---|
197 | *
|
---|
198 | * Author : Patrick Haller [Wed, 1999/12/29 09:00]
|
---|
199 | *****************************************************************************/
|
---|
200 |
|
---|
201 | ODINFUNCTION2(LPSTR, StrChrIA,
|
---|
202 | LPCSTR, lpStart,
|
---|
203 | WORD, wMatch)
|
---|
204 | {
|
---|
205 | LPSTR lpRes;
|
---|
206 |
|
---|
207 | wMatch = tolower(wMatch);
|
---|
208 | lpRes = strchr(lpStart, wMatch); // lower case comparsion
|
---|
209 | if (NULL == lpRes)
|
---|
210 | {
|
---|
211 | wMatch = toupper(wMatch);
|
---|
212 | lpRes = strchr(lpStart, wMatch); // upper case comparsion
|
---|
213 | }
|
---|
214 |
|
---|
215 | return lpRes;
|
---|
216 | }
|
---|
217 |
|
---|
218 |
|
---|
219 | /*****************************************************************************
|
---|
220 | * Name : StrChrIW
|
---|
221 | * Purpose : Searches a string for the first occurrence of a character that
|
---|
222 | * matches the specified character. The comparison is not case sensitive.
|
---|
223 | * Parameters: LPCSTR lpStart Address of the string to be searched.
|
---|
224 | * TCHAR wMatch Character to be used for comparison.
|
---|
225 | * Variables :
|
---|
226 | * Result : Returns the address of the first occurrence of the character in
|
---|
227 | * the string if successful, or NULL otherwise.
|
---|
228 | * Remark : SHELL32.
|
---|
229 | * Status : COMPLETELY IMPLEMENTED UNTESTED UNKNOWN
|
---|
230 | *
|
---|
231 | * Author : Patrick Haller [Wed, 1999/12/29 09:00]
|
---|
232 | *****************************************************************************/
|
---|
233 |
|
---|
234 | ODINFUNCTION2(LPWSTR, StrChrIW,
|
---|
235 | LPCWSTR, lpStart,
|
---|
236 | WCHAR, wMatch)
|
---|
237 | {
|
---|
238 | LPWSTR lpRes;
|
---|
239 |
|
---|
240 | wMatch = towlower(wMatch);
|
---|
241 | lpRes = (WCHAR*)wcschr((const wchar_t*)lpStart, wMatch); // lower case comparsion
|
---|
242 | if (NULL == lpRes)
|
---|
243 | {
|
---|
244 | wMatch = towupper(wMatch);
|
---|
245 | lpRes = (WCHAR*)wcschr((const wchar_t*)lpStart, wMatch); // upper case comparsion
|
---|
246 | }
|
---|
247 |
|
---|
248 | return lpRes;
|
---|
249 | }
|
---|
250 |
|
---|
251 |
|
---|
252 | /*****************************************************************************
|
---|
253 | * Name : StrCpyA
|
---|
254 | * Purpose : copy a string
|
---|
255 | * Parameters:
|
---|
256 | * Variables :
|
---|
257 | * Result :
|
---|
258 | * Remark : not exported ?
|
---|
259 | * Status : UNTESTED
|
---|
260 | *
|
---|
261 | * Author :
|
---|
262 | *****************************************************************************/
|
---|
263 |
|
---|
264 | ODINFUNCTIONNODBG2(LPSTR, StrCpyA,
|
---|
265 | LPSTR, lpDest,
|
---|
266 | LPCSTR, lpSource)
|
---|
267 | {
|
---|
268 | return lstrcpyA(lpDest,
|
---|
269 | lpSource);
|
---|
270 | }
|
---|
271 |
|
---|
272 |
|
---|
273 | /*****************************************************************************
|
---|
274 | * Name : StrSpnA
|
---|
275 | * Purpose : find the first occurence of a character in string1
|
---|
276 | * that is not contained in the set of characters specified by
|
---|
277 | * string2.
|
---|
278 | * Parameters:
|
---|
279 | * Variables :
|
---|
280 | * Result :
|
---|
281 | * Remark : COMCTL32undoc.StrSpnW, CRTDLL.strspn
|
---|
282 | * Status : UNTESTED
|
---|
283 | *
|
---|
284 | * Author :
|
---|
285 | *****************************************************************************/
|
---|
286 |
|
---|
287 | ODINFUNCTION2(INT, StrSpnA,
|
---|
288 | LPCSTR, lpString1,
|
---|
289 | LPCSTR, lpString2)
|
---|
290 | {
|
---|
291 | // 2001-08-30 PH
|
---|
292 | // copied from implementation in COMCTL32
|
---|
293 | if ( (lpString1 == NULL) ||
|
---|
294 | (lpString2 == NULL) )
|
---|
295 | return 0;
|
---|
296 |
|
---|
297 | LPSTR lpLoop = (LPSTR)lpString1;
|
---|
298 |
|
---|
299 | for (; (*lpLoop != 0); lpLoop++ )
|
---|
300 | if ( StrChrA( lpString2, *lpLoop ) )
|
---|
301 | return (INT) (lpLoop - lpString1);
|
---|
302 |
|
---|
303 | return (INT) (lpLoop - lpString1);
|
---|
304 | }
|
---|
305 |
|
---|
306 |
|
---|
307 | /*****************************************************************************
|
---|
308 | * Name : StrSpnW
|
---|
309 | * Purpose : find the first occurence of a character in string1
|
---|
310 | * that is not contained in the set of characters specified by
|
---|
311 | * string2.
|
---|
312 | * Parameters:
|
---|
313 | * Variables :
|
---|
314 | * Result :
|
---|
315 | * Remark : COMCTL32undoc.StrSpnW, CRTDLL.strspn
|
---|
316 | * Status : UNTESTED
|
---|
317 | *
|
---|
318 | * Author :
|
---|
319 | *****************************************************************************/
|
---|
320 |
|
---|
321 | ODINFUNCTION2(INT, StrSpnW,
|
---|
322 | LPCWSTR, lpString1,
|
---|
323 | LPCWSTR, lpString2)
|
---|
324 | {
|
---|
325 | // 2001-08-30 PH
|
---|
326 | // copied from implementation in COMCTL32
|
---|
327 | if ( (lpString1 == NULL) ||
|
---|
328 | (lpString2 == NULL) )
|
---|
329 | return 0;
|
---|
330 |
|
---|
331 | LPWSTR lpLoop = (LPWSTR)lpString1;
|
---|
332 |
|
---|
333 | for (; (*lpLoop != 0); lpLoop++ )
|
---|
334 | if ( StrChrW( lpString2, *lpLoop ) )
|
---|
335 | return (INT) (lpLoop - lpString1);
|
---|
336 |
|
---|
337 | return (INT) (lpLoop - lpString1);
|
---|
338 | }
|
---|
339 |
|
---|
340 |
|
---|
341 | /*****************************************************************************
|
---|
342 | * Name : StrPBrkA
|
---|
343 | * Purpose : find the first occurence in string1 of any character from string2
|
---|
344 | * Parameters:
|
---|
345 | * Variables :
|
---|
346 | * Result :
|
---|
347 | * Remark :
|
---|
348 | * Status : UNTESTED
|
---|
349 | *
|
---|
350 | * Author :
|
---|
351 | *****************************************************************************/
|
---|
352 |
|
---|
353 | ODINFUNCTION2(LPSTR, StrPBrkA,
|
---|
354 | LPCSTR, lpString1,
|
---|
355 | LPCSTR, lpString2)
|
---|
356 | {
|
---|
357 | register LPSTR s1;
|
---|
358 |
|
---|
359 | while (*lpString1)
|
---|
360 | {
|
---|
361 | for (s1 = (LPSTR)lpString2;
|
---|
362 | *s1 && *s1 != *lpString1;
|
---|
363 | s1++)
|
---|
364 | /* empty */
|
---|
365 | ;
|
---|
366 |
|
---|
367 | if (*s1)
|
---|
368 | return (LPSTR)lpString1;
|
---|
369 |
|
---|
370 | lpString1++;
|
---|
371 | }
|
---|
372 |
|
---|
373 | return (LPSTR)NULL;
|
---|
374 | }
|
---|
375 |
|
---|
376 |
|
---|
377 | /*****************************************************************************
|
---|
378 | * Name : StrPBrkW
|
---|
379 | * Purpose : find the first occurence in string1 of any character from string2
|
---|
380 | * Parameters:
|
---|
381 | * Variables :
|
---|
382 | * Result :
|
---|
383 | * Remark :
|
---|
384 | * Status : UNTESTED
|
---|
385 | *
|
---|
386 | * Author :
|
---|
387 | *****************************************************************************/
|
---|
388 |
|
---|
389 | ODINFUNCTION2(LPWSTR, StrPBrkW,
|
---|
390 | LPCWSTR, lpString1,
|
---|
391 | LPCWSTR, lpString2)
|
---|
392 | {
|
---|
393 | register LPWSTR s1;
|
---|
394 |
|
---|
395 | while (*lpString1)
|
---|
396 | {
|
---|
397 | for (s1 = (LPWSTR)lpString2;
|
---|
398 | *s1 && *s1 != *lpString1;
|
---|
399 | s1++)
|
---|
400 | /* empty */
|
---|
401 | ;
|
---|
402 |
|
---|
403 | if (*s1)
|
---|
404 | return (LPWSTR)lpString1;
|
---|
405 |
|
---|
406 | lpString1++;
|
---|
407 | }
|
---|
408 |
|
---|
409 | return (LPWSTR)NULL;
|
---|
410 | }
|
---|
411 |
|
---|
412 |
|
---|
413 | /*************************************************************************
|
---|
414 | * StrRStrIA [SHLWAPI]
|
---|
415 | */
|
---|
416 | LPSTR WINAPI StrRStrIA(LPCSTR lpFirst, LPCSTR lpSrch)
|
---|
417 | {
|
---|
418 | INT iLen = lstrlenA(lpFirst) - lstrlenA(lpSrch);
|
---|
419 |
|
---|
420 | // lpSrch cannot fit into lpFirst
|
---|
421 | if (iLen < 0)
|
---|
422 | return (LPSTR)NULL;
|
---|
423 |
|
---|
424 | LPSTR lpThis = (LPSTR)lpFirst + iLen;
|
---|
425 |
|
---|
426 | while (lpThis >= lpFirst)
|
---|
427 | {
|
---|
428 | LPCSTR p1 = lpThis, p2 = lpSrch;
|
---|
429 | while (*p1 && *p2 && toupper(*p1) == toupper(*p2)) { p1++; p2++; }
|
---|
430 | if (!*p2) return (LPSTR)lpThis;
|
---|
431 | lpThis--;
|
---|
432 | }
|
---|
433 |
|
---|
434 | return NULL;
|
---|
435 | }
|
---|
436 |
|
---|
437 |
|
---|
438 | /*************************************************************************
|
---|
439 | * StrRStrIW [SHLWAPI]
|
---|
440 | */
|
---|
441 | LPWSTR WINAPI StrRStrIW(LPCWSTR lpFirst, LPCWSTR lpSrch)
|
---|
442 | {
|
---|
443 | INT iLen = lstrlenW(lpFirst) - lstrlenW(lpSrch);
|
---|
444 |
|
---|
445 | // lpSrch cannot fit into lpFirst
|
---|
446 | if (iLen < 0)
|
---|
447 | return (LPWSTR)NULL;
|
---|
448 |
|
---|
449 | LPWSTR lpThis = (LPWSTR)lpFirst + iLen;
|
---|
450 |
|
---|
451 | while (lpThis >= lpFirst)
|
---|
452 | {
|
---|
453 | LPCWSTR p1 = lpThis, p2 = lpSrch;
|
---|
454 | while (*p1 && *p2 && toupperW(*p1) == toupperW(*p2)) { p1++; p2++; }
|
---|
455 | if (!*p2) return (LPWSTR)lpThis;
|
---|
456 | lpThis--;
|
---|
457 | }
|
---|
458 |
|
---|
459 | return NULL;
|
---|
460 | }
|
---|