Release 950216

Thu Feb 16 18:57:31 1995  Alexandre Julliard  (julliard@sunsite.unc.edu)

	* [if1632/call.S]
	Only save the lower 16-bits of SP and BP.

	* [if1632/callback.c]
	When calling to 16-bit code, restore DS from its previous value on
	entry to the 32-bit code, instead of from the code segment owner.

	* [if1632/relay.c] [include/stackframe.h]
	Use a structure to represent the 16-bit stack frame layout
	instead of hard-coded offsets.
	
	* [rc/Imakefile]
	Use y.tab.c for bison output file for compatibility with yacc.

	* [tools/build.c]
	Small optimization for calls to 32-bit code.

Sun Feb 12 03:19:47 1995  Michael Veksler (s1678223@t2.technion.ac.il)

	* [tools/build.c]
	Fixed bug (inflicted by previous change) - SEGV on ZMAGIC file format.

Sun Feb 11 20:00:00 1995  Göran Thyni  (goran@norrsken.bildbasen.se)

	* [debugger/dbg.y]
	Remove unnecessary sym-table loading when stopped in 16-bit mode.

	* [include/segmem.h] [loader/selector.c]
        Added dynamic alloction of selectors.
        Fixed some problems with large programs SIGSEGV-ing while
        running out of selectors.

	* [include/segmem.h] [loader/selector.c] [if1632/callback.c] 
          [memory/global.c] [memory/heap.c] [memory/linear.c]
	Use __AHSHIFT and __AHINCR instead of 3 and 8.

Mon Feb  6 18:07:38 1995  Cameron Heide  (heide@ee.ualberta.ca)

        * [misc/dos_fs.c]
        Better relative path handling when converting filenames between
        dos and unix, allowing '.' to be used in the Windows path.
        Startup working dir is now based on current working dir.

Sat Feb  4 21:21:13 1995  Michael Veksler (s1678223@t2.technion.ac.il)

	* [if1632/relay.c] [include/dlls.h] [tools/build.c]
	Squeezed data structure that references internal dll's (mostly
	"struct dll_table_entry_s"). Caused 20% reduction in executable
	code size.

Fri Feb  3 18:53:15 1995  Martin v. Loewis  (loewis@marie)

	* [Imakefile]
	make wine.sym only when making emulator

	* [misc/file.c]
	OpenFile(): report as not implemented for WINELIB

	* [misc/winsock.c]
	Fix CONVERT_HOSTENT and friends for use with WINELIB

	* [rc/Imakefile][rc/rc.y][rc/parser.c]
	Rename rc.y to parser.y
	Use flex and bison on Sun

	* [toolkit/sup.c]
	CallWindowProc: fix parameter type

	* [windows/event.c]
	Commented #ifdef sparc
diff --git a/ANNOUNCE b/ANNOUNCE
index ed22ab8..7fbbef7 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -1,14 +1,14 @@
-This is release 950202 of Wine the MS Windows emulator.  This is still a
+This is release 950216 of Wine the MS Windows emulator.  This is still a
 developer's only release.  There are many bugs and many unimplemented API
 features.  Most applications still do not work.
 
 Patches should be submitted to "wine-new@amscons.com".  Please don't forget
 to include a ChangeLog entry.  I'll make a new release every other Sunday.
 
-WHAT'S NEW with Wine-950202: (see ChangeLog for details)
-	- Maximized windows
-	- Edit control now uses \r\n for line endings
-	- Better registry functions
+WHAT'S NEW with Wine-950216: (see ChangeLog for details)
+	- Size optimizations in DLL relay code
+	- Portability fixes for WineLib
+	- Handling of relative paths in DOS filenames
 	- Lots of bug fixes
 
 See the README file in the distribution for installation instructions.
@@ -17,11 +17,11 @@
 the release is available at the ftp sites.  The sources will be available
 from the following locations:
 
-	sunsite.unc.edu:/pub/Linux/ALPHA/wine/Wine-950202.tar.gz
-	aris.com:/pub/linux/ALPHA/Wine/development/Wine-950202.tar.gz
-	tsx-11.mit.edu:/pub/linux/ALPHA/Wine/development/Wine-950202.tar.gz
-	ftp.funet.fi:/pub/OS/Linux/ALPHA/Wine/Wine-950202.tar.gz
-	ftp.wonderland.org:/Wine/Wine-950202.tar.gz
+	sunsite.unc.edu:/pub/Linux/ALPHA/wine/Wine-950216.tar.gz
+	aris.com:/pub/linux/ALPHA/Wine/development/Wine-950216.tar.gz
+	tsx-11.mit.edu:/pub/linux/ALPHA/Wine/development/Wine-950216.tar.gz
+	ftp.funet.fi:/pub/OS/Linux/ALPHA/Wine/Wine-950216.tar.gz
+	ftp.wonderland.org:/Wine/Wine-950216.tar.gz
 
 If you submitted a patch, please check to make sure it has been
 included in the new release.
@@ -41,4 +41,4 @@
 
 --
 Alexandre Julliard
-julliard@lamisun.epfl.ch
+julliard@sunsite.unc.edu
diff --git a/ChangeLog b/ChangeLog
index f2a9d94..f7b26b1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,78 @@
 ----------------------------------------------------------------------
+Thu Feb 16 18:57:31 1995  Alexandre Julliard  (julliard@sunsite.unc.edu)
+
+	* [if1632/call.S]
+	Only save the lower 16-bits of SP and BP.
+
+	* [if1632/callback.c]
+	When calling to 16-bit code, restore DS from its previous value on
+	entry to the 32-bit code, instead of from the code segment owner.
+
+	* [if1632/relay.c] [include/stackframe.h]
+	Use a structure to represent the 16-bit stack frame layout
+	instead of hard-coded offsets.
+	
+	* [rc/Imakefile]
+	Use y.tab.c for bison output file for compatibility with yacc.
+
+	* [tools/build.c]
+	Small optimization for calls to 32-bit code.
+
+Sun Feb 12 03:19:47 1995  Michael Veksler (s1678223@t2.technion.ac.il)
+
+	* [tools/build.c]
+	Fixed bug (inflicted by previous change) - SEGV on ZMAGIC file format.
+
+Sun Feb 11 20:00:00 1995  Göran Thyni  (goran@norrsken.bildbasen.se)
+
+	* [debugger/dbg.y]
+	Remove unnecessary sym-table loading when stopped in 16-bit mode.
+
+	* [include/segmem.h] [loader/selector.c]
+        Added dynamic alloction of selectors.
+        Fixed some problems with large programs SIGSEGV-ing while
+        running out of selectors.
+
+	* [include/segmem.h] [loader/selector.c] [if1632/callback.c] 
+          [memory/global.c] [memory/heap.c] [memory/linear.c]
+	Use __AHSHIFT and __AHINCR instead of 3 and 8.
+
+Mon Feb  6 18:07:38 1995  Cameron Heide  (heide@ee.ualberta.ca)
+
+        * [misc/dos_fs.c]
+        Better relative path handling when converting filenames between
+        dos and unix, allowing '.' to be used in the Windows path.
+        Startup working dir is now based on current working dir.
+
+Sat Feb  4 21:21:13 1995  Michael Veksler (s1678223@t2.technion.ac.il)
+
+	* [if1632/relay.c] [include/dlls.h] [tools/build.c]
+	Squeezed data structure that references internal dll's (mostly
+	"struct dll_table_entry_s"). Caused 20% reduction in executable
+	code size.
+
+Fri Feb  3 18:53:15 1995  Martin v. Loewis  (loewis@marie)
+
+	* [Imakefile]
+	make wine.sym only when making emulator
+
+	* [misc/file.c]
+	OpenFile(): report as not implemented for WINELIB
+
+	* [misc/winsock.c]
+	Fix CONVERT_HOSTENT and friends for use with WINELIB
+
+	* [rc/Imakefile][rc/rc.y][rc/parser.c]
+	Rename rc.y to parser.y
+	Use flex and bison on Sun
+
+	* [toolkit/sup.c]
+	CallWindowProc: fix parameter type
+
+	* [windows/event.c]
+	Commented #ifdef sparc
+
+----------------------------------------------------------------------
 Wed Feb  1 19:27:55 1995  Alexandre Julliard  (julliard@lamisun.epfl.ch)
 
 	* [windows/nonclient.c] [windows/winpos.c]
diff --git a/Configure b/Configure
index 63e261c..1366714 100644
--- a/Configure
+++ b/Configure
@@ -8,7 +8,7 @@
 WINELIB=''
 SHORTNAMES=''
 XPM=''
-LANG=not_matching
+LANGUAGE=not_matching
 NEWBUILD=''
 ALLDEFINES=''
 
@@ -57,15 +57,15 @@
 fi
 
 LANGS=`echo En rc/sysres_*.rc | sed -e 's/rc\/sysres_//g' -e 's/\.rc//g' -e 's/ /\//g;'`
-while	expr "$LANGS" : ".*$LANG" = 0 > /dev/null
+while	expr "$LANGS" : ".*$LANGUAGE" = 0 > /dev/null
 do
-	prompt "Language ($LANGS)" LANG En
-	if	expr "$LANGS" : ".*$LANG" = 0 > /dev/null
+	prompt "Language ($LANGS)" LANGUAGE En
+	if	expr "$LANGS" : ".*$LANGUAGE" = 0 > /dev/null
 	then
-		echo "\"$LANG\" is not a supported language."
+		echo "\"$LANGUAGE\" is not a supported language."
 	fi
 done
-ALLDEFINES="$ALLDEFINES -ALANG\($LANG\)"
+ALLDEFINES="$ALLDEFINES -ALANG\($LANGUAGE\)"
 
 if [ "`(domainname)`" = 'amscons.com' ]
 then
diff --git a/DEVELOPERS-HINTS b/DEVELOPERS-HINTS
index ecca5a0..b090fea 100644
--- a/DEVELOPERS-HINTS
+++ b/DEVELOPERS-HINTS
@@ -1,14 +1,5 @@
 This is intend to be a document to help new developers get started.
-Existing developers should feel free to add there comments.
-
-SUBMITTING YOUR WORK:
-
-Submissions of code for inclussion into Wine should be sent to
-wine-new@amscons.com (Bob Amstadt).  You MUST provide a suitable
-ChangeLog entry for any work that you submit.  I prefer new code
-to be submitted as unified diffs (diff -u) off of the latest release.  
-Releases are every Tuesday evening (approximately 17:00 PST or 
-Wednesday 01:00 GMT).
+Existing developers should feel free to add their comments.
 
 MEMORY AND SEGMENTS:
 
diff --git a/Imakefile b/Imakefile
index cd14207..a51022f 100644
--- a/Imakefile
+++ b/Imakefile
@@ -97,10 +97,10 @@
 
 MakeSubdirs($(SUBDIRS))
 DependSubdirs($(SUBDIRS))
-AllTarget(wine.sym)
 
 #ifndef WINELIB
 NormalProgramTarget(wine,$(OBJS),$(DEPXLIB),$(XPM_LIB) $(XLIB),$(SYSLIBS))
+AllTarget(wine.sym)
 #else
 NormalLibraryTarget(wine,$(OBJS))
 #endif
diff --git a/controls/listbox.c b/controls/listbox.c
index 96a194f..e2bac73 100644
--- a/controls/listbox.c
+++ b/controls/listbox.c
@@ -597,7 +597,6 @@
 	LPLISTSTRUCT lpls;
 	PAINTSTRUCT ps;
 	HBRUSH 	hBrush;
-	HWND	hWndParent;
 	DWORD   itemData;
 	HDC 	hdc;
 	RECT 	rect;
@@ -647,8 +646,8 @@
 		dprintf_listbox(stddeb,"LBOX WM_DRAWITEM #%d left=%d top=%d right=%d bottom=%d !\n", 
 			i-1, lpls->dis.rcItem.left, lpls->dis.rcItem.top, 
 			lpls->dis.rcItem.right, lpls->dis.rcItem.bottom);
-		dprintf_listbox(stddeb,"LBOX WM_DRAWITEM Parent=%X &dis=%lX CtlID=%u !\n", 
-			hWndParent, (LONG)&lpls->dis, lpls->dis.CtlID);
+		dprintf_listbox(stddeb,"LBOX WM_DRAWITEM &dis=%lX CtlID=%u !\n", 
+			(LONG)&lpls->dis, lpls->dis.CtlID);
 		dprintf_listbox(stddeb,"LBOX WM_DRAWITEM %08lX!\n",lpls->dis.itemData);
 		if (HasStrings(wndPtr))
 		  dprintf_listbox(stddeb,"  '%s'\n",lpls->itemText);
diff --git a/debugger/dbg.y b/debugger/dbg.y
index 3ac7b7e..d1992f6 100644
--- a/debugger/dbg.y
+++ b/debugger/dbg.y
@@ -179,7 +179,7 @@
 
 	/* This is intended to read the entry points from the Windows image, and
 	   insert them in the hash table.  It does not work yet, so it is commented out. */
-	if(!loaded_symbols){
+	if(dbg_mode == 32 && !loaded_symbols){
 		loaded_symbols++;
 		read_symboltable("wine.sym");
 #if 0
diff --git a/if1632/call.S b/if1632/call.S
index 326c874..d1958d3 100644
--- a/if1632/call.S
+++ b/if1632/call.S
@@ -36,11 +36,11 @@
 /**********************************************************************
  *	Places to keep info about the current 16-bit stack frame.
  */
-	.globl A(IF1632_Saved16_esp),A(IF1632_Saved16_ebp),A(IF1632_Saved16_ss)
-A(IF1632_Saved16_esp:)
-	.long	0
-A(IF1632_Saved16_ebp:)
-	.long	0
+	.globl A(IF1632_Saved16_sp),A(IF1632_Saved16_bp),A(IF1632_Saved16_ss)
+A(IF1632_Saved16_sp:)
+	.word	0
+A(IF1632_Saved16_bp:)
+	.word	0
 A(IF1632_Saved16_ss:)
 	.word	0
 
@@ -236,13 +236,13 @@
 	movl	%ebp,A(IF1632_Saved32_ebp)
 
 	movw	A(IF1632_Saved16_ss),%ss
-	movl	A(IF1632_Saved16_esp),%esp
-	movl	A(IF1632_Saved16_ebp),%ebp
+	movw	A(IF1632_Saved16_sp),%sp
+	movw	A(IF1632_Saved16_bp),%bp
 
 	/*
 	 * Call entry point
 	 */
-	movw	%ax,%ds
+ 	movw	%ax,%ds
 	movw	%ax,%di
 	.byte	0x66
 	lcall	%fs:(%edx)
@@ -267,8 +267,8 @@
 	popl	%eax
 
 	movw	%ss,A(IF1632_Saved16_ss)
-	movl	%esp,A(IF1632_Saved16_esp)
-	movl	%ebp,A(IF1632_Saved16_ebp)
+	movw	%esp,A(IF1632_Saved16_sp)
+	movw	%ebp,A(IF1632_Saved16_bp)
 
 	movw	A(IF1632_Saved32_ss),%ss
 	movl	A(IF1632_Saved32_esp),%esp
@@ -313,7 +313,8 @@
 	.align	4
 	.globl A(CallTo32)
 A(CallTo32:)
-	pushl	%ebp
+	andl	$0x0000ffff,%esp
+	pushw	%bp
 	movl	%esp,%ebp
 
 	/*
@@ -335,13 +336,13 @@
 	 * Save old stack save variables, save stack registers, reload
 	 * stack registers.
 	 */
-	pushl	A(IF1632_Saved16_esp)
-	pushl	A(IF1632_Saved16_ebp)
+	pushw	A(IF1632_Saved16_sp)
+	pushw	A(IF1632_Saved16_bp)
 	pushw	A(IF1632_Saved16_ss)
 
 	movw	%ss,A(IF1632_Saved16_ss)
-	movl	%esp,A(IF1632_Saved16_esp)
-	movl	%ebp,A(IF1632_Saved16_ebp)
+	movw	%sp,A(IF1632_Saved16_sp)
+	movw	%bp,A(IF1632_Saved16_bp)
 
 	movw	A(IF1632_Saved32_ss),%ss
 	movl	A(IF1632_Saved32_esp),%esp
@@ -352,7 +353,7 @@
 	 */
 	pushl	%edx
 	pushw	A(IF1632_Saved16_ss)
-	pushw	A(IF1632_Saved16_esp)
+	pushw	A(IF1632_Saved16_sp)
 	pushl	%eax
 	call	A(DLLRelay)
 
@@ -364,18 +365,17 @@
  	 * Restore registers, but do not destroy return value.
 	 */
 	movw	A(IF1632_Saved16_ss),%ss
-	movl	A(IF1632_Saved16_esp),%esp
-	movl	A(IF1632_Saved16_ebp),%ebp
+	movw	A(IF1632_Saved16_sp),%sp
+	movw	A(IF1632_Saved16_bp),%bp
 
 	popw	A(IF1632_Saved16_ss)
-	popl	A(IF1632_Saved16_ebp)
-	popl	A(IF1632_Saved16_esp)
+	popw	A(IF1632_Saved16_bp)
+	popw	A(IF1632_Saved16_sp)
 
 	popw	%es
 	popw	%ds
+	popw	%bp
 
-	.align	2,0x90
-	leave
 	/*
 	 * Now we need to ditch the parameter bytes that were left on the
 	 * stack. We do this by effectively popping the number of bytes,
@@ -415,7 +415,8 @@
 	.align	4
 	.globl A(CallTo32_16)
 A(CallTo32_16:)
-	pushl	%ebp
+	andl	$0x0000ffff,%esp
+	pushw	%bp
 	movl	%esp,%ebp
 
 	/*
@@ -437,13 +438,13 @@
 	 * Save old stack save variables, save stack registers, reload
 	 * stack registers.
 	 */
-	pushl	A(IF1632_Saved16_esp)
-	pushl	A(IF1632_Saved16_ebp)
+	pushw	A(IF1632_Saved16_sp)
+	pushw	A(IF1632_Saved16_bp)
 	pushw	A(IF1632_Saved16_ss)
 
 	movw	%ss,A(IF1632_Saved16_ss)
-	movl	%esp,A(IF1632_Saved16_esp)
-	movl	%ebp,A(IF1632_Saved16_ebp)
+	movw	%esp,A(IF1632_Saved16_sp)
+	movw	%ebp,A(IF1632_Saved16_bp)
 
 	movw	A(IF1632_Saved32_ss),%ss
 	movl	A(IF1632_Saved32_esp),%esp
@@ -454,7 +455,7 @@
 	 */
 	pushl	%edx
 	pushw	A(IF1632_Saved16_ss)
-	pushw	A(IF1632_Saved16_esp)
+	pushw	A(IF1632_Saved16_sp)
 	pushl	%eax
 	call	A(DLLRelay)
 
@@ -466,18 +467,17 @@
  	 * Restore registers, but do not destroy return value.
 	 */
 	movw	A(IF1632_Saved16_ss),%ss
-	movl	A(IF1632_Saved16_esp),%esp
-	movl	A(IF1632_Saved16_ebp),%ebp
+	movw	A(IF1632_Saved16_sp),%sp
+	movw	A(IF1632_Saved16_bp),%bp
 
 	popw	A(IF1632_Saved16_ss)
-	popl	A(IF1632_Saved16_ebp)
-	popl	A(IF1632_Saved16_esp)
+	popw	A(IF1632_Saved16_bp)
+	popw	A(IF1632_Saved16_sp)
 
 	popw	%es
 	popw	%ds
+	popw	%bp
 
-	.align	2,0x90
-	leave
 	/*
 	 * Now we need to ditch the parameter bytes that were left on the
 	 * stack. We do this by effectively popping the number of bytes,
@@ -508,18 +508,17 @@
  	 * Restore 16-bit stack
 	 */
 	movw	A(IF1632_Saved16_ss),%ss
-	movl	A(IF1632_Saved16_esp),%esp
-	movl	A(IF1632_Saved16_ebp),%ebp
+	movw	A(IF1632_Saved16_sp),%sp
+	movw	A(IF1632_Saved16_bp),%bp
 
 	popw	A(IF1632_Saved16_ss)
-	popl	A(IF1632_Saved16_ebp)
-	popl	A(IF1632_Saved16_esp)
+	popw	A(IF1632_Saved16_bp)
+	popw	A(IF1632_Saved16_sp)
 
 	popw	%es
 	popw	%ds
+	popw	%bp
 
-	.align	2,0x90
-	leave
 	/*
 	 * This leaves us with a stack that has number of arguments,
 	 * the return address, the saved registers, and the return 
diff --git a/if1632/callback.c b/if1632/callback.c
index c820f6b..e0617e2 100644
--- a/if1632/callback.c
+++ b/if1632/callback.c
@@ -11,15 +11,15 @@
 #include "wine.h"
 #include "segmem.h"
 #include <setjmp.h>
+#include "stackframe.h"
 #include "dlls.h"
 #include "stddebug.h"
 #include "debug.h"
 #include "if1632.h"
 
-extern SEGDESC Segments[];
 extern unsigned short IF1632_Saved16_ss;
-extern unsigned long  IF1632_Saved16_ebp;
-extern unsigned long  IF1632_Saved16_esp;
+extern unsigned short IF1632_Saved16_bp;
+extern unsigned short IF1632_Saved16_sp;
 extern unsigned short IF1632_Saved32_ss;
 extern unsigned long  IF1632_Saved32_ebp;
 extern unsigned long  IF1632_Saved32_esp;
@@ -40,34 +40,23 @@
 PushOn16(int size, unsigned int value)
 {
     char *p = (char *) (((unsigned int)IF1632_Saved16_ss << 16) +
-			(IF1632_Saved16_esp & 0xffff));
+			IF1632_Saved16_sp);
     if (size)
     {
 	unsigned long *lp = (unsigned long *) p - 1;
 	
 	*lp = value;
-	IF1632_Saved16_esp -= 4;
+	IF1632_Saved16_sp -= 4;
     }
     else
     {
 	unsigned short *sp = (unsigned short *) p - 1;
 	
 	*sp = value;
-	IF1632_Saved16_esp -= 2;
+	IF1632_Saved16_sp -= 2;
     }
 }
 
-/**********************************************************************
- *					FindDataSegmentForCode
- */
-static unsigned short
-FindDataSegmentForCode(unsigned long csip)
-{
-    unsigned int seg_idx;
-    
-    seg_idx = (unsigned short) (csip >> 19);
-    return Segments[seg_idx].owner;
-}
 
 /**********************************************************************
  *					CallBack16
@@ -90,8 +79,7 @@
 
     va_end(ap);
 
-    return CallTo16((unsigned int) func, 
-		    FindDataSegmentForCode((unsigned long) func));
+    return CallTo16((unsigned int) func, pStack16Frame->ds );
 }
 
 /**********************************************************************
@@ -201,8 +189,7 @@
 	PushOn16( CALLBACK_SIZE_WORD, message );
 	PushOn16( CALLBACK_SIZE_WORD, wParam );
 	PushOn16( CALLBACK_SIZE_LONG, lParam );
-	return CallTo16((unsigned int) func, 
-			FindDataSegmentForCode((unsigned long) func));   
+	return CallTo16((unsigned int) func, pStack16Frame->ds );
     }
     else
     {
@@ -222,8 +209,7 @@
 	PushOn16( CALLBACK_SIZE_WORD, xPos );
 	PushOn16( CALLBACK_SIZE_WORD, yPos );
 	PushOn16( CALLBACK_SIZE_LONG, lParam );
-	CallTo16((unsigned int) func, 
-		 FindDataSegmentForCode((unsigned long) func));   
+	CallTo16((unsigned int) func, pStack16Frame->ds );
     }
     else
     {
@@ -241,8 +227,7 @@
 	PushOn16( CALLBACK_SIZE_WORD, code );
 	PushOn16( CALLBACK_SIZE_WORD, wParam );
 	PushOn16( CALLBACK_SIZE_LONG, lParam );
-	return CallTo16((unsigned int) func, 
-			FindDataSegmentForCode((unsigned long) func));   
+	return CallTo16((unsigned int) func, pStack16Frame->ds );
     }
     else
     {
@@ -260,8 +245,7 @@
 	PushOn16( CALLBACK_SIZE_WORD, hdc );
 	PushOn16( CALLBACK_SIZE_LONG, lParam );
 	PushOn16( CALLBACK_SIZE_WORD, cch );
-	return CallTo16((unsigned int) func, 
-			FindDataSegmentForCode((unsigned long) func));   
+	return CallTo16((unsigned int) func, pStack16Frame->ds );
     }
     else
     {
@@ -295,12 +279,12 @@
 	WORD retval;
 	jmp_buf *tmp_jmp;
 	char *stack16 =  (char *) (((unsigned int)IF1632_Saved16_ss << 16) +
-		(IF1632_Saved16_esp & 0xffff));
+                                   IF1632_Saved16_sp);
 
 	sb = malloc (sizeof (struct special_buffer));
 	
-	sb -> regs [0] = IF1632_Saved16_esp;
-	sb -> regs [1] = IF1632_Saved16_ebp;
+	sb -> regs [0] = IF1632_Saved16_sp & 0xffff;
+	sb -> regs [1] = IF1632_Saved16_bp & 0xffff;
 	sb -> regs [2] = IF1632_Saved16_ss & 0xffff;
 	sb -> regs [3] = IF1632_Saved32_esp;
 	sb -> regs [4] = IF1632_Saved32_ebp;
@@ -311,14 +295,14 @@
 	
 	if ((retval = setjmp (*tmp_jmp)))
 	{
-		IF1632_Saved16_esp = sb -> regs [0];
-		IF1632_Saved16_ebp = sb -> regs [1];
+		IF1632_Saved16_sp = sb -> regs [0] & 0xffff;
+		IF1632_Saved16_bp = sb -> regs [1] & 0xffff;
 		IF1632_Saved16_ss = sb -> regs [2] & 0xffff;
 		IF1632_Saved32_esp = sb -> regs [3];
 		IF1632_Saved32_ebp = sb -> regs [4];
 		IF1632_Saved32_ss = sb -> regs [5] & 0xffff;
 		stack16 = (char *) (((unsigned int)IF1632_Saved16_ss << 16) +
-				(IF1632_Saved16_esp & 0xffff));
+                                    IF1632_Saved16_sp);
 
 		memcpy (stack16, sb -> stack_part, STACK_DEPTH_16);
 		dprintf_catch (stddeb, "Been thrown here: %d, retval = %d\n", 
diff --git a/if1632/kernel.spec b/if1632/kernel.spec
index e265567..d3b738c 100644
--- a/if1632/kernel.spec
+++ b/if1632/kernel.spec
@@ -221,8 +221,8 @@
 #328 _DEBUGOUTPUT
 #329 K329
 #332 THHOOK
-334 pascal IsBadReadPtr(ptr long) IsBadReadPtr(1 2)
-335 pascal IsBadWritePtr(ptr long) IsBadWritePtr(1 2)
+334 pascal IsBadReadPtr(ptr word) IsBadReadPtr(1 2)
+335 pascal IsBadWritePtr(ptr word) IsBadWritePtr(1 2)
 336 pascal IsBadCodePtr(ptr) IsBadCodePtr(1)
 337 pascal IsBadStringPtr(ptr word) IsBadStringPtr(1 2)
 #338 HASGPHANDLER
diff --git a/if1632/relay.c b/if1632/relay.c
index e286bb8..faf17a6 100644
--- a/if1632/relay.c
+++ b/if1632/relay.c
@@ -22,6 +22,7 @@
 #include "prototypes.h"
 #include "dlls.h"
 #include "options.h"
+#include "stackframe.h"
 #include "stddebug.h"
 /* #define DEBUG_RELAY */
 /* #define DEBUG_STACK */
@@ -59,11 +60,34 @@
 };
 /* don't forget to increase N_BUILTINS in dll.h if you add a dll */
 
-#ifndef WINELIB
-unsigned short *Stack16Frame;
+/* the argument conversion tables for each dll */
+struct dll_conversions {
+	unsigned short *dst_args;   /*  Offsets to arguments on stack */
+	unsigned char *src_types;   /* Argument types              */
+} dll_conversion_table[N_BUILTINS]= {
+  KERNEL_offsets,   KERNEL_types,   /* KERNEL     */
+  USER_offsets,     USER_types,     /* USER       */
+  GDI_offsets,      GDI_types,      /* GDI        */
+  UNIXLIB_offsets,  UNIXLIB_types,  /* UNIXLIB    */
+  WIN87EM_offsets,  WIN87EM_types,  /* WIN87EM    */
+  SHELL_offsets,    SHELL_types,    /* SHELL      */
+  SOUND_offsets,    SOUND_types,    /* SOUND      */
+  KEYBOARD_offsets, KEYBOARD_types, /* KEYBOARD   */
+  WINSOCK_offsets,  WINSOCK_types,  /* WINSOCK    */
+  STRESS_offsets,   STRESS_types,   /* STRESS,     */
+  MMSYSTEM_offsets, MMSYSTEM_types, /* MMSYSTEM   */
+  SYSTEM_offsets,   SYSTEM_types,   /* SYSTEM     */
+  TOOLHELP_offsets, TOOLHELP_types, /* TOOLHELP   */
+  MOUSE_offsets,    MOUSE_types,    /* MOUSE      */
+  COMMDLG_offsets,  COMMDLG_types   /* EMUCOMMDLG */
+};
 
-extern unsigned long  IF1632_Saved16_esp;
-extern unsigned long  IF1632_Saved16_ebp;
+
+#ifndef WINELIB
+STACK16FRAME *pStack16Frame;
+
+extern unsigned short IF1632_Saved16_sp;
+extern unsigned short IF1632_Saved16_bp;
 extern unsigned short IF1632_Saved16_ss;
 
 /**********************************************************************
@@ -88,7 +112,7 @@
 DLLRelay(unsigned int func_num, unsigned int seg_off)
 {
     struct dll_table_entry_s *dll_p;
-    unsigned short *saved_Stack16Frame;
+    STACK16FRAME *pOldStack16Frame;
     unsigned int offset;
     unsigned int dll_id;
     unsigned int ordinal;
@@ -97,13 +121,16 @@
     int (*func_ptr)();
     int i;
     int ret_val;
+    int conv_ref;
+    unsigned char *type_conv;
+    unsigned short *offset_conv;
     
     /*
      * Determine address of arguments.
      */
-    saved_Stack16Frame = Stack16Frame;
-    Stack16Frame = (unsigned short *) seg_off;
-    arg_ptr = (void *) (seg_off + 0x18);
+    pOldStack16Frame = pStack16Frame;
+    pStack16Frame = (STACK16FRAME *) seg_off;
+    arg_ptr = (void *)pStack16Frame->args;
 
     /*
      * Extract the DLL number and ordinal number.
@@ -122,8 +149,8 @@
 	       dll_builtin_table[dll_id].dll_name, ordinal,
 	       seg_off >> 16, seg_off & 0xffff);
 	printf("ret=%08x", *ret_addr);
-	printf("  ESP=%08lx, EBP=%08lx, SS=%04x\n", 
-	       IF1632_Saved16_esp, IF1632_Saved16_ebp,
+	printf("  ESP=%04x, EBP=%04x, SS=%04x\n", 
+	       IF1632_Saved16_sp, IF1632_Saved16_bp,
 	       IF1632_Saved16_ss);
 
 	if(debugging_stack)
@@ -164,21 +191,24 @@
     if (dll_p->n_args == 0)
     {
 	ret_val = (*func_ptr)(arg_ptr);
-	Stack16Frame = saved_Stack16Frame;
+        pStack16Frame = pOldStack16Frame;
 	return ret_val;
     }
 
     /*
      * Getting this far means we need to convert the 16-bit argument stack.
      */
-    for (i = 0; i < dll_p->n_args; i++)
+    conv_ref= dll_p->conv_reference;
+    type_conv= dll_conversion_table[dll_id].src_types + conv_ref;
+    offset_conv= dll_conversion_table[dll_id].dst_args + conv_ref;
+    for (i = 0; i < dll_p->n_args; i++,type_conv++,offset_conv++)
     {
 	short *sp;
 	int *ip;
 	
-	offset = dll_p->args[i].dst_arg;
+	offset = *offset_conv;
 
-	switch (dll_p->args[i].src_type)
+	switch (*type_conv)
 	{
 	  case DLL_ARGTYPE_SIGNEDWORD:
 	    sp = (short *) ((char *) arg_ptr + offset);
@@ -223,7 +253,7 @@
 	       dll_builtin_table[dll_id].dll_name, ordinal);
     }
 
-    Stack16Frame = saved_Stack16Frame;
+    pStack16Frame = pOldStack16Frame;
     return ret_val;
 }
 #endif
diff --git a/include/brush.h b/include/brush.h
index 3f41e59..c548dbe 100644
--- a/include/brush.h
+++ b/include/brush.h
@@ -9,7 +9,9 @@
 
 #include "gdi.h"
 
+#ifndef WINELIB
 #pragma pack(1)
+#endif
 
   /* GDI logical brush object */
 typedef struct
@@ -18,7 +20,9 @@
     LOGBRUSH    logbrush WINE_PACKED;
 } BRUSHOBJ;
 
+#ifndef WINELIB
 #pragma pack(4)
+#endif
 
 extern BOOL BRUSH_Init(void);
 extern int BRUSH_GetObject( BRUSHOBJ * brush, int count, LPSTR buffer );
diff --git a/include/class.h b/include/class.h
index 07531bd..5c99d1d 100644
--- a/include/class.h
+++ b/include/class.h
@@ -11,7 +11,9 @@
 
 #define CLASS_MAGIC   0x4b4e      /* 'NK' */
 
+#ifndef WINELIB
 #pragma pack(1)
+#endif
 
   /* !! Don't change this structure (see GetClassLong()) */
 typedef struct tagCLASS
@@ -25,7 +27,9 @@
     WORD         wExtra[1];     /* Class extra bytes */
 } CLASS;
 
+#ifndef WINELIB
 #pragma pack(4)
+#endif
 
 
 HCLASS CLASS_FindClassByName( char * name, WORD hinstance, CLASS **ptr );
diff --git a/include/dialog.h b/include/dialog.h
index ad4b9de..ca1f418 100644
--- a/include/dialog.h
+++ b/include/dialog.h
@@ -14,7 +14,9 @@
 extern int DialogBoxIndirectPtr( HINSTANCE hInst, LPCSTR dlgTemplate,
                           HWND owner, WNDPROC dlgProc);
 
+#ifndef WINELIB
 #pragma pack(1)
+#endif
 
   /* Dialog info structure.
    * This structure is stored into the window extra bytes (cbWndExtra).
@@ -70,6 +72,8 @@
     LPSTR               faceName;
 } DLGTEMPLATE;
 
+#ifndef WINELIB
 #pragma pack(4)
+#endif
 
 #endif  /* DIALOG_H */
diff --git a/include/dlls.h b/include/dlls.h
index b4a3fc0..169dac1 100644
--- a/include/dlls.h
+++ b/include/dlls.h
@@ -51,12 +51,6 @@
 
 extern struct  w_files *wine_files;
 
-typedef struct dll_arg_relocation_s
-{
-    unsigned short dst_arg;	/* Offset to argument on stack		*/
-    unsigned char src_type;	/* Argument type			*/
-} DLL_ARG;
-
 #define DLL	0
 #define EXE	1
 
@@ -82,12 +76,13 @@
      */
     char *export_name;
     void *handler;		/* Address of function to process request */
-    int handler_type;		/* C or PASCAL calling convention	  */
+    char handler_type;		/* C or PASCAL calling convention	  */
+    char n_args;			/* Number of arguments passed to function */
+    short conv_reference ; /* reference to Argument conversion data  */
 #ifdef WINESTAT
     int used;			/* Number of times this function referenced */
 #endif
-    int n_args;			/* Number of arguments passed to function */
-    DLL_ARG args[DLL_MAX_ARGS]; /* Argument conversion data		  */
+    
 };
 
 struct dll_name_table_entry_s
@@ -114,6 +109,43 @@
 extern struct dll_table_entry_s MOUSE_table[];
 extern struct dll_table_entry_s COMMDLG_table[];
 
+
+extern unsigned short KERNEL_offsets[];
+extern unsigned short USER_offsets[];
+extern unsigned short GDI_offsets[];
+extern unsigned short UNIXLIB_offsets[];
+extern unsigned short WIN87EM_offsets[];
+extern unsigned short MMSYSTEM_offsets[];
+extern unsigned short SHELL_offsets[];
+extern unsigned short SOUND_offsets[];
+extern unsigned short KEYBOARD_offsets[];
+extern unsigned short WINSOCK_offsets[];
+extern unsigned short STRESS_offsets[];
+extern unsigned short SYSTEM_offsets[];
+extern unsigned short TOOLHELP_offsets[];
+extern unsigned short MOUSE_offsets[];
+extern unsigned short COMMDLG_offsets[];
+
+
+extern unsigned char KERNEL_types[];
+extern unsigned char USER_types[];
+extern unsigned char GDI_types[];
+extern unsigned char UNIXLIB_types[];
+extern unsigned char WIN87EM_types[];
+extern unsigned char MMSYSTEM_types[];
+extern unsigned char SHELL_types[];
+extern unsigned char SOUND_types[];
+extern unsigned char KEYBOARD_types[];
+extern unsigned char WINSOCK_types[];
+extern unsigned char STRESS_types[];
+extern unsigned char SYSTEM_types[];
+extern unsigned char TOOLHELP_types[];
+extern unsigned char MOUSE_types[];
+extern unsigned char COMMDLG_types[];
+
+
 #define N_BUILTINS	15
 
 #endif /* DLLS_H */
+
+
diff --git a/include/dos_fs.h b/include/dos_fs.h
index 79b5ce4..b32d900 100644
--- a/include/dos_fs.h
+++ b/include/dos_fs.h
@@ -29,6 +29,8 @@
 extern struct dosdirent *DOS_opendir(char *dosdirname); 
 extern struct dosdirent *DOS_readdir(struct dosdirent *de);
 extern void DOS_closedir(struct dosdirent *de);
+extern void DOS_ExpandToFullPath(char *filename, int drive);
+extern void DOS_ExpandToFullUnixPath(char *filename);
 
 extern char WindowsPath[256];
 
diff --git a/include/font.h b/include/font.h
index b26a260..3f90f9a 100644
--- a/include/font.h
+++ b/include/font.h
@@ -9,7 +9,9 @@
 
 #include "gdi.h"
 
+#ifndef WINELIB
 #pragma pack(1)
+#endif
 
   /* GDI logical font object */
 typedef struct
@@ -18,7 +20,9 @@
     LOGFONT     logfont WINE_PACKED;
 } FONTOBJ;
 
+#ifndef WINELIB
 #pragma pack(4)
+#endif
 
 extern BOOL FONT_Init( void );
 extern int FONT_GetObject( FONTOBJ * font, int count, LPSTR buffer );
diff --git a/include/gdi.h b/include/gdi.h
index 07bde36..476782f 100644
--- a/include/gdi.h
+++ b/include/gdi.h
@@ -27,7 +27,9 @@
 #define METAFILE_MAGIC        0x4f50
 #define METAFILE_DC_MAGIC     0x4f51
 
+#ifndef WINELIB
 #pragma pack(1)
+#endif
 
 typedef struct tagGDIOBJHDR
 {
@@ -72,7 +74,9 @@
     WORD   colorRes;      /* 108: color resolution */    
 } DeviceCaps;
 
+#ifndef WINELIB
 #pragma pack(4)
+#endif
 
 
   /* Device independent DC information */
diff --git a/include/heap.h b/include/heap.h
index fd234de..043d013 100644
--- a/include/heap.h
+++ b/include/heap.h
@@ -7,8 +7,8 @@
 #define HEAP_H
 
 #include "segmem.h"
-#include "regfunc.h"
 #include "atom.h"
+#include "stackframe.h"
 
 /**********************************************************************
  * LOCAL HEAP STRUCTURES AND FUNCTIONS
@@ -48,11 +48,8 @@
 extern void *WIN16_LocalReAlloc(unsigned int handle, int flags, int bytes);
 extern unsigned int WIN16_LocalUnlock(unsigned int handle);
 
-#if 0
-#define HEAP_OWNER	(Segments[Stack16Frame[11] >> 3].owner)
-#endif
 /* Use ds instead of owner of cs */
-#define HEAP_OWNER	Stack16Frame[6]
+#define HEAP_OWNER	(pStack16Frame->ds)
 #define LOCALHEAP()	(&HEAP_LocalFindHeap(HEAP_OWNER)->free_list)
 #define LOCALATOMTABLE() (&HEAP_LocalFindHeap(HEAP_OWNER)->local_table)
 
diff --git a/include/palette.h b/include/palette.h
index ddb76e0..d5145f2 100644
--- a/include/palette.h
+++ b/include/palette.h
@@ -9,7 +9,9 @@
 
 #include "gdi.h"
 
+#ifndef WINELIB
 #pragma pack(1)
+#endif
 
   /* GDI logical palette object */
 typedef struct
@@ -18,7 +20,9 @@
     LOGPALETTE  logpalette WINE_PACKED;
 } PALETTEOBJ;
 
+#ifndef WINELIB
 #pragma pack(4)
+#endif
 
 extern int PALETTE_GetObject( PALETTEOBJ * palette, int count, LPSTR buffer );
      
diff --git a/include/pen.h b/include/pen.h
index 2e2b512..1fc160c 100644
--- a/include/pen.h
+++ b/include/pen.h
@@ -9,7 +9,9 @@
 
 #include "gdi.h"
 
+#ifndef WINELIB
 #pragma pack(1)
+#endif
 
   /* GDI logical pen object */
 typedef struct
@@ -18,7 +20,9 @@
     LOGPEN      logpen WINE_PACKED;
 } PENOBJ;
 
+#ifndef WINELIB
 #pragma pack(4)
+#endif
 
 extern int PEN_GetObject( PENOBJ * pen, int count, LPSTR buffer );
 extern HPEN PEN_SelectObject( DC * dc, HPEN hpen, PENOBJ * pen );
diff --git a/include/regfunc.h b/include/regfunc.h
index d68a2d7..913ca86 100644
--- a/include/regfunc.h
+++ b/include/regfunc.h
@@ -5,10 +5,9 @@
 #define REGFUNC_H
 
 #include "wine.h"
+#include "stackframe.h"
 
-extern unsigned short *Stack16Frame;
-
-#define _CONTEXT ((struct sigcontext_struct *) &Stack16Frame[12])
+#define _CONTEXT ((struct sigcontext_struct *) pStack16Frame->args)
 #define _AX	(_CONTEXT->sc_eax)
 #define _BX	(_CONTEXT->sc_ebx)
 #define _CX	(_CONTEXT->sc_ecx)
diff --git a/include/segmem.h b/include/segmem.h
index 527002a..583adc9 100644
--- a/include/segmem.h
+++ b/include/segmem.h
@@ -26,23 +26,28 @@
 /*
  * Array to track selector allocation.
  */
-#define MAX_SELECTORS		512
 #define SELECTOR_ISFREE		0x8000
 #define SELECTOR_IS32BIT        0x4000
 #define SELECTOR_INDEXMASK	0x0fff
 
-extern unsigned short SelectorMap[MAX_SELECTORS];
+#define __AHSHIFT 3
+#define __AHINCR  (1 << __AHSHIFT)
+
+extern unsigned short* SelectorMap;
 
 #ifdef HAVE_IPC
 #define SAFEMAKEPTR(s, o) ((void *)(((int) (s) << 16) | ((o) & 0xffff)))
 #define FIXPTR(p)	  (p)
 #else
 #define SAFEMAKEPTR(s, o) \
-    ((void *)(((int)SelectorMap[SelectorMap[(s) >> 3] & SELECTOR_INDEXMASK] \
-                    << 19) | 0x70000 | ((o) & 0xffff)))
+  ((void*)(((int)SelectorMap[SelectorMap[(s)>>__AHSHIFT] & SELECTOR_INDEXMASK]\
+	    << (16 + __AHSHIFT)) | 0x70000 | ((o) & 0xffff)))
 #define FIXPTR(p)	  SAFEMAKEPTR((unsigned long) (p) >> 16, (p))
 #endif
 
+#define MAKESELECTOR(fp) ((unsigned short) (fp >> (16 + __AHSHIFT)))
+ 
+
 /*
  * Structure to hold info about each selector we create.
  */
@@ -79,14 +84,14 @@
 #ifdef __ELF__
 #define FIRST_SELECTOR 2
 #define IS_16_BIT_ADDRESS(addr)  \
-     (!(SelectorMap[(unsigned int)(addr)>>19]& SELECTOR_IS32BIT))
+  (!(SelectorMap[(unsigned int)(addr) >> (16+__AHSHIFT)]& SELECTOR_IS32BIT))
 #else
 #define FIRST_SELECTOR	8
 #define IS_16_BIT_ADDRESS(addr)  \
-     ((unsigned int)(addr) >= (((FIRST_SELECTOR << 3) | 0x0007) << 16))
+     ((unsigned int)(addr) >= (((FIRST_SELECTOR << __AHSHIFT) | 7) << 16))
 #endif
 
 
-extern SEGDESC Segments[];
+extern SEGDESC* Segments;
 
 #endif /* SEGMEM_H */
diff --git a/include/stackframe.h b/include/stackframe.h
new file mode 100644
index 0000000..9c008d7
--- /dev/null
+++ b/include/stackframe.h
@@ -0,0 +1,29 @@
+/*
+ * 16-bit mode stack frame layout
+ *
+ * Copyright 1995 Alexandre Julliard
+ */
+
+#ifndef WINE_STACKFRAME_H
+#define WINE_STACKFRAME_H
+
+#include <windows.h>
+
+typedef struct
+{
+    WORD    saved_ss;
+    WORD    saved_bp;
+    WORD    saved_sp;
+    WORD    es;
+    WORD    ds;
+    WORD    bp;
+    WORD    arg_length;
+    WORD    ip;
+    WORD    cs;
+    WORD    args[1];
+} STACK16FRAME;
+
+
+extern STACK16FRAME *pStack16Frame;
+
+#endif /* WINE_STACKFRAME_H */
diff --git a/include/windows.h b/include/windows.h
index 0c4c17e..088d0fa 100644
--- a/include/windows.h
+++ b/include/windows.h
@@ -5,7 +5,9 @@
 
 #include <wintypes.h>
 
+#ifndef WINELIB
 #pragma pack(1)
+#endif
 
 typedef struct { 
 	INT x;
@@ -2260,7 +2262,9 @@
 #define META_CREATEBITMAP            0x06FE
 #define META_CREATEREGION            0x06FF
 
+#ifndef WINELIB
 #pragma pack(4)
+#endif
 
 
 #define F(ret,name) ret name(void);
diff --git a/include/wintypes.h b/include/wintypes.h
index da99fed..a74457e 100644
--- a/include/wintypes.h
+++ b/include/wintypes.h
@@ -70,8 +70,6 @@
 #define WINE_PACKED __attribute__ ((packed))
 #endif
 
-#pragma pack(1)
-
 #define LOBYTE(w)           ((BYTE)(w))
 #define HIBYTE(w)           ((BYTE)((UINT)(w) >> 8))
 
diff --git a/loader/main.c b/loader/main.c
index 10dd883..01136c8 100644
--- a/loader/main.c
+++ b/loader/main.c
@@ -17,7 +17,6 @@
 #include "library.h"
 #include "windows.h"
 #include "wineopts.h"
-#include "dos_fs.h"
 #include "task.h"
 #include "prototypes.h"
 #include "options.h"
diff --git a/loader/selector.c b/loader/selector.c
index 8254460..bfa5e7f 100644
--- a/loader/selector.c
+++ b/loader/selector.c
@@ -59,8 +59,11 @@
 unsigned char ran_out = 0;
 int LastUsedSelector = FIRST_SELECTOR - 1;
 
-unsigned short SelectorMap[MAX_SELECTORS];
-SEGDESC Segments[MAX_SELECTORS];
+#define MAX_SELECTORS (512 * 2)
+
+int max_selectors = 0;
+unsigned short* SelectorMap;
+SEGDESC* Segments;
 
 #ifdef DEV_ZERO
     static FILE *zfile = NULL;
@@ -82,15 +85,19 @@
  *					InitSelectors
  */
 void
-InitSelectors(void) {
+InitSelectors(void) 
+{
     int i;
-    for (i = 0; i < MAX_SELECTORS; i++) {
+    max_selectors = MAX_SELECTORS;
+    SelectorMap = malloc(max_selectors * sizeof(unsigned short));
+    Segments    = malloc(max_selectors * sizeof(SEGDESC));
+    for (i = 0; i < max_selectors; i++) {
 	if (i < FIRST_SELECTOR) {
 	    SelectorMap[i] = SELECTOR_IS32BIT;
 #ifdef __ELF__
 	    /* quick hack, just reserves 4 meg for wine. */
-	} else if ((i << 19) >= 0x8000000 &&
-		   (i << 19) <= 0x8400000) {
+	} else if ((i << (16 + __AHSHIFT)) >= 0x8000000 &&
+		   (i << (16 + __AHSHIFT)) <= 0x8400000) {
 	    SelectorMap[i]= SELECTOR_IS32BIT;
 #endif
 	} else {
@@ -118,10 +125,23 @@
     n_found = 0;
     for (i = LastUsedSelector + 1; i != LastUsedSelector; i++)
     {
-	if (i >= MAX_SELECTORS)
+	if (i >= max_selectors)
 	{
-	    n_found = 0;
-	    i = FIRST_SELECTOR;
+	    int j;
+	    max_selectors += MAX_SELECTORS;
+	    dprintf_selectors(stddeb, "Expanding no of segments to %d.\n", 
+			      max_selectors);
+            SelectorMap =
+	      realloc(SelectorMap, max_selectors * sizeof(unsigned short));
+            Segments = realloc(Segments, max_selectors * sizeof(SEGDESC));
+	    if (!SelectorMap || !Segments)
+	      {
+		fprintf(stderr,
+			"FindUnusedSelectors: Out of memory! Exiting\n");
+		exit (-1);
+	      }
+            for (j = max_selectors - MAX_SELECTORS; j < max_selectors; j++)
+	      SelectorMap[j] = 0;
 	}
 
 	if (SelectorMap[i] && n_found) n_found=0;
@@ -174,7 +194,7 @@
 
 	SelectorMap[i_new] = i_new;
     
-	s_new->selector  = (i_new << 3) | 0x0007;
+	s_new->selector  = (i_new << __AHSHIFT) | 0x0007;
 	s_new->base_addr = (void *) ((long) s_new->selector << 16);
 	s_new->length    = s_old->length;
 	s_new->flags     = s_old->flags;
@@ -280,7 +300,7 @@
     
     if (old_selector)
     {
-	i_old = (old_selector >> 3);
+	i_old = (old_selector >> __AHSHIFT);
 #ifdef HAVE_IPC
 	selector = IPCCopySelector(i_old, i_new, 0);
 	if (selector < 0)
@@ -289,7 +309,7 @@
 	    return selector;
 #else
 	s_old = &Segments[i_old];
-	s_new->selector = (i_new << 3) | 0x0007;
+	s_new->selector = (i_new << __AHSHIFT) | 0x0007;
 	*s_new = *s_old;
 	SelectorMap[i_new] = SelectorMap[i_old];
 
@@ -310,7 +330,7 @@
 	SelectorMap[i_new] = i_new;
     }
 
-    return (i_new << 3) | 0x0007;
+    return (i_new << __AHSHIFT) | 0x0007;
 }
 
 /**********************************************************************
@@ -325,8 +345,8 @@
     SEGDESC *src_s;
     int src_idx, dst_idx;
 
-    src_idx = src_selector >> 3;
-    dst_idx = dst_selector >> 3;
+    src_idx = src_selector >> __AHSHIFT;
+    dst_idx = dst_selector >> __AHSHIFT;
 
     if (src_idx == dst_idx)
     {
@@ -356,13 +376,13 @@
     int alias_count;
     int i;
 
-    src_idx = (SelectorMap[src_selector >> 3]);
-    dst_idx = dst_selector >> 3;
+    src_idx = (SelectorMap[src_selector >> __AHSHIFT]);
+    dst_idx = dst_selector >> __AHSHIFT;
     src_s = &Segments[src_idx];
     dst_s = &Segments[dst_idx];
 
     alias_count = 0;
-    for (i = FIRST_SELECTOR; i < MAX_SELECTORS; i++)
+    for (i = FIRST_SELECTOR; i < max_selectors; i++)
 	if (SelectorMap[i] == src_idx)
 	    alias_count++;
     
@@ -392,7 +412,7 @@
 	 */
 	SelectorMap[dst_idx] = dst_idx;
 	*dst_s = *src_s;
-	dst_s->selector  = (dst_idx << 3) | 0x0007;
+	dst_s->selector  = (dst_idx << __AHSHIFT) | 0x0007;
 	dst_s->base_addr = (void *) ((unsigned int) dst_s->selector << 16);
 	dst_s->type      = MODIFY_LDT_CONTENTS_DATA;
 #ifdef DEV_ZERO
@@ -458,9 +478,9 @@
 {
     int sel_idx;
 
-    for (sel_idx = FIRST_SELECTOR; sel_idx < MAX_SELECTORS; sel_idx++)
+    for (sel_idx = FIRST_SELECTOR; sel_idx < max_selectors; sel_idx++)
 	if (SelectorMap[sel_idx])
-	    FreeSelector((sel_idx << 3) | 7);
+	    FreeSelector((sel_idx << __AHSHIFT) | 7);
 }
 
 /**********************************************************************
@@ -474,9 +494,9 @@
     int i;
 
 #ifdef HAVE_IPC
-    sel_idx = sel >> 3;
+    sel_idx = sel >> __AHSHIFT;
 
-    if (sel_idx < FIRST_SELECTOR || sel_idx >= MAX_SELECTORS)
+    if (sel_idx < FIRST_SELECTOR || sel_idx >= max_selectors)
 	return 0;
     
     s = &Segments[sel_idx];
@@ -492,7 +512,7 @@
 	shmdt(s->base_addr);
 
 	alias_count = 0;
-	for (i = FIRST_SELECTOR; i < MAX_SELECTORS; i++)
+	for (i = FIRST_SELECTOR; i < max_selectors; i++)
 	    if (SelectorMap[i] && Segments[i].shm_key == s->shm_key)
 		alias_count++;
 	
@@ -505,19 +525,19 @@
     }
     
 #else /* HAVE_IPC */
-    sel_idx = SelectorMap[sel >> 3];
+    sel_idx = SelectorMap[sel >> __AHSHIFT];
 
-    if (sel_idx < FIRST_SELECTOR || sel_idx >= MAX_SELECTORS)
+    if (sel_idx < FIRST_SELECTOR || sel_idx >= max_selectors)
 	return 0;
     
-    if (sel_idx != (sel >> 3))
+    if (sel_idx != (sel >> __AHSHIFT))
     {
-	SelectorMap[sel >> 3] = 0;
+	SelectorMap[sel >> __AHSHIFT] = 0;
 	return 0;
     }
     
     alias_count = 0;
-    for (i = FIRST_SELECTOR; i < MAX_SELECTORS; i++)
+    for (i = FIRST_SELECTOR; i < max_selectors; i++)
 	if (SelectorMap[i] == sel_idx)
 	    alias_count++;
 
@@ -526,7 +546,7 @@
 	s = &Segments[sel_idx];
 	munmap(s->base_addr, ((s->length + PAGE_SIZE) & ~(PAGE_SIZE - 1)));
 	memset(s, 0, sizeof(*s));
-	SelectorMap[sel >> 3] = 0;
+	SelectorMap[sel >> __AHSHIFT] = 0;
     }
 #endif /* HAVE_IPC */
 
@@ -565,7 +585,7 @@
 	    s->flags = NE_SEGFLAGS_DATA;
 	}
 	
-	s->selector = (i << 3) | 0x0007;
+	s->selector = (i << __AHSHIFT) | 0x0007;
 	s->length = length;
 #ifdef DEV_ZERO
 	if (zfile == NULL)
@@ -886,8 +906,8 @@
     int SelectorTableLength;
     int i;
     int status;
-    int old_length, file_image_length;
-    int saved_old_length;
+    int old_length, file_image_length = 0;
+    int saved_old_length = 0;
 
     auto_data_sel=0;
     /*
@@ -1006,7 +1026,7 @@
     s = selectors;
     for (i = 0; i < ne_header->n_segment_tab; i++, s++)
     {
-	Segments[s->selector >> 3].owner = auto_data_sel;
+	Segments[s->selector >> __AHSHIFT].owner = auto_data_sel;
 	if (s->selector == auto_data_sel)
 	    HEAP_LocalInit(auto_data_sel, s->base_addr + saved_old_length, 
 			   0x10000 - 2 - saved_old_length 
diff --git a/memory/global.c b/memory/global.c
index 7d5d469..a3e5eb7 100644
--- a/memory/global.c
+++ b/memory/global.c
@@ -508,7 +508,7 @@
 	 */
 	if (g->sequence == -1)
 	{
-	    free_map[g->handle >> 3] = 1;
+	    free_map[g->handle >> __AHSHIFT] = 1;
 	    if (g->handle > max_selector_used)
 		max_selector_used = g->handle;
 	}
@@ -519,7 +519,7 @@
 	else if (g->handle == 0)
 	{
 	    selector = (unsigned int) g->addr >> 16;
-	    free_map[selector >> 3] = 0;
+	    free_map[selector >> __AHSHIFT] = 0;
 	    if (selector > max_selector_used)
 		max_selector_used = selector;
 	}
@@ -528,7 +528,7 @@
     /*
      * All segments past the biggest selector used are free.
      */
-    for (i = (max_selector_used >> 3) + 1; i < 512; i++)
+    for (i = (max_selector_used >> __AHSHIFT) + 1; i < 512; i++)
 	free_map[i] = 1;
 
     /*
@@ -792,7 +792,7 @@
 	 */
 	if (g->sequence == -1)
 	{
-	    free_map[g->handle >> 3] = 1;
+	    free_map[g->handle >> __AHSHIFT] = 1;
 	    if (g->handle > max_selector_used)
 		max_selector_used = g->handle;
 	}
@@ -803,7 +803,7 @@
 	else if (g->handle == 0)
 	{
 	    selector = (unsigned int) g->addr >> 16;
-	    free_map[selector >> 3] = 0;
+	    free_map[selector >> __AHSHIFT] = 0;
 	    if (selector > max_selector_used)
 		max_selector_used = selector;
 	}
@@ -812,7 +812,7 @@
     /*
      * All segments past the biggest selector used are free.
      */
-    for (i = (max_selector_used >> 3) + 1; i < 512; i++)
+    for (i = (max_selector_used >> __AHSHIFT) + 1; i < 512; i++)
 	free_map[i] = 1;
 
     /*
diff --git a/memory/heap.c b/memory/heap.c
index 939eb83..54157d0 100644
--- a/memory/heap.c
+++ b/memory/heap.c
@@ -426,7 +426,7 @@
     void *m;
     
     dprintf_heap(stddeb,"WIN16_LocalAlloc: flags %x, bytes %d\n", flags,bytes);
-    dprintf_heap(stddeb,"    called from segment %04x, ds=%04x\n", Stack16Frame[11],Stack16Frame[6]);
+    dprintf_heap(stddeb,"    called from segment %04x, ds=%04x\n", pStack16Frame->cs,pStack16Frame->ds);
 
     m = HEAP_Alloc(LOCALHEAP(), flags, bytes);
 	
@@ -494,7 +494,7 @@
     if (segment == 0)
     {
 	/* Get current DS */
-	segment = Stack16Frame[6];
+	segment = pStack16Frame->ds;
     }
 
     dprintf_heap(stddeb, "WIN16_LocalInit   segment=%04x  start=%04x  end=%04x\n", segment, start, end);
@@ -504,11 +504,11 @@
        data (and the stack if there is one). As we don't know the length
        of the data and stack right now, we simply put the local heap at the
        end of the segment */
-    if ((start==0)&&(Segments[segment>>3].owner==segment))
+    if ((start==0)&&(Segments[segment>>__AHSHIFT].owner==segment))
     {
         return;
-        start = Segments[segment>>3].length-end-2;
-        end   = Segments[segment>>3].length-1;  
+        start = Segments[segment>>__AHSHIFT].length-end-2;
+        end   = Segments[segment>>__AHSHIFT].length-1;  
         dprintf_heap(stddeb, "Changed to  start=%04x  end=%04x\n",start,end);
     }
 
diff --git a/memory/linear.c b/memory/linear.c
index cab6fb9..1d09b14 100644
--- a/memory/linear.c
+++ b/memory/linear.c
@@ -100,7 +100,8 @@
 	 i < loc_idx + g_first->length; 
 	 i++, addr += 0x10000, g = g->next)
     {
-	if ((MemoryKeys[i] = IPCCopySelector(g->handle >> 3, addr, 0)) < 0)
+	if ((MemoryKeys[i] = IPCCopySelector(g->handle >> __AHSHIFT,
+					     addr, 0)) < 0)
 	    return NULL;
 	g->linear_addr = (void *) addr;
 	g->linear_count = 1;
diff --git a/misc/dos_fs.c b/misc/dos_fs.c
index 235205d..c9df6e7 100644
--- a/misc/dos_fs.c
+++ b/misc/dos_fs.c
@@ -28,7 +28,7 @@
 #include "wine.h"
 #include "windows.h"
 #include "msdos.h"
-/* #include "dos_fs.h" */
+#include "dos_fs.h"
 #include "autoconf.h"
 #include "comm.h"
 #include "stddebug.h"
@@ -183,7 +183,25 @@
 	DosDrives[25].serialnumber = 0x12345678;
 	DosDrives[25].disabled = 0;
 
-	DOS_SetDefaultDrive(2);
+        /* Get the startup directory and try to map it to a DOS drive
+         * and directory.  (i.e., if we start in /dos/windows/word and
+         * drive C is defined as /dos, the starting wd for C will be
+         * /windows/word)  Also set the default drive to whatever drive
+         * corresponds to the directory we started in.
+         */
+        getcwd(temp, 254);
+        strcat(temp, "/");      /* For DOS_GetDosFileName */
+        strcpy(temp, DOS_GetDosFileName(temp));
+        if(temp[0] != 'Z')
+        {
+            ToUnix(&temp[2]);
+            strcpy(DosDrives[temp[0] - 'A'].cwd, &temp[2]);
+            DOS_SetDefaultDrive(temp[0] - 'A');
+        }
+        else
+        {
+	    DOS_SetDefaultDrive(2);
+        }
 
 	for (x=0; x!=MAX_DOS_DRIVES; x++) {
 		if (DosDrives[x].rootdir != NULL) {
@@ -409,6 +427,11 @@
 	} else
 		drive = CurrentDrive;
 
+        /* Expand the filename to it's full path if it doesn't
+         * start from the root.
+         */
+        DOS_ExpandToFullPath(dosfilename, drive);
+
 	strcpy(temp, DosDrives[drive].rootdir);
 	strcat(temp, DosDrives[drive].cwd);
 	GetUnixDirName(temp + strlen(DosDrives[drive].rootdir), dosfilename);
@@ -417,12 +440,19 @@
 	return(temp);
 }
 
+/* Note: This function works on directories as well as long as
+ * the directory ends in a slash.
+ */
 char *DOS_GetDosFileName(char *unixfilename)
 { 
 	int i;
 	static char temp[256], rootdir[256];
 	/*   /dos/windows/system.ini => c:\windows\system.ini */
 	
+        /* Expand it if it's a relative name.
+         */
+        DOS_ExpandToFullUnixPath(unixfilename);
+
 	for (i = 0 ; i != MAX_DOS_DRIVES; i++) {
 		if (DosDrives[i].rootdir != NULL) {
  			strcpy(rootdir, DosDrives[i].rootdir);
@@ -500,6 +530,53 @@
 	return 1;
 }
 
+/* DOS_ExpandToFullPath takes a dos-style filename and converts it
+ * into a full path based on the current working directory.
+ * (e.g., "foo.bar" => "d:\\moo\\foo.bar")
+ */
+void DOS_ExpandToFullPath(char *filename, int drive)
+{
+        char temp[256];
+
+        dprintf_dosfs(stddeb, "DOS_ExpandToFullPath: Original = %s\n", filename);
+
+        /* If the filename starts with '/' or '\',
+         * don't bother -- we're already at the root.
+         */
+        if(filename[0] == '/' || filename[0] == '\\')
+            return;
+
+        strcpy(temp, DosDrives[drive].cwd);
+        strcat(temp, filename);
+        strcpy(filename, temp);
+
+        dprintf_dosfs(stddeb, "                      Expanded = %s\n", temp); 
+}
+
+/* DOS_ExpandToFullUnixPath takes a unix filename and converts it
+ * into a full path based on the current working directory.  Thus,
+ * it's probably not a good idea to get a relative name, change the
+ * working directory, and then convert it...
+ */
+void DOS_ExpandToFullUnixPath(char *filename)
+{
+        char temp[256];
+
+        if(filename[0] == '/')
+            return;
+
+        getcwd(temp, 255);
+        if(strncmp(filename, "./", 2))
+                strcat(temp, filename + 1);
+        else
+        {
+                strcat(temp, "/");
+                strcat(temp, filename);
+        }
+        dprintf_dosfs(stddeb, "DOS_ExpandToFullUnixPath: %s => %s\n", filename, temp);
+        strcpy(filename, temp);
+}
+
 int DOS_GetSerialNumber(int drive, unsigned long *serialnumber)
 {
 	if (!DOS_ValidDrive(drive)) 
diff --git a/misc/file.c b/misc/file.c
index f97e28f..50cfdcd 100644
--- a/misc/file.c
+++ b/misc/file.c
@@ -113,6 +113,9 @@
  **************************************************************************/
 INT OpenFile (LPSTR lpFileName, LPOFSTRUCT ofs, WORD wStyle)
 {
+#ifdef WINELIB
+    dprintf_file(stdnimp, "OpenFile: not implemented\n");
+#else
 #ifndef PROCEMU
     struct sigcontext_struct  ccontext;
                               /* To make macros like EAX happy */
@@ -256,6 +259,7 @@
       }
 
     return AX;
+#endif /*WINELIB*/
 }
 
 /**************************************************************************
diff --git a/misc/winsocket.c b/misc/winsocket.c
index 6aea8a7..5578804 100644
--- a/misc/winsocket.c
+++ b/misc/winsocket.c
@@ -219,9 +219,9 @@
 
 }
 #else
-#define CONVERT_HOSTENT(a,b)	memcpy(&a, &b, sizeof(a))
-#define CONVERT_PROTOENT(a,b)	memcpy(&a, &b, sizeof(a))
-#define CONVERT_SERVENT(a,b)	memcpy(&a, &b, sizeof(a))
+#define CONVERT_HOSTENT(a,b)	memcpy(a, &b, sizeof(a))
+#define CONVERT_PROTOENT(a,b)	memcpy(a, &b, sizeof(a))
+#define CONVERT_SERVENT(a,b)	memcpy(a, &b, sizeof(a))
 #endif
 
 SOCKET WINSOCK_accept(SOCKET s, struct sockaddr *addr, INT *addrlen)
diff --git a/miscemu/kernel.c b/miscemu/kernel.c
index 27b08b5..70b3283 100644
--- a/miscemu/kernel.c
+++ b/miscemu/kernel.c
@@ -20,7 +20,7 @@
 KERNEL_LockSegment(int segment)
 {
     if (segment == -1)
-	segment = *(Stack16Frame + 6);
+	segment = pStack16Frame->ds;
 
     if (debugging_relay)
 	fprintf(stddeb,"LockSegment: segment %x\n", segment);
@@ -35,7 +35,7 @@
 KERNEL_UnlockSegment(int segment)
 {
     if (segment == -1)
-	segment = *(Stack16Frame + 6);
+	segment = pStack16Frame->ds;
 
     if (debugging_relay)
     	fprintf(stddeb,"UnlockSegment: segment %x\n", segment);
diff --git a/rc/Imakefile b/rc/Imakefile
index 9e89e0c..650fb31 100644
--- a/rc/Imakefile
+++ b/rc/Imakefile
@@ -33,12 +33,15 @@
 
 SRCS = \
 	lex.yy.c \
-	rc.tab.c \
-	winerc.c
+	winerc.c \
+	y.tab.c
 
 OBJS = $(SRCS:.c=.o)
 
-#ifdef i386BsdArchitecture
+#ifdef SunArchitecture
+YACC=bison -y
+LEX=flex
+LOCAL_LIBRARIES = -ly -ll
 #endif
 #if defined(i386BsdArchitecture) || defined(i386FreeBsd) || defined(FreeBSDArchitecture)
 LOCAL_LIBRARIES = -ll
@@ -47,17 +50,17 @@
 LOCAL_LIBRARIES = -lfl
 #endif
 
-depend:: rc.tab.c rc.tab.h lex.yy.c
+depend:: y.tab.c y.tab.h lex.yy.c
 
 clean::
-	$(RM) lex.yy.c rc.tab* y.tab.c
+	$(RM) lex.yy.c y.tab.*
 
 ComplexProgramTarget(winerc)
 
-rc.tab.c rc.tab.h: rc.y
-	$(YACC) -b rc -d --debug rc.y
+y.tab.c y.tab.h: parser.y
+	$(YACC) -d -t parser.y
 
-lex.yy.c: rc.l rc.tab.h
-	$(LEX) -I rc.l
+lex.yy.c: parser.l y.tab.h
+	$(LEX) -I parser.l
  
 
diff --git a/rc/parser.h b/rc/parser.h
new file mode 100644
index 0000000..5064c60
--- /dev/null
+++ b/rc/parser.h
@@ -0,0 +1,106 @@
+/*
+ *
+ * Copyright  Martin von Loewis, 1994
+ *
+ */
+
+/* resource types */
+enum rt {acc,bmp,cur,dlg,fnt,ico,men,rdt,str};
+/* generic resource
+   Bytes can be inserted at arbitrary positions, the data field (res) 
+   grows as required. As the dialog header contains the number of 
+   controls, this number is generated in num_entries. If n_type if 0,
+   the resource name is i_name, and s_name otherwise. Top level
+   resources are linked via next. All gen_res objects are linked via
+   g_prev, g_next for debugging purposes. space is the length of res,
+   size is the used part of res.
+   As most bison rules are right recursive, new items are usually 
+   inserted at the beginning
+*/   
+typedef struct gen_res{
+	int size,space;
+	int num_entries;
+	enum rt type;
+	union{
+		int i_name;
+		char* s_name;
+	}n;
+	int n_type; /*0 - integer, 1 = string*/
+	struct gen_res *next;
+	struct gen_res *g_prev,*g_next;
+	unsigned char res[0];
+} gen_res;
+
+/* control/dialog style. or collects styles, and collects NOT styles */
+typedef struct rc_style{
+	int and, or;
+}rc_style;
+
+/* create a new resource */
+gen_res *new_res(void);
+/* double the space of the resource */
+gen_res* grow(gen_res*);
+/* insert byte array at the beginning, increase count */
+gen_res* insert_at_beginning(gen_res*,char*,int);
+/* insert byte array at offset */
+gen_res* insert_bytes(gen_res*,char*,int,int);
+/* delete bytes at offset */
+gen_res* delete_bytes(gen_res*,int,int);
+/* create a new style */
+rc_style* new_style(void);
+/* convert \t to tab etc. */
+char* parse_c_string(char*);
+/* get the resources type, convert dlg to "DIALOG" and so on */
+char* get_typename(gen_res*);
+
+gen_res* add_accelerator(int,int,int,gen_res*);
+gen_res* add_string_accelerator(char*,int,int,gen_res*);
+gen_res* add_ascii_accelerator(int,int,int,gen_res*);
+gen_res* add_vk_accelerator(int,int,int,gen_res*);
+
+gen_res* new_dialog(void);
+gen_res* dialog_style(rc_style*,gen_res*);
+int dialog_get_menu(gen_res*);
+int dialog_get_class(gen_res*);
+int dialog_get_caption(gen_res*);
+int dialog_get_fontsize(gen_res*);
+gen_res* dialog_caption(char*,gen_res*);
+gen_res* dialog_font(short,char*,gen_res*);
+gen_res* dialog_class(char*,gen_res*);
+gen_res* dialog_menu(char*,gen_res*);
+gen_res* create_control_desc(int,int,int,int,int,rc_style*);
+gen_res* label_control_desc(char*,gen_res*);
+gen_res* create_generic_control(char*,int,char*,rc_style*,int,int,int,int);
+gen_res* add_control(int,int,gen_res*,gen_res*);
+gen_res* add_icon(char*,int,int,int,gen_res*,gen_res*);
+gen_res* add_generic_control(gen_res*,gen_res*);
+gen_res* make_dialog(gen_res*,int,int,int,int,gen_res*);
+
+gen_res *hex_to_raw(char*,gen_res*);
+gen_res *make_bitmap(gen_res*);
+gen_res *make_icon(gen_res*);
+gen_res *make_cursor(gen_res*);
+gen_res *load_file(char*);
+
+gen_res *add_menuitem(char*,int,int,gen_res*);
+gen_res *add_popup(char*,short,gen_res*,gen_res*);
+gen_res *make_menu(gen_res*);
+
+gen_res *add_resource(gen_res*,gen_res*);
+
+void create_output(gen_res*);
+void set_out_file(char*);
+
+#define CT_BUTTON 	0x80
+#define CT_EDIT 	0x81
+#define CT_STATIC 	0x82
+#define CT_LISTBOX	0x83
+#define CT_SCROLLBAR 0x84
+#define CT_COMBOBOX	0x85
+
+extern int verbose;
+
+#ifdef __sun__
+#define strtoul strtol
+#endif
+
diff --git a/rc/parser.l b/rc/parser.l
new file mode 100644
index 0000000..338a13f
--- /dev/null
+++ b/rc/parser.l
@@ -0,0 +1,75 @@
+%{
+/*
+ *
+ * Copyright  Martin von Loewis, 1994
+ *
+ */
+static char Copyright[] = "Copyright Martin von Loewis, 1994";
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "parser.h"
+#include "y.tab.h"
+%}
+%%
+ACCELERATORS	return ACCELERATORS;
+ALT		return ALT;
+ASCII		return ASCII;
+BEGIN		return tBEGIN;
+BITMAP		return tBITMAP;
+CAPTION		return CAPTION;
+CHECKBOX	return CHECKBOX;
+CHECKED		return CHECKED;
+CLASS		return CLASS;
+COMBOBOX	return COMBOBOX;
+CONTROL		return CONTROL;
+CTEXT		return CTEXT;
+CURSOR		return CURSOR;
+DEFPUSHBUTTON	return DEFPUSHBUTTON;
+DIALOG		return DIALOG;
+DISCARDABLE	return DISCARDABLE;
+EDITTEXT	return EDITTEXT;
+END		return tEND;
+FIXED		return FIXED;
+FONT		return FONT;
+GRAYED		return GRAYED;
+GROUPBOX	return GROUPBOX;
+HELP		return HELP;
+ICON		return ICON;
+INACTIVE	return INACTIVE;
+LISTBOX		return LISTBOX;
+LTEXT		return LTEXT;
+MENU		return MENU;
+MENUBARBREAK	return MENUBARBREAK;
+MENUBREAK	return MENUBREAK;
+MENUITEM	return MENUITEM;
+MOVEABLE	return MOVEABLE;
+LOADONCALL	return LOADONCALL;
+NOINVERT	return NOINVERT;
+NOT			return NOT;
+NUMBER		return NUMBER;
+POPUP		return POPUP;
+PRELOAD		return PRELOAD;
+PUSHBUTTON	return PUSHBUTTON;
+PURE		return PURE;
+RADIOBUTTON	return RADIOBUTTON;
+RCDATA		return RCDATA;
+RTEXT		return RTEXT;
+SCROLLBAR	return SCROLLBAR;
+SHIFT		return SHIFT;
+SEPARATOR	return SEPARATOR;
+STRING		return STRING;
+STRINGTABLE	return STRINGTABLE;
+STYLE		return STYLE;
+VERSIONINFO	return VERSIONINFO;
+VIRTKEY		return VIRTKEY;
+\{			return tBEGIN;
+\}			return tEND;
+[+-]?[0-9]+	yylval.num=atoi(yytext);return NUMBER;
+0x[0-9A-Fa-f]+L?	yylval.num=strtoul(yytext,0,16);return NUMBER;
+[A-Za-z][A-Za-z_0-9]*	yylval.str=strdup(yytext);return IDENT;
+\"[^"]*\"	yylval.str=parse_c_string(yytext);return STRING;
+\'[^']*\'   yylval.str=strdup(yytext+1);return SINGLE_QUOTED;
+[ \t\n\r]		;
+.			return yytext[0];
diff --git a/rc/parser.y b/rc/parser.y
new file mode 100644
index 0000000..9ba6969
--- /dev/null
+++ b/rc/parser.y
@@ -0,0 +1,210 @@
+%{
+/*
+ *
+ * Copyright  Martin von Loewis, 1994
+ */
+
+static char Copyright[] = "Copyright Martin von Loewis, 1994";
+
+#include <stdio.h>
+#include "parser.h"
+#include "windows.h"
+%}
+%union{
+	gen_res *res;
+	char *str;
+	int num;
+	struct rc_style *style;
+}
+%token <num> NUMBER
+%token <str> STRING SINGLE_QUOTED IDENT
+%token ACCELERATORS ALT ASCII tBEGIN tBITMAP CAPTION CHECKBOX CHECKED 
+%token CLASS COMBOBOX CONTROL CTEXT CURSOR DEFPUSHBUTTON DIALOG 
+%token DISCARDABLE EDITTEXT tEND FIXED FONT GRAYED GROUPBOX HELP ICON 
+%token IDENT INACTIVE LISTBOX LTEXT MENU MENUBARBREAK MENUBREAK MENUITEM 
+%token MOVEABLE LOADONCALL NOINVERT NOT NOT_SUPPORTED POPUP PRELOAD 
+%token PURE PUSHBUTTON RADIOBUTTON RCDATA RTEXT SCROLLBAR SHIFT SEPARATOR 
+%token SINGLE_QUOTED STRING STRINGTABLE STYLE VERSIONINFO VIRTKEY
+%type <res> resource_file resource resources resource_definition accelerators
+%type <res> events bitmap cursor dialog dlg_attributes controls 
+%type <res> generic_control labeled_control control_desc font icon 
+%type <res> iconinfo menu menu_body item_definitions rcdata raw_data raw_elements 
+%type <res> stringtable strings versioninfo
+%type <num> acc_options item_options
+%type <style> style optional_style
+%%
+
+resource_file: resources {create_output($1);}
+
+/*resources are put into a linked list*/
+resources:	{$$=0;}
+		|resource resources {$$=add_resource($1,$2);}
+		;
+
+/* get the name for a single resource*/
+resource:	NUMBER resource_definition
+		{$$=$2;$$->n.i_name=$1;$$->n_type=0;
+			if(verbose)fprintf(stderr,"Got %s %d\n",get_typename($2),$1);
+		}
+		| IDENT resource_definition
+		{$$=$2;$$->n.s_name=$1;$$->n_type=1;
+			if(verbose)fprintf(stderr,"Got %s %s\n",get_typename($2),$1);
+		}
+
+/* get the value for a single resource*/
+resource_definition:	accelerators {$$=$1;}
+		| bitmap {$$=$1;}
+		| cursor {$$=$1;}
+		| dialog {$$=$1;}
+		| font {$$=$1;}
+		| icon {$$=$1;}
+		| menu {$$=$1;}
+		| rcdata {$$=$1;}
+		| stringtable {$$=$1;}
+		| versioninfo {$$=$1;}
+
+/* have to use tBEGIN because BEGIN is predefined */
+accelerators:	ACCELERATORS  tBEGIN  events tEND {$$=$3;$$->type=acc;}
+/* the events are collected in a gen_res, as the accelerator resource is just
+   an array of events */
+events:		{$$=new_res();}
+		| STRING ',' NUMBER acc_options  events 
+			{$$=add_string_accelerator($1,$3,$4,$5);}
+		| NUMBER ',' NUMBER ',' ASCII acc_options  events 
+			{$$=add_ascii_accelerator($1,$3,$6,$7);}
+		| NUMBER ',' NUMBER ',' VIRTKEY acc_options  events 
+			{$$=add_vk_accelerator($1,$3,$6,$7);}
+acc_options:	{$$=0;}
+		| ',' NOINVERT acc_options {$$=$3|2;}
+		| ',' ALT acc_options      {$$=$3|16;}
+		| ',' SHIFT acc_options	   {$$=$3|4;}
+		| ',' CONTROL acc_options  {$$=$3|8;}
+
+bitmap:		tBITMAP load_and_memoption STRING {$$=make_bitmap(load_file($3));}
+		| tBITMAP load_and_memoption raw_data {$$=make_bitmap($3);}
+
+/* load and memory options are ignored */
+load_and_memoption:	| lamo load_and_memoption
+lamo:	PRELOAD | LOADONCALL | FIXED | MOVEABLE | DISCARDABLE | PURE
+
+cursor:		CURSOR load_and_memoption STRING {$$=make_cursor(load_file($3));}
+		|CURSOR load_and_memoption raw_data {$$=make_cursor($3);}
+
+dialog:		DIALOG load_and_memoption NUMBER ',' NUMBER ',' NUMBER ',' NUMBER 
+		dlg_attributes
+		tBEGIN  controls tEND 
+		{$$=make_dialog($10,$3,$5,$7,$9,$12);}
+
+dlg_attributes:	{$$=new_dialog();}
+		| STYLE style dlg_attributes 
+		  {$$=dialog_style($2,$3);}
+		| CAPTION STRING dlg_attributes
+		  {$$=dialog_caption($2,$3);}
+		| FONT NUMBER ',' STRING dlg_attributes 
+		  {$$=dialog_font($2,$4,$5);}
+		| CLASS STRING dlg_attributes
+		  {$$=dialog_class($2,$3);}
+		| MENU STRING dlg_attributes
+		  {$$=dialog_menu($2,$3);}
+
+/* the controls are collected into a gen_res, and finally the dialog header 
+   is put at the beginning */
+controls:	{$$=new_res();}
+		| CHECKBOX  labeled_control controls 
+		  {$$=add_control(CT_BUTTON, BS_CHECKBOX, $2, $3);}
+		| COMBOBOX control_desc controls 
+		  {$$=add_control(CT_COMBOBOX, 0, $2, $3);}
+		| CONTROL generic_control controls
+		  {$$=add_generic_control($2, $3);}
+		| CTEXT labeled_control controls 
+		  {$$=add_control(CT_STATIC, SS_CENTER, $2, $3);}
+		| DEFPUSHBUTTON labeled_control controls 
+		  {$$=add_control(CT_BUTTON, BS_DEFPUSHBUTTON, $2, $3);}
+		| EDITTEXT control_desc controls 
+		  {$$=add_control(CT_EDIT, 0, $2, $3);}
+		| GROUPBOX labeled_control controls 
+		  {$$=add_control(CT_BUTTON, BS_GROUPBOX, $2, $3);}
+		/*special treatment for icons, as the extent is optional*/
+		| ICON STRING ',' NUMBER ',' NUMBER ',' NUMBER iconinfo controls
+		  {$$=add_icon($2, $4, $6, $8, $9, $10);}
+		| LISTBOX control_desc controls 
+		  {$$=add_control(CT_LISTBOX, 0, $2, $3);}
+		| LTEXT labeled_control controls 
+		  {$$=add_control(CT_STATIC, SS_LEFT, $2, $3);}
+		| PUSHBUTTON labeled_control controls 
+		  {$$=add_control(CT_BUTTON, BS_PUSHBUTTON, $2, $3);}
+		| RADIOBUTTON labeled_control controls 
+		  {$$=add_control(CT_BUTTON, BS_RADIOBUTTON, $2, $3);}
+		| RTEXT labeled_control controls 
+		  {$$=add_control(CT_STATIC, SS_RIGHT, $2, $3);}
+		| SCROLLBAR control_desc controls		
+		  {$$=add_control(CT_SCROLLBAR, 0, $2, $3);}
+
+
+labeled_control: STRING ',' control_desc {$$=label_control_desc($1,$3);}
+control_desc:	NUMBER ',' NUMBER ',' NUMBER ',' NUMBER ',' NUMBER optional_style 
+		{$$=create_control_desc($1,$3,$5,$7,$9,$10);}
+
+optional_style: {$$=0;}|
+		',' style {$$=$2;}
+
+iconinfo:	/*set extent and style to 0 if they are not provided */
+		{$$=create_control_desc(0,0,0,0,0,0);} 
+		/* x and y are overwritten later */
+		| ',' NUMBER ',' NUMBER optional_style
+        {$$=create_control_desc(0,0,0,$2,$4,$5);}
+
+generic_control:	STRING ',' NUMBER ',' STRING ',' style ',' NUMBER
+		',' NUMBER ',' NUMBER ',' NUMBER
+		{$$=create_generic_control($1,$3,$5,$7,$9,$11,$13,$15);}
+
+font:		FONT load_and_memoption STRING {$$=make_font(load_file($3));}
+
+icon:		ICON load_and_memoption STRING {$$=make_icon(load_file($3));}
+		| ICON load_and_memoption raw_data {$$=make_icon($3);}
+
+menu:		MENU load_and_memoption menu_body {$$=make_menu($3);}
+/* menu items are collected in a gen_res and prefixed with the menu header*/
+menu_body:	tBEGIN item_definitions tEND {$$=$2;}
+item_definitions:	{$$=new_res();}
+		| MENUITEM STRING ',' NUMBER item_options item_definitions
+		  {$$=add_menuitem($2,$4,$5,$6);}
+		| MENUITEM SEPARATOR item_definitions
+		  {$$=add_menuitem("",0,0,$3);}
+		| POPUP STRING item_options menu_body item_definitions
+		  {$$=add_popup($2,$3,$4,$5);}
+item_options:	{$$=0;}
+		| ',' CHECKED item_options {$$=$3|MF_CHECKED;}
+		| ',' GRAYED item_options {$$=$3|MF_GRAYED;}
+		| ',' HELP item_options {$$=$3|MF_HELP;}
+		| ',' INACTIVE item_options {$$=$3|MF_DISABLED;}
+		| ',' MENUBARBREAK item_options {$$=$3|MF_MENUBARBREAK;}
+		| ',' MENUBREAK item_options {$$=$3|MF_MENUBREAK;}
+
+rcdata:		RCDATA load_and_memoption raw_data {$$=make_raw($3);}
+
+raw_data:	tBEGIN raw_elements tEND {$$=$2;}
+raw_elements:	SINGLE_QUOTED {$$=hex_to_raw($1,new_res());}
+		| NUMBER {$$=int_to_raw($1,new_res());}
+		| SINGLE_QUOTED raw_elements {$$=hex_to_raw($1,$2);}
+		| NUMBER ',' raw_elements {$$=int_to_raw($1,$3);}
+
+stringtable:	STRINGTABLE load_and_memoption tBEGIN strings tEND
+			{$$=$4;}
+strings:	{$$=0;}|
+		NUMBER STRING strings {$$=0;}
+
+versioninfo:	VERSIONINFO NOT_SUPPORTED {$$=0;}
+
+/* NOT x | NOT y | a | b means (a|b)& ~x & ~y
+   NOT is used to disable default styles */
+style:		NUMBER {$$=new_style();$$->or=$1;}
+		| NOT NUMBER {$$=new_style();$$->and=~($2);}
+		| '(' style ')' {$$=$2;}
+		| style '|' style {$$=$1;$$->or|=$3->or;$$->and&=$3->and;}
+%%
+int yyerror(char *s)
+{
+	puts(s);
+}
+
diff --git a/rc/winerc.c b/rc/winerc.c
index 06dc7df..b2c9d31 100644
--- a/rc/winerc.c
+++ b/rc/winerc.c
@@ -14,8 +14,8 @@
 #include <string.h>
 #include <windows.h>
 #include <neexe.h>
-#include "rc.h"
-#include "rc.tab.h"
+#include "parser.h"
+#include "y.tab.h"
 
 char usage[]="winerc -dvc -p prefix -o outfile < infile \n";
 
diff --git a/toolkit/sup.c b/toolkit/sup.c
index e420c8f..dc66854 100644
--- a/toolkit/sup.c
+++ b/toolkit/sup.c
@@ -7,7 +7,7 @@
 
 /* HANDLE hSysRes = 1; */
 
-LONG CallWindowProc (FARPROC func, HWND hwnd, WORD message,
+LONG CallWindowProc (WNDPROC func, HWND hwnd, WORD message,
 		     WORD wParam, LONG lParam)
 {
     (*func)(hwnd, message, wParam, lParam);
diff --git a/tools/build.c b/tools/build.c
index c2ea2f2..9549673 100644
--- a/tools/build.c
+++ b/tools/build.c
@@ -706,6 +706,10 @@
     FILE *fp;
     char filename[80];
     int i, ci, add_count;
+    int prev_index;      /* Index to previous #define (-1 if none) */
+
+    /* the difference between last #define and the current */
+    int prev_n_args;
     
     if (argc < 2)
     {
@@ -761,11 +765,11 @@
     fprintf (fp, "#define __ASSEMBLY__\n");
     fprintf (fp, "#include <asm/segment.h>\n");
 #endif
+#if 0
     fprintf(fp, "\t.globl " PREFIX "%s_Dispatch\n", UpperDLLName);
     fprintf(fp, PREFIX "%s_Dispatch:\n", UpperDLLName);
     fprintf(fp, "\tandl\t$0x0000ffff,%%esp\n");
     fprintf(fp, "\tandl\t$0x0000ffff,%%ebp\n");
-    fprintf(fp, "\torl\t$0x%08x,%%eax\n", DLLId << 16);
 #ifdef __ELF__
     fprintf(fp, "\tljmp\t$USER_CS, $" PREFIX "CallTo32\n\n");
 #else
@@ -776,12 +780,12 @@
     fprintf(fp, PREFIX "%s_Dispatch_16:\n", UpperDLLName);
     fprintf(fp, "\tandl\t$0x0000ffff,%%esp\n");
     fprintf(fp, "\tandl\t$0x0000ffff,%%ebp\n");
-    fprintf(fp, "\torl\t$0x%08x,%%eax\n", DLLId << 16);
 #ifdef __ELF__
     fprintf(fp, "\tljmp\t$USER_CS, $" PREFIX "CallTo32_16\n\n");
 #else
     fprintf(fp, "\tjmp\t_CallTo32_16\n\n");
 #endif
+#endif
 
     odp = OrdinalDefinitions;
     for (i = 0; i <= Limit; i++, odp++)
@@ -791,9 +795,13 @@
 	if (!odp->valid)
 	{
 	    fprintf(fp, PREFIX "%s_Ordinal_%d:\n", UpperDLLName, i);
-	    fprintf(fp, "\tmovl\t$%d,%%eax\n", i);
+	    fprintf(fp, "\tmovl\t$0x%08x,%%eax\n", (DLLId << 16) | i);
 	    fprintf(fp, "\tpushw\t$0\n");
-	    fprintf(fp, "\tjmp\t" PREFIX "%s_Dispatch\n\n", UpperDLLName);
+#ifdef __ELF__
+            fprintf(fp, "\tljmp\t$USER_CS, $" PREFIX "CallTo32\n\n");
+#else
+            fprintf(fp, "\tjmp\t_CallTo32\n\n");
+#endif
 	}
 	else
 	{
@@ -847,32 +855,48 @@
 		fprintf(fp, "\tpushl\t%d(%%ebp)\n",
 			sizeof(struct sigcontext_struct));
 		fprintf(fp, "\tmovl\t%%eax,%%ebp\n");
-		fprintf(fp, "\tmovl\t$%d,%%eax\n", i);
+                fprintf(fp, "\tmovl\t$0x%08x,%%eax\n", (DLLId << 16) | i);
 		fprintf(fp, "\tpushw\t$%d\n", 
 			sizeof(struct sigcontext_struct) + 4);
-		fprintf(fp, "\tjmp\t" PREFIX "%s_Dispatch\n\n", UpperDLLName);
+#ifdef __ELF__
+                fprintf(fp, "\tljmp\t$USER_CS, $" PREFIX "CallTo32\n\n");
+#else
+                fprintf(fp, "\tjmp\t_CallTo32\n\n");
+#endif
 		break;
 
 	      case FUNCTYPE_PASCAL:
 		fprintf(fp, PREFIX "%s_Ordinal_%d:\n", UpperDLLName, i);
-		fprintf(fp, "\tmovl\t$%d,%%eax\n", i);
+                fprintf(fp, "\tmovl\t$0x%08x,%%eax\n", (DLLId << 16) | i);
 		fprintf(fp, "\tpushw\t$%d\n", fdp->arg_16_size);
-		fprintf(fp, "\tjmp\t" PREFIX "%s_Dispatch\n\n", UpperDLLName);
-		break;
+#ifdef __ELF__
+                fprintf(fp, "\tljmp\t$USER_CS, $" PREFIX "CallTo32\n\n");
+#else
+                fprintf(fp, "\tjmp\t_CallTo32\n\n");
+#endif
+                break;
 		
 	      case FUNCTYPE_PASCAL_16:
 		fprintf(fp, PREFIX "%s_Ordinal_%d:\n", UpperDLLName, i);
-		fprintf(fp, "\tmovl\t$%d,%%eax\n", i);
+                fprintf(fp, "\tmovl\t$0x%08x,%%eax\n", (DLLId << 16) | i);
 		fprintf(fp, "\tpushw\t$%d\n", fdp->arg_16_size);
-		fprintf(fp, "\tjmp\t" PREFIX "%s_Dispatch_16\n\n", UpperDLLName);
+#ifdef __ELF__
+                fprintf(fp, "\tljmp\t$USER_CS, $" PREFIX "CallTo32_16\n\n");
+#else
+                fprintf(fp, "\tjmp\t_CallTo32_16\n\n");
+#endif
 		break;
 		
 	      case FUNCTYPE_C:
 	      default:
 		fprintf(fp, PREFIX "%s_Ordinal_%d:\n", UpperDLLName, i);
-		fprintf(fp, "\tmovl\t$%d,%%eax\n", i);
+                fprintf(fp, "\tmovl\t$0x%08x,%%eax\n", (DLLId << 16) | i);
 		fprintf(fp, "\tpushw\t$0\n");
-		fprintf(fp, "\tjmp\t" PREFIX "%s_Dispatch\n\n", UpperDLLName);
+#ifdef __ELF__
+                fprintf(fp, "\tljmp\t$USER_CS, $" PREFIX "CallTo32\n\n");
+#else
+                fprintf(fp, "\tjmp\t_CallTo32\n\n");
+#endif
 		break;
 	    }
 	}
@@ -907,7 +931,71 @@
 	    fprintf(fp, "extern int %s();\n", fdp->internal_name);
 	}
     }
+    /******* Michael Veksler 95-2-3 (pointers instead of fixed data) ****/
+    fprintf(fp,"unsigned short  %s_offsets[]={\n" , UpperDLLName);
+    prev_index=-1;  /* Index to previous #define (-1 if none) */
+
+    /* the difference between last #define and the current */
+    prev_n_args= 0;
     
+    odp = OrdinalDefinitions;
+    for (i = 0; i <= Limit; i++, odp++)
+    {
+	int argnum;
+	fdp = odp->additional_data;
+
+	switch (odp->type)
+	{
+	  case FUNCTYPE_PASCAL:
+	  case FUNCTYPE_PASCAL_16:
+	  case FUNCTYPE_REG:
+	    if (!odp->valid || fdp->n_args_32 <=0 )
+	       continue;
+	    if (prev_index<0) 
+		fprintf(fp,"#\tdefine %s_ref_%d   0\n\t", UpperDLLName, i);
+	    else
+		fprintf(fp,"#\tdefine %s_ref_%d   %s_ref_%d+%d\n\t",
+			UpperDLLName,i, UpperDLLName,prev_index ,prev_n_args);
+	    for (argnum = 0; argnum < fdp->n_args_32; argnum++)
+		 fprintf(fp, "%d, ",
+		         fdp->arg_16_offsets[fdp->arg_indices_32[argnum]-1]);
+	    fprintf(fp,"\n");
+	    
+	    prev_n_args=fdp->n_args_32;
+	    prev_index=i;
+	}
+    }    
+    fprintf(fp,"};\n");
+
+
+    fprintf(fp,"unsigned char  %s_types[]={\n" , UpperDLLName);
+
+    odp = OrdinalDefinitions;
+    for (i = 0; i <= Limit; i++, odp++)
+    {
+	int argnum;
+
+	fdp = odp->additional_data;
+
+	switch (odp->type)
+	{
+	  case FUNCTYPE_PASCAL:
+	  case FUNCTYPE_PASCAL_16:
+	  case FUNCTYPE_REG:
+	    if (!odp->valid || fdp->n_args_32 <=0 )
+	       continue;
+	    
+	    fprintf(fp,"/* %s_%d */\n\t", UpperDLLName, i);
+	    
+	    for (argnum = 0; argnum < fdp->n_args_32; argnum++)
+		fprintf(fp, "%d, ", fdp->arg_types_16[argnum]);
+	    fprintf(fp,"\n");
+	}
+    }    
+    fprintf(fp,"};\n");
+
+
+    /**************************************************/
     fprintf(fp, "\nstruct dll_table_entry_s %s_table[%d] =\n", 
 	    UpperDLLName, Limit + 1);
     fprintf(fp, "{\n");
@@ -927,23 +1015,15 @@
 	    fprintf(fp, "    { 0x%x, %s_Ordinal_%d, ", UTEXTSEL, UpperDLLName, i);
 	    fprintf(fp, "\042%s\042, ", odp->export_name);
 	    fprintf(fp, "%s, DLL_HANDLERTYPE_PASCAL, ", fdp->internal_name);
-#ifdef WINESTAT
-	    fprintf(fp, "0, ");
-#endif	    
 	    fprintf(fp, "%d, ", fdp->n_args_32);
 	    if (fdp->n_args_32 > 0)
-	    {
-		int argnum;
-		
-		fprintf(fp, "\n      {\n");
-		for (argnum = 0; argnum < fdp->n_args_32; argnum++)
-		{
-		    fprintf(fp, "        { %d, %d },\n",
-			    fdp->arg_16_offsets[fdp->arg_indices_32[argnum]-1],
-			    fdp->arg_types_16[argnum]);
-		}
-		fprintf(fp, "      }\n    ");
-	    }
+	       fprintf(fp,"%s_ref_%d", UpperDLLName, i);
+	    else
+	       fprintf(fp,"      0    ");
+	       
+#ifdef WINESTAT
+	    fprintf(fp, ",0 ");
+#endif	    
 	    fprintf(fp, "}, \n");
 	    break;
 		
diff --git a/windows/event.c b/windows/event.c
index 4f4a2cf..06b3ded 100644
--- a/windows/event.c
+++ b/windows/event.c
@@ -31,10 +31,12 @@
 #endif
 #endif
 
+#ifdef WHO_NEEDS_DIRTY_HACKS
 #ifdef sparc
 /* Dirty hack to compile with Sun's OpenWindows */
 typedef char *XPointer;
 #endif
+#endif
 
 #define NB_BUTTONS      3     /* Windows can handle 3 buttons */
 
diff --git a/windows/message.c b/windows/message.c
index 2fd510e..d77c2b6 100644
--- a/windows/message.c
+++ b/windows/message.c
@@ -19,7 +19,6 @@
 #include "wineopts.h"
 #include "sysmetrics.h"
 #include "hook.h"
-#include "win.h"
 #include "event.h"
 #include "winpos.h"
 #include "stddebug.h"
diff --git a/windows/nonclient.c b/windows/nonclient.c
index 6f586a4..c12e293 100644
--- a/windows/nonclient.c
+++ b/windows/nonclient.c
@@ -8,7 +8,6 @@
 #include "win.h"
 #include "class.h"
 #include "message.h"
-#include "scroll.h"
 #include "sysmetrics.h"
 #include "user.h"
 #include "dialog.h"
diff --git a/windows/win.c b/windows/win.c
index 5148b94..3d9e49a 100644
--- a/windows/win.c
+++ b/windows/win.c
@@ -733,7 +733,7 @@
 		      adresses.
                       FIXME: There should be a jump table somewhere in if1632
 		   */
-		   long x=Stack16Frame[11]<<16 | 0x0010;
+		   long x=pStack16Frame->cs<<16 | 0x0010;
 		   /* Just to make Borland's OWL happy */
 		   return x;
 		}