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