Use ERR instead of DPRINTF in dump_pidl_hex.
[wine/testsucceed.git] / dlls / shell32 / debughlp.c
blob03dceaf04fe21d09f469c53a0426789829a2a8a3
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 "windef.h"
26 #include "wingdi.h"
27 #include "pidl.h"
28 #include "shlguid.h"
29 #include "shldisp.h"
30 #include "wine/debug.h"
31 #include "debughlp.h"
32 #include "docobj.h"
33 #include "shell32_main.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(pidl);
38 static
39 LPITEMIDLIST _dbg_ILGetNext(LPCITEMIDLIST pidl)
41 WORD len;
43 if(pidl)
45 len = pidl->mkid.cb;
46 if (len)
48 return (LPITEMIDLIST) (((LPBYTE)pidl)+len);
51 return NULL;
54 static
55 BOOL _dbg_ILIsDesktop(LPCITEMIDLIST pidl)
57 return ( !pidl || (pidl && pidl->mkid.cb == 0x00) );
60 static
61 LPPIDLDATA _dbg_ILGetDataPointer(LPCITEMIDLIST pidl)
63 if(pidl && pidl->mkid.cb != 0x00)
64 return (LPPIDLDATA) &(pidl->mkid.abID);
65 return NULL;
68 static
69 LPSTR _dbg_ILGetTextPointer(LPCITEMIDLIST pidl)
71 LPPIDLDATA pdata =_dbg_ILGetDataPointer(pidl);
73 if (pdata)
75 switch (pdata->type)
77 case PT_GUID:
78 case PT_SHELLEXT:
79 case PT_YAGUID:
80 return NULL;
82 case PT_DRIVE:
83 case PT_DRIVE1:
84 case PT_DRIVE2:
85 case PT_DRIVE3:
86 return (LPSTR)&(pdata->u.drive.szDriveName);
88 case PT_FOLDER:
89 case PT_FOLDER1:
90 case PT_VALUE:
91 case PT_IESPECIAL1:
92 case PT_IESPECIAL2:
93 return (LPSTR)&(pdata->u.file.szNames);
95 case PT_WORKGRP:
96 case PT_COMP:
97 case PT_NETWORK:
98 case PT_NETPROVIDER:
99 case PT_SHARE:
100 return (LPSTR)&(pdata->u.network.szNames);
103 return NULL;
106 static
107 LPSTR _dbg_ILGetSTextPointer(LPCITEMIDLIST pidl)
109 LPPIDLDATA pdata =_dbg_ILGetDataPointer(pidl);
111 if (pdata)
113 switch (pdata->type)
115 case PT_FOLDER:
116 case PT_VALUE:
117 case PT_IESPECIAL1:
118 case PT_IESPECIAL2:
119 return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1);
121 case PT_WORKGRP:
122 return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1);
125 return NULL;
128 static
129 IID* _dbg_ILGetGUIDPointer(LPCITEMIDLIST pidl)
131 LPPIDLDATA pdata =_ILGetDataPointer(pidl);
133 if (pdata)
135 switch (pdata->type)
137 case PT_SHELLEXT:
138 case PT_GUID:
139 case PT_YAGUID:
140 return &(pdata->u.guid.guid);
143 return NULL;
146 static
147 DWORD _dbg_ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
149 DWORD dwReturn=0;
150 LPSTR szSrc;
151 GUID const * riid;
152 char szTemp[MAX_PATH];
154 if (!pidl) return 0;
156 if (szOut)
157 *szOut = 0;
159 if (_dbg_ILIsDesktop(pidl))
161 /* desktop */
162 if (szOut) lstrcpynA(szOut, "Desktop", uOutSize);
163 dwReturn = strlen ("Desktop");
165 else if (( szSrc = _dbg_ILGetTextPointer(pidl) ))
167 /* filesystem */
168 if (szOut) lstrcpynA(szOut, szSrc, uOutSize);
169 dwReturn = strlen(szSrc);
171 else if (( riid = _dbg_ILGetGUIDPointer(pidl) ))
173 if (szOut)
174 sprintf( szOut, "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
175 riid->Data1, riid->Data2, riid->Data3,
176 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
177 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7] );
178 dwReturn = strlen (szTemp);
180 return dwReturn;
186 void pdump (LPCITEMIDLIST pidl)
188 LPCITEMIDLIST pidltemp = pidl;
190 if (!TRACE_ON(pidl)) return;
192 if (! pidltemp)
194 MESSAGE ("-------- pidl=NULL (Desktop)\n");
196 else
198 MESSAGE ("-------- pidl=%p\n", pidl);
199 if (pidltemp->mkid.cb)
203 DWORD dwAttrib = 0;
204 LPPIDLDATA pData = _dbg_ILGetDataPointer(pidltemp);
205 DWORD type = pData->type;
206 LPSTR szLongName = _dbg_ILGetTextPointer(pidltemp);
207 LPSTR szShortName = _dbg_ILGetSTextPointer(pidltemp);
208 char szName[MAX_PATH];
210 _dbg_ILSimpleGetText(pidltemp, szName, MAX_PATH);
211 if( PT_FOLDER == type || PT_VALUE == type)
212 dwAttrib = pData->u.file.uFileAttribs;
214 MESSAGE ("[%p] size=%04u type=%lx attr=0x%08lx name=\"%s\" (%s,%s)\n",
215 pidltemp, pidltemp->mkid.cb,type,dwAttrib,szName,debugstr_a(szLongName), debugstr_a(szShortName));
217 pidltemp = _dbg_ILGetNext(pidltemp);
219 } while (pidltemp && pidltemp->mkid.cb);
221 else
223 MESSAGE ("empty pidl (Desktop)\n");
225 pcheck(pidl);
229 static void dump_pidl_hex( LPCITEMIDLIST pidl )
231 const unsigned char *p = (const unsigned char *)pidl;
232 const int max_bytes = 0x80, max_line = 0x10;
233 char szHex[max_line*3+1], szAscii[max_line+1];
234 int i, n;
236 n = pidl->mkid.cb;
237 if( n>max_bytes )
238 n = max_bytes;
239 for( i=0; i<n; i++ )
241 sprintf( &szHex[ (i%max_line)*3 ], "%02X ", p[i] );
242 szAscii[ (i%max_line) ] = isprint( p[i] ) ? p[i] : '.';
244 /* print out at the end of each line and when we're finished */
245 if( i!=(n-1) && (i%max_line) != (max_line-1) )
246 continue;
247 szAscii[ (i%max_line)+1 ] = 0;
248 ERR("%-*s %s\n", max_line*3, szHex, szAscii );
252 BOOL pcheck( LPCITEMIDLIST pidl )
254 DWORD type;
255 LPCITEMIDLIST pidltemp = pidl;
257 while( pidltemp && pidltemp->mkid.cb )
259 type = _dbg_ILGetDataPointer(pidltemp)->type;
260 switch( type )
262 case PT_CPLAPPLET:
263 case PT_GUID:
264 case PT_SHELLEXT:
265 case PT_DRIVE:
266 case PT_DRIVE1:
267 case PT_DRIVE2:
268 case PT_DRIVE3:
269 case PT_FOLDER:
270 case PT_VALUE:
271 case PT_VALUEW:
272 case PT_FOLDER1:
273 case PT_WORKGRP:
274 case PT_COMP:
275 case PT_NETPROVIDER:
276 case PT_NETWORK:
277 case PT_IESPECIAL1:
278 case PT_YAGUID:
279 case PT_IESPECIAL2:
280 case PT_SHARE:
281 break;
282 default:
283 ERR("unknown IDLIST %p [%p] size=%u type=%lx\n",
284 pidl, pidltemp, pidltemp->mkid.cb,type );
285 dump_pidl_hex( pidltemp );
286 return FALSE;
288 pidltemp = _dbg_ILGetNext(pidltemp);
290 return TRUE;
293 static char shdebugstr_buf1[100];
294 static char shdebugstr_buf2[100];
295 static char * shdebugstr_buf = shdebugstr_buf1;
297 static struct {
298 REFIID riid;
299 const char *name;
300 } InterfaceDesc[] = {
301 {&IID_IUnknown, "IID_IUnknown"},
302 {&IID_IClassFactory, "IID_IClassFactory"},
303 {&IID_IShellView, "IID_IShellView"},
304 {&IID_IOleCommandTarget, "IID_IOleCommandTarget"},
305 {&IID_IDropTarget, "IID_IDropTarget"},
306 {&IID_IDropSource, "IID_IDropSource"},
307 {&IID_IViewObject, "IID_IViewObject"},
308 {&IID_IContextMenu, "IID_IContextMenu"},
309 {&IID_IShellExtInit, "IID_IShellExtInit"},
310 {&IID_IShellFolder, "IID_IShellFolder"},
311 {&IID_IShellFolder2, "IID_IShellFolder2"},
312 {&IID_IPersist, "IID_IPersist"},
313 {&IID_IPersistFolder, "IID_IPersistFolder"},
314 {&IID_IPersistFolder2, "IID_IPersistFolder2"},
315 {&IID_IPersistFolder3, "IID_IPersistFolder3"},
316 {&IID_IExtractIconA, "IID_IExtractIconA"},
317 {&IID_IExtractIconW, "IID_IExtractIconW"},
318 {&IID_IDataObject, "IID_IDataObject"},
319 {&IID_IAutoComplete, "IID_IAutoComplete"},
320 {&IID_IAutoComplete2, "IID_IAutoComplete2"},
321 {&IID_IShellLinkA, "IID_IShellLinkA"},
322 {&IID_IShellLinkW, "IID_IShellLinkW"},
323 {NULL,NULL}};
325 const char * shdebugstr_guid( const struct _GUID *id )
327 int i;
328 const char* name = NULL;
329 char clsidbuf[100];
331 shdebugstr_buf = (shdebugstr_buf == shdebugstr_buf1) ? shdebugstr_buf2 : shdebugstr_buf1;
333 if (!id) {
334 strcpy (shdebugstr_buf, "(null)");
335 } else {
336 for (i=0;InterfaceDesc[i].riid && !name;i++) {
337 if (IsEqualIID(InterfaceDesc[i].riid, id)) name = InterfaceDesc[i].name;
339 if (!name) {
340 if (HCR_GetClassNameA(id, clsidbuf, 100))
341 name = clsidbuf;
344 sprintf( shdebugstr_buf, "\n\t{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x} (%s)",
345 id->Data1, id->Data2, id->Data3,
346 id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
347 id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7], name ? name : "unknown" );
349 return shdebugstr_buf;