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