Added a WINEDEBUG environment variable that allows turning on debug
output as early as possible during startup.

diff --git a/dlls/ntdll/server.c b/dlls/ntdll/server.c
index 5db3df3..269b7c3 100644
--- a/dlls/ntdll/server.c
+++ b/dlls/ntdll/server.c
@@ -55,9 +55,12 @@
 #include "wine/library.h"
 #include "wine/pthread.h"
 #include "wine/server.h"
+#include "wine/debug.h"
 #include "winerror.h"
 #include "ntdll_misc.h"
 
+WINE_DEFAULT_DEBUG_CHANNEL(server);
+
 /* Some versions of glibc don't define this */
 #ifndef SCM_RIGHTS
 #define SCM_RIGHTS 1
@@ -480,7 +483,7 @@
 {
     static int started;  /* we only try once */
     char *path, *p;
-    char *argv[2];
+    char *argv[3];
 
     if (!started)
     {
@@ -489,6 +492,9 @@
         if (pid == -1) fatal_perror( "fork" );
         if (!pid)
         {
+            argv[0] = "wineserver";
+            argv[1] = TRACE_ON(server) ? "-d" : NULL;
+            argv[2] = NULL;
             /* if server is explicitly specified, use this */
             if ((p = getenv("WINESERVER")))
             {
@@ -499,14 +505,13 @@
                     sprintf( path, "%s/%s", oldcwd, p );
                     p = path;
                 }
-                execl( p, p, NULL );
+                argv[0] = p;
+                execv( argv[0], argv );
                 fatal_perror( "could not exec the server '%s'\n"
                               "    specified in the WINESERVER environment variable", p );
             }
             /* now use the standard search strategy */
-            argv[0] = "wineserver";
-            argv[1] = NULL;
-            wine_exec_wine_binary( "wineserver", argv, NULL );
+            wine_exec_wine_binary( argv[0], argv, NULL );
             fatal_error( "could not exec wineserver\n" );
         }
         waitpid( pid, &status, 0 );
diff --git a/documentation/wine.man.in b/documentation/wine.man.in
index 4e7358a..d1338ec 100644
--- a/documentation/wine.man.in
+++ b/documentation/wine.man.in
@@ -11,20 +11,18 @@
 section of the man page.
 .SH DESCRIPTION
 .B wine
-.I program
-loads and runs the given program, where the program is a DOS, Windows 3.x,
-or Win32 executable (x86 binaries only).
+loads and runs the given program, where the program is a DOS, Windows
+3.x, or Win32 executable (x86 binaries only).
 .PP
 For debugging wine, use
 .B winedbg
-.I program
 instead.
 .PP
 For running CUI executables (Windows console programs), use
 .B wineconsole
 instead of
-.B wine
-. This will display all the output in a separate windows (this requires X11 to
+.B wine.
+This will display all the output in a separate windows (this requires X11 to
 run). Not using
 .B wineconsole
 for CUI programs will only provide very limited console support, and your
@@ -39,8 +37,10 @@
 A large percentage of the API has been implemented,
 although there are still several major pieces of work left to do.
 .SH REQUIREMENTS AND INSTALLATION
-Read the README file in the Wine source distribution and the wine.conf
-man page to know what Wine requires and how it is installed from source.
+Read the README file in the Wine source distribution and the
+.BR wine.conf (5)
+man page to know what Wine requires and how it is installed from
+source.
 .SH OPTIONS
 .TP
 .I --debugmsg [xxx]#name[,[xxx1]#name1]
@@ -57,11 +57,11 @@
 channel are turned on.  Each channel will print messages about a particular
 component of 
 .B wine.  
-# is required and can be either + or -.  Note that 
-there is not a space after the comma between names. yyy are either the
-name of a whole DLL or a single API entry by name you either
-want to include or exclude from the relay listing.  Case doesn't matter
-for these.  You can do the same for snoop.
+# can be either + or - to switch the specified channel on or off
+respectively.  If there is no
+.I xxx
+part before it, a leading + can be omitted. Note that spaces are not
+allowed anywhere in the string.
 .PP
 For instance:
 .PP
@@ -77,32 +77,12 @@
 .br 
 .I --debugmsg +relay
 will turn on all relay messages. For more control on including or excluding
-functions and dlls look into the [Debug] section of the wine configuration file.
+functions and dlls from the relay trace look into the [Debug] section
+of the wine configuration file.
 .PP
-The full list of names is:
-all, accel, advapi, animate, aspi, atom, avifile, bitblt, bitmap, caret,
-cdrom, class, clipboard, clipping, combo, comboex, comm, commctrl, commdlg,
-console, crtdll, cursor, datetime, dc, ddeml, ddraw, debug, debugstr,
-delayhlp, dialog, dinput, dll, dosfs, dosmem, dplay, driver, dsound, edit,
-elfdll, enhmetafile, event, exec, file, fixup, font, gdi, global, graphics,
-header, heap, hook, hotkey, icmp, icon, imagehlp, imagelist, imm, int, int10,
-int16, int17, int19, int21, int31, io, ipaddress, joystick, key, keyboard,
-loaddll, ldt, listbox, listview, local, mci, mcianim, mciavi, mcicda, mcimidi,
-mciwave, mdi, menu, message, metafile, midi, mmaux, mmio, mmsys, mmtime,
-module, monthcal, mpr, msacm, msg, msvideo, nativefont, nonclient, ntdll,
-odbc, ole, opengl, pager, palette, pidl, print, process, profile, progress, 
-prop, propsheet, psapi, psdrv, ras, rebar, reg, region, relay, resource, 
-richedit, scroll, segment, seh, selector, sendmsg, server, setupapi, 
-setupx, shell, snoop, sound, static, statusbar, storage, stress, string, 
-syscolor, system, tab, tape, tapi, task, text, thread, thunk, timer, toolbar,
-toolhelp, tooltips, trackbar, treeview, ttydrv, tweak, typelib, updown, ver,
-virtual, vxd, wave, win, win16drv, win32, winedbg, wing, wininet, winsock,
-winspool, wnet, x11 and x11drv.
-
-.PP
-For more information on debugging messages, see the file 
-.I documentation/running.sgml
-in the source distribution (FIXME: outdated).
+For more information on debugging messages, see the
+.I Running Wine
+chapter of the Wine User Guide.
 .RE
 .PD 1
 .SH PROGRAM/ARGUMENTS
@@ -204,6 +184,10 @@
 and if this doesn't exist it will then look for a file named "wine" in
 the path and in a few other likely locations.
 .TP
+.I WINEDEBUG
+Turns debugging messages on or off. The syntax of the variable is
+identical to the syntax of the arguments for the --debugmsg option.
+.TP
 .I WINEDLLPATH
 Specifies the path(s) in which to search for builtin dlls and Winelib
 applications. This is a list of directories separated by ":". In
@@ -312,7 +296,7 @@
 The latest snapshot of the code may be obtained via CVS.  For information
 on how to do this, please see
 .I
-http://www.winehq.org/development/
+http://www.winehq.org/cvs
 .PP
 WineHQ, the
 .B wine
@@ -326,14 +310,15 @@
 newsgroup is 
 .I comp.emulators.ms-windows.wine.
 It is used for discussion of various 
-.B wine end user aspects/help.
+.B wine
+end user aspects/help.
 .PP
 For further information about 
 .B wine
 development, you might want to subscribe to the 
 .B wine 
 mailing lists at
-.I http://www.winehq.org/development/#ml
+.I http://www.winehq.org/forums
 .SH FILES
 .PD 0
 .TP
diff --git a/libs/wine/debug.c b/libs/wine/debug.c
index 7419cb2..2fb76fd 100644
--- a/libs/wine/debug.c
+++ b/libs/wine/debug.c
@@ -155,11 +155,7 @@
         if ((next = strchr( opt, ',' ))) *next++ = 0;
 
         p = opt + strcspn( opt, "+-" );
-        if (!p[0] || !p[1])  /* bad option, skip it */
-        {
-            errors++;
-            continue;
-        }
+        if (!p[0]) p = opt;  /* assume it's a debug channel name */
 
         if (p > opt)
         {
@@ -182,10 +178,15 @@
         }
         else
         {
-            if (*p == '+') set = ~0;
-            else clear = ~0;
+            if (*p == '-') clear = ~0;
+            else set = ~0;
         }
-        p++;
+        if (*p == '+' || *p == '-') p++;
+        if (!p[0])
+        {
+            errors++;
+            continue;
+        }
         if (!strcmp( p, "all" )) p = "";  /* empty string means all */
         wine_dbg_add_option( p, set, clear );
     }
diff --git a/libs/wine/loader.c b/libs/wine/loader.c
index 3a8b5a2..04eeae3 100644
--- a/libs/wine/loader.c
+++ b/libs/wine/loader.c
@@ -412,6 +412,22 @@
 
 
 /***********************************************************************
+ *           debug_usage
+ */
+static void debug_usage(void)
+{
+    static const char usage[] =
+        "Syntax of the WINEDEBUG variable:\n"
+        "  WINEDEBUG=[class]+xxx,[class]-yyy,...\n\n"
+        "Example: WINEDEBUG=+all,warn-heap\n"
+        "    turns on all messages except warning heap messages\n"
+        "Available message classes: err, warn, fixme, trace\n";
+    write( 2, usage, sizeof(usage) - 1 );
+    exit(1);
+}
+
+
+/***********************************************************************
  *           wine_init
  *
  * Main Wine initialisation.
@@ -419,6 +435,7 @@
 void wine_init( int argc, char *argv[], char *error, int error_size )
 {
     extern char **environ;
+    char *wine_debug;
     int file_exists;
     void *ntdll;
     void (*init_func)(void);
@@ -429,6 +446,12 @@
     __wine_main_argv = argv;
     __wine_main_environ = environ;
 
+    if ((wine_debug = getenv("WINEDEBUG")))
+    {
+        if (!strcmp( wine_debug, "help" )) debug_usage();
+        wine_dbg_parse_options( wine_debug );
+    }
+
     if (!(ntdll = dlopen_dll( "ntdll.dll", error, error_size, 0, &file_exists ))) return;
     if (!(init_func = wine_dlsym( ntdll, "__wine_process_init", error, error_size ))) return;
     init_func();