Release 950817

Thu Aug 17 19:30:14 1995  Alexandre Julliard  <julliard@sunsite.unc.edu>

	* [*/Makefile.in]
	Removed winelibclean target, as it doesn't work anyway.

	* [controls/button.c]
	Avoid drawing the focus rectangle outside of the button.

	* [controls/widgets.c]
	Fixed bug with the size of the reserved bytes for the Edit
	control (caused Eudora to crash).

	* [debugger/*] [include/debugger.h]
	Unified debugger address handling. Segmented and linear addresses
	are no grouped in a single type DBG_ADDR.
	All commands now accept seg:off addresses.
	Module entry points are now loaded upon first entry to the
	debugger, so that entry points of the loaded executable also
	appear in the symbol table.

	* [include/registers.h] [miscemu/*.c]
	Register macros are now of the form 'AX_reg(context)' instead of 'AX'.
	This makes code less readable, but will prevent a lot of name
	clashes with other definitions. It also avoids a hidden reference
	to the 'context' variable.

	* [ipc/dde_atom.c] [misc/atom.c]
	All *AddAtom and *FindAtom functions now take a SEGPTR parameter,
	to allow supporting integer atoms.
	Moved atom.c to memory/ directory.

	* [loader/task.c]
	Fixed environment allocation to compute the size dynamically.
	Added 'windir' environment variable.
	Fixed GetDOSEnvironment() to return the current task environment.

	* [windows/message.c]
	Fixed bug in MSG_GetWindowForEvent().

Wed Aug  9 11:40:43 1995  Marcus Meissner  <msmeissn@faui01.informatik.uni-erlangen.de>

	* [include/ole.h]
	Added a lot of structures  from my Borland Manual. Neither complete,
	nor 100% right (check please)
	
	* [misc/shell.c]
	Fixed some of the Reg* functions.
	Enhanced ShellExecute.
	Please test: wine "regedit.exe /v" mplayer.exe soundrec.exe
	Do YOU know the format of \WINDOWS\REG.DAT? Mail me please :)

	* [misc/dos_fs.c]
	Make umsdos mounted windows dirs work again.

	* [miscemu/emulate.c]
	Added some comments, preimplementation of subfunction 7.

	* [multimedia/mmsystem.c]
	Implemented mciSendString. not complete, not clean, not
	necessarily working (only checked with a program which uses
 	'cdaudio' (one working program is cool.exe, a shareware waveditor
 	with cdaudio play facilities.)

	* [multimedia/mcicda.c]
	Segptr fixes in DriverProc
	Default cdrom drive in Linux is /dev/cdrom ... usually a symbolic
 	link to your real cdrom device.

Tue Aug  8 19:41:50 CDT 1995 Daniel Schepler <dks2@cec.wustl.edu>

	* [loader/resource.c]
	Don't crash in a LoadString to NULL

	* [loader/resource.c]
	Fixed accelerators to work with modifiers.  (ALT-x modifiers still
 	won't work unless the ALT keypress exited the menu.)

	* [misc/file.c]
	Expand a file to the current offset with an _lwrite of size zero.

	* [misc/file.c]
	Set a newly created file to read-write instead of write-only.
	
Sun Aug  6 20:28:35 1995  Anand Kumria <akumria@ozemail.com.au>

	* [misc/main.c] [include/msdos.h]
	Fixed to return DOS version 6.22, and the correct byte order
	for Windows programs.

Wed Aug  2 12:36:33 1995   Bernd Schmidt <crux@pool.informatik.rwth-aachen.de>

	* [include/options.h] [memory/global.c] [misc/main.c]
	Make the new IPC run-time selectible, disabling it by default.
	(I think it's only useful for libwine, anyway.)

	* [loader/task.c] [memory/selector.c]
	In FreeSelector(), walk up the stack and fix the frames.

	* [objects/dib.c]
	Missing break statement in DIB_SetImageBits_RLE8().
	In GetDIBits(), set the compression flag in the bitmap info to zero.

	* [windows/dialog.c]
	GetNextDlgGroupItem() needs to treat the first child as if it had
	an implicit WS_GROUP bit set.

Mon Jul 31 15:44:47 EDT 1995 Louis-D. Dubeau <ldd@step.polymtl.ca>

	* [misc/dos_fs.c]
	Quick'n dirty fix for the initialisation of the Z: information
	structure.
diff --git a/loader/task.c b/loader/task.c
index 53d1006..7350965 100644
--- a/loader/task.c
+++ b/loader/task.c
@@ -10,6 +10,7 @@
 #include "windows.h"
 #include "task.h"
 #include "callback.h"
+#include "dos_fs.h"
 #include "debugger.h"
 #include "global.h"
 #include "instance.h"
@@ -36,6 +37,7 @@
 static HTASK hTaskToKill = 0;
 static HTASK hLockedTask = 0;
 static WORD nTaskCount = 0;
+static HANDLE hDOSEnvironment = 0;
 
   /* TASK_Reschedule() 16-bit entry point */
 static FARPROC TASK_RescheduleProc;
@@ -43,13 +45,122 @@
 #define TASK_SCHEDULE()  CallTo16_word_(TASK_RescheduleProc,0)
 
 
+static HANDLE TASK_CreateDOSEnvironment(void);
+
+
 /***********************************************************************
  *           TASK_Init
  */
 BOOL TASK_Init(void)
 {
     TASK_RescheduleProc = (FARPROC)GetWndProcEntry16( "TASK_Reschedule" );
-    return TRUE;
+    if (!(hDOSEnvironment = TASK_CreateDOSEnvironment()))
+        fprintf( stderr, "Not enough memory for DOS Environment\n" );
+    return (hDOSEnvironment != 0);
+}
+
+
+/***********************************************************************
+ *           TASK_CreateDOSEnvironment
+ *
+ * Create the original DOS environment.
+ */
+static HANDLE TASK_CreateDOSEnvironment(void)
+{
+    static const char program_name[] = "KRNL386.EXE";
+    char **e, *p;
+    int initial_size, size;
+    HANDLE handle;
+
+    extern char **environ;
+    extern char WindowsDirectory[], SystemDirectory[];
+
+    /* DOS environment format:
+     * ASCIIZ   string 1
+     * ASCIIZ   string 2
+     * ...
+     * ASCIIZ   string n
+     * ASCIIZ   PATH=xxx
+     * ASCIIZ   windir=xxx
+     * BYTE     0
+     * WORD     1
+     * ASCIIZ   program name (e.g. C:\WINDOWS\SYSTEM\KRNL386.EXE)
+     */
+
+    /* First compute the size of the fixed part of the environment */
+
+    initial_size = 5 +                            /* PATH= */
+                   strlen(WindowsPath) + 1 +      /* path value */
+                   7 +                            /* windir= */
+                   strlen(WindowsDirectory) + 1 + /* windir value */
+                   1 +                            /* BYTE 0 at end */
+                   sizeof(WORD) +                 /* WORD 1 */
+                   strlen(SystemDirectory) + 1 +  /* program directory */
+                   strlen(program_name) + 1;      /* program name */
+
+    /* Compute the total size of the Unix environment (except path) */
+
+    for (e = environ, size = initial_size; *e; e++)
+    {
+	if (strncasecmp(*e, "path=", 5))
+	{
+            int len = strlen(*e) + 1;
+            if (size + len >= 32767)
+            {
+                fprintf( stderr, "Warning: environment larger than 32k.\n" );
+                break;
+            }
+            size += len;
+	}
+    }
+
+
+    /* Now allocate the environment */
+
+    if (!(handle = GlobalAlloc( GMEM_FIXED, size ))) return 0;
+    p = (char *)GlobalLock( handle );
+
+    /* And fill it with the Unix environment */
+
+    for (e = environ, size = initial_size; *e; e++)
+    {
+	if (strncasecmp(*e, "path=", 5))
+	{
+            int len = strlen(*e) + 1;
+            if (size + len >= 32767) break;
+            strcpy( p, *e );
+            size += len;
+            p    += len;
+	}
+    }
+
+    /* Now add the path and Windows directory */
+
+    strcpy( p, "PATH=" );
+    strcat( p, WindowsPath );
+    p += strlen(p) + 1;
+
+    strcpy( p, "windir=" );
+    strcat( p, WindowsDirectory );
+    p += strlen(p) + 1;
+
+    /* Now add the program name */
+
+    *p++ = '\0';
+    *(WORD *)p = 1;
+    p += sizeof(WORD);
+    strcpy( p, SystemDirectory );
+    strcat( p, "\\" );
+    strcat( p, program_name );
+
+    /* Display it */
+
+    p = (char *) GlobalLock( 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 );
+
+    return handle;
 }
 
 
@@ -229,7 +340,7 @@
                    0 /*dx*/, 0 /*si*/, ds_reg /*di*/ );
     /* This should never return */
     fprintf( stderr, "TASK_CallToStart: Main program returned!\n" );
-    exit(1);
+    TASK_KillCurrentTask( 1 );
 }
 
 
@@ -241,6 +352,7 @@
 {
     HTASK hTask;
     TDB *pTask;
+    HANDLE hParentEnv;
     NE_MODULE *pModule;
     SEGTABLEENTRY *pSegTable;
     LPSTR name;
@@ -260,7 +372,24 @@
     if (!hTask) return 0;
     pTask = (TDB *)GlobalLock( hTask );
 
-      /* get current directory */
+      /* Allocate the new environment block */
+
+    if (!(hParentEnv = hEnvironment))
+    {
+        TDB *pParent = (TDB *)GlobalLock( hCurrentTask );
+        hParentEnv = pParent ? pParent->pdb.environment : hDOSEnvironment;
+    }
+    /* FIXME: do we really need to make a copy also when */
+    /*        we don't use the parent environment? */
+    if (!(hEnvironment = GlobalAlloc( GMEM_FIXED, GlobalSize( hParentEnv ) )))
+    {
+        GlobalFree( hTask );
+        return 0;
+    }
+    memcpy( GlobalLock( hEnvironment ), GlobalLock( hParentEnv ),
+            GlobalSize( hParentEnv ) );
+
+      /* Get current directory */
     
     GetModuleFileName( hModule, filename, sizeof(filename) );
     name = strrchr(filename, '\\');
@@ -355,8 +484,8 @@
                  pSegTable[pModule->ss-1].minsize + pModule->stack_size) & ~1;
     stack16Top = (char *)PTR_SEG_OFF_TO_LIN( pTask->ss, pTask->sp );
     frame16 = (STACK16FRAME *)stack16Top - 1;
-    frame16->saved_ss = pTask->ss;
-    frame16->saved_sp = pTask->sp;
+    frame16->saved_ss = 0; /*pTask->ss;*/
+    frame16->saved_sp = 0; /*pTask->sp;*/
     frame16->ds = frame16->es = pTask->hInstance;
     frame16->entry_point = 0;
     frame16->ordinal_number = 24;  /* WINPROCS.24 is TASK_Reschedule */
@@ -380,8 +509,9 @@
 
     if (Options.debug)
     {
+        DBG_ADDR addr = { pSegTable[pModule->cs-1].selector, pModule->ip };
         fprintf( stderr, "Task '%s': ", name );
-        DEBUG_AddBreakpoint( pSegTable[pModule->cs-1].selector, pModule->ip );
+        DEBUG_AddBreakpoint( &addr );
     }
 
       /* Add the task to the linked list */
@@ -844,6 +974,18 @@
 
 
 /***********************************************************************
+ *           GetDOSEnvironment   (KERNEL.131)
+ */
+SEGPTR GetDOSEnvironment(void)
+{
+    TDB *pTask;
+
+    if (!(pTask = (TDB *)GlobalLock( hCurrentTask ))) return 0;
+    return WIN16_GlobalLock( pTask->pdb.environment );
+}
+
+
+/***********************************************************************
  *           GetNumTasks   (KERNEL.152)
  */
 WORD GetNumTasks(void)