13 #include "wine/unicode.h"
14 #include "debugtools.h"
16 DEFAULT_DEBUG_CHANNEL(shell);
18 /*************************************************************************
21 LPSTR WINAPI StrChrA (LPCSTR str, WORD c)
23 TRACE("%s %i\n", str,c);
24 return strchr(str, c);
27 /*************************************************************************
31 LPWSTR WINAPI StrChrW (LPCWSTR str, WCHAR x )
33 TRACE("%s 0x%04x\n",debugstr_w(str),x);
34 return strchrW(str, x);
37 /*************************************************************************
40 int WINAPI StrCmpIW ( LPCWSTR wstr1, LPCWSTR wstr2 )
42 TRACE("%s %s\n", debugstr_w(wstr1),debugstr_w(wstr2));
43 return strcmpiW( wstr1, wstr2 );
46 /*************************************************************************
49 INT WINAPI StrCmpNA ( LPCSTR str1, LPCSTR str2, INT len)
51 TRACE("%s %s %i stub\n", str1,str2,len);
52 return strncmp(str1, str2, len);
55 /*************************************************************************
58 INT WINAPI StrCmpNW ( LPCWSTR wstr1, LPCWSTR wstr2, INT len)
60 TRACE("%s %s %i stub\n", debugstr_w(wstr1),debugstr_w(wstr2),len);
61 return strncmpW(wstr1, wstr2, len);
64 /*************************************************************************
67 int WINAPI StrCmpNIA ( LPCSTR str1, LPCSTR str2, int len)
69 TRACE("%s %s %i stub\n", str1,str2,len);
70 return strncasecmp(str1, str2, len);
73 /*************************************************************************
76 int WINAPI StrCmpNIW ( LPCWSTR wstr1, LPCWSTR wstr2, int len)
78 TRACE("%s %s %i stub\n", debugstr_w(wstr1),debugstr_w(wstr2),len);
79 return strncmpiW(wstr1, wstr2, len);
82 /*************************************************************************
85 int WINAPI StrCmpW ( LPCWSTR wstr1, LPCWSTR wstr2 )
87 TRACE("%s %s\n", debugstr_w(wstr1),debugstr_w(wstr2));
88 return strcmpW( wstr1, wstr2 );
91 /*************************************************************************
94 LPWSTR WINAPI StrCatW( LPWSTR wstr1, LPCWSTR wstr2 )
96 return strcatW( wstr1, wstr2 );
100 /*************************************************************************
103 LPWSTR WINAPI StrCpyW( LPWSTR wstr1, LPCWSTR wstr2 )
105 return strcpyW( wstr1, wstr2 );
109 /*************************************************************************
112 LPWSTR WINAPI StrCpyNW( LPWSTR wstr1, LPCWSTR wstr2, int n )
114 return lstrcpynW( wstr1, wstr2, n );
118 /*************************************************************************
121 LPSTR WINAPI StrStrA(LPCSTR lpFirst, LPCSTR lpSrch)
125 LPCSTR p1 = lpFirst, p2 = lpSrch;
126 while (*p1 && *p2 && *p1 == *p2) { p1++; p2++; }
127 if (!*p2) return (LPSTR)lpFirst;
133 /*************************************************************************
136 LPWSTR WINAPI StrStrW(LPCWSTR lpFirst, LPCWSTR lpSrch)
140 LPCWSTR p1 = lpFirst, p2 = lpSrch;
141 while (*p1 && *p2 && *p1 == *p2) { p1++; p2++; }
142 if (!*p2) return (LPWSTR)lpFirst;
148 /*************************************************************************
151 LPSTR WINAPI StrStrIA(LPCSTR lpFirst, LPCSTR lpSrch)
155 LPCSTR p1 = lpFirst, p2 = lpSrch;
156 while (*p1 && *p2 && toupper(*p1) == toupper(*p2)) { p1++; p2++; }
157 if (!*p2) return (LPSTR)lpFirst;
163 /*************************************************************************
166 LPWSTR WINAPI StrStrIW(LPCWSTR lpFirst, LPCWSTR lpSrch)
170 LPCWSTR p1 = lpFirst, p2 = lpSrch;
171 while (*p1 && *p2 && toupperW(*p1) == toupperW(*p2)) { p1++; p2++; }
172 if (!*p2) return (LPWSTR)lpFirst;
178 /*************************************************************************
179 * StrToIntA [SHLWAPI]
181 int WINAPI StrToIntA(LPCSTR lpSrc)
183 TRACE("%s\n", lpSrc);
187 /*************************************************************************
188 * StrToIntW [SHLWAPI]
190 int WINAPI StrToIntW(LPCWSTR lpSrc)
194 TRACE("%s\n", debugstr_w(lpSrc));
195 WideCharToMultiByte( CP_ACP, 0, lpSrc, -1, buffer, sizeof(buffer), NULL, NULL );
196 buffer[sizeof(buffer)-1] = 0;
200 /*************************************************************************
203 LPSTR WINAPI StrDupA (LPCSTR lpSrc)
205 int len = strlen(lpSrc);
206 LPSTR lpDest = (LPSTR) LocalAlloc(LMEM_FIXED, len+1);
208 TRACE("%s\n", lpSrc);
210 if (lpDest) strcpy(lpDest, lpSrc);
214 /*************************************************************************
217 LPWSTR WINAPI StrDupW (LPCWSTR lpSrc)
219 int len = strlenW(lpSrc);
220 LPWSTR lpDest = (LPWSTR) LocalAlloc(LMEM_FIXED, sizeof(WCHAR) * (len+1));
222 TRACE("%s\n", debugstr_w(lpSrc));
224 if (lpDest) strcpyW(lpDest, lpSrc);
228 /*************************************************************************
231 int WINAPI StrCSpnA (LPCSTR lpStr, LPCSTR lpSet)
233 int i,j, pos = strlen(lpStr);
235 TRACE("(%p %s %p %s)\n",
236 lpStr, debugstr_a(lpStr), lpSet, debugstr_a(lpSet));
238 for (i=0; i < strlen(lpSet) ; i++ )
240 for (j = 0; j < pos;j++)
242 if (lpStr[j] == lpSet[i])
248 TRACE("-- %u\n", pos);
252 /*************************************************************************
255 int WINAPI StrCSpnW (LPCWSTR lpStr, LPCWSTR lpSet)
257 int i,j, pos = strlenW(lpStr);
259 TRACE("(%p %s %p %s)\n",
260 lpStr, debugstr_w(lpStr), lpSet, debugstr_w(lpSet));
262 for (i=0; i < strlenW(lpSet) ; i++ )
264 for (j = 0; j < pos;j++)
266 if (lpStr[j] == lpSet[i])
272 TRACE("-- %u\n", pos);
276 /**************************************************************************
277 * StrRChrA [SHLWAPI.@]
280 LPSTR WINAPI StrRChrA( LPCSTR lpStart, LPCSTR lpEnd, WORD wMatch )
282 LPCSTR lpGotIt = NULL;
283 BOOL dbcs = IsDBCSLeadByte( LOBYTE(wMatch) );
285 TRACE("(%p, %p, %x)\n", lpStart, lpEnd, wMatch);
287 if (!lpEnd) lpEnd = lpStart + strlen(lpStart);
289 for(; lpStart < lpEnd; lpStart = CharNextA(lpStart))
291 if (*lpStart != LOBYTE(wMatch)) continue;
292 if (dbcs && lpStart[1] != HIBYTE(wMatch)) continue;
295 return (LPSTR)lpGotIt;
299 /**************************************************************************
300 * StrRChrW [SHLWAPI.@]
303 LPWSTR WINAPI StrRChrW( LPCWSTR lpStart, LPCWSTR lpEnd, WORD wMatch)
305 LPCWSTR lpGotIt = NULL;
307 TRACE("(%p, %p, %x)\n", lpStart, lpEnd, wMatch);
308 if (!lpEnd) lpEnd = lpStart + strlenW(lpStart);
310 for(; lpStart < lpEnd; lpStart = CharNextW(lpStart))
311 if (*lpStart == wMatch) lpGotIt = lpStart;
313 return (LPWSTR)lpGotIt;
317 /*************************************************************************
318 * StrCatBuffA [SHLWAPI]
320 * Appends back onto front, stopping when front is size-1 characters long.
324 LPSTR WINAPI StrCatBuffA(LPSTR front, LPCSTR back, INT size)
326 LPSTR dst = front + strlen(front);
327 LPCSTR src = back, end = front + size - 1;
329 while(dst < end && *src)
335 /*************************************************************************
336 * StrCatBuffW [SHLWAPI]
338 * Appends back onto front, stopping when front is size-1 characters long.
342 LPWSTR WINAPI StrCatBuffW(LPWSTR front, LPCWSTR back, INT size)
344 LPWSTR dst = front + strlenW(front);
345 LPCWSTR src = back, end = front + size - 1;
347 while(dst < end && *src)
353 /*************************************************************************
354 * StrRetToBufA [SHLWAPI.@]
356 * converts a STRRET to a normal string
359 * the pidl is for STRRET OFFSET
361 HRESULT WINAPI StrRetToBufA (LPSTRRET src, const ITEMIDLIST *pidl, LPSTR dest, DWORD len)
363 TRACE("dest=0x%p len=0x%lx strret=0x%p pidl=%p stub\n",dest,len,src,pidl);
368 WideCharToMultiByte(CP_ACP, 0, src->u.pOleStr, -1, (LPSTR)dest, len, NULL, NULL);
369 /* SHFree(src->u.pOleStr); FIXME: is this right? */
373 lstrcpynA((LPSTR)dest, src->u.cStr, len);
377 lstrcpynA((LPSTR)dest, ((LPCSTR)&pidl->mkid)+src->u.uOffset, len);
381 FIXME("unknown type!\n");
391 /*************************************************************************
392 * StrRetToBufW [SHLWAPI.@]
394 * converts a STRRET to a normal string
397 * the pidl is for STRRET OFFSET
399 HRESULT WINAPI StrRetToBufW (LPSTRRET src, const ITEMIDLIST *pidl, LPWSTR dest, DWORD len)
401 TRACE("dest=0x%p len=0x%lx strret=0x%p pidl=%p stub\n",dest,len,src,pidl);
406 lstrcpynW((LPWSTR)dest, src->u.pOleStr, len);
407 /* SHFree(src->u.pOleStr); FIXME: is this right? */
411 if (!MultiByteToWideChar( CP_ACP, 0, src->u.cStr, -1, dest, len ) && len)
418 if (!MultiByteToWideChar( CP_ACP, 0, ((LPCSTR)&pidl->mkid)+src->u.uOffset, -1,
425 FIXME("unknown type!\n");
427 { *(LPSTR)dest = '\0';
434 /*************************************************************************
435 * StrFormatByteSizeA [SHLWAPI]
437 LPSTR WINAPI StrFormatByteSizeA ( DWORD dw, LPSTR pszBuf, UINT cchBuf )
439 TRACE("%lx %p %i\n", dw, pszBuf, cchBuf);
441 { sprintf (buf,"%ld bytes", dw);
443 else if ( dw<1048576L)
444 { sprintf (buf,"%3.1f KB", (FLOAT)dw/1024);
446 else if ( dw < 1073741824L)
447 { sprintf (buf,"%3.1f MB", (FLOAT)dw/1048576L);
450 { sprintf (buf,"%3.1f GB", (FLOAT)dw/1073741824L);
452 lstrcpynA (pszBuf, buf, cchBuf);
456 /*************************************************************************
457 * StrFormatByteSizeW [SHLWAPI]
459 LPWSTR WINAPI StrFormatByteSizeW ( DWORD dw, LPWSTR pszBuf, UINT cchBuf )
462 StrFormatByteSizeA( dw, buf, sizeof(buf) );
463 if (!MultiByteToWideChar( CP_ACP, 0, buf, -1, pszBuf, cchBuf ) && cchBuf)
464 pszBuf[cchBuf-1] = 0;
468 /*************************************************************************
469 * wnsprintfA [SHLWAPI]
471 int WINAPIV wnsprintfA(LPSTR lpOut, int cchLimitIn, LPCSTR lpFmt, ...)
476 va_start( valist, lpFmt );
477 res = wvsnprintfA( lpOut, cchLimitIn, lpFmt, valist );
482 /*************************************************************************
483 * wnsprintfW [SHLWAPI]
485 int WINAPIV wnsprintfW(LPWSTR lpOut, int cchLimitIn, LPCWSTR lpFmt, ...)
490 va_start( valist, lpFmt );
491 res = wvsnprintfW( lpOut, cchLimitIn, lpFmt, valist );