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/Imakefile b/loader/Imakefile
index 3ec199f..848d137 100644
--- a/loader/Imakefile
+++ b/loader/Imakefile
@@ -9,7 +9,6 @@
 	ne_resource.c \
 	pe_image.c \
 	pe_resource.c \
-	selector.c \
 	signal.c \
 	resource.c \
 	task.c 
diff --git a/loader/Makefile.in b/loader/Makefile.in
index b9cd285..f250120 100644
--- a/loader/Makefile.in
+++ b/loader/Makefile.in
@@ -10,7 +10,7 @@
 MODULE 	= loader
 
 SRCS 	= main.c module.c ne_image.c ne_resource.c pe_image.c \
-	pe_resource.c selector.c signal.c resource.c task.c
+	pe_resource.c signal.c resource.c task.c
  
 OBJS = $(SRCS:.c=.o)
 
@@ -25,26 +25,16 @@
 depend:
 	sed '/\#\#\# Dependencies/q' < Makefile > tmp_make
 	$(CC) $(DIVINCL) $(XINCL) -MM *.c >> tmp_make
-	cp tmp_make Makefile
-	rm tmp_make
+	mv tmp_make Makefile
 
 clean:
 	rm -f *.o \#*\# *~ tmp_make
 
 distclean: clean
-	rm Makefile
+	rm -f Makefile
 
 countryclean:
 
-NAMES = $(SRCS:.c=)
-
-winelibclean:
-	for i in $(NAMES); do \
-	if test `grep -c WINELIB $$i.c` -ne 0; then \
-	rm $$i.o; \
-	fi; \
-	done
- 
 dummy:
 
 ### Dependencies:
diff --git a/loader/main.c b/loader/main.c
index 0e301df..384e3f3 100644
--- a/loader/main.c
+++ b/loader/main.c
@@ -57,18 +57,15 @@
       /* Create built-in modules */
     if (!MODULE_Init()) return 0;
 
+      /* Initialize the DOS file system */
+    DOS_InitFS();
+
       /* Initialize tasks */
     if (!TASK_Init()) return 0;
 
       /* Initialize interrupt vectors */
     if (!INT_Init()) return 0;
 
-      /* Initialize the DOS file system */
-    DOS_InitFS();
-
-      /* Create DOS environment */
-    CreateSelectors();
-
       /* Initialize signal handling */
     init_wine_signals();
 
diff --git a/loader/module.c b/loader/module.c
index 12cf6ba..45891b3 100644
--- a/loader/module.c
+++ b/loader/module.c
@@ -35,8 +35,6 @@
  */
 BOOL MODULE_Init(void)
 {
-    extern void load_entrypoints( HMODULE );
-
     HMODULE hModule;
     NE_MODULE *pModule;
     SEGTABLEENTRY *pSegTable;
@@ -82,7 +80,6 @@
 
         pModule->next = hFirstModule;
         hFirstModule = hModule;
-        load_entrypoints( hModule );
     }
 
       /* Initialize some KERNEL exported values */
@@ -1169,6 +1166,22 @@
 }
 
 
+/***********************************************************************
+ *           GetWndProcEntry16 (not a Windows API function)
+ *
+ * Return an entry point from the WINPROCS dll.
+ */
+WNDPROC GetWndProcEntry16( char *name )
+{
+    WORD ordinal;
+    static HMODULE hModule = 0;
+
+    if (!hModule) hModule = GetModuleHandle( "WINPROCS" );
+    ordinal = MODULE_GetOrdinal( hModule, name );
+    return MODULE_GetEntryPoint( hModule, ordinal );
+}
+
+
 /**********************************************************************
  *	    ModuleFirst    (TOOLHELP.59)
  */
diff --git a/loader/resource.c b/loader/resource.c
index 4e6bbfc..90e9216 100644
--- a/loader/resource.c
+++ b/loader/resource.c
@@ -549,36 +549,33 @@
     if (hAccel == 0 || msg == NULL) return 0;
     if (msg->message != WM_KEYDOWN &&
     	msg->message != WM_KEYUP &&
+	msg->message != WM_SYSKEYDOWN &&
+	msg->message != WM_SYSKEYUP &&
     	msg->message != WM_CHAR) return 0;
 
     dprintf_accel(stddeb, "TranslateAccelerators hAccel=%04X !\n", hAccel);
 
     lpAccelTbl = (LPACCELHEADER)GlobalLock(hAccel);
     for (i = 0; i < lpAccelTbl->wCount; i++) {
-	if (lpAccelTbl->tbl[i].type & VIRTKEY_ACCEL) {
-	    if (msg->wParam == lpAccelTbl->tbl[i].wEvent &&
-		msg->message == WM_KEYDOWN) {
-		if ((lpAccelTbl->tbl[i].type & SHIFT_ACCEL) &&
-		    !(GetKeyState(VK_SHIFT) & 0xf)) {
+	if(lpAccelTbl->tbl[i].type & VIRTKEY_ACCEL) {
+	    if(msg->wParam == lpAccelTbl->tbl[i].wEvent &&
+	       (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)) {
+		INT mask = 0;
+
+		if(GetKeyState(VK_SHIFT) & 0xf) mask |= SHIFT_ACCEL;
+		if(GetKeyState(VK_CONTROL) & 0xf) mask |= CONTROL_ACCEL;
+		if(GetKeyState(VK_MENU) & 0xf) mask |= ALT_ACCEL;
+		if(mask == (lpAccelTbl->tbl[i].type &
+			    (SHIFT_ACCEL | CONTROL_ACCEL | ALT_ACCEL))) {
+		    SendMessage(hWnd, WM_COMMAND, lpAccelTbl->tbl[i].wIDval,
+				0x00010000L);
 		    GlobalUnlock(hAccel);
-		    return 0;
-		}
-		if ((lpAccelTbl->tbl[i].type & CONTROL_ACCEL) &&
-		    !(GetKeyState(VK_CONTROL) & 0xf)) {
-		    GlobalUnlock(hAccel);
-		    return 0;
-		}
-		if ((lpAccelTbl->tbl[i].type & ALT_ACCEL) &&
-		    !(GetKeyState(VK_MENU) & 0xf)) {
-		    GlobalUnlock(hAccel);
-		    return 0;
-		}
-		SendMessage(hWnd, WM_COMMAND, lpAccelTbl->tbl[i].wIDval, 0x00010000L);
-		GlobalUnlock(hAccel);
-		return 1;
-		}
-	    if (msg->message == WM_KEYUP) return 1;
+		    return 1;
+	        }
+		if (msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP)
+		    return 1;
 	    }
+	}
 	else {
 	    if (msg->wParam == lpAccelTbl->tbl[i].wEvent &&
 		msg->message == WM_CHAR) {
@@ -619,6 +616,8 @@
     dprintf_resource( stddeb, "strlen = %d\n", (int)*p );
     
     i = min(buflen - 1, *p);
+    if (buffer == NULL)
+	return i;
     if (i > 0) {
 	memcpy(buffer, p + 1, i);
 	buffer[i] = '\0';
diff --git a/loader/selector.c b/loader/selector.c
deleted file mode 100644
index ab211bd..0000000
--- a/loader/selector.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Selector manipulation functions
- *
- * Copyright 1993 Robert J. Amstadt
- * Copyright 1995 Alexandre Julliard
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#ifndef WINELIB
-
-#include "windows.h"
-#include "global.h"
-#include "module.h"
-#include "stddebug.h"
-/* #define DEBUG_SELECTORS */
-#include "debug.h"
-
-
-#define MAX_ENV_SIZE 16384  /* Max. environment size (ought to be dynamic) */
-
-static HANDLE EnvironmentHandle = 0;
-
-
-extern char WindowsPath[256];
-
-extern char **environ;
-
-
-
-WNDPROC GetWndProcEntry16( char *name )
-{
-    WORD ordinal;
-    static HMODULE hModule = 0;
-
-    if (!hModule) hModule = GetModuleHandle( "WINPROCS" );
-    ordinal = MODULE_GetOrdinal( hModule, name );
-    return MODULE_GetEntryPoint( hModule, ordinal );
-}
-
-
-/***********************************************************************
- *           GetDOSEnvironment   (KERNEL.131)
- */
-SEGPTR GetDOSEnvironment(void)
-{
-    return WIN16_GlobalLock( EnvironmentHandle );
-}
-
-
-/**********************************************************************
- *           CreateEnvironment
- */
-static HANDLE CreateEnvironment(void)
-{
-    HANDLE handle;
-    char **e;
-    char *p;
-
-    handle = GlobalAlloc( GMEM_MOVEABLE, MAX_ENV_SIZE );
-    if (!handle) return 0;
-    p = (char *) GlobalLock( handle );
-
-    /*
-     * Fill environment with Windows path, the Unix environment,
-     * and program name.
-     */
-    strcpy(p, "PATH=");
-    strcat(p, WindowsPath);
-    p += strlen(p) + 1;
-
-    for (e = environ; *e; e++)
-    {
-	if (strncasecmp(*e, "path", 4))
-	{
-	    strcpy(p, *e);
-	    p += strlen(p) + 1;
-	}
-    }
-
-    *p++ = '\0';
-
-    /*
-     * Display environment
-     */
-    p = (char *) GlobalLock( handle );
-    dprintf_selectors(stddeb, "Environment at %p\n", p);
-    for (; *p; p += strlen(p) + 1) dprintf_selectors(stddeb, "    %s\n", p);
-
-    return handle;
-}
-
-
-
-/**********************************************************************
- *					CreateSelectors
- */
-void CreateSelectors(void)
-{
-    if(!EnvironmentHandle) EnvironmentHandle = CreateEnvironment();
-}
-
-
-#endif /* ifndef WINELIB */
diff --git a/loader/signal.c b/loader/signal.c
index 4ede072..82d9651 100644
--- a/loader/signal.c
+++ b/loader/signal.c
@@ -55,13 +55,15 @@
 #endif
     if (signal != SIGTRAP)
     {
-        if (CS == WINE_CODE_SELECTOR)
+        if (CS_reg(context) == WINE_CODE_SELECTOR)
         {
             fprintf(stderr, "Segmentation fault in Wine program (%x:%lx)."
-                            "  Please debug\n", CS, EIP );
+                            "  Please debug\n",
+                            CS_reg(context), EIP_reg(context) );
         }
         else if (INSTR_EmulateInstruction( context )) return;
-        fprintf(stderr,"In win_fault %x:%lx\n", CS, EIP );
+        fprintf( stderr,"In win_fault %x:%lx\n",
+                 CS_reg(context), EIP_reg(context) );
     }
     XUngrabPointer(display, CurrentTime);
     XUngrabServer(display);
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)