Implemented localeconv() with libc function.
[wine.git] / dlls / shell32 / debughlp.c
blob9cac1dcbf1865fff382cc822d21a646b2402e977
1 /*
2 * Helper functions for debugging
4 * Copyright 1998, 2002 Juergen Schmied
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <ctype.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <stdio.h>
25 #include "pidl.h"
26 #include "shlguid.h"
27 #include "wine/debug.h"
28 #include "debughlp.h"
29 #include "docobj.h"
30 #include "shell32_main.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(pidl);
35 LPITEMIDLIST _dbg_ILGetNext(LPITEMIDLIST pidl)
37 WORD len;
39 if(pidl)
41 len = pidl->mkid.cb;
42 if (len)
44 pidl = (LPITEMIDLIST) (((LPBYTE)pidl)+len);
45 return pidl;
48 return NULL;
51 BOOL _dbg_ILIsDesktop(LPCITEMIDLIST pidl)
53 return ( !pidl || (pidl && pidl->mkid.cb == 0x00) );
56 LPPIDLDATA _dbg_ILGetDataPointer(LPITEMIDLIST pidl)
58 if(pidl && pidl->mkid.cb != 0x00)
59 return (LPPIDLDATA) &(pidl->mkid.abID);
60 return NULL;
63 LPSTR _dbg_ILGetTextPointer(LPCITEMIDLIST pidl)
65 LPPIDLDATA pdata =_dbg_ILGetDataPointer(pidl);
67 if (pdata)
69 switch (pdata->type)
71 case PT_MYCOMP:
72 case PT_SPECIAL:
73 return NULL;
75 case PT_DRIVE:
76 case PT_DRIVE1:
77 case PT_DRIVE2:
78 case PT_DRIVE3:
79 return (LPSTR)&(pdata->u.drive.szDriveName);
81 case PT_FOLDER:
82 case PT_FOLDER1:
83 case PT_VALUE:
84 case PT_IESPECIAL1:
85 case PT_IESPECIAL2:
86 return (LPSTR)&(pdata->u.file.szNames);
88 case PT_WORKGRP:
89 case PT_COMP:
90 case PT_NETWORK:
91 case PT_NETPROVIDER:
92 case PT_SHARE:
93 return (LPSTR)&(pdata->u.network.szNames);
96 return NULL;
99 LPSTR _dbg_ILGetSTextPointer(LPCITEMIDLIST pidl)
101 LPPIDLDATA pdata =_dbg_ILGetDataPointer(pidl);
103 if (pdata)
105 switch (pdata->type)
107 case PT_FOLDER:
108 case PT_VALUE:
109 case PT_IESPECIAL1:
110 case PT_IESPECIAL2:
111 return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1);
113 case PT_WORKGRP:
114 return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1);
117 return NULL;
120 REFIID _dbg_ILGetGUIDPointer(LPCITEMIDLIST pidl)
122 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
124 if (pdata)
126 switch (pdata->type)
128 case PT_SPECIAL:
129 case PT_MYCOMP:
130 return (REFIID) &(pdata->u.mycomp.guid);
133 return NULL;
136 DWORD _dbg_ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
138 DWORD dwReturn=0;
139 LPSTR szSrc;
140 GUID const * riid;
141 char szTemp[MAX_PATH];
143 if (!pidl) return 0;
145 if (szOut)
146 *szOut = 0;
148 if (_dbg_ILIsDesktop(pidl))
150 /* desktop */
151 if (szOut) strncpy(szOut, "Desktop", uOutSize);
152 dwReturn = strlen ("Desktop");
154 else if (( szSrc = _dbg_ILGetTextPointer(pidl) ))
156 /* filesystem */
157 if (szOut) strncpy(szOut, szSrc, uOutSize);
158 dwReturn = strlen(szSrc);
160 else if (( riid = _dbg_ILGetGUIDPointer(pidl) ))
162 if (szOut)
163 sprintf( szOut, "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
164 riid->Data1, riid->Data2, riid->Data3,
165 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
166 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7] );
167 dwReturn = strlen (szTemp);
169 return dwReturn;
175 void pdump (LPCITEMIDLIST pidl)
177 LPITEMIDLIST pidltemp = pidl;
179 if (!TRACE_ON(pidl)) return;
181 if (! pidltemp)
183 MESSAGE ("-------- pidl=NULL (Desktop)\n");
185 else
187 MESSAGE ("-------- pidl=%p\n", pidl);
188 if (pidltemp->mkid.cb)
192 DWORD dwAttrib = 0;
193 LPPIDLDATA pData = _dbg_ILGetDataPointer(pidltemp);
194 DWORD type = pData->type;
195 LPSTR szLongName = _dbg_ILGetTextPointer(pidltemp);
196 LPSTR szShortName = _dbg_ILGetSTextPointer(pidltemp);
197 char szName[MAX_PATH];
199 _dbg_ILSimpleGetText(pidltemp, szName, MAX_PATH);
200 if( PT_FOLDER == type)
201 dwAttrib = pData->u.folder.uFileAttribs;
202 else if( PT_VALUE == type)
203 dwAttrib = pData->u.file.uFileAttribs;
205 MESSAGE ("[%p] size=%04u type=%lx attr=0x%08lx name=\"%s\" (%s,%s)\n",
206 pidltemp, pidltemp->mkid.cb,type,dwAttrib,szName,debugstr_a(szLongName), debugstr_a(szShortName));
208 pidltemp = _dbg_ILGetNext(pidltemp);
210 } while (pidltemp->mkid.cb);
212 else
214 MESSAGE ("empty pidl (Desktop)\n");
216 pcheck(pidl);
219 #define BYTES_PRINTED 32
220 BOOL pcheck (LPCITEMIDLIST pidl)
222 DWORD type, ret=TRUE;
223 LPITEMIDLIST pidltemp = pidl;
225 if (pidltemp && pidltemp->mkid.cb)
226 { do
227 { type = _dbg_ILGetDataPointer(pidltemp)->type;
228 switch (type)
229 { case PT_DESKTOP:
230 case PT_MYCOMP:
231 case PT_SPECIAL:
232 case PT_DRIVE:
233 case PT_DRIVE1:
234 case PT_DRIVE2:
235 case PT_DRIVE3:
236 case PT_FOLDER:
237 case PT_VALUE:
238 case PT_FOLDER1:
239 case PT_WORKGRP:
240 case PT_COMP:
241 case PT_NETWORK:
242 case PT_IESPECIAL1:
243 case PT_IESPECIAL2:
244 case PT_SHARE:
245 break;
246 default:
248 char szTemp[BYTES_PRINTED*4 + 1];
249 int i;
250 unsigned char c;
252 memset(szTemp, ' ', BYTES_PRINTED*4 + 1);
253 for ( i = 0; (i<pidltemp->mkid.cb) && (i<BYTES_PRINTED); i++)
255 c = ((unsigned char *)pidltemp)[i];
257 szTemp[i*3+0] = ((c>>4)>9)? (c>>4)+55 : (c>>4)+48;
258 szTemp[i*3+1] = ((0x0F&c)>9)? (0x0F&c)+55 : (0x0F&c)+48;
259 szTemp[i*3+2] = ' ';
260 szTemp[i+BYTES_PRINTED*3] = (c>=0x20 && c <=0x80) ? c : '.';
262 szTemp[BYTES_PRINTED*4] = 0x00;
263 ERR("unknown IDLIST %p [%p] size=%u type=%lx\n%s\n",pidl, pidltemp, pidltemp->mkid.cb,type, szTemp);
264 ret = FALSE;
267 pidltemp = _dbg_ILGetNext(pidltemp);
268 } while (pidltemp->mkid.cb);
270 return ret;
273 static char shdebugstr_buf1[100];
274 static char shdebugstr_buf2[100];
275 static char * shdebugstr_buf = shdebugstr_buf1;
277 static struct {
278 REFIID riid;
279 char *name;
280 } InterfaceDesc[] = {
281 {&IID_IUnknown, "IID_IUnknown"},
282 {&IID_IClassFactory, "IID_IClassFactory"},
283 {&IID_IShellView, "IID_IShellView"},
284 {&IID_IOleCommandTarget, "IID_IOleCommandTarget"},
285 {&IID_IDropTarget, "IID_IDropTarget"},
286 {&IID_IDropSource, "IID_IDropSource"},
287 {&IID_IViewObject, "IID_IViewObject"},
288 {&IID_IContextMenu, "IID_IContextMenu"},
289 {&IID_IShellExtInit, "IID_IShellExtInit"},
290 {&IID_IShellFolder, "IID_IShellFolder"},
291 {&IID_IShellFolder2, "IID_IShellFolder2"},
292 {&IID_IPersist, "IID_IPersist"},
293 {&IID_IPersistFolder, "IID_IPersistFolder"},
294 {&IID_IPersistFolder2, "IID_IPersistFolder2"},
295 {&IID_IPersistFolder3, "IID_IPersistFolder3"},
296 {&IID_IExtractIconA, "IID_IExtractIconA"},
297 {&IID_IExtractIconW, "IID_IExtractIconW"},
298 {&IID_IDataObject, "IID_IDataObject"},
299 {NULL,NULL}};
301 const char * shdebugstr_guid( const struct _GUID *id )
303 int i;
304 char* name = NULL;
305 char clsidbuf[100];
307 shdebugstr_buf = (shdebugstr_buf == shdebugstr_buf1) ? shdebugstr_buf2 : shdebugstr_buf1;
309 if (!id) {
310 strcpy (shdebugstr_buf, "(null)");
311 } else {
312 for (i=0;InterfaceDesc[i].riid && !name;i++) {
313 if (IsEqualIID(InterfaceDesc[i].riid, id)) name = InterfaceDesc[i].name;
315 if (!name) {
316 if (HCR_GetClassNameA(id, clsidbuf, 100))
317 name = clsidbuf;
320 sprintf( shdebugstr_buf, "\n\t{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x} (%s)",
321 id->Data1, id->Data2, id->Data3,
322 id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
323 id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7], name ? name : "unknown" );
325 return shdebugstr_buf;