Release 980301

Sun Mar  1 10:45:23 1998  Andreas Mohr <100.30936@germany.net>

	* [loader/ne_image.c]
	Fixed problem with weird DLLs (NE_FFLAGS_SINGLEDATA && DGROUP = 0).

	* [msdos/dosmem.c]
	Export address for __0000H, too.

	* [msdos/dpmi.c]
	Changed MemAlloc functions to return less fragmented addresses.

Sat Feb 28 18:50:12 1998  Alexandre Julliard  <julliard@lrc.epfl.ch>

	* [scheduler/process.c] [scheduler/sysdeps.c]
	Don't use %fs register before threading initialization.

Sat Feb 28 14:04:56 1998  Kristian Nielsen  <kristian.nielsen@risoe.dk>

	* [configure.in] [include/acconfig.h]
	Autoconf macro to check for non-reentrant X libraries.

	* [windows/winpos.c]
	In SetWindowPos32(), do not cause WM_SIZE messages when the
	SWP_NOSIZE flag is specified. This fixes the division-by-zero in
	Borland C++ 4.0 "Open Project" menu item.

Sat Feb 28 13:11:26 1998  James Moody  <013263m@dragon.acadiau.ca>

	* [ole/ole2nls.c]
	Changed "English" values from German to English.

	* [files/dos_fs.c]
	Fixed off-by-one month bug.

Fri Feb 27 22:12:01 1998  Douglas Ridgway  <ridgway@winehq.com>

	* [windows/win.c]
	Fix winelib class menu loading bug.

	* [include/module.h] [loader/module.c]
	LoadModule32 should be implemented in terms of CreateProcess.

	* [programs/view/*]
	Metafile viewer sample program.

	* [documentation/wine.texinfo] [documentation/Makefile.in]
	Improvements and additions, HTML target.

Fri Feb 27 04:27:48 1998  Dimitrie O. Paun <dimi@cs.toronto.edu>

	* [*/*]
	Switched to the new debug messages interface. For more information
	please refer to documentation/debug-msgs. Because the new scheme
	introduces a new semantic level, I had to manually do through
	about 530 dprintf_xxx!  The rest of about 2400 where transformed
	via a script.  Because of the large number of changes that I had
	to do, some may have not come out as nicely as I wanted them.  If
	this is the case, please let me know. There is a lot of work left
	to do: -- a few hundred printf's to be converted -- about 2300
	fprintf's to be converted -- about 600 FIXME's to be transformed
	The problem is that in the above mentioned cases, a lot of manual
	intervention is required because a lot of the information is
	missing.  There are also a lot of other things to be done to the
	interface and so forth. I have now ideas for a at least a month
	worth of full time work :) I will proceed with many changes in the
	next few releases, so please do not start modifing things because
	there will be a hell of a lot of conflicts. If you have ideas that
	you want to integrate or you want to work on different things,
	please coordinate with me.

Thu Feb 26 13:04:29 1998  David Lee Lambert <lamber45@egr.msu.edu>

	* [ole/ole2nls.c] [include/windows.h]
	First try at OLE date- and time-formatting functions.

Wed Feb 25 11:20:35 1998 Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de>

	* [files/*.c]
	Changed dos device handling, added 'CON' devicehandling.

	* [graphics/ddraw.c]
	Bug fixes, some additions.

	* [if1632/builtin.c][loader/module.c][library/winestub.c]
	Small hack so we don't need a dummy BUILTIN_LoadModule
	in winestub.c.

	* [ole/*][relay32/ole32.spec][if1632/storage.spec]
	storage.dll started. winword loads documents (saving
	doesn't work yet, dunno why).
	Several ole additions, some cleanups and bugfixes.
	IMalloc16 implemented.

	* [loader/pe_image.c]
	Added some comments, fixed circular dll references,
	fixed modref ordering, fixed tls allocation.

	* [memory/global.c]
	Added validity checks before every GET_ARENA_PTR.
	(several functions rely on Global* return values
	 on invalid handles, like IsTask).
	Implemented GlobalUnlockFree16.

	* [memory/virtual.c]
	Replaced dprintf_virtual by fprintf, so we can
	do 'info map' again in the debugger. Increase read
	linesize for Linux2.1 cases.

	* [misc/cpu.c][misc/registry.c]
	Moved cpu registry initialization to misc/cpu.c.

	* [multimedia/dsound.c]
	Enhanced, replaced GETOSPACE bufferingcheck by SETFRAGMENT.

	* [relay32/crtdll.spec][relay32/ntdll.spec]
	Replaced some ptr by respective 'str' and 'wstr' arguments
	for libc functions.

	* [scheduler/thread.c]
	Added some sanity checks to stackallocation, tlshandling fixed.

	* [tools/build.c]
	Fixed cdecl argumenttype order (was reversed).

	* [win32/ordinals.c]
	Implemented KERNEL_449.

	* [windows/dinput.c]
	Some fixes, needs much more work. Tomb Raider2 works with keyboard ;)

Tue Feb 24 20:46:37 1998  James Juran   <jrj120@psu.edu>

	* [windows/win.c]
	Fixed USER32 ordinal numbers in documentation.

Sat Feb 21 12:30:38 1998  John Richardson <jrichard@zko.dec.com>

	* [files/file.c] [include/k32obj.h] [memory/virtual.c]
	[scheduler/critsection.c] [scheduler/event.c] [scheduler/handle.c]
	[scheduler/k32obj.c] [scheduler/mutex.c] [scheduler/process.c]
	[scheduler/semaphore.c] [scheduler/thread.c]
	Added generic k32obj read and write routines for k32objs that
	support I/O.

	* [documentation/console]
	Updated console docs.

	* [win32/console.c]
	Make console work like a k32obj that supports I/O.

	* [include/windows.h]
	Make WriteFile and ReadFile take HANDLE32 for handle.

Sun Feb 15 14:07:07 1998  Dimitrie O. Paun  <dimi@mail.cs.toronto.edu>

	* [controls/menu.c] [misc/ver.c] [multimedia/dsound.c]
	  [multimedia/joystick.c] [windows/dialog.c]
	Modified some dprintf_xxx's to prepare them for a new
	dprintf_ scheme. Basically, I changed the dprintf's that
	outputed a line with many dprintf calls to do just one
	dprintf call.
diff --git a/loader/main.c b/loader/main.c
index e255cc7..d2a6423 100644
--- a/loader/main.c
+++ b/loader/main.c
@@ -11,8 +11,6 @@
 #include <string.h>
 #include <errno.h>
 #include "windows.h"
-#include "module.h"
-#include "selectors.h"
 #include "bitmap.h"
 #include "comm.h"
 #include "win.h"
@@ -27,7 +25,6 @@
 #include "heap.h"
 #include "keyboard.h"
 #include "miscemu.h"
-#include "neexe.h"
 #include "options.h"
 #include "spy.h"
 #include "task.h"
@@ -36,7 +33,6 @@
 #include "dce.h"
 #include "shell.h"
 #include "winproc.h"
-#include "stddebug.h"
 #include "debug.h"
 
 
diff --git a/loader/module.c b/loader/module.c
index c7216e6..8bc0783 100644
--- a/loader/module.c
+++ b/loader/module.c
@@ -16,7 +16,6 @@
 #include "file.h"
 #include "global.h"
 #include "heap.h"
-#include "hook.h"
 #include "module.h"
 #include "neexe.h"
 #include "process.h"
@@ -25,7 +24,6 @@
 #include "stackframe.h"
 #include "task.h"
 #include "toolhelp.h"
-#include "stddebug.h"
 #include "debug.h"
 #include "callback.h"
 
@@ -34,6 +32,9 @@
 static HMODULE16 hFirstModule = 0;
 static HMODULE16 hCachedModule = 0;  /* Module cached by MODULE_OpenFile */
 
+static HMODULE32 MODULE_LoadModule(LPCSTR name,BOOL32 force) { return 0; }
+HMODULE32 (*fnBUILTIN_LoadModule)(LPCSTR name,BOOL32 force) = MODULE_LoadModule;
+
 
 /***********************************************************************
  *           MODULE_GetPtr
@@ -268,7 +269,7 @@
     static int cachedfd = -1;
 
     hModule = MODULE_HANDLEtoHMODULE16(hModule);
-    dprintf_module( stddeb, "MODULE_OpenFile(%04x) cache: mod=%04x fd=%d\n",
+    dprintf_info(module, "MODULE_OpenFile(%04x) cache: mod=%04x fd=%d\n",
                     hModule, hCachedModule, cachedfd );
     if (!(pModule = MODULE_GetPtr( hModule ))) return -1;
     if (hCachedModule == hModule) return cachedfd;
@@ -279,7 +280,7 @@
         (cachedfd = open( full_name.long_name, O_RDONLY )) == -1)
         fprintf( stderr, "MODULE_OpenFile: can't open file '%s' for module %04x\n",
                  name, hModule );
-    dprintf_module( stddeb, "MODULE_OpenFile: opened '%s' -> %d\n",
+    dprintf_info(module, "MODULE_OpenFile: opened '%s' -> %d\n",
                     name, cachedfd );
     return cachedfd;
 }
@@ -568,7 +569,7 @@
     {
         fastload_offset=ne_header.fastload_offset<<ne_header.align_shift_count;
         fastload_length=ne_header.fastload_length<<ne_header.align_shift_count;
-        dprintf_module( stddeb, "Using fast-load area offset=%x len=%d\n",
+        dprintf_info(module, "Using fast-load area offset=%x len=%d\n",
                         fastload_offset, fastload_length );
         if ((fastload = HeapAlloc( SystemHeap, 0, fastload_length )) != NULL)
         {
@@ -755,7 +756,7 @@
 
     if (!(pModule = MODULE_GetPtr( hModule ))) return 0;
 
-    dprintf_module( stddeb, "MODULE_GetOrdinal(%04x,'%s')\n",
+    dprintf_info(module, "MODULE_GetOrdinal(%04x,'%s')\n",
                     hModule, name );
 
       /* First handle names of the form '#xxxx' */
@@ -778,7 +779,7 @@
     {
         if (((BYTE)*cpnt == len) && !memcmp( cpnt+1, buffer, len ))
         {
-            dprintf_module( stddeb, "  Found: ordinal=%d\n",
+            dprintf_info(module, "  Found: ordinal=%d\n",
                             *(WORD *)(cpnt + *cpnt + 1) );
             return *(WORD *)(cpnt + *cpnt + 1);
         }
@@ -796,7 +797,7 @@
     {
         if (((BYTE)*cpnt == len) && !memcmp( cpnt+1, buffer, len ))
         {
-            dprintf_module( stddeb, "  Found: ordinal=%d\n",
+            dprintf_info(module, "  Found: ordinal=%d\n",
                             *(WORD *)(cpnt + *cpnt + 1) );
             return *(WORD *)(cpnt + *cpnt + 1);
         }
@@ -1043,7 +1044,7 @@
     if (ordinal) WEP = MODULE_GetEntryPoint( hModule, ordinal );
     if (!WEP)
     {
-	dprintf_module( stddeb, "module %04x doesn't have a WEP\n", hModule );
+	dprintf_warn(module, "module %04x doesn't have a WEP\n", hModule );
 	return FALSE;
     }
     return Callbacks->CallWindowsExitProc( WEP, WEP_FREE_DLL );
@@ -1157,13 +1158,13 @@
         if (!hModule)  /* We have to load the module */
         {
             /* Try to load the built-in first if not disabled */
-            if ((hModule = BUILTIN_LoadModule( name, FALSE )))
+            if ((hModule = fnBUILTIN_LoadModule( name, FALSE )))
                 return MODULE_HANDLEtoHMODULE16( hModule );
             
             if ((hFile = OpenFile32( name, &ofs, OF_READ )) == HFILE_ERROR32)
             {
                 /* Now try the built-in even if disabled */
-                if ((hModule = BUILTIN_LoadModule( name, TRUE )))
+                if ((hModule = fnBUILTIN_LoadModule( name, TRUE )))
                 {
                     fprintf( stderr, "Warning: could not load Windows DLL '%s', using built-in module.\n", name );
                     return MODULE_HANDLEtoHMODULE16( hModule );
@@ -1267,12 +1268,34 @@
 }
 
 /**********************************************************************
- *	    LoadModule32    (KERNEL32)
- * FIXME: check this function
+ *	    LoadModule32    (KERNEL32.499)
+ *
+ * FIXME
+ *
+ *  This should get implemented via CreateProcess -- MODULE_Load
+ *  is resolutely 16-bit.
  */
 DWORD LoadModule32( LPCSTR name, LPVOID paramBlock ) 
 {
+#ifdef 0
+  LOADPARAMS32 *p = paramBlock;
+  STARTUPINFO st;
+  PROCESSINFORMATION pi;
+  st.cb = sizeof(STARTUPINFO);
+  st.wShowWindow = p->lpCmdShow[2] ; WRONG
+
+  BOOL32 ret = CreateProcess32A( name, p->lpCmdLine, 
+				 NULL, NULL, FALSE, 0, p->lpEnvAddress,
+				 NULL, &st, &pi);
+  if (!ret) {
+    /*    handle errors appropriately */
+  }
+  CloseHandle32(pi.hProcess);
+  CloseHandle32(pi.hThread); 
+
+#else
     return MODULE_Load( name, paramBlock, 0 );
+#endif
 }
 
 
@@ -1284,7 +1307,7 @@
     NE_MODULE *pModule;
 
     if (!(pModule = MODULE_GetPtr( hModule ))) return FALSE;
-    dprintf_module( stddeb, "FreeModule16: %s count %d\n", 
+    dprintf_info(module, "FreeModule16: %s count %d\n", 
 		    MODULE_GetModuleName(hModule), pModule->count );
 
     return MODULE_FreeModule( hModule, GlobalLock16(GetCurrentTask()) );
@@ -1312,7 +1335,7 @@
 {
     HMODULE32	hModule;
 
-    dprintf_win32(stddeb, "GetModuleHandleA: %s\n", module ? module : "NULL");
+    dprintf_info(win32, "GetModuleHandleA: %s\n", module ? module : "NULL");
 /* Freecell uses the result of GetModuleHandleA(0) as the hInstance in
 all calls to e.g. CreateWindowEx. */
     if (module == NULL) {
@@ -1341,7 +1364,7 @@
     NE_MODULE *pModule;
 
     if (!(pModule = MODULE_GetPtr( hModule ))) return 0;
-    dprintf_module( stddeb, "GetModuleUsage(%04x): returning %d\n",
+    dprintf_info(module, "GetModuleUsage(%04x): returning %d\n",
                     hModule, pModule->count );
     return pModule->count;
 }
@@ -1358,7 +1381,7 @@
     if (!hModule) hModule = GetCurrentTask();
     if (!(pModule = MODULE_GetPtr( hModule ))) return 0;
     lstrcpyn32A( lpFileName, NE_MODULE_NAME(pModule), nSize );
-    dprintf_module( stddeb, "GetModuleFileName16: %s\n", lpFileName );
+    dprintf_info(module, "GetModuleFileName16: %s\n", lpFileName );
     return strlen(lpFileName);
 }
 
@@ -1378,7 +1401,7 @@
     }
     if (!(pModule = MODULE_GetPtr( hModule ))) return 0;
     lstrcpyn32A( lpFileName, NE_MODULE_NAME(pModule), size );
-    dprintf_module( stddeb, "GetModuleFileName32A: %s\n", lpFileName );
+    dprintf_info(module, "GetModuleFileName32A: %s\n", lpFileName );
     return strlen(lpFileName);
 }                   
  
@@ -1473,7 +1496,7 @@
  */
 BOOL32 WINAPI FreeLibrary32(HINSTANCE32 hLibModule)
 {
-	dprintf_module(stddeb,"FreeLibrary: hLibModule: %08x\n", hLibModule);
+	dprintf_info(module,"FreeLibrary: hLibModule: %08x\n", hLibModule);
 	return MODULE_FreeModule(hLibModule, 
 	                         GlobalLock16(GetCurrentTask()) );
 }
@@ -1491,7 +1514,7 @@
         fprintf( stderr, "LoadLibrary not supported in Winelib\n" );
         return 0;
     }
-    dprintf_module( stddeb, "LoadLibrary: (%08x) %s\n", (int)libname, libname);
+    dprintf_info(module, "LoadLibrary: (%08x) %s\n", (int)libname, libname);
 
     handle = MODULE_Load( libname, (LPVOID)-1, 0 );
     if (handle == (HINSTANCE16)2)  /* file not found */
@@ -1521,7 +1544,7 @@
  */
 void WINAPI FreeLibrary16( HINSTANCE16 handle )
 {
-    dprintf_module( stddeb,"FreeLibrary: %04x\n", handle );
+    dprintf_info(module,"FreeLibrary: %04x\n", handle );
     FreeModule16( handle );
 }
 
@@ -1553,7 +1576,7 @@
 {
     LOADPARAMS params;
     HGLOBAL16 cmdShowHandle, cmdLineHandle;
-    HINSTANCE16 handle = 2;
+    HINSTANCE32 handle = 2;
     WORD *cmdShowPtr;
     char *p, *cmdline, filename[256];
     static int use_load_module = 1;
@@ -1630,7 +1653,7 @@
 	    params.cmdLine  = (SEGPTR)WIN16_GlobalLock16( cmdLineHandle );
 	    params.showCmd  = (SEGPTR)WIN16_GlobalLock16( cmdShowHandle );
 	    params.reserved = 0;
-	    handle = LoadModule16( filename, &params );
+	    handle = LoadModule32( filename, &params );
 	    if (handle == 2)  /* file not found */
 	    {
 		/* Check that the original file name did not have a suffix */
@@ -1735,16 +1758,16 @@
     hModule = MODULE_HANDLEtoHMODULE16(hModule);
     if (HIWORD(name)) {
         ordinal = MODULE_GetOrdinal( hModule, name );
-        dprintf_module( stddeb, "WIN32_GetProcAddress16: %04x '%s'\n",
+        dprintf_info(module, "WIN32_GetProcAddress16: %04x '%s'\n",
                         hModule, name );
     } else {
         ordinal = LOWORD(name);
-        dprintf_module( stddeb, "GetProcAddress: %04x %04x\n",
+        dprintf_info(module, "GetProcAddress: %04x %04x\n",
                         hModule, ordinal );
     }
     if (!ordinal) return (FARPROC16)0;
     ret = MODULE_GetEntryPoint( hModule, ordinal );
-    dprintf_module(stddeb,"WIN32_GetProcAddress16: returning %08x\n",(UINT32)ret);
+    dprintf_info(module,"WIN32_GetProcAddress16: returning %08x\n",(UINT32)ret);
     return ret;
 }
 
@@ -1762,20 +1785,20 @@
     if (HIWORD(name) != 0)
     {
         ordinal = MODULE_GetOrdinal( hModule, (LPSTR)PTR_SEG_TO_LIN(name) );
-        dprintf_module( stddeb, "GetProcAddress: %04x '%s'\n",
+        dprintf_info(module, "GetProcAddress: %04x '%s'\n",
                         hModule, (LPSTR)PTR_SEG_TO_LIN(name) );
     }
     else
     {
         ordinal = LOWORD(name);
-        dprintf_module( stddeb, "GetProcAddress: %04x %04x\n",
+        dprintf_info(module, "GetProcAddress: %04x %04x\n",
                         hModule, ordinal );
     }
     if (!ordinal) return (FARPROC16)0;
 
     ret = MODULE_GetEntryPoint( hModule, ordinal );
 
-    dprintf_module( stddeb, "GetProcAddress: returning %08x\n", (UINT32)ret );
+    dprintf_info(module, "GetProcAddress: returning %08x\n", (UINT32)ret );
     return ret;
 }
 
@@ -1788,9 +1811,9 @@
     NE_MODULE *pModule;
 
     if (HIWORD(function))
-	dprintf_win32(stddeb,"GetProcAddress32(%08lx,%s)\n",(DWORD)hModule,function);
+	dprintf_info(win32,"GetProcAddress32(%08lx,%s)\n",(DWORD)hModule,function);
     else
-	dprintf_win32(stddeb,"GetProcAddress32(%08lx,%p)\n",(DWORD)hModule,function);
+	dprintf_info(win32,"GetProcAddress32(%08lx,%p)\n",(DWORD)hModule,function);
     if (!(pModule = MODULE_GetPtr( hModule )))
         return (FARPROC32)0;
     if (!pModule->module32)
diff --git a/loader/ne_image.c b/loader/ne_image.c
index d092b3d..7b13bab 100644
--- a/loader/ne_image.c
+++ b/loader/ne_image.c
@@ -23,7 +23,6 @@
 #include "file.h"
 #include "module.h"
 #include "stackframe.h"
-#include "stddebug.h"
 #include "debug.h"
 #include "xmalloc.h"
 
@@ -55,7 +54,7 @@
     if (!pSeg->filepos) return TRUE;  /* No file image, just return */
 	
     fd = MODULE_OpenFile( pModule->self );
-    dprintf_module( stddeb, "Loading segment %d, selector=%04x, flags=%04x\n",
+    dprintf_info(module, "Loading segment %d, selector=%04x, flags=%04x\n",
                     segnum, pSeg->selector, pSeg->flags );
     lseek( fd, pSeg->filepos << pModule->alignment, SEEK_SET );
     if (pSeg->size) size = pSeg->size;
@@ -143,7 +142,7 @@
     read( fd, &count, sizeof(count) );
     if (!count) return TRUE;
 
-    dprintf_fixup( stddeb, "Fixups for %*.*s, segment %d, selector %04x\n",
+    dprintf_info(fixup, "Fixups for %*.*s, segment %d, selector %04x\n",
                    *((BYTE *)pModule + pModule->name_table),
                    *((BYTE *)pModule + pModule->name_table),
                    (char *)pModule + pModule->name_table + 1,
@@ -153,7 +152,7 @@
     if (read( fd, reloc_entries, count * sizeof(struct relocation_entry_s)) !=
             count * sizeof(struct relocation_entry_s))
     {
-        dprintf_fixup( stddeb, "Unable to read relocation information\n" );
+        dprintf_warn(fixup, "Unable to read relocation information\n" );
         return FALSE;
     }
 
@@ -194,14 +193,14 @@
                             (char *)pTarget + pTarget->name_table + 1,
                             ordinal );
             }
-            if (debugging_fixup)
+            if (debugging_info(fixup))
             {
                 NE_MODULE *pTarget = MODULE_GetPtr( module );
-                fprintf( stddeb,"%d: %*.*s.%d=%04x:%04x\n", i + 1, 
-                         *((BYTE *)pTarget + pTarget->name_table),
-                         *((BYTE *)pTarget + pTarget->name_table),
-                         (char *)pTarget + pTarget->name_table + 1,
-                         ordinal, HIWORD(address), LOWORD(address) );
+                dprintf_info(fixup, "%d: %*.*s.%d=%04x:%04x\n", i + 1, 
+			     *((BYTE *)pTarget + pTarget->name_table),
+			     *((BYTE *)pTarget + pTarget->name_table),
+			     (char *)pTarget + pTarget->name_table + 1,
+			     ordinal, HIWORD(address), LOWORD(address) );
             }
 	    break;
 	    
@@ -215,20 +214,20 @@
 
             address = MODULE_GetEntryPoint( module, ordinal );
 
-            if (!address)
+            if (debugging_err(fixup) && !address)
             {
                 NE_MODULE *pTarget = MODULE_GetPtr( module );
-                fprintf( stderr, "Warning: no handler for %.*s.%s, setting to 0:0\n",
-                        *((BYTE *)pTarget + pTarget->name_table),
-                        (char *)pTarget + pTarget->name_table + 1, func_name );
+                dprintf_err(fixup, "Warning: no handler for %.*s.%s, setting to 0:0\n",
+			    *((BYTE *)pTarget + pTarget->name_table),
+			    (char *)pTarget + pTarget->name_table + 1, func_name );
             }
-            if (debugging_fixup)
+            if (debugging_info(fixup))
             {
-                NE_MODULE *pTarget = MODULE_GetPtr( module );
-                fprintf( stddeb,"%d: %.*s.%s=%04x:%04x\n", i + 1, 
-                         *((BYTE *)pTarget + pTarget->name_table),
-                         (char *)pTarget + pTarget->name_table + 1,
-                         func_name, HIWORD(address), LOWORD(address) );
+	        NE_MODULE *pTarget = MODULE_GetPtr( module );
+                dprintf_info(fixup, "%d: %.*s.%s=%04x:%04x\n", i + 1, 
+			     *((BYTE *)pTarget + pTarget->name_table),
+			     (char *)pTarget + pTarget->name_table + 1,
+			     func_name, HIWORD(address), LOWORD(address) );
             }
 	    break;
 	    
@@ -242,7 +241,7 @@
                 address = (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( pSegTable[rep->target1-1].selector, rep->target2 );
 	    }
 	    
-	    dprintf_fixup(stddeb,"%d: %04x:%04x\n", 
+	    dprintf_info(fixup,"%d: %04x:%04x\n", 
 			  i + 1, HIWORD(address), LOWORD(address) );
 	    break;
 
@@ -255,21 +254,17 @@
 	     * successfully emulate the coprocessor if it doesn't
 	     * exist.
 	     */
-	    dprintf_fixup(stddeb,
-                   "%d: ADDR TYPE %d,  TYPE %d,  OFFSET %04x,  ",
+	    dprintf_info(fixup,
+                   "%d: ADDR TYPE %d,  TYPE %d,  OFFSET %04x,  TARGET %04x %04x\n",
 		   i + 1, rep->address_type, rep->relocation_type, 
-		   rep->offset);
-	    dprintf_fixup(stddeb,"TARGET %04x %04x\n", 
-		   rep->target1, rep->target2);
+		   rep->offset, rep->target1, rep->target2);
 	    continue;
 	    
 	  default:
-	    dprintf_fixup(stddeb,
-		   "WARNING: %d: ADDR TYPE %d,  unknown TYPE %d,  OFFSET %04x,  ",
-		   i + 1, rep->address_type, rep->relocation_type, 
-		   rep->offset);
-	    dprintf_fixup(stddeb,"TARGET %04x %04x\n", 
-		    rep->target1, rep->target2);
+	    dprintf_warn(fixup, "WARNING: %d: ADDR TYPE %d,  "
+			  "unknown TYPE %d, OFFSET %04x, TARGET %04x %04x\n",
+			  i + 1, rep->address_type, rep->relocation_type, 
+			  rep->offset, rep->target1, rep->target2);
 	    free(reloc_entries);
 	    return FALSE;
 	}
@@ -287,7 +282,7 @@
 	  case NE_RADDR_LOWBYTE:
             do {
                 sp = PTR_SEG_OFF_TO_LIN( pSeg->selector, offset );
-                dprintf_fixup(stddeb,"    %04x:%04x:%04x BYTE%s\n",
+                dprintf_info(fixup,"    %04x:%04x:%04x BYTE%s\n",
                               pSeg->selector, offset, *sp, additive ? " additive":"");
                 offset = *sp;
 		if(additive)
@@ -301,7 +296,7 @@
 	  case NE_RADDR_OFFSET16:
 	    do {
                 sp = PTR_SEG_OFF_TO_LIN( pSeg->selector, offset );
-		dprintf_fixup(stddeb,"    %04x:%04x:%04x OFFSET16%s\n",
+		dprintf_info(fixup,"    %04x:%04x:%04x OFFSET16%s\n",
                               pSeg->selector, offset, *sp, additive ? " additive" : "" );
 		offset = *sp;
 		*sp = LOWORD(address);
@@ -313,7 +308,7 @@
 	  case NE_RADDR_POINTER32:
 	    do {
                 sp = PTR_SEG_OFF_TO_LIN( pSeg->selector, offset );
-		dprintf_fixup(stddeb,"    %04x:%04x:%04x POINTER32%s\n",
+		dprintf_info(fixup,"    %04x:%04x:%04x POINTER32%s\n",
                               pSeg->selector, offset, *sp, additive ? " additive" : "" );
 		offset = *sp;
 		*sp    = LOWORD(address);
@@ -326,7 +321,7 @@
 	  case NE_RADDR_SELECTOR:
 	    do {
                 sp = PTR_SEG_OFF_TO_LIN( pSeg->selector, offset );
-		dprintf_fixup(stddeb,"    %04x:%04x:%04x SELECTOR%s\n",
+		dprintf_info(fixup,"    %04x:%04x:%04x SELECTOR%s\n",
                               pSeg->selector, offset, *sp, additive ? " additive" : "" );
 		offset = *sp;
 		*sp    = HIWORD(address);
@@ -339,12 +334,10 @@
 	    break;
 	    
 	  default:
-	    dprintf_fixup(stddeb,
-		   "WARNING: %d: unknown ADDR TYPE %d,  TYPE %d,  OFFSET %04x,  ",
+	    dprintf_warn(fixup, "WARNING: %d: unknown ADDR TYPE %d,  "
+			  "TYPE %d,  OFFSET %04x,  TARGET %04x %04x\n",
 		   i + 1, rep->address_type, rep->relocation_type, 
-		   rep->offset);
-	    dprintf_fixup(stddeb,
-		   "TARGET %04x %04x\n", rep->target1, rep->target2);
+		   rep->offset, rep->target1, rep->target2);
 	    free(reloc_entries);
 	    return FALSE;
 	}
@@ -374,7 +367,7 @@
         DWORD oldstack;
         WORD saved_dgroup = pSegTable[pModule->dgroup - 1].selector;
 
-        dprintf_module(stddeb, "MODULE_Load: %.*s is a self-loading module!\n",
+        dprintf_info(module, "NE_LoadAllSegments: %.*s is a self-loading module!\n",
                        *((BYTE*)pModule + pModule->name_table),
                        (char *)pModule + pModule->name_table + 1);
         if (!NE_LoadSegment( pModule, 1 )) return FALSE;
@@ -431,7 +424,7 @@
         BYTE *pstr = (BYTE *)pModule + pModule->import_table + *pModRef;
         memcpy( buffer, pstr + 1, *pstr );
         strcpy( buffer + *pstr, ".dll" );
-        dprintf_module( stddeb, "Loading '%s'\n", buffer );
+        dprintf_info(module, "Loading '%s'\n", buffer );
         if (!(*pModRef = MODULE_FindModule( buffer )))
         {
             /* If the DLL is not loaded yet, load it and store */
@@ -483,12 +476,13 @@
     WORD dgroup = 0;
     WORD sel;
     BYTE *p, *fixup_ptr, count;
+    dbg_decl_str(module, 512);
 
     pSegTable = NE_SEG_TABLE(pModule);
     if (pModule->flags & NE_FFLAGS_SINGLEDATA)
         dgroup = pSegTable[pModule->dgroup-1].selector;
 
-    dprintf_module( stddeb, "MODULE_FixupPrologs(%04x)\n", pModule->self );
+    dprintf_info(module, "MODULE_FixupPrologs(%04x)\n", pModule->self );
     p = (BYTE *)pModule + pModule->entry_table;
     while (*p)
     {
@@ -509,21 +503,23 @@
         p += 2;
         while (count-- > 0)
         {
-            dprintf_module( stddeb,"Flags: %04x, sel %02x ", *p, sel);
+	    dbg_reset_str(module);
+            dsprintf(module,"Flags: %04x, sel %02x ", *p, sel);
             /* According to the output generated by TDUMP, the flags mean:
              * 0x0001 function is exported
 	     * 0x0002 Single data (seems to occur only in DLLs)
 	     */
 	    if (sel == 0xff) { /* moveable */
-		dprintf_module( stddeb, "(%02x) o %04x ", p[3], *(WORD *)(p+4) );
+		dsprintf(module, "(%02x) o %04x", p[3], *(WORD *)(p+4) );
 		fixup_ptr = (char *)GET_SEL_BASE(pSegTable[p[3]-1].selector) + *(WORD *)(p + 4);
 	    } else { /* fixed */
-		dprintf_module( stddeb, "offset %04x ", *(WORD *)(p+1) );
-		fixup_ptr = (char *)GET_SEL_BASE(pSegTable[sel-1].selector) + *(WORD *)(p + 1);
+		dsprintf(module, "offset %04x", *(WORD *)(p+1) );
+		fixup_ptr = (char *)GET_SEL_BASE(pSegTable[sel-1].selector) + 
+		  *(WORD *)(p + 1);
 	    }
-	    dprintf_module( stddeb, "Signature: %02x %02x %02x,ff %x\n",
-			   fixup_ptr[0], fixup_ptr[1], fixup_ptr[2],
-			   pModule->flags );
+	    dprintf_info(module, "%s Signature: %02x %02x %02x,ff %x\n",
+			    dbg_str(module), fixup_ptr[0], fixup_ptr[1], 
+			    fixup_ptr[2], pModule->flags );
             if (*p & 0x0001)
             {
                 /* Verify the signature */
@@ -553,11 +549,11 @@
 			}
                     }
                 } else {
-		    dprintf_fixup( stddeb, "Unknown signature\n" );
+		    dprintf_warn(fixup, "Unknown signature\n" );
 		}
             }
 	    else
-	      dprintf_module( stddeb,"\n");
+	      dprintf_info(module,"\n");
             p += (sel == 0xff) ? 6 : 3;  
         }
     }
@@ -618,8 +614,17 @@
     }
     else  /* DATA SINGLE DLL */
     {
-        DS_reg(&context)  = pSegTable[pModule->dgroup-1].selector;
-        ECX_reg(&context) = pModule->heap_size;
+	if (pModule->dgroup) {
+            DS_reg(&context)  = pSegTable[pModule->dgroup-1].selector;
+            ECX_reg(&context) = pModule->heap_size;
+	}
+	else /* hmm, DLL has no dgroup,
+		but why has it NE_FFLAGS_SINGLEDATA set ?
+		Buggy DLL compiler ? */
+	{
+            DS_reg(&context)  = 0;
+            ECX_reg(&context) = 0;
+	}
     }
 
     CS_reg(&context)  = pSegTable[pModule->cs-1].selector;
@@ -630,7 +635,7 @@
 
 
     pModule->cs = 0;  /* Don't initialize it twice */
-    dprintf_dll( stddeb, "Calling LibMain, cs:ip=%04lx:%04x ds=%04lx di=%04x cx=%04x\n", 
+    dprintf_info(dll, "Calling LibMain, cs:ip=%04lx:%04x ds=%04lx di=%04x cx=%04x\n", 
                  CS_reg(&context), IP_reg(&context), DS_reg(&context),
                  DI_reg(&context), CX_reg(&context) );
     Callbacks->CallRegisterShortProc( &context, 0 );
diff --git a/loader/ne_resource.c b/loader/ne_resource.c
index 0e340bd..b091411 100644
--- a/loader/ne_resource.c
+++ b/loader/ne_resource.c
@@ -18,7 +18,6 @@
 #include "module.h"
 #include "neexe.h"
 #include "resource.h"
-#include "stddebug.h"
 #include "debug.h"
 
 #define  NEXT_TYPEINFO(pTypeInfo) ((NE_TYPEINFO *)((char*)((pTypeInfo) + 1) + \
@@ -47,13 +46,13 @@
 	pNameInfo = (NE_NAMEINFO *)(pTypeInfo + 1);
 	for (count = pTypeInfo->count; count > 0; count--, pNameInfo++)
 	{
-            dprintf_resource( stddeb, "NameTable entry: type=%04x id=%04x\n",
+            dprintf_info(resource, "NameTable entry: type=%04x id=%04x\n",
                               pTypeInfo->type_id, pNameInfo->id );
             handle = LoadResource16( pModule->self, 
 				   (HRSRC16)((int)pNameInfo - (int)pModule) );
             for(p = (WORD*)LockResource16(handle); p && *p; p = (WORD *)((char*)p+*p))
             {
-                dprintf_resource( stddeb,"  type=%04x '%s' id=%04x '%s'\n",
+                dprintf_info(resource,"  type=%04x '%s' id=%04x '%s'\n",
                                   p[1], (char *)(p+3), p[2],
                                   (char *)(p+3)+strlen((char *)(p+3))+1 );
                 /* Check for correct type */
@@ -81,7 +80,7 @@
 
                 /* If we get here, we've found the entry */
 
-                dprintf_resource( stddeb, "  Found!\n" );
+                dprintf_info(resource, "  Found!\n" );
                 ret = MAKELONG( p[1], p[2] );
                 break;
             }
@@ -113,11 +112,11 @@
 		BYTE *p = (BYTE*)pModule + pModule->res_table + pTypeInfo->type_id;
 		if ((*p == len) && !lstrncmpi32A( p+1, str, len ))
 		{
-		    dprintf_resource( stddeb, "  Found type '%s'\n", str );
+		    dprintf_info(resource, "  Found type '%s'\n", str );
 		    return pTypeInfo;
 		}
 	    }
-	    dprintf_resource( stddeb, "  Skipping type %04x\n", pTypeInfo->type_id );
+	    dprintf_info(resource, "  Skipping type %04x\n", pTypeInfo->type_id );
 	    pTypeInfo = NEXT_TYPEINFO(pTypeInfo);
 	}
     }
@@ -128,10 +127,10 @@
 	{
             if (pTypeInfo->type_id == id)
 	    {
-		dprintf_resource( stddeb, "  Found type %04x\n", id );
+		dprintf_info(resource, "  Found type %04x\n", id );
 		return pTypeInfo;
 	    }
-	    dprintf_resource( stddeb, "  Skipping type %04x\n", pTypeInfo->type_id );
+	    dprintf_info(resource, "  Skipping type %04x\n", pTypeInfo->type_id );
 	    pTypeInfo = NEXT_TYPEINFO(pTypeInfo);
 	}
     }
@@ -189,7 +188,7 @@
 	WORD sizeShift = *(WORD *)((char *)pModule + pModule->res_table);
 	NE_NAMEINFO* pNameInfo = (NE_NAMEINFO*)((char*)pModule + hRsrc);
 
-        dprintf_resource( stddeb, "NEResourceHandler: loading, pos=%d, len=%d\n",
+        dprintf_info(resource, "NEResourceHandler: loading, pos=%d, len=%d\n",
                          (int)pNameInfo->offset << sizeShift,
                          (int)pNameInfo->length << sizeShift );
 	if( hMemObj )
@@ -217,7 +216,7 @@
     NE_MODULE *pModule = MODULE_GetPtr( hModule );
     NE_TYPEINFO *pTypeInfo = (NE_TYPEINFO *)((char *)pModule + pModule->res_table + 2);
 
-    dprintf_resource(stddeb,"InitResourceHandler[%04x]\n", hModule );
+    dprintf_info(resource,"InitResourceHandler[%04x]\n", hModule );
 
     while(pTypeInfo->type_id)
     {
@@ -280,15 +279,15 @@
 	    hRsrc = NE_FindResourceFromType(pModule, pTypeInfo, resId);
 	    if( hRsrc )
 	    {
-		dprintf_resource( stddeb, "    Found id %08lx\n", resId );
+		dprintf_info(resource, "    Found id %08lx\n", resId );
 		return hRsrc;
 	    }
-	    dprintf_resource( stddeb, "    Not found, going on\n" );
+	    dprintf_info(resource, "    Not found, going on\n" );
 	    pTypeInfo = NEXT_TYPEINFO(pTypeInfo);
 	}
     } while( pTypeInfo );
 
-    dprintf_resource( stddeb, "failed!\n");
+    dprintf_warn(resource, "failed!\n");
     return 0;
 }
 
@@ -389,7 +388,7 @@
 	    && !(GlobalFlags16(pNameInfo->handle) & GMEM_DISCARDED))
 	{
 	    pNameInfo->usage++;
-	    dprintf_resource( stddeb, "  Already loaded, new count=%d\n",
+	    dprintf_info(resource, "  Already loaded, new count=%d\n",
 			      pNameInfo->usage );
 	}
 	else
@@ -460,7 +459,7 @@
         pTypeInfo = (NE_TYPEINFO *)pNameInfo;
     }
 
-    dprintf_resource(stddeb, "NE_FreeResource[%04x]: no intrinsic resource for %04x\n", 
+    dprintf_info(resource, "NE_FreeResource[%04x]: no intrinsic resource for %04x\n", 
 			      hModule, handle );
     GlobalFree16( handle ); /* it could have been DirectResAlloc()'ed */
     return handle;
diff --git a/loader/pe_image.c b/loader/pe_image.c
index 96a9b15..842c7f7 100644
--- a/loader/pe_image.c
+++ b/loader/pe_image.c
@@ -1,7 +1,7 @@
 /* 
  *  Copyright	1994	Eric Youndale & Erik Bos
  *  Copyright	1995	Martin von Löwis
- *  Copyright   1996    Marcus Meissner
+ *  Copyright   1996-98 Marcus Meissner
  *
  *	based on Eric Youndale's pe-test and:
  *
@@ -9,8 +9,26 @@
  * make that:
  *	ftp.microsoft.com:/developr/MSDN/OctCD/PEFILE.ZIP
  */
+/* Notes:
+ * Before you start changing something in this file be aware of the following:
+ *
+ * - There are several functions called recursively. In a very subtle and 
+ *   obscure way. DLLs can reference each other recursively etc.
+ * - If you want to enhance, speed up or clean up something in here, think
+ *   twice WHY it is implemented in that strange way. There is usually a reason.
+ *   Though sometimes it might just be lazyness ;)
+ * - In PE_MapImage, right before fixup_imports() all external and internal 
+ *   state MUST be correct since this function can be called with the SAME image
+ *   AGAIN. (Thats recursion for you.) That means MODREF.module and
+ *   NE_MODULE.module32.
+ * - No, you cannot use Linux mmap() to mmap() the images directly. Linux aligns
+ *   them at pagesize (4096), Win32 requires 512 byte alignment.
+ * - All those function map things into a new addresspace. From the wrong
+ *   process and the wrong thread. So calling other API functions will mess 
+ *   things up badly sometimes.
+ */
 
-#include <ctype.h>
+/*#include <ctype.h>*/
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -32,7 +50,6 @@
 #include "global.h"
 #include "task.h"
 #include "ldt.h"
-#include "stddebug.h"
 #include "debug.h"
 #include "xmalloc.h"
 
@@ -57,7 +74,7 @@
   IMAGE_EXPORT_DIRECTORY *pe_exports = (IMAGE_EXPORT_DIRECTORY*)RVA(rva_start);
 
   Module = (char*)RVA(pe_exports->Name);
-  dprintf_win32(stddeb,"\n*******EXPORT DATA*******\nModule name is %s, %ld functions, %ld names\n", 
+  dprintf_info(win32,"\n*******EXPORT DATA*******\nModule name is %s, %ld functions, %ld names\n", 
 	 Module,
 	 pe_exports->NumberOfFunctions,
 	 pe_exports->NumberOfNames);
@@ -66,19 +83,23 @@
   functions=function=(u_long*) RVA(pe_exports->AddressOfFunctions);
   name=(u_char**) RVA(pe_exports->AddressOfNames);
 
-  dprintf_win32(stddeb," Ord    RVA     Addr   Name\n" );
+  dprintf_info(win32," Ord    RVA     Addr   Name\n" );
   for (i=0;i<pe_exports->NumberOfFunctions;i++, function++)
   {
       if (!*function) continue;  /* No such function */
-      dprintf_win32( stddeb,"%4ld %08lx %08x",
-                     i + pe_exports->Base, *function, RVA(*function) );
-      /* Check if we have a name for it */
-      for (j = 0; j < pe_exports->NumberOfNames; j++)
+      if (debugging_info(win32)){
+	dbg_decl_str(win32, 1024);
+
+	dsprintf(win32,"%4ld %08lx %08x",
+		 i + pe_exports->Base, *function, RVA(*function) );
+	/* Check if we have a name for it */
+	for (j = 0; j < pe_exports->NumberOfNames; j++)
           if (ordinal[j] == i)
-              dprintf_win32( stddeb, "  %s", (char*)RVA(name[j]) );
-      if ((*function >= rva_start) && (*function <= rva_end))
-	  dprintf_win32(stddeb, " (forwarded -> %s)", (char *)RVA(*function));
-      dprintf_win32( stddeb,"\n" );
+	    dsprintf(win32, "  %s", (char*)RVA(name[j]) );
+	if ((*function >= rva_start) && (*function <= rva_end))
+	  dsprintf(win32, " (forwarded -> %s)", (char *)RVA(*function));
+	dprintf_info(win32,"%s\n", dbg_str(win32));
+      }
   }
 }
 
@@ -114,9 +135,9 @@
 	exports   = pem->pe_export;
 
 	if (HIWORD(funcName))
-		dprintf_win32(stddeb,"PE_FindExportedFunction(%s)\n",funcName);
+		dprintf_info(win32,"PE_FindExportedFunction(%s)\n",funcName);
 	else
-		dprintf_win32(stddeb,"PE_FindExportedFunction(%d)\n",(int)funcName);
+		dprintf_info(win32,"PE_FindExportedFunction(%d)\n",(int)funcName);
 	if (!exports) {
 		fprintf(stderr,"Module %08x/MODREF %p doesn't have a exports table.\n",hModule,pem);
 		return NULL;
@@ -136,6 +157,7 @@
 			if(!strcmp(ename,funcName))
                         {
                             addr = function[*ordinal];
+                            if (!addr) return NULL;
                             if ((addr < rva_start) || (addr >= rva_end))
                                 return (FARPROC32)RVA(addr);
                             forward = (char *)RVA(addr);
@@ -146,11 +168,12 @@
 		}
 	} else {
 		if (LOWORD(funcName)-exports->Base > exports->NumberOfFunctions) {
-			dprintf_win32(stddeb,"	ordinal %d out of range!\n",
+			dprintf_info(win32,"	ordinal %d out of range!\n",
                                       LOWORD(funcName));
 			return NULL;
 		}
 		addr = function[(int)funcName-exports->Base];
+                if (!addr) return NULL;
 		if ((addr < rva_start) || (addr >= rva_end))
 			return (FARPROC32)RVA(addr);
 		forward = (char *)RVA(addr);
@@ -183,7 +206,7 @@
         modname = "<unknown>";
 
     /* OK, now dump the import list */
-    dprintf_win32 (stddeb, "\nDumping imports list\n");
+    dprintf_info(win32, "\nDumping imports list\n");
 
     /* first, count the number of imported non-internal modules */
     pe_imp = pem->pe_import;
@@ -230,27 +253,24 @@
 		xpem = xpem->next;
 	}
 	if (xpem) {
-		/* it has been loaded *BEFORE* us, so we have to init
-		 * it before us. we just swap the two modules which should
-		 * work.
+		/* It has been loaded *BEFORE* us, so we have to initialize
+		 * it before us. We cannot just link in the xpem before pem,
+		 * since xpem might reference more dlls which would be in the
+		 * wrong order after that.
+		 * Instead we link in pem right AFTER xpem, which should keep
+		 * the correct order. (I am not 100% sure about that.)
 		 */
-		/* unlink xpem from chain */
+		/* unlink pem from chain */
 		ypem = &(process->modref_list);
 		while (*ypem) {
-			if ((*ypem)==xpem)
-				break;
-			ypem = &((*ypem)->next);
-		}
-		*ypem		= xpem->next;
-
-		/* link it directly before pem */
-		ypem		= &(process->modref_list);
-		while (*ypem) {
 			if ((*ypem)==pem)
 				break;
 			ypem = &((*ypem)->next);
 		}
-		*ypem		= xpem;
+		*ypem		= pem->next;
+
+		/* link pem directly AFTER xpem */
+		pem->next	= xpem->next;
 		xpem->next	= pem;
 		
 	}
@@ -265,12 +285,12 @@
 
 	Module = (char *) RVA(pe_imp->Name);
         hImpModule = MODULE_HANDLEtoHMODULE32( MODULE_FindModule(Module) );
-	dprintf_win32 (stddeb, "%s\n", Module);
+	dprintf_info(win32, "%s\n", Module);
 
 	/* FIXME: forwarder entries ... */
 
 	if (pe_imp->u.OriginalFirstThunk != 0) { /* original MS style */
-	    dprintf_win32 (stddeb, "Microsoft style imports used\n");
+	    dprintf_info(win32, "Microsoft style imports used\n");
 	    import_list =(LPIMAGE_THUNK_DATA) RVA(pe_imp->u.OriginalFirstThunk);
 	    thunk_list = (LPIMAGE_THUNK_DATA) RVA(pe_imp->FirstThunk);
 
@@ -278,7 +298,7 @@
 		if (IMAGE_SNAP_BY_ORDINAL(import_list->u1.Ordinal)) {
 		    int ordinal = IMAGE_ORDINAL(import_list->u1.Ordinal);
 
-		    dprintf_win32 (stddeb, "--- Ordinal %s,%d\n", Module, ordinal);
+		    dprintf_info(win32, "--- Ordinal %s,%d\n", Module, ordinal);
 		    thunk_list->u1.Function=(LPDWORD)PE_FindExportedFunction(
                         process, hImpModule, (LPCSTR)ordinal);
 		    if (!thunk_list->u1.Function) {
@@ -288,7 +308,7 @@
 		    }
 		} else {		/* import by name */
 		    pe_name = (LPIMAGE_IMPORT_BY_NAME)RVA(import_list->u1.AddressOfData);
-		    dprintf_win32 (stddeb, "--- %s %s.%d\n", pe_name->Name, Module, pe_name->Hint);
+		    dprintf_info(win32, "--- %s %s.%d\n", pe_name->Name, Module, pe_name->Hint);
 		    thunk_list->u1.Function=(LPDWORD)PE_FindExportedFunction(
                         process, hImpModule, pe_name->Name);
 		    if (!thunk_list->u1.Function) {
@@ -301,14 +321,14 @@
 		thunk_list++;
 	    }
 	} else {	/* Borland style */
-	    dprintf_win32 (stddeb, "Borland style imports used\n");
+	    dprintf_info(win32, "Borland style imports used\n");
 	    thunk_list = (LPIMAGE_THUNK_DATA) RVA(pe_imp->FirstThunk);
 	    while (thunk_list->u1.Ordinal) {
 		if (IMAGE_SNAP_BY_ORDINAL(thunk_list->u1.Ordinal)) {
 		    /* not sure about this branch, but it seems to work */
 		    int ordinal = IMAGE_ORDINAL(thunk_list->u1.Ordinal);
 
-		    dprintf_win32(stddeb,"--- Ordinal %s.%d\n",Module,ordinal);
+		    dprintf_info(win32,"--- Ordinal %s.%d\n",Module,ordinal);
 		    thunk_list->u1.Function=(LPDWORD)PE_FindExportedFunction(
                         process, hImpModule, (LPCSTR) ordinal);
 		    if (!thunk_list->u1.Function) {
@@ -318,7 +338,7 @@
 		    }
 		} else {
 		    pe_name=(LPIMAGE_IMPORT_BY_NAME) RVA(thunk_list->u1.AddressOfData);
-		    dprintf_win32(stddeb,"--- %s %s.%d\n",
+		    dprintf_info(win32,"--- %s %s.%d\n",
 		   		  pe_name->Name,Module,pe_name->Hint);
 		    thunk_list->u1.Function=(LPDWORD)PE_FindExportedFunction(
                         process, hImpModule, pe_name->Name );
@@ -342,11 +362,11 @@
     int i,vma_size = 0;
     IMAGE_SECTION_HEADER *pe_seg = PE_SECTIONS(hModule);
 
-    dprintf_win32(stddeb, "Dump of segment table\n");
-    dprintf_win32(stddeb, "   Name    VSz  Vaddr     SzRaw   Fileadr  *Reloc *Lineum #Reloc #Linum Char\n");
+    dprintf_info(win32, "Dump of segment table\n");
+    dprintf_info(win32, "   Name    VSz  Vaddr     SzRaw   Fileadr  *Reloc *Lineum #Reloc #Linum Char\n");
     for (i = 0; i< PE_HEADER(hModule)->FileHeader.NumberOfSections; i++)
     {
-        dprintf_win32(stddeb, "%8s: %4.4lx %8.8lx %8.8lx %8.8lx %8.8lx %8.8lx %4.4x %4.4x %8.8lx\n", 
+        dprintf_info(win32, "%8s: %4.4lx %8.8lx %8.8lx %8.8lx %8.8lx %8.8lx %4.4x %4.4x %8.8lx\n", 
                       pe_seg->Name, 
                       pe_seg->Misc.VirtualSize,
                       pe_seg->VirtualAddress,
@@ -381,14 +401,14 @@
 		char *page = (char*) RVA(r->VirtualAddress);
 		int count = (r->SizeOfBlock - 8)/2;
 		int i;
-		dprintf_fixup(stddeb, "%x relocations for page %lx\n",
+		dprintf_info(fixup, "%x relocations for page %lx\n",
 			count, r->VirtualAddress);
 		/* patching in reverse order */
 		for(i=0;i<count;i++)
 		{
 			int offset = r->TypeOffset[i] & 0xFFF;
 			int type = r->TypeOffset[i] >> 12;
-			dprintf_fixup(stddeb,"patching %x type %x\n", offset, type);
+			dprintf_info(fixup,"patching %x type %x\n", offset, type);
 			switch(type)
 			{
 			case IMAGE_REL_BASED_ABSOLUTE: break;
@@ -495,8 +515,8 @@
 /**********************************************************************
  * This maps a loaded PE dll into the address space of the specified process.
  */
-static HMODULE32 PE_MapImage( HMODULE32 hModule, PDB32 *process,
-                              OFSTRUCT *ofs, DWORD flags )
+static BOOL32 PE_MapImage( HMODULE32 *phModule, PDB32 *process,
+                           OFSTRUCT *ofs, DWORD flags )
 {
 	PE_MODREF		*pem;
 	int			i, result;
@@ -504,6 +524,7 @@
 	IMAGE_DATA_DIRECTORY	dir;
 	char			*modname;
 	int			vma_size;
+	HMODULE32		hModule = *phModule;
 
         IMAGE_SECTION_HEADER *pe_seg;
         IMAGE_DOS_HEADER *dos_header = (IMAGE_DOS_HEADER *)hModule;
@@ -524,7 +545,7 @@
 
 	load_addr = nt_header->OptionalHeader.ImageBase;
 	vma_size = calc_vma_size( hModule );
-	dprintf_win32(stddeb, "Load addr is %lx\n",load_addr);
+	dprintf_info(win32, "Load addr is %lx\n",load_addr);
 	load_addr = (DWORD)VirtualAlloc( (void*)load_addr, vma_size,
                                          MEM_RESERVE | MEM_COMMIT,
                                          PAGE_EXECUTE_READWRITE );
@@ -533,9 +554,12 @@
 						 MEM_RESERVE | MEM_COMMIT,
 						 PAGE_EXECUTE_READWRITE );
 	}
-	pem->module = (HMODULE32)load_addr;
+	/* *phModule is the module32 entry in the NE_MODULE. We need to
+	 * change it here, since it can get referenced by fixup_imports()
+	 */
+	pem->module = *phModule = (HMODULE32)load_addr;
 
-	dprintf_win32(stddeb, "Load addr is really %lx, range %x\n",
+	dprintf_info(win32, "Load addr is really %lx, range %x\n",
                       load_addr, vma_size);
 	
         /* Store the NT header at the load addr
@@ -611,10 +635,10 @@
 	}
 
 	if(nt_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXCEPTION].Size)
-		dprintf_win32(stdnimp,"Exception directory ignored\n");
+		dprintf_fixme(win32,"Exception directory ignored\n");
 
 	if(nt_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_SECURITY].Size)
-		dprintf_win32(stdnimp,"Security directory ignored\n");
+		dprintf_fixme(win32,"Security directory ignored\n");
 
 
 
@@ -628,29 +652,29 @@
 
 	if(nt_header->OptionalHeader.DataDirectory
 		[IMAGE_DIRECTORY_ENTRY_COPYRIGHT].Size)
-		dprintf_win32(stdnimp,"Copyright string ignored\n");
+		dprintf_fixme(win32,"Copyright string ignored\n");
 
 	if(nt_header->OptionalHeader.DataDirectory
 		[IMAGE_DIRECTORY_ENTRY_GLOBALPTR].Size)
-		dprintf_win32(stdnimp,"Global Pointer (MIPS) ignored\n");
+		dprintf_fixme(win32,"Global Pointer (MIPS) ignored\n");
 
 	if(nt_header->OptionalHeader.DataDirectory
 		[IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG].Size)
-		dprintf_win32(stdnimp,"Load Configuration directory ignored\n");
+		dprintf_fixme(win32,"Load Configuration directory ignored\n");
 
 	if(nt_header->OptionalHeader.DataDirectory
 		[IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT].Size)
-		dprintf_win32(stdnimp,"Bound Import directory ignored\n");
+		dprintf_fixme(win32,"Bound Import directory ignored\n");
 
 	if(nt_header->OptionalHeader.DataDirectory
 		[IMAGE_DIRECTORY_ENTRY_IAT].Size)
-		dprintf_win32(stdnimp,"Import Address Table directory ignored\n");
+		dprintf_fixme(win32,"Import Address Table directory ignored\n");
 	if(nt_header->OptionalHeader.DataDirectory[13].Size)
-		dprintf_win32(stdnimp,"Unknown directory 13 ignored\n");
+		dprintf_fixme(win32,"Unknown directory 13 ignored\n");
 	if(nt_header->OptionalHeader.DataDirectory[14].Size)
-		dprintf_win32(stdnimp,"Unknown directory 14 ignored\n");
+		dprintf_fixme(win32,"Unknown directory 14 ignored\n");
 	if(nt_header->OptionalHeader.DataDirectory[15].Size)
-		dprintf_win32(stdnimp,"Unknown directory 15 ignored\n");
+		dprintf_fixme(win32,"Unknown directory 15 ignored\n");
 
 	if(pem->pe_reloc)	do_relocations(pem);
 	if(pem->pe_export)	dump_exports(pem->module);
@@ -691,7 +715,7 @@
         /* Now that we got everything at the right address,
          * we can unmap the previous module */
         UnmapViewOfFile( (LPVOID)hModule );
-        return (HMODULE32)load_addr;
+        return 1;
 }
 
 HINSTANCE16 MODULE_CreateInstance(HMODULE16 hModule,LOADPARAMS *params);
@@ -705,7 +729,7 @@
                                HFILE32 hFile, DWORD flags)
 {
 	OFSTRUCT	ofs;
-	HMODULE32	hModule,ret;
+	HMODULE32	hModule;
 	NE_MODULE	*pModule;
 	PE_MODREF	*pem;
 
@@ -767,13 +791,11 @@
 		if (pModule->module32 < 32) return 21;
 	}
 	/* recurse */
-	ret = PE_MapImage( pModule->module32, process, &ofs,flags);
-	if (!ret) {
+	if (!PE_MapImage( &(pModule->module32), process, &ofs,flags)) {
 		/* should free this module and the already referenced ones */
 		return 0;
 	}
-	pModule->module32 = ret;
-	return ret;
+	return pModule->module32;
 }
 
 /*****************************************************************************
@@ -784,7 +806,7 @@
 HINSTANCE16 PE_LoadModule( HFILE32 hFile, OFSTRUCT *ofs, LOADPARAMS* params )
 {
     HMODULE16 hModule16;
-    HMODULE32 hModule32, ret;
+    HMODULE32 hModule32;
     HINSTANCE16 hInstance;
     NE_MODULE *pModule;
     THDB *thdb = THREAD_Current();
@@ -807,20 +829,19 @@
         TDB *pTask = (TDB *)GlobalLock16( hTask );
         thdb = pTask->thdb;
     }
-    if (!(ret = PE_MapImage( hModule32, thdb->process, ofs, 0 )))
+    if (!PE_MapImage( &(pModule->module32), thdb->process, ofs, 0 ))
     {
-     	/* FIXME: should destroy the task created ... */
+     	/* FIXME: should destroy the task created and free referenced stuff */
         return 0;
     }
-    pModule->module32 = ret;
-    /* yuck. but there is no other good place to do that... */
+    /* FIXME: Yuck. Is there no other good place to do that? */
     PE_InitTls( thdb );
     return hInstance;
 }
 
 int PE_UnloadImage( HMODULE32 hModule )
 {
-	printf("PEunloadImage() called!\n");
+	fprintf(stderr,"PEunloadImage() called!\n");
 	/* free resources, image, unmap */
 	return 1;
 }
@@ -848,7 +869,7 @@
     ) {
         FARPROC32 entry = (FARPROC32)RVA_PTR( pem->module,
                                           OptionalHeader.AddressOfEntryPoint );
-        dprintf_relay( stddeb, "CallTo32(entryproc=%p,module=%08x,type=%ld,res=%p)\n",
+        dprintf_info(relay, "CallTo32(entryproc=%p,module=%08x,type=%ld,res=%p)\n",
                        entry, pem->module, type, lpReserved );
         entry( pem->module, type, lpReserved );
     }
@@ -899,7 +920,7 @@
 			DataDirectory[IMAGE_FILE_THREAD_LOCAL_STORAGE].VirtualAddress);
 		
 		if (!(pem->flags & PE_MODREF_TLS_ALLOCED)) {
-			pem->tlsindex = TlsAlloc();
+			pem->tlsindex = THREAD_TlsAlloc(thdb);
 			*(pdir->AddressOfIndex)=pem->tlsindex;   
 		}
 		pem->flags |= PE_MODREF_TLS_ALLOCED;
@@ -929,4 +950,3 @@
 	}
 	return TRUE;
 }
-
diff --git a/loader/pe_resource.c b/loader/pe_resource.c
index 60fa5b8..da06142 100644
--- a/loader/pe_resource.c
+++ b/loader/pe_resource.c
@@ -22,7 +22,6 @@
 #include "libres.h"
 #include "stackframe.h"
 #include "neexe.h"
-#include "stddebug.h"
 #include "debug.h"
 
 /**********************************************************************
diff --git a/loader/resource.c b/loader/resource.c
index 5e98fb5..8d7ad81 100644
--- a/loader/resource.c
+++ b/loader/resource.c
@@ -20,16 +20,10 @@
 #include "task.h"
 #include "module.h"
 #include "resource.h"
-#include "stddebug.h"
+#include "debugstr.h"
 #include "debug.h"
 #include "libres.h"
 
-#define PrintId(name) \
-    if (HIWORD((DWORD)name)) \
-        dprintf_resource( stddeb, "'%s'", (char *)PTR_SEG_TO_LIN(name)); \
-    else \
-        dprintf_resource( stddeb, "#%04x", LOWORD(name)); 
-
 extern WORD WINE_LanguageId;
 
 /* error message when 16-bit resource function is called for Win32 module */
@@ -45,28 +39,30 @@
     NE_MODULE *pModule;
 
     hModule = MODULE_HANDLEtoHMODULE16( hModule ); 
-    dprintf_resource(stddeb, "FindResource16: module=%04x", hModule );
 
     if (HIWORD(name))  /* Check for '#xxx' name */
     {
 	char *ptr = PTR_SEG_TO_LIN( name );
 	if (ptr[0] == '#')
-	    if (!(name = (SEGPTR)atoi( ptr + 1 ))) return 0;
+	    if (!(name = (SEGPTR)atoi( ptr + 1 ))) {
+	      dprintf_warn(resource, "Incorrect resource name: %s\n", ptr);
+	      return 0;
+	    }
     }
 
-    dprintf_resource( stddeb, " name=" );
-    PrintId( name );
-
     if (HIWORD(type))  /* Check for '#xxx' type */
     {
 	char *ptr = PTR_SEG_TO_LIN( type );
 	if (ptr[0] == '#')
-	    if (!(type = (SEGPTR)atoi( ptr + 1 ))) return 0;
+	  if (!(type = (SEGPTR)atoi( ptr + 1 ))){
+	    dprintf_warn(resource, "Incorrect resource type: %s\n", ptr);
+	    return 0;
+	  }
     }
 
-    dprintf_resource( stddeb, " type=" );
-    PrintId( type );
-    dprintf_resource( stddeb, "\n" );
+    dprintf_info(resource, "FindResource16: module=%04x name=%s type=%s\n", 
+		 hModule, debugres(PTR_SEG_TO_LIN(name)), 
+		 debugres(PTR_SEG_TO_LIN(type)) );
 
     if ((pModule = MODULE_GetPtr( hModule )))
     {
@@ -129,18 +125,11 @@
 
         if (!hModule) hModule = GetTaskDS();
         hModule = MODULE_HANDLEtoHMODULE32( hModule );
-        dprintf_resource(stddeb, "FindResource32W: module=%08x type=",
-                         hModule );
-        if (HIWORD(type))
-            dprintf_resource(stddeb,"%p",type);
-        else
-            dprintf_resource(stddeb,"#%p",type);
-        dprintf_resource( stddeb, " name=" );
-        if (HIWORD(name))
-            dprintf_resource(stddeb,"%p",name);
-        else
-            dprintf_resource(stddeb,"#%p",name);
-        dprintf_resource( stddeb, "\n" );
+        dprintf_info(resource, "FindResource32W: module=%08x "
+			 "type=%s%p name=%s%p\n", hModule,
+			 (HIWORD(type))? "" : "#", type, 
+			 (HIWORD(name))? "" : "#", name);
+
         if (!(pModule = MODULE_GetPtr( hModule ))) return 0;
         if (!(pModule->flags & NE_FFLAGS_WIN32)) return 0;
         return PE_FindResourceEx32W(hModule,name,type,lang);
@@ -165,7 +154,7 @@
     NE_MODULE *pModule;
 
     hModule = MODULE_HANDLEtoHMODULE16( hModule );
-    dprintf_resource(stddeb, "LoadResource16: module=%04x res=%04x\n",
+    dprintf_info(resource, "LoadResource16: module=%04x res=%04x\n",
                      hModule, hRsrc );
     if (!hRsrc) return 0;
     if ((pModule = MODULE_GetPtr( hModule )))
@@ -193,7 +182,7 @@
 
         if (!hModule) hModule = GetTaskDS(); /* FIXME: see FindResource32W */
         hModule = MODULE_HANDLEtoHMODULE32( hModule );
-        dprintf_resource(stddeb, "LoadResource32: module=%04x res=%04x\n",
+        dprintf_info(resource, "LoadResource32: module=%04x res=%04x\n",
                          hModule, hRsrc );
         if (!hRsrc) return 0;
 
@@ -218,7 +207,7 @@
     HMODULE16 hModule;
     NE_MODULE *pModule;
 
-    dprintf_resource(stddeb, "LockResource: handle=%04x\n", handle );
+    dprintf_info(resource, "LockResource: handle=%04x\n", handle );
     if (!handle) return (SEGPTR)0;
     hModule = MODULE_HANDLEtoHMODULE16( handle );
     if (!(pModule = MODULE_GetPtr( hModule ))) return 0;
@@ -238,7 +227,7 @@
         HMODULE16 hModule;
         NE_MODULE *pModule;
 
-        dprintf_resource(stddeb, "LockResource: handle=%04x\n", handle );
+        dprintf_info(resource, "LockResource: handle=%04x\n", handle );
         if (!handle) return NULL;
         hModule = MODULE_HANDLEtoHMODULE16( handle );
         if (!(pModule = MODULE_GetPtr( hModule ))) return 0;
@@ -272,7 +261,7 @@
         HMODULE16 hModule;
         NE_MODULE *pModule;
 
-        dprintf_resource(stddeb, "FreeResource16: handle=%04x\n", handle );
+        dprintf_info(resource, "FreeResource16: handle=%04x\n", handle );
         if (!handle) return FALSE;
         hModule = MODULE_HANDLEtoHMODULE16( handle );
         if (!(pModule = MODULE_GetPtr( hModule ))) return 0;
@@ -304,7 +293,7 @@
     NE_MODULE *pModule;
 
     hModule = MODULE_HANDLEtoHMODULE16( hModule );
-    dprintf_resource(stddeb, "AccessResource16: module=%04x res=%04x\n",
+    dprintf_info(resource, "AccessResource16: module=%04x res=%04x\n",
                      hModule, hRsrc );
     if (!hRsrc) return 0;
     if (!(pModule = MODULE_GetPtr( hModule ))) return 0;
@@ -327,7 +316,7 @@
 INT32 WINAPI AccessResource32( HINSTANCE32 hModule, HRSRC32 hRsrc )
 {
     hModule = MODULE_HANDLEtoHMODULE32( hModule );
-    dprintf_resource(stddeb, "AccessResource: module=%04x res=%04x\n",
+    dprintf_info(resource, "AccessResource: module=%04x res=%04x\n",
                      hModule, hRsrc );
     if (!hRsrc) return 0;
     fprintf(stderr,"AccessResource32: not implemented\n");
@@ -343,7 +332,7 @@
     NE_MODULE *pModule;
 
     hModule = MODULE_HANDLEtoHMODULE16( hModule );
-    dprintf_resource(stddeb, "SizeofResource16: module=%04x res=%04x\n",
+    dprintf_info(resource, "SizeofResource16: module=%04x res=%04x\n",
                      hModule, hRsrc );
     if (!(pModule = MODULE_GetPtr( hModule ))) return 0;
     if (!__winelib)
@@ -365,7 +354,7 @@
 DWORD WINAPI SizeofResource32( HINSTANCE32 hModule, HRSRC32 hRsrc )
 {
     hModule = MODULE_HANDLEtoHMODULE32( hModule );
-    dprintf_resource(stddeb, "SizeofResource32: module=%04x res=%04x\n",
+    dprintf_info(resource, "SizeofResource32: module=%04x res=%04x\n",
                      hModule, hRsrc );
     if (!__winelib) return PE_SizeofResource32(hModule,hRsrc);
     else
@@ -384,7 +373,7 @@
     NE_MODULE *pModule;
 
     hModule = MODULE_HANDLEtoHMODULE16( hModule );
-    dprintf_resource(stddeb, "AllocResource: module=%04x res=%04x size=%ld\n",
+    dprintf_info(resource, "AllocResource: module=%04x res=%04x size=%ld\n",
                      hModule, hRsrc, size );
     if (!hRsrc) return 0;
     if (!(pModule = MODULE_GetPtr( hModule ))) return 0;
@@ -408,7 +397,7 @@
 HGLOBAL16 WINAPI DirectResAlloc( HINSTANCE16 hInstance, WORD wType,
                                  UINT16 wSize )
 {
-    dprintf_resource(stddeb,"DirectResAlloc(%04x,%04x,%04x)\n",
+    dprintf_info(resource,"DirectResAlloc(%04x,%04x,%04x)\n",
                      hInstance, wType, wSize );
     hInstance = MODULE_HANDLEtoHMODULE16(hInstance);
     if(!hInstance)return 0;
@@ -427,10 +416,10 @@
     HRSRC16	hRsrc;
 
     if (HIWORD(lpTableName))
-        dprintf_accel( stddeb, "LoadAccelerators: %04x '%s'\n",
+        dprintf_info(accel, "LoadAccelerators: %04x '%s'\n",
                       instance, (char *)PTR_SEG_TO_LIN( lpTableName ) );
     else
-        dprintf_accel( stddeb, "LoadAccelerators: %04x %04x\n",
+        dprintf_info(accel, "LoadAccelerators: %04x %04x\n",
                        instance, LOWORD(lpTableName) );
 
     if (!(hRsrc = FindResource16( instance, lpTableName, RT_ACCELERATOR )))
@@ -452,10 +441,10 @@
     HRSRC32 hRsrc;
 
     if (HIWORD(lpTableName))
-        dprintf_accel( stddeb, "LoadAccelerators: %04x '%s'\n",
+        dprintf_info(accel, "LoadAccelerators: %04x '%s'\n",
                       instance, (char *)( lpTableName ) );
     else
-        dprintf_accel( stddeb, "LoadAccelerators: %04x %04x\n",
+        dprintf_info(accel, "LoadAccelerators: %04x %04x\n",
                        instance, LOWORD(lpTableName) );
 
     if (!(hRsrc = FindResource32W( instance, lpTableName, 
@@ -516,7 +505,7 @@
     int string_num;
     int i;
 
-    dprintf_resource(stddeb,"LoadString: inst=%04x id=%04x buff=%08x len=%d\n",
+    dprintf_info(resource,"LoadString: inst=%04x id=%04x buff=%08x len=%d\n",
                      instance, resource_id, (int) buffer, buflen);
 
     hrsrc = FindResource16( instance, (SEGPTR)((resource_id>>4)+1), RT_STRING );
@@ -529,7 +518,7 @@
     for (i = 0; i < string_num; i++)
 	p += *p + 1;
     
-    dprintf_resource( stddeb, "strlen = %d\n", (int)*p );
+    dprintf_info(resource, "strlen = %d\n", (int)*p );
     
     i = MIN(buflen - 1, *p);
     if (buffer == NULL)
@@ -547,7 +536,7 @@
     }
     FreeResource16( hmem );
 
-    dprintf_resource(stddeb,"LoadString // '%s' copied !\n", buffer);
+    dprintf_info(resource,"LoadString // '%s' copied !\n", buffer);
     return i;
 }
 
@@ -565,7 +554,7 @@
 
     if (HIWORD(resource_id)==0xFFFF) /* netscape 3 passes this */
 	resource_id = (UINT32)(-((INT32)resource_id));
-    dprintf_resource(stddeb, "LoadString: instance = %04x, id = %04x, buffer = %08x, "
+    dprintf_info(resource, "LoadString: instance = %04x, id = %04x, buffer = %08x, "
 	   "length = %d\n", instance, (int)resource_id, (int) buffer, buflen);
 
     hrsrc = FindResource32W( instance, (LPCWSTR)((resource_id>>4)+1), 
@@ -579,7 +568,7 @@
     for (i = 0; i < string_num; i++)
 	p += *p + 1;
     
-    dprintf_resource( stddeb, "strlen = %d\n", (int)*p );
+    dprintf_info(resource, "strlen = %d\n", (int)*p );
     
     i = MIN(buflen - 1, *p);
     if (buffer == NULL)
@@ -598,7 +587,7 @@
 #endif
     }
 #if 0
-    dprintf_resource(stddeb,"LoadString // '%s' copied !\n", buffer);
+    dprintf_info(resource,"LoadString // '%s' copied !\n", buffer);
 #endif
     return i;
 }
@@ -669,8 +658,7 @@
 	CHAR	str[1];
     } *stre;
 
-    dprintf_resource(stddeb, "LoadMessage: instance = %04x, id = %04x, buffer = %08x, "
-	   "length = %d\n", instance, (int)id, (int) buffer, buflen);
+    dprintf_info(resource, "LoadMessage: instance = %08lx, id = %08lx, buffer = %p, length = %ld\n", (DWORD)instance, (DWORD)id, buffer, (DWORD)buflen);
 
     /*FIXME: I am not sure about the '1' ... But I've only seen those entries*/
     hrsrc = FindResourceEx32W(instance,(LPWSTR)1,(LPCWSTR)RT_MESSAGELIST,lang);
@@ -698,7 +686,7 @@
     	stre = (struct _stringentry*)(((char*)stre)+slen);
     }
     slen=stre->len;
-    dprintf_resource(stddeb,"	- strlen=%d\n",slen);
+    dprintf_info(resource,"	- strlen=%d\n",slen);
     i = MIN(buflen - 1, slen);
     if (buffer == NULL)
 	return slen; /* different to LoadString */
@@ -712,7 +700,7 @@
 	}
     }
     if (buffer)
-	    dprintf_resource(stddeb,"LoadMessage // '%s' copied !\n", buffer);
+	    dprintf_info(resource,"LoadMessage // '%s' copied !\n", buffer);
     return i;
 }
 
@@ -749,14 +737,13 @@
 
     hModule = GetExePtr( hModule );
 
-    dprintf_resource(stddeb, "SetResourceHandler: module=%04x type=", hModule );
-    PrintId( s );
-    dprintf_resource( stddeb, "\n" );
+    dprintf_info(resource, "SetResourceHandler: module=%04x type=%s\n", 
+		 hModule, debugres(PTR_SEG_TO_LIN(s)) );
 
     if ((pModule = MODULE_GetPtr( hModule )))
     {
 	if (pModule->flags & NE_FFLAGS_WIN32)
-	    fprintf(stderr,"SetResourceHandler: %s", NEWin32FailureString);
+	    fprintf(stderr,"SetResourceHandler: %s\n", NEWin32FailureString);
 	else if (pModule->res_table)
 	    return NE_SetResourceHandler( hModule, s, resourceHandler );
     }
diff --git a/loader/signal.c b/loader/signal.c
index 66def5d..0092b22 100644
--- a/loader/signal.c
+++ b/loader/signal.c
@@ -33,6 +33,7 @@
 
 #if defined(linux) && defined(__i386__)
 /* This is the sigaction structure from the Linux 2.1.20 kernel.  */
+#undef sa_handler
 struct kernel_sigaction
 {
     void (*sa_handler)();
diff --git a/loader/task.c b/loader/task.c
index eeeaeb0..ce56b0a 100644
--- a/loader/task.c
+++ b/loader/task.c
@@ -29,7 +29,6 @@
 #include "toolhelp.h"
 #include "winnt.h"
 #include "thread.h"
-#include "stddebug.h"
 #include "debug.h"
 #include "dde_proc.h"
 
@@ -177,9 +176,9 @@
     /* Display it */
 
     p = (char *) GlobalLock16( handle );
-    dprintf_task(stddeb, "Master DOS environment at %p\n", p);
-    for (; *p; p += strlen(p) + 1) dprintf_task(stddeb, "    %s\n", p);
-    dprintf_task( stddeb, "Progname: %s\n", p+3 );
+    dprintf_info(task, "Master DOS environment at %p\n", p);
+    for (; *p; p += strlen(p) + 1) dprintf_info(task, "    %s\n", p);
+    dprintf_info(task, "Progname: %s\n", p+3 );
 
     return handle;
 }
@@ -348,7 +347,7 @@
 
         InitApp( pTask->hModule );
         PE_InitializeDLLs( PROCESS_Current(), DLL_PROCESS_ATTACH, (LPVOID)-1 );
-        dprintf_relay( stddeb, "CallTo32(entryproc=%p)\n", entry );
+        dprintf_info(relay, "CallTo32(entryproc=%p)\n", entry );
         exit_code = entry();
         TASK_KillCurrentTask( exit_code );
     }
@@ -377,7 +376,7 @@
         ECX_reg(&context) = pModule->heap_size;
         EDI_reg(&context) = context.SegDs;
 
-        dprintf_task( stddeb, "Starting main program: cs:ip=%04lx:%04x ds=%04lx ss:sp=%04x:%04x\n",
+        dprintf_info(task, "Starting main program: cs:ip=%04lx:%04x ds=%04lx ss:sp=%04x:%04x\n",
                       CS_reg(&context), IP_reg(&context), DS_reg(&context),
                       SELECTOROF(pTask->thdb->cur_stack),
                       OFFSETOF(pTask->thdb->cur_stack) );
@@ -564,7 +563,7 @@
 
     TASK_LinkTask( hTask );
 
-    dprintf_task( stddeb, "CreateTask: module='%s' cmdline='%s' task=%04x\n",
+    dprintf_info(task, "CreateTask: module='%s' cmdline='%s' task=%04x\n",
                   name, cmdLine, hTask );
 
     return hTask;
@@ -622,7 +621,7 @@
     TDB* pTask = (TDB*) GlobalLock16( hCurrentTask );
     if (!pTask) USER_ExitWindows();  /* No current task yet */
 
-    dprintf_task(stddeb, "Killing task %04x\n", hCurrentTask );
+    dprintf_info(task, "Killing task %04x\n", hCurrentTask );
 
     /* Delete active sockets */
 
@@ -644,7 +643,7 @@
 
     if (nTaskCount <= 1)
     {
-        dprintf_task( stddeb, "\nthis is the last task, exiting\n" );
+        dprintf_info(task, "\nthis is the last task, exiting\n" );
         USER_ExitWindows();
     }
 
@@ -725,7 +724,7 @@
         {
             pNewTask = (TDB *)GlobalLock16( hTask );
 
-	    dprintf_task( stddeb, "\ttask = %04x, events = %i\n", hTask, pNewTask->nEvents);
+	    dprintf_info(task, "\ttask = %04x, events = %i\n", hTask, pNewTask->nEvents);
 
             if (pNewTask->nEvents) break;
             hTask = pNewTask->hNext;
@@ -740,11 +739,11 @@
 
     if (hTask == hCurrentTask) 
     {
-       dprintf_task( stddeb, "returning to the current task(%04x)\n", hTask );
+       dprintf_info(task, "returning to the current task(%04x)\n", hTask );
        return;  /* Nothing to do */
     }
     pNewTask = (TDB *)GlobalLock16( hTask );
-    dprintf_task( stddeb, "Switching to task %04x (%.8s)\n",
+    dprintf_info(task, "Switching to task %04x (%.8s)\n",
                   hTask, pNewTask->module_name );
 
      /* Make the task the last in the linked list (round-robin scheduling) */
@@ -1013,7 +1012,7 @@
     thunk = PTR_SEG_TO_LIN( thunkaddr );
     lfunc = PTR_SEG_TO_LIN( func );
 
-    dprintf_task( stddeb, "MakeProcInstance(%08lx,%04x): got thunk %08lx\n",
+    dprintf_info(task, "MakeProcInstance(%08lx,%04x): got thunk %08lx\n",
                   (DWORD)func, hInstance, (DWORD)thunkaddr );
     if (((lfunc[0]==0x8c) && (lfunc[1]==0xd8)) ||
     	((lfunc[0]==0x1e) && (lfunc[1]==0x58))
@@ -1037,7 +1036,7 @@
  */
 void WINAPI FreeProcInstance16( FARPROC16 func )
 {
-    dprintf_task( stddeb, "FreeProcInstance(%08lx)\n", (DWORD)func );
+    dprintf_info(task, "FreeProcInstance(%08lx)\n", (DWORD)func );
     if (!__winelib) TASK_FreeThunk( hCurrentTask, (SEGPTR)func );
 }
 
@@ -1119,7 +1118,7 @@
 
     if (!(pTask = (TDB *)GlobalLock16( hCurrentTask ))) return;
     if (!(pData = (INSTANCEDATA *)GlobalLock16( seg ))) return;
-    dprintf_task( stddeb, "SwitchStackTo: old=%04x:%04x new=%04x:%04x\n",
+    dprintf_info(task, "SwitchStackTo: old=%04x:%04x new=%04x:%04x\n",
                   SELECTOROF( pTask->thdb->cur_stack ),
                   OFFSETOF( pTask->thdb->cur_stack ), seg, ptr );
 
@@ -1168,7 +1167,7 @@
         fprintf( stderr, "SwitchStackBack: no previous SwitchStackTo\n" );
         return;
     }
-    dprintf_task( stddeb, "SwitchStackBack: restoring stack %04x:%04x\n",
+    dprintf_info(task, "SwitchStackBack: restoring stack %04x:%04x\n",
                   SELECTOROF(pData->old_ss_sp), OFFSETOF(pData->old_ss_sp) );
 
     oldFrame = (STACK16FRAME *)PTR_SEG_TO_LIN( pTask->thdb->cur_stack );
@@ -1182,7 +1181,7 @@
 
     newFrame = (STACK16FRAME *)PTR_SEG_TO_LIN( pTask->thdb->cur_stack );
     newFrame->frame32 = oldFrame->frame32;
-    if (debugging_relay)
+    if (debugging_info(relay))
     {
         newFrame->entry_ip = oldFrame->entry_ip;
         newFrame->entry_cs = oldFrame->entry_cs;
@@ -1447,7 +1446,7 @@
     TDB *pTask;
     INSTANCEDATA *pInstData;
 
-    dprintf_toolhelp( stddeb, "TaskNext(%p): task=%04x\n", lpte, lpte->hNext );
+    dprintf_info(toolhelp, "TaskNext(%p): task=%04x\n", lpte, lpte->hNext );
     if (!lpte->hNext) return FALSE;
     pTask = (TDB *)GlobalLock16( lpte->hNext );
     if (!pTask || pTask->magic != TDB_MAGIC) return FALSE;