Release 961208

Sun Dec  8 14:51:57 1996  Alexandre Julliard  <julliard@lrc.epfl.ch>

	* [configure.in]
	Added check to see if the compiler supports building a DLL when
	the --with-dll option is used.

	* [controls/listbox.c]
	Don't send LBN_SELCHANGE too often.
	Added WM_CHARTOITEM support.

	* [Make.rules.in] [library/Makefile.in]
	Build winestub.o and link it with Winelib programs.

	* [objects/text.c]
	Added support for '&&' in DrawText().

	* [tools/build.c]
	Added -o option.

Sat Dec 7 12:07:07 1996  Andrew Lewycky <plewycky@oise.utoronto.ca>

	* [win32/thread.c]
	GetCurrentThread(): return -2 (current thread pseudo-handle).
	GetCurrentThreadId(): return GetCurrentTask().

	* [objects/font.c] [if1632/gdi32.spec]
	GetTextExtentPoint32{A,W}Buggy(): for future bug-compatibility.

	* [win32/findfile.c]
	FindClose(): ignore INVALID_HANDLE_VALUE (like Win95).

	* [windows/hook.c] [include/hook.h] [if1632/user.spec]
	  [if1632/user32.spec] [windows/focus.c] [windows/message.c]
	  [windows/nonclient.c] [windows/win.c] [windows/winpos.c]
	Hooks rewritten to support Win32.

	* [misc/winsock.c]
	WINSOCK_select(): need to put sockets with errors into exceptfds.
	WINSOCK_socket(): fix error return.

	* [windows/win.c]
	SetWindowWord(): call SetParent on GWW_HWNDPARENT.

Wed Dec  4 22:03:05 1996  Andrew Taylor <andrew@riscan.com>

	* [files/dos_fs.c]
	Check if buf is NULL before copying string in GetFullPathName32A().

Wed Dec  4 21:40:59 1996  Robert Pouliot <krynos@clic.net>

        * [graphics/wing.c] [if1632/wing.spec]
	Implemented many WinG functions, but some don't seem to
	work correctly (probably due to the one not done).
	
Wed Dec  4 03:38:25 1996  Lee Jaekil <juria@puma.kaitech.re.kr>

	* [misc/main.c]
	Implemented a few more of the SystemParametersInfo() cases.

Sun Dec  1 22:30:00 1996  Alex Korobka <alex@trantor.pharm.sunysb.edu> 

	* [controls/button.c]
	Improved focus rectangle painting.

	* [windows/dialog.c] [windows/defdlg.c]
	Fixed IE3.0 problems with DWL_MSGRESULT.

Sun Dec  1 20:49:32 1996  Albrecht Kleine  <kleine@ak.sax.de>

	* [files/profile.c]
	Changed error handling in PROFILE_SetString().
diff --git a/tools/Makefile.in b/tools/Makefile.in
index fb8436a..c1d3f14 100644
--- a/tools/Makefile.in
+++ b/tools/Makefile.in
@@ -4,10 +4,10 @@
 SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 
-PROGRAMS = build makedep
+PROGRAMS = build makedep fnt2bdf
 MODULE   = none
 
-C_SRCS = build.c makedep.c
+C_SRCS = build.c makedep.c fnt2bdf.c
 
 all: $(PROGRAMS)
 
@@ -19,4 +19,7 @@
 makedep: makedep.o
 	$(CC) $(CFLAGS) -o makedep makedep.o
 
+fnt2bdf: fnt2bdf.o
+	$(CC) $(CFLAGS) -o fnt2bdf fnt2bdf.o
+
 ### Dependencies:
diff --git a/tools/build.c b/tools/build.c
index 76de29e..2381002 100644
--- a/tools/build.c
+++ b/tools/build.c
@@ -10,6 +10,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
+#include <unistd.h>
 #include "wintypes.h"
 #include "registers.h"
 #include "winerror.h"  /* for ERROR_CALL_NOT_IMPLEMENTED */
@@ -253,6 +254,12 @@
     return token;
 }
 
+
+/*******************************************************************
+ *         ParseVariable
+ *
+ * Parse a variable definition.
+ */
 static int ParseVariable( ORDDEF *odp )
 {
     char *endptr;
@@ -264,7 +271,7 @@
     if (*token != '(')
     {
 	fprintf(stderr, "%d: Expected '(' got '%s'\n", Line, token);
-	exit(1);
+	return -1;
     }
 
     n_values = 0;
@@ -288,14 +295,14 @@
 	{
 	    fprintf(stderr, "%d: Expected number value, got '%s'\n", Line,
 		    token);
-	    exit(1);
+	    return -1;
 	}
     }
     
     if (token == NULL)
     {
 	fprintf(stderr, "%d: End of file in variable declaration\n", Line);
-	exit(1);
+	return -1;
     }
 
     odp->u.var.n_values = n_values;
@@ -304,6 +311,12 @@
     return 0;
 }
 
+
+/*******************************************************************
+ *         ParseExportFunction
+ *
+ * Parse a function definition.
+ */
 static int ParseExportFunction( ORDDEF *odp )
 {
     char *token;
@@ -315,19 +328,19 @@
         if (odp->type == TYPE_STDCALL)
         {
             fprintf( stderr, "%d: 'stdcall' not supported for Win16\n", Line );
-            exit(1);
+            return -1;
         }
         if (odp->type == TYPE_CDECL)
         {
             fprintf( stderr, "%d: 'cdecl' not supported for Win16\n", Line );
-            exit(1);
+            return -1;
         }
         break;
     case SPEC_WIN32:
         if ((odp->type == TYPE_PASCAL) || (odp->type == TYPE_PASCAL_16))
         {
             fprintf( stderr, "%d: 'pascal' not supported for Win32\n", Line );
-            exit(1);
+            return -1;
         }
         break;
     default:
@@ -338,7 +351,7 @@
     if (*token != '(')
     {
 	fprintf(stderr, "%d: Expected '(' got '%s'\n", Line, token);
-	exit(1);
+	return -1;
     }
 
     for (i = 0; i < sizeof(odp->u.func.arg_types)-1; i++)
@@ -358,7 +371,7 @@
         else
         {
             fprintf(stderr, "%d: Unknown variable type '%s'\n", Line, token);
-            exit(1);
+            return -1;
         }
         if (SpecType == SPEC_WIN32)
         {
@@ -366,14 +379,14 @@
             {
                 fprintf( stderr, "%d: Type '%s' not supported for Win32\n",
                          Line, token );
-                exit(1);
+                return -1;
             }
         }
     }
     if (*token != ')')
     {
         fprintf( stderr, "%d: Too many arguments\n", Line );
-        exit(1);
+        return -1;
     }
     odp->u.func.arg_types[i] = '\0';
     if ((odp->type == TYPE_STDCALL) && !i)
@@ -398,7 +411,7 @@
     {
 	fprintf(stderr, "%d: Expected number value, got '%s'\n", Line,
 		token);
-	exit(1);
+	return -1;
     }
 
     odp->u.abs.value = value;
@@ -422,7 +435,7 @@
     {
 	fprintf(stderr, "%d: Expected number value, got '%s'\n", Line,
 		token);
-	exit(1);
+	return -1;
     }
 
     token = GetToken();
@@ -431,7 +444,7 @@
     {
 	fprintf(stderr, "%d: Expected number value, got '%s'\n", Line,
 		token);
-	exit(1);
+	return -1;
     }
 
     return 0;
@@ -461,7 +474,7 @@
     if (SpecType == SPEC_WIN16)
     {
         fprintf( stderr, "%d: 'extern' not supported for Win16\n", Line );
-        exit(1);
+        return -1;
     }
     strcpy( odp->u.ext.link_name, GetToken() );
     return 0;
@@ -481,7 +494,7 @@
     if (ordinal >= MAX_ORDINALS)
     {
 	fprintf(stderr, "%d: Ordinal number too large\n", Line);
-	exit(1);
+	return -1;
     }
     if (ordinal > Limit) Limit = ordinal;
 
@@ -489,7 +502,7 @@
     if (!(token = GetToken()))
     {
 	fprintf(stderr, "%d: Expected type after ordinal\n", Line);
-	exit(1);
+	return -1;
     }
 
     for (odp->type = 0; odp->type < TYPE_NBTYPES; odp->type++)
@@ -501,13 +514,13 @@
         fprintf( stderr,
                  "%d: Expected type after ordinal, found '%s' instead\n",
                  Line, token );
-        exit(1);
+        return -1;
     }
 
     if (!(token = GetToken()))
     {
         fprintf( stderr, "%d: Expected name after type\n", Line );
-        exit(1);
+        return -1;
     }
     strcpy( odp->name, token );
 
@@ -533,10 +546,16 @@
 	return ParseExtern( odp );
     default:
         fprintf( stderr, "Should not happen\n" );
-        exit(1);
+        return -1;
     }
 }
 
+
+/*******************************************************************
+ *         ParseTopLevel
+ *
+ * Parse a spec file.
+ */
 static int ParseTopLevel(void)
 {
     char *token;
@@ -556,7 +575,7 @@
             else
             {
                 fprintf(stderr, "%d: Type must be 'win16' or 'win32'\n", Line);
-                exit(1);
+                return -1;
             }
         }
 	else if (strcmp(token, "base") == 0)
@@ -565,7 +584,7 @@
             if (!IsNumberString(token))
             {
 		fprintf(stderr, "%d: Expected number after base\n", Line);
-		exit(1);
+		return -1;
             }
             Base = atoi(token);
 	}
@@ -575,7 +594,7 @@
             if (!IsNumberString(token))
             {
 		fprintf(stderr, "%d: Expected number after heap\n", Line);
-		exit(1);
+		return -1;
             }
             DLLHeapSize = atoi(token);
 	}
@@ -592,7 +611,7 @@
 	{
 	    fprintf(stderr, 
 		    "%d: Expected name, id, length or ordinal\n", Line);
-	    exit(1);
+	    return -1;
 	}
     }
 
@@ -633,19 +652,20 @@
  *
  * Dump a byte stream into the assembly code.
  */
-static void DumpBytes( const unsigned char *data, int len,
+static void DumpBytes( FILE *outfile, const unsigned char *data, int len,
                        const char *section, const char *label_start )
 {
     int i;
-    if (section) printf( "\t%s\n", section );
-    if (label_start) printf( "%s:\n", label_start );
+    if (section) fprintf( outfile, "\t%s\n", section );
+    if (label_start) fprintf( outfile, "%s:\n", label_start );
     for (i = 0; i < len; i++)
     {
-        if (!(i & 0x0f)) printf( "\t.byte " );
-        printf( "%d", *data++ );
-        if (i < len - 1) printf( "%c", ((i & 0x0f) != 0x0f) ? ',' : '\n' );
+        if (!(i & 0x0f)) fprintf( outfile, "\t.byte " );
+        fprintf( outfile, "%d", *data++ );
+        if (i < len - 1)
+            fprintf( outfile, "%c", ((i & 0x0f) != 0x0f) ? ',' : '\n' );
     }
-    printf( "\n" );
+    fprintf( outfile, "\n" );
 }
 
 
@@ -655,7 +675,8 @@
  * Build the in-memory representation of a 16-bit NE module, and dump it
  * as a byte stream into the assembly code.
  */
-static int BuildModule16( int max_code_offset, int max_data_offset )
+static int BuildModule16( FILE *outfile, int max_code_offset,
+                          int max_data_offset )
 {
     ORDDEF *odp;
     int i;
@@ -830,7 +851,7 @@
 
       /* Dump the module content */
 
-    DumpBytes( (char *)pModule, (int)pstr - (int)pModule,
+    DumpBytes( outfile, (char *)pModule, (int)pstr - (int)pModule,
                ".data", "Module_Start" );
     return (int)pstr - (int)pModule;
 }
@@ -842,7 +863,7 @@
  * Build the in-memory representation of a 32-bit pseudo-NE module, and dump it
  * as a byte stream into the assembly code.
  */
-static int BuildModule32(void)
+static int BuildModule32( FILE *outfile )
 {
     char *buffer;
     NE_MODULE *pModule;
@@ -940,27 +961,27 @@
 
       /* Dump the module content */
 
-    DumpBytes( (char *)pModule, (int)pstr - (int)pModule,
+    DumpBytes( outfile, (char *)pModule, (int)pstr - (int)pModule,
                ".data", "Module_Start" );
     return (int)pstr - (int)pModule;
 }
 
 
 /*******************************************************************
- *         BuildSpec32Files
+ *         BuildSpec32File
  *
  * Build a Win32 assembly file from a spec file.
  */
-static void BuildSpec32Files(void)
+static int BuildSpec32File( FILE *outfile )
 {
     ORDDEF *odp;
     int i, module_size, len;
     char buffer[1024];
 
-    printf( "/* File generated automatically; do not edit! */\n" );
-    printf( "\t.text\n" );
-    printf( "\t.align 4\n" );
-    printf( "Code_Start:\n\n" );
+    fprintf( outfile, "/* File generated automatically; do not edit! */\n" );
+    fprintf( outfile, "\t.text\n" );
+    fprintf( outfile, "\t.align 4\n" );
+    fprintf( outfile, "Code_Start:\n\n" );
 
     odp = OrdinalDefinitions;
     for (i = 0; i <= Limit; i++, odp++)
@@ -974,62 +995,59 @@
         case TYPE_CDECL:
         case TYPE_STUB:
         case TYPE_REGISTER:
-            printf( "/* %s.%d (%s) */\n",
-                     DLLName, i, odp->name);
-            printf( "%s_%d:\n", DLLName, i );
-            printf( "\tpushl %%ebp\n" );
-            printf( "\tpushl $" PREFIX "%s\n", odp->u.func.link_name );
-            printf( "\tcall " PREFIX "CallFrom32_%s_%d\n",
-                    (odp->type == TYPE_REGISTER) ? "regs" :
-                    ((odp->type == TYPE_STDCALL) ? "stdcall" : "cdecl"),
-                    strlen(odp->u.func.arg_types));
-            printf( "\tnop\n" );
+            fprintf( outfile, "/* %s.%d (%s) */\n", DLLName, i, odp->name);
+            fprintf( outfile, "%s_%d:\n", DLLName, i );
+            fprintf( outfile, "\tpushl %%ebp\n" );
+            fprintf( outfile, "\tpushl $" PREFIX "%s\n",odp->u.func.link_name);
+            fprintf( outfile, "\tcall " PREFIX "CallFrom32_%s_%d\n",
+                     (odp->type == TYPE_REGISTER) ? "regs" :
+                     ((odp->type == TYPE_STDCALL) ? "stdcall" : "cdecl"),
+                     strlen(odp->u.func.arg_types));
+            fprintf( outfile, "\tnop\n" );
             break;
 
         case TYPE_RETURN:
-            printf( "/* %s.%d (%s) */\n",
-                     DLLName, i, odp->name);
-            printf( "%s_%d:\n", DLLName, i );
-            printf( "\tmovl $%d,%%eax\n", ERROR_CALL_NOT_IMPLEMENTED );
-            printf( "\tmovl %%eax," PREFIX "WIN32_LastError\n" );
-            printf( "\tmovl $%d,%%eax\n", odp->u.ret.ret_value );
+            fprintf( outfile, "/* %s.%d (%s) */\n", DLLName, i, odp->name);
+            fprintf( outfile, "%s_%d:\n", DLLName, i );
+            fprintf( outfile, "\tmovl $%d,%%eax\n",ERROR_CALL_NOT_IMPLEMENTED);
+            fprintf( outfile, "\tmovl %%eax," PREFIX "WIN32_LastError\n" );
+            fprintf( outfile, "\tmovl $%d,%%eax\n", odp->u.ret.ret_value );
             if (odp->u.ret.arg_size)
             {
-                printf( "\tret $%d\n", odp->u.ret.arg_size );
-                printf( "\tnop\n" );
-                printf( "\tnop\n" );
+                fprintf( outfile, "\tret $%d\n", odp->u.ret.arg_size );
+                fprintf( outfile, "\tnop\n" );
+                fprintf( outfile, "\tnop\n" );
             }
-            else printf( "\tret\n" );
+            else fprintf( outfile, "\tret\n" );
             break;
 
         case TYPE_BYTE:
-            printf( "/* %s.%d (%s) */\n",
-                     DLLName, i, odp->name);
-            printf( "\t.data\n" );
-            printf( "%s_%d:\n", DLLName, i );
+            fprintf( outfile, "/* %s.%d (%s) */\n", DLLName, i, odp->name);
+            fprintf( outfile, "\t.data\n" );
+            fprintf( outfile, "%s_%d:\n", DLLName, i );
             len = StoreVariableCode( buffer, 1, odp );
-            DumpBytes( buffer, len, NULL, NULL );
-            printf( "\t.text\n" );
+            DumpBytes( outfile, buffer, len, NULL, NULL );
+            fprintf( outfile, "\t.text\n" );
             break;
 
         case TYPE_WORD:
-            printf( "/* %s.%d (%s) */\n",
+            fprintf( outfile, "/* %s.%d (%s) */\n",
                      DLLName, i, odp->name);
-            printf( "\t.data\n" );
-            printf( "%s_%d:\n", DLLName, i );
+            fprintf( outfile, "\t.data\n" );
+            fprintf( outfile, "%s_%d:\n", DLLName, i );
             len = StoreVariableCode( buffer, 2, odp );
-            DumpBytes( buffer, len, NULL, NULL );
-            printf( "\t.text\n" );
+            DumpBytes( outfile, buffer, len, NULL, NULL );
+            fprintf( outfile, "\t.text\n" );
             break;
 
         case TYPE_LONG:
-            printf( "/* %s.%d (%s) */\n",
+            fprintf( outfile, "/* %s.%d (%s) */\n",
                      DLLName, i, odp->name);
-            printf( "\t.data\n" );
-            printf( "%s_%d:\n", DLLName, i );
+            fprintf( outfile, "\t.data\n" );
+            fprintf( outfile, "%s_%d:\n", DLLName, i );
             len = StoreVariableCode( buffer, 4, odp );
-            DumpBytes( buffer, len, NULL, NULL );
-            printf( "\t.text\n" );
+            DumpBytes( outfile, buffer, len, NULL, NULL );
+            fprintf( outfile, "\t.text\n" );
             break;
 
         case TYPE_EXTERN:
@@ -1038,42 +1056,42 @@
         default:
             fprintf(stderr,"build: function type %d not available for Win32\n",
                     odp->type);
-            exit(1);
+            return -1;
         }
     }
 
-    module_size = BuildModule32();
+    module_size = BuildModule32( outfile );
 
     /* Output the DLL functions table */
 
-    printf( "\t.text\n" );
-    printf( "\t.align 4\n" );
-    printf( "Functions:\n" );
+    fprintf( outfile, "\t.text\n" );
+    fprintf( outfile, "\t.align 4\n" );
+    fprintf( outfile, "Functions:\n" );
     odp = OrdinalDefinitions;
     for (i = 0; i <= Limit; i++, odp++)
     {
         switch(odp->type)
         {
         case TYPE_INVALID:
-            printf( "\t.long 0\n" );
+            fprintf( outfile, "\t.long 0\n" );
             break;
         case TYPE_EXTERN:
-            printf( "\t.long " PREFIX "%s\n", odp->u.ext.link_name );
+            fprintf( outfile, "\t.long " PREFIX "%s\n", odp->u.ext.link_name );
             break;
         default:
-            printf( "\t.long %s_%d\n", DLLName, i );
+            fprintf( outfile, "\t.long %s_%d\n", DLLName, i );
             break;
         }
     }
 
     /* Output the DLL names table */
 
-    printf( "FuncNames:\n" );
+    fprintf( outfile, "FuncNames:\n" );
     odp = OrdinalDefinitions;
     for (i = 0; i <= Limit; i++, odp++)
     {
-        if (odp->type == TYPE_INVALID) printf( "\t.long 0\n" );
-        else printf( "\t.long Name_%d\n", i );
+        if (odp->type == TYPE_INVALID) fprintf( outfile, "\t.long 0\n" );
+        else fprintf( outfile, "\t.long Name_%d\n", i );
     }
 
     /* Output the DLL names */
@@ -1081,32 +1099,33 @@
     for (i = 0, odp = OrdinalDefinitions; i <= Limit; i++, odp++)
     {
         if (odp->type != TYPE_INVALID)
-            printf( "Name_%d:\t.ascii \"%s\\0\"\n", i, odp->name );
+            fprintf( outfile, "Name_%d:\t.ascii \"%s\\0\"\n", i, odp->name );
     }
 
     /* Output the DLL descriptor */
 
-    printf( "DLLName:\t.ascii \"%s\\0\"\n", DLLName );
-    printf( "\t.align 4\n" );
-    printf( "\t.globl " PREFIX "%s_Descriptor\n", DLLName );
-    printf( PREFIX "%s_Descriptor:\n", DLLName );
-    printf( "\t.long DLLName\n" );          /* Name */
-    printf( "\t.long Module_Start\n" );     /* Module start */
-    printf( "\t.long %d\n", module_size );  /* Module size */
-    printf( "\t.long %d\n", Base );         /* Base */
-    printf( "\t.long %d\n", Limit+1 );      /* Size */
-    printf( "\t.long Code_Start\n" );       /* Code start */
-    printf( "\t.long Functions\n" );        /* Functions */
-    printf( "\t.long FuncNames\n" );        /* Function names */
+    fprintf( outfile, "DLLName:\t.ascii \"%s\\0\"\n", DLLName );
+    fprintf( outfile, "\t.align 4\n" );
+    fprintf( outfile, "\t.globl " PREFIX "%s_Descriptor\n", DLLName );
+    fprintf( outfile, PREFIX "%s_Descriptor:\n", DLLName );
+    fprintf( outfile, "\t.long DLLName\n" );          /* Name */
+    fprintf( outfile, "\t.long Module_Start\n" );     /* Module start */
+    fprintf( outfile, "\t.long %d\n", module_size );  /* Module size */
+    fprintf( outfile, "\t.long %d\n", Base );         /* Base */
+    fprintf( outfile, "\t.long %d\n", Limit+1 );      /* Size */
+    fprintf( outfile, "\t.long Code_Start\n" );       /* Code start */
+    fprintf( outfile, "\t.long Functions\n" );        /* Functions */
+    fprintf( outfile, "\t.long FuncNames\n" );        /* Function names */
+    return 0;
 }
 
 
 /*******************************************************************
- *         BuildSpec16Files
+ *         BuildSpec16File
  *
  * Build a Win16 assembly file from a spec file.
  */
-static void BuildSpec16Files(void)
+static int BuildSpec16File( FILE *outfile )
 {
     ORDDEF *odp;
     int i;
@@ -1117,9 +1136,9 @@
     memset( data, 0, 16 );
     data_offset = 16;
 
-    printf( "/* File generated automatically; do not edit! */\n" );
-    printf( "\t.text\n" );
-    printf( "Code_Start:\n" );
+    fprintf( outfile, "/* File generated automatically; do not edit! */\n" );
+    fprintf( outfile, "\t.text\n" );
+    fprintf( outfile, "Code_Start:\n" );
     code_offset = 0;
 
     odp = OrdinalDefinitions;
@@ -1151,17 +1170,17 @@
             break;
 
           case TYPE_RETURN:
-            printf( "/* %s.%d */\n", DLLName, i);
-            printf( "\tmovw $%d,%%ax\n", LOWORD(odp->u.ret.ret_value) );
-            printf( "\tmovw $%d,%%dx\n", HIWORD(odp->u.ret.ret_value) );
-            printf( "\t.byte 0x66\n");
+            fprintf( outfile,"/* %s.%d */\n", DLLName, i);
+            fprintf( outfile,"\tmovw $%d,%%ax\n",LOWORD(odp->u.ret.ret_value));
+            fprintf( outfile,"\tmovw $%d,%%dx\n",HIWORD(odp->u.ret.ret_value));
+            fprintf( outfile,"\t.byte 0x66\n");
             if (odp->u.ret.arg_size != 0)
-                printf( "\tlret $%d\n\n", odp->u.ret.arg_size);
+                fprintf( outfile, "\tlret $%d\n\n", odp->u.ret.arg_size);
             else
             {
-                printf( "\tlret\n");
-                printf( "\tnop\n");
-                printf( "\tnop\n\n");
+                fprintf( outfile, "\tlret\n");
+                fprintf( outfile, "\tnop\n");
+                fprintf( outfile, "\tnop\n\n");
             }
             odp->offset = code_offset;
             code_offset += 12;  /* Assembly code is 12 bytes long */
@@ -1171,19 +1190,19 @@
           case TYPE_PASCAL:
           case TYPE_PASCAL_16:
           case TYPE_STUB:
-            printf( "/* %s.%d */\n", DLLName, i);
-            printf( "\tpushw %%bp\n" );
-            printf( "\tpushl $" PREFIX "%s\n", odp->u.func.link_name );
+            fprintf( outfile, "/* %s.%d */\n", DLLName, i);
+            fprintf( outfile, "\tpushw %%bp\n" );
+            fprintf( outfile, "\tpushl $" PREFIX "%s\n",odp->u.func.link_name);
             /* FreeBSD does not understand lcall, so do it the hard way */
-            printf( "\t.byte 0x9a /*lcall*/\n" );
-            printf( "\t.long " PREFIX "CallFrom16_%s_%s\n",
-                    (odp->type == TYPE_REGISTER) ? "regs" :
-                    (odp->type == TYPE_PASCAL) ? "long" : "word",
-                    odp->u.func.arg_types );
-            printf( "\t.byte 0x%02x,0x%02x\n", /* Some asms don't have .word */
-                    LOBYTE(WINE_CODE_SELECTOR), HIBYTE(WINE_CODE_SELECTOR) );
-            printf( "\tnop\n" );
-            printf( "\tnop\n\n" );
+            fprintf( outfile, "\t.byte 0x9a /*lcall*/\n" );
+            fprintf( outfile, "\t.long " PREFIX "CallFrom16_%s_%s\n",
+                     (odp->type == TYPE_REGISTER) ? "regs" :
+                     (odp->type == TYPE_PASCAL) ? "long" : "word",
+                     odp->u.func.arg_types );
+            fprintf( outfile,"\t.byte 0x%02x,0x%02x\n", /* Some asms don't have .word */
+                     LOBYTE(WINE_CODE_SELECTOR), HIBYTE(WINE_CODE_SELECTOR) );
+            fprintf( outfile, "\tnop\n" );
+            fprintf( outfile, "\tnop\n\n" );
             odp->offset = code_offset;
             code_offset += 16;  /* Assembly code is 16 bytes long */
             break;
@@ -1191,65 +1210,65 @@
           default:
             fprintf(stderr,"build: function type %d not available for Win16\n",
                     odp->type);
-            exit(1);
+            return -1;
 	}
     }
 
     if (!code_offset)  /* Make sure the code segment is not empty */
     {
-        printf( "\t.byte 0\n" );
+        fprintf( outfile, "\t.byte 0\n" );
         code_offset++;
     }
 
     /* Output data segment */
 
-    DumpBytes( data, data_offset, NULL, "Data_Start" );
+    DumpBytes( outfile, data, data_offset, NULL, "Data_Start" );
 
     /* Build the module */
 
-    module_size = BuildModule16( code_offset, data_offset );
+    module_size = BuildModule16( outfile, code_offset, data_offset );
 
     /* Output the DLL descriptor */
 
-    printf( "\t.text\n" );
-    printf( "DLLName:\t.ascii \"%s\\0\"\n", DLLName );
-    printf( "\t.align 4\n" );
-    printf( "\t.globl " PREFIX "%s_Descriptor\n", DLLName );
-    printf( PREFIX "%s_Descriptor:\n", DLLName );
-    printf( "\t.long DLLName\n" );          /* Name */
-    printf( "\t.long Module_Start\n" );     /* Module start */
-    printf( "\t.long %d\n", module_size );  /* Module size */
-    printf( "\t.long Code_Start\n" );       /* Code start */
-    printf( "\t.long Data_Start\n" );       /* Data start */
+    fprintf( outfile, "\t.text\n" );
+    fprintf( outfile, "DLLName:\t.ascii \"%s\\0\"\n", DLLName );
+    fprintf( outfile, "\t.align 4\n" );
+    fprintf( outfile, "\t.globl " PREFIX "%s_Descriptor\n", DLLName );
+    fprintf( outfile, PREFIX "%s_Descriptor:\n", DLLName );
+    fprintf( outfile, "\t.long DLLName\n" );          /* Name */
+    fprintf( outfile, "\t.long Module_Start\n" );     /* Module start */
+    fprintf( outfile, "\t.long %d\n", module_size );  /* Module size */
+    fprintf( outfile, "\t.long Code_Start\n" );       /* Code start */
+    fprintf( outfile, "\t.long Data_Start\n" );       /* Data start */
+    return 0;
 }
 
 
 /*******************************************************************
- *         BuildSpecFiles
+ *         BuildSpecFile
  *
  * Build an assembly file from a spec file.
  */
-static void BuildSpecFiles( char *specname )
+static int BuildSpecFile( FILE *outfile, char *specname )
 {
     SpecFp = fopen( specname, "r");
     if (SpecFp == NULL)
     {
 	fprintf(stderr, "Could not open specification file, '%s'\n", specname);
-	exit(1);
+        return -1;
     }
 
-    ParseTopLevel();
+    if (ParseTopLevel() < 0) return -1;
+
     switch(SpecType)
     {
-    case SPEC_INVALID:
-        fprintf( stderr, "%s: Missing 'type' declaration\n", specname );
-        exit(1);
     case SPEC_WIN16:
-        BuildSpec16Files();
-        break;
+        return BuildSpec16File( outfile );
     case SPEC_WIN32:
-        BuildSpec32Files();
-        break;
+        return BuildSpec32File( outfile );
+    default:
+        fprintf( stderr, "%s: Missing 'type' declaration\n", specname );
+        return -1;
     }
 }
 
@@ -1273,65 +1292,62 @@
  * (ebp+4)   ret addr
  * (ebp)     ebp
  */
-static void BuildCall32LargeStack(void)
+static void BuildCall32LargeStack( FILE *outfile )
 {
     /* Function header */
 
-    printf( "/**********\n" );
-    printf( " * " PREFIX "CallTo32_LargeStack\n" );
-    printf( " **********/\n" );
-    printf( "\t.align 4\n" );
-    printf( "\t.globl " PREFIX "CallTo32_LargeStack\n\n" );
-    printf( PREFIX "CallTo32_LargeStack:\n" );
+    fprintf( outfile, "\n\t.align 4\n" );
+    fprintf( outfile, "\t.globl " PREFIX "CallTo32_LargeStack\n" );
+    fprintf( outfile, PREFIX "CallTo32_LargeStack:\n" );
     
     /* Entry code */
 
-    printf( "\tpushl %%ebp\n" );
-    printf( "\tmovl %%esp,%%ebp\n" );
+    fprintf( outfile, "\tpushl %%ebp\n" );
+    fprintf( outfile, "\tmovl %%esp,%%ebp\n" );
 
     /* Save registers */
 
-    printf( "\tpushl %%ecx\n" );
-    printf( "\tpushl %%esi\n" );
-    printf( "\tpushl %%edi\n" );
+    fprintf( outfile, "\tpushl %%ecx\n" );
+    fprintf( outfile, "\tpushl %%esi\n" );
+    fprintf( outfile, "\tpushl %%edi\n" );
 
     /* Retrieve the original 32-bit stack pointer and switch to it if any */
 
-    printf( "\tmovl " PREFIX "IF1632_Original32_esp, %%eax\n" );
-    printf( "\torl %%eax,%%eax\n" );
-    printf( "\tje no_orig_esp\n" );
-    printf( "\tmovl %%eax,%%esp\n" );
-    printf( "no_orig_esp:\n" );
+    fprintf( outfile, "\tmovl " PREFIX "IF1632_Original32_esp, %%eax\n" );
+    fprintf( outfile, "\torl %%eax,%%eax\n" );
+    fprintf( outfile, "\tje no_orig_esp\n" );
+    fprintf( outfile, "\tmovl %%eax,%%esp\n" );
+    fprintf( outfile, "no_orig_esp:\n" );
 
     /* Transfer the arguments */
 
-    printf( "\tmovl 12(%%ebp),%%ecx\n" );
-    printf( "\torl %%ecx,%%ecx\n" );
-    printf( "\tje no_args\n" );
-    printf( "\tleal 16(%%ebp),%%esi\n" );
-    printf( "\tshll $2,%%ecx\n" );
-    printf( "\tsubl %%ecx,%%esp\n" );
-    printf( "\tmovl %%esp,%%edi\n" );
-    printf( "\tshrl $2,%%ecx\n" );
-    printf( "\tcld\n" );
-    printf( "\trep; movsl\n" );
-    printf( "no_args:\n" );
+    fprintf( outfile, "\tmovl 12(%%ebp),%%ecx\n" );
+    fprintf( outfile, "\torl %%ecx,%%ecx\n" );
+    fprintf( outfile, "\tje no_args\n" );
+    fprintf( outfile, "\tleal 16(%%ebp),%%esi\n" );
+    fprintf( outfile, "\tshll $2,%%ecx\n" );
+    fprintf( outfile, "\tsubl %%ecx,%%esp\n" );
+    fprintf( outfile, "\tmovl %%esp,%%edi\n" );
+    fprintf( outfile, "\tshrl $2,%%ecx\n" );
+    fprintf( outfile, "\tcld\n" );
+    fprintf( outfile, "\trep; movsl\n" );
+    fprintf( outfile, "no_args:\n" );
 
     /* Call the function */
 
-    printf( "\tcall 8(%%ebp)\n" );
+    fprintf( outfile, "\tcall 8(%%ebp)\n" );
 
     /* Switch back to the normal stack */
 
-    printf( "\tleal -12(%%ebp),%%esp\n" );
+    fprintf( outfile, "\tleal -12(%%ebp),%%esp\n" );
 
     /* Restore registers and return */
 
-    printf( "\tpopl %%edi\n" );
-    printf( "\tpopl %%esi\n" );
-    printf( "\tpopl %%ecx\n" );
-    printf( "\tpopl %%ebp\n" );
-    printf( "\tret\n" );
+    fprintf( outfile, "\tpopl %%edi\n" );
+    fprintf( outfile, "\tpopl %%esi\n" );
+    fprintf( outfile, "\tpopl %%ecx\n" );
+    fprintf( outfile, "\tpopl %%ebp\n" );
+    fprintf( outfile, "\tret\n" );
 }
 
 
@@ -1347,17 +1363,17 @@
  *  (bp+2)    ip
  *  (bp)      bp
  */
-static int TransferArgs16To32( char *args )
+static int TransferArgs16To32( FILE *outfile, char *args )
 {
     int i, pos16, pos32;
 
     /* Save ebx first */
 
-    printf( "\tpushl %%ebx\n" );
+    fprintf( outfile, "\tpushl %%ebx\n" );
 
     /* Get the 32-bit stack pointer */
 
-    printf( "\tmovl " PREFIX "IF1632_Saved32_esp,%%ebx\n" );
+    fprintf( outfile, "\tmovl " PREFIX "IF1632_Saved32_esp,%%ebx\n" );
 
     /* Copy the arguments */
 
@@ -1370,33 +1386,33 @@
         switch(args[i-1])
         {
         case 'w':  /* word */
-            printf( "\tmovzwl %d(%%ebp),%%eax\n", pos16 );
-            printf( "\tmovl %%eax,%d(%%ebx)\n", pos32 );
+            fprintf( outfile, "\tmovzwl %d(%%ebp),%%eax\n", pos16 );
+            fprintf( outfile, "\tmovl %%eax,%d(%%ebx)\n", pos32 );
             pos16 += 2;
             break;
 
         case 's':  /* s_word */
-            printf( "\tmovswl %d(%%ebp),%%eax\n", pos16 );
-            printf( "\tmovl %%eax,%d(%%ebx)\n", pos32 );
+            fprintf( outfile, "\tmovswl %d(%%ebp),%%eax\n", pos16 );
+            fprintf( outfile, "\tmovl %%eax,%d(%%ebx)\n", pos32 );
             pos16 += 2;
             break;
 
         case 'l':  /* long */
-            printf( "\tmovl %d(%%ebp),%%eax\n", pos16 );
-            printf( "\tmovl %%eax,%d(%%ebx)\n", pos32 );
+            fprintf( outfile, "\tmovl %d(%%ebp),%%eax\n", pos16 );
+            fprintf( outfile, "\tmovl %%eax,%d(%%ebx)\n", pos32 );
             pos16 += 4;
             break;
 
         case 'p':  /* ptr */
             /* Get the selector */
-            printf( "\tmovw %d(%%ebp),%%ax\n", pos16 + 2 );
+            fprintf( outfile, "\tmovw %d(%%ebp),%%ax\n", pos16 + 2 );
             /* Get the selector base */
-            printf( "\tandl $0xfff8,%%eax\n" );
-            printf( "\tmovl " PREFIX "ldt_copy(%%eax),%%eax\n" );
-            printf( "\tmovl %%eax,%d(%%ebx)\n", pos32 );
+            fprintf( outfile, "\tandl $0xfff8,%%eax\n" );
+            fprintf( outfile, "\tmovl " PREFIX "ldt_copy(%%eax),%%eax\n" );
+            fprintf( outfile, "\tmovl %%eax,%d(%%ebx)\n", pos32 );
             /* Add the offset */
-            printf( "\tmovzwl %d(%%ebp),%%eax\n", pos16 );
-            printf( "\taddl %%eax,%d(%%ebx)\n", pos32 );
+            fprintf( outfile, "\tmovzwl %d(%%ebp),%%eax\n", pos16 );
+            fprintf( outfile, "\taddl %%eax,%d(%%ebx)\n", pos32 );
             pos16 += 4;
             break;
 
@@ -1407,7 +1423,7 @@
 
     /* Restore ebx */
     
-    printf( "\tpopl %%ebx\n" );
+    fprintf( outfile, "\tpopl %%ebx\n" );
 
     return pos16 - 6;  /* Return the size of the 16-bit args */
 }
@@ -1420,30 +1436,30 @@
  * The only valid registers in the context structure are:
  *   eax, ebx, ecx, edx, esi, edi, ds, es, (some of the) flags
  */
-static void BuildContext16(void)
+static void BuildContext16( FILE *outfile )
 {
     /* Save ebx first */
 
-    printf( "\tpushl %%ebx\n" );
+    fprintf( outfile, "\tpushl %%ebx\n" );
 
     /* Get the 32-bit stack pointer */
 
-    printf( "\tmovl " PREFIX "IF1632_Saved32_esp,%%ebx\n" );
+    fprintf( outfile, "\tmovl " PREFIX "IF1632_Saved32_esp,%%ebx\n" );
 
     /* Store the registers */
 
-    printf( "\tpopl %d(%%ebx)\n", SIGCONTEXTOFFSET(EBX) ); /* Get ebx from stack*/
-    printf( "\tmovl %%eax,%d(%%ebx)\n", SIGCONTEXTOFFSET(EAX) );
-    printf( "\tmovl %%ecx,%d(%%ebx)\n", SIGCONTEXTOFFSET(ECX) );
-    printf( "\tmovl %%edx,%d(%%ebx)\n", SIGCONTEXTOFFSET(EDX) );
-    printf( "\tmovl %%esi,%d(%%ebx)\n", SIGCONTEXTOFFSET(ESI) );
-    printf( "\tmovl %%edi,%d(%%ebx)\n", SIGCONTEXTOFFSET(EDI) );
-    printf( "\tmovw -10(%%ebp),%%ax\n" );  /* Get saved ds from stack */
-    printf( "\tmovw %%ax,%d(%%ebx)\n", SIGCONTEXTOFFSET(DS) );
-    printf( "\tmovw -6(%%ebp),%%ax\n" );  /* Get saved es from stack */
-    printf( "\tmovw %%ax,%d(%%ebx)\n", SIGCONTEXTOFFSET(ES) );
-    printf( "\tpushfl\n" );
-    printf( "\tpopl %d(%%ebx)\n", SIGCONTEXTOFFSET(EFL) );
+    fprintf( outfile, "\tpopl %d(%%ebx)\n", SIGCONTEXTOFFSET(EBX) ); /* Get ebx from stack*/
+    fprintf( outfile, "\tmovl %%eax,%d(%%ebx)\n", SIGCONTEXTOFFSET(EAX) );
+    fprintf( outfile, "\tmovl %%ecx,%d(%%ebx)\n", SIGCONTEXTOFFSET(ECX) );
+    fprintf( outfile, "\tmovl %%edx,%d(%%ebx)\n", SIGCONTEXTOFFSET(EDX) );
+    fprintf( outfile, "\tmovl %%esi,%d(%%ebx)\n", SIGCONTEXTOFFSET(ESI) );
+    fprintf( outfile, "\tmovl %%edi,%d(%%ebx)\n", SIGCONTEXTOFFSET(EDI) );
+    fprintf( outfile, "\tmovw -10(%%ebp),%%ax\n" ); /*Get saved ds from stack*/
+    fprintf( outfile, "\tmovw %%ax,%d(%%ebx)\n", SIGCONTEXTOFFSET(DS) );
+    fprintf( outfile, "\tmovw -6(%%ebp),%%ax\n" ); /*Get saved es from stack*/
+    fprintf( outfile, "\tmovw %%ax,%d(%%ebx)\n", SIGCONTEXTOFFSET(ES) );
+    fprintf( outfile, "\tpushfl\n" );
+    fprintf( outfile, "\tpopl %d(%%ebx)\n", SIGCONTEXTOFFSET(EFL) );
 }
 
 
@@ -1452,26 +1468,26 @@
  *
  * Restore the registers from the context structure
  */
-static void RestoreContext16(void)
+static void RestoreContext16( FILE *outfile )
 {
     /* Get the 32-bit stack pointer */
 
-    printf( "\tmovl " PREFIX "IF1632_Saved32_esp,%%ebx\n" );
+    fprintf( outfile, "\tmovl " PREFIX "IF1632_Saved32_esp,%%ebx\n" );
 
     /* Restore the registers */
 
-    printf( "\tmovl %d(%%ebx),%%ecx\n", SIGCONTEXTOFFSET(ECX) );
-    printf( "\tmovl %d(%%ebx),%%edx\n", SIGCONTEXTOFFSET(EDX) );
-    printf( "\tmovl %d(%%ebx),%%esi\n", SIGCONTEXTOFFSET(ESI) );
-    printf( "\tmovl %d(%%ebx),%%edi\n", SIGCONTEXTOFFSET(EDI) );
-    printf( "\tpopl %%eax\n" );  /* Remove old ds and ip from stack */
-    printf( "\tpopl %%eax\n" );  /* Remove old cs and es from stack */
-    printf( "\tpushw %d(%%ebx)\n", SIGCONTEXTOFFSET(DS) ); /* Push new ds */
-    printf( "\tpushw %d(%%ebx)\n", SIGCONTEXTOFFSET(ES) ); /* Push new es */
-    printf( "\tpushl %d(%%ebx)\n", SIGCONTEXTOFFSET(EFL) );
-    printf( "\tpopfl\n" );
-    printf( "\tmovl %d(%%ebx),%%eax\n", SIGCONTEXTOFFSET(EAX) );
-    printf( "\tmovl %d(%%ebx),%%ebx\n", SIGCONTEXTOFFSET(EBX) );
+    fprintf( outfile, "\tmovl %d(%%ebx),%%ecx\n", SIGCONTEXTOFFSET(ECX) );
+    fprintf( outfile, "\tmovl %d(%%ebx),%%edx\n", SIGCONTEXTOFFSET(EDX) );
+    fprintf( outfile, "\tmovl %d(%%ebx),%%esi\n", SIGCONTEXTOFFSET(ESI) );
+    fprintf( outfile, "\tmovl %d(%%ebx),%%edi\n", SIGCONTEXTOFFSET(EDI) );
+    fprintf( outfile, "\tpopl %%eax\n" ); /* Remove old ds and ip from stack */
+    fprintf( outfile, "\tpopl %%eax\n" ); /* Remove old cs and es from stack */
+    fprintf( outfile, "\tpushw %d(%%ebx)\n", SIGCONTEXTOFFSET(DS) ); /* Push new ds */
+    fprintf( outfile, "\tpushw %d(%%ebx)\n", SIGCONTEXTOFFSET(ES) ); /*Push new es */
+    fprintf( outfile, "\tpushl %d(%%ebx)\n", SIGCONTEXTOFFSET(EFL) );
+    fprintf( outfile, "\tpopfl\n" );
+    fprintf( outfile, "\tmovl %d(%%ebx),%%eax\n", SIGCONTEXTOFFSET(EAX) );
+    fprintf( outfile, "\tmovl %d(%%ebx),%%ebx\n", SIGCONTEXTOFFSET(EBX) );
 }
 
 
@@ -1498,7 +1514,7 @@
  * (sp)    word   low word of ip of 16-bit entry point
  *
  */
-static void BuildCallFrom16Func( char *profile )
+static void BuildCallFrom16Func( FILE *outfile, char *profile )
 {
     int argsize = 0;
     int short_ret = 0;
@@ -1517,119 +1533,117 @@
 
     /* Function header */
 
-    printf( "/**********\n" );
-    printf( " * " PREFIX "CallFrom16_%s\n", profile );
-    printf( " **********/\n" );
-    printf( "\t.align 4\n" );
-    printf( "\t.globl " PREFIX "CallFrom16_%s\n\n", profile );
-    printf( PREFIX "CallFrom16_%s:\n", profile );
+    fprintf( outfile, "\n\t.align 4\n" );
+    fprintf( outfile, "\t.globl " PREFIX "CallFrom16_%s\n", profile );
+    fprintf( outfile, PREFIX "CallFrom16_%s:\n", profile );
 
     /* Setup bp to point to its copy on the stack */
 
-    printf( "\tmovzwl %%sp,%%ebp\n" );
-    printf( "\taddw $12,%%bp\n" );
+    fprintf( outfile, "\tmovzwl %%sp,%%ebp\n" );
+    fprintf( outfile, "\taddw $12,%%bp\n" );
 
     /* Save 16-bit ds and es */
 
     /* Stupid FreeBSD assembler doesn't know these either */
-    /* printf( "\tmovw %%ds,-10(%%ebp)\n" ); */
-    printf( "\t.byte 0x66,0x8c,0x5d,0xf6\n" );
-    /* printf( "\tmovw %%es,-6(%%ebp)\n" ); */
-    printf( "\t.byte 0x66,0x8c,0x45,0xfa\n" );
+    /* fprintf( outfile, "\tmovw %%ds,-10(%%ebp)\n" ); */
+    fprintf( outfile, "\t.byte 0x66,0x8c,0x5d,0xf6\n" );
+    /* fprintf( outfile, "\tmovw %%es,-6(%%ebp)\n" ); */
+    fprintf( outfile, "\t.byte 0x66,0x8c,0x45,0xfa\n" );
 
     /* Restore 32-bit ds and es */
 
-    printf( "\tpushl $0x%04x%04x\n", WINE_DATA_SELECTOR, WINE_DATA_SELECTOR );
-    printf( "\tpopw %%ds\n" );
-    printf( "\tpopw %%es\n" );
+    fprintf( outfile, "\tpushl $0x%04x%04x\n",
+             WINE_DATA_SELECTOR, WINE_DATA_SELECTOR );
+    fprintf( outfile, "\tpopw %%ds\n" );
+    fprintf( outfile, "\tpopw %%es\n" );
 
 
     /* Save the 16-bit stack */
 
-    printf( "\tpushw " PREFIX "IF1632_Saved16_sp\n" );
-    printf( "\tpushw " PREFIX "IF1632_Saved16_ss\n" );
+    fprintf( outfile, "\tpushw " PREFIX "IF1632_Saved16_sp\n" );
+    fprintf( outfile, "\tpushw " PREFIX "IF1632_Saved16_ss\n" );
 #ifdef __svr4__
-    printf("\tdata16\n");
+    fprintf( outfile,"\tdata16\n");
 #endif
-    printf( "\tmovw %%ss," PREFIX "IF1632_Saved16_ss\n" );
-    printf( "\tmovw %%sp," PREFIX "IF1632_Saved16_sp\n" );
+    fprintf( outfile, "\tmovw %%ss," PREFIX "IF1632_Saved16_ss\n" );
+    fprintf( outfile, "\tmovw %%sp," PREFIX "IF1632_Saved16_sp\n" );
 
     /* Transfer the arguments */
 
-    if (reg_func) BuildContext16();
-    else if (*args) argsize = TransferArgs16To32( args );
+    if (reg_func) BuildContext16( outfile );
+    else if (*args) argsize = TransferArgs16To32( outfile, args );
 
     /* Get the address of the API function */
 
-    printf( "\tmovl -4(%%ebp),%%eax\n" );
+    fprintf( outfile, "\tmovl -4(%%ebp),%%eax\n" );
 
     /* If necessary, save %edx over the API function address */
 
     if (!reg_func && short_ret)
-        printf( "\tmovl %%edx,-4(%%ebp)\n" );
+        fprintf( outfile, "\tmovl %%edx,-4(%%ebp)\n" );
 
     /* Switch to the 32-bit stack */
 
-    printf( "\tmovl " PREFIX "IF1632_Saved32_esp,%%ebp\n" );
-    printf( "\tpushw %%ds\n" );
-    printf( "\tpopw %%ss\n" );
-    printf( "\tleal -%d(%%ebp),%%esp\n",
-            reg_func ? sizeof(SIGCONTEXT) : 4 * strlen(args) );
+    fprintf( outfile, "\tmovl " PREFIX "IF1632_Saved32_esp,%%ebp\n" );
+    fprintf( outfile, "\tpushw %%ds\n" );
+    fprintf( outfile, "\tpopw %%ss\n" );
+    fprintf( outfile, "\tleal -%d(%%ebp),%%esp\n",
+             reg_func ? sizeof(SIGCONTEXT) : 4 * strlen(args) );
     if (reg_func)  /* Push the address of the context struct */
-        printf( "\tpushl %%esp\n" );
+        fprintf( outfile, "\tpushl %%esp\n" );
 
     /* Setup %ebp to point to the previous stack frame (built by CallTo16) */
 
-    printf( "\taddl $24,%%ebp\n" );
+    fprintf( outfile, "\taddl $24,%%ebp\n" );
 
     /* Print the debug information before the call */
 
     if (debugging)
     {
-        printf( "\tpushl %%eax\n" );
-        printf( "\tpushl $Profile_%s\n", profile );
-        printf( "\tpushl $%d\n", reg_func ? 2 : (short_ret ? 1 : 0) );
-        printf( "\tcall " PREFIX "RELAY_DebugCallFrom16\n" );
-        printf( "\tpopl %%eax\n" );
-        printf( "\tpopl %%eax\n" );
-        printf( "\tpopl %%eax\n" );
+        fprintf( outfile, "\tpushl %%eax\n" );
+        fprintf( outfile, "\tpushl $Profile_%s\n", profile );
+        fprintf( outfile, "\tpushl $%d\n", reg_func ? 2 : (short_ret ? 1 : 0));
+        fprintf( outfile, "\tcall " PREFIX "RELAY_DebugCallFrom16\n" );
+        fprintf( outfile, "\tpopl %%eax\n" );
+        fprintf( outfile, "\tpopl %%eax\n" );
+        fprintf( outfile, "\tpopl %%eax\n" );
     }
 
     /* Call the entry point */
 
-    printf( "\tcall %%eax\n" );
+    fprintf( outfile, "\tcall %%eax\n" );
 
     /* Print the debug information after the call */
 
     if (debugging)
     {
-        printf( "\tpushl %%eax\n" );
-        printf( "\tpushl $%d\n", reg_func ? 2 : (short_ret ? 1 : 0) );
-        printf( "\tcall " PREFIX "RELAY_DebugCallFrom16Ret\n" );
-        printf( "\tpopl %%eax\n" );
-        printf( "\tpopl %%eax\n" );
+        fprintf( outfile, "\tpushl %%eax\n" );
+        fprintf( outfile, "\tpushl $%d\n", reg_func ? 2 : (short_ret ? 1 : 0));
+        fprintf( outfile, "\tcall " PREFIX "RELAY_DebugCallFrom16Ret\n" );
+        fprintf( outfile, "\tpopl %%eax\n" );
+        fprintf( outfile, "\tpopl %%eax\n" );
     }
 
     /* Restore the 16-bit stack */
 
 #ifdef __svr4__
-    printf( "\tdata16\n");
+    fprintf( outfile, "\tdata16\n");
 #endif
-    printf( "\tmovw " PREFIX "IF1632_Saved16_ss,%%ss\n" );
-    printf( "\tmovw " PREFIX "IF1632_Saved16_sp,%%sp\n" );
+    fprintf( outfile, "\tmovw " PREFIX "IF1632_Saved16_ss,%%ss\n" );
+    fprintf( outfile, "\tmovw " PREFIX "IF1632_Saved16_sp,%%sp\n" );
 #ifdef __svr4__
-    printf( "\tdata16\n");
+    fprintf( outfile, "\tdata16\n");
 #endif
-    printf( "\tpopw " PREFIX "IF1632_Saved16_ss\n" );
+    fprintf( outfile, "\tpopw " PREFIX "IF1632_Saved16_ss\n" );
 #ifdef __svr4__
-    printf( "\tdata16\n");
+    fprintf( outfile, "\tdata16\n");
 #endif
-    printf( "\tpopw " PREFIX "IF1632_Saved16_sp\n" );
+    fprintf( outfile, "\tpopw " PREFIX "IF1632_Saved16_sp\n" );
 
     if (reg_func)
     {
         /* Restore registers from the context structure */
-        RestoreContext16();
+        RestoreContext16( outfile );
         
         /* Calc the arguments size */
         while (*args)
@@ -1651,48 +1665,48 @@
         }
 
         /* Restore ds and es */
-        printf( "\tpopw %%es\n" );
-        printf( "\tpopw %%ds\n" );
+        fprintf( outfile, "\tpopw %%es\n" );
+        fprintf( outfile, "\tpopw %%ds\n" );
 
         /* Remove the entry point from the stack */
         /* (we don't use add to avoid modifying the carry flag) */
-        printf( "\tpopl %%ebp\n" );
+        fprintf( outfile, "\tpopl %%ebp\n" );
     }
     else
     {
         /* Restore ds and es */
-        printf( "\tpopw %%bp\n" );       /* Remove ip */
-        printf( "\tpopl %%ebp\n" );      /* Remove ds and cs */
-        printf( "\tmovw %%bp,%%ds\n" );  /* Restore ds */
-        printf( "\tpopw %%es\n" );       /* Restore es */
+        fprintf( outfile, "\tpopw %%bp\n" );       /* Remove ip */
+        fprintf( outfile, "\tpopl %%ebp\n" );      /* Remove ds and cs */
+        fprintf( outfile, "\tmovw %%bp,%%ds\n" );  /* Restore ds */
+        fprintf( outfile, "\tpopw %%es\n" );       /* Restore es */
 
-        if (short_ret) printf( "\tpopl %%edx\n" );     /* Restore edx */
+        if (short_ret) fprintf( outfile, "\tpopl %%edx\n" );  /* Restore edx */
         else
         {
             /* Get the return value into dx:ax */
-            printf( "\tpushl %%eax\n" );
-            printf( "\tpopw %%ax\n" );
-            printf( "\tpopw %%dx\n" );
+            fprintf( outfile, "\tpushl %%eax\n" );
+            fprintf( outfile, "\tpopw %%ax\n" );
+            fprintf( outfile, "\tpopw %%dx\n" );
             /* Remove API entry point */
-            printf( "\taddl $4,%%esp\n" );
+            fprintf( outfile, "\taddl $4,%%esp\n" );
         }
     }
 
     /* Restore bp */
 
-    printf( "\tpopw %%bp\n" );
+    fprintf( outfile, "\tpopw %%bp\n" );
 
     /* Remove the arguments and return */
 
     if (argsize)
     {
-        printf( "\t.byte 0x66\n" );
-        printf( "\tlret $%d\n", argsize );
+        fprintf( outfile, "\t.byte 0x66\n" );
+        fprintf( outfile, "\tlret $%d\n", argsize );
     }
     else
     {
-        printf( "\t.byte 0x66\n" );
-        printf( "\tlret\n" );
+        fprintf( outfile, "\t.byte 0x66\n" );
+        fprintf( outfile, "\tlret\n" );
     }
 }
 
@@ -1718,7 +1732,7 @@
  *                               WORD ax, WORD bx, WORD cx, WORD dx,
  *                               WORD si, WORD di );
  */
-static void BuildCallTo16Func( char *profile )
+static void BuildCallTo16Func( FILE *outfile, char *profile )
 {
     int short_ret = 0;
     int reg_func = 0;
@@ -1734,91 +1748,88 @@
 
     /* Function header */
 
-    printf( "/**********\n" );
-    printf( " * " PREFIX "CallTo16_%s\n", profile );
-    printf( " **********/\n" );
-    printf( "\t.align 4\n" );
-    printf( "\t.globl " PREFIX "CallTo16_%s\n\n", profile );
-    printf( PREFIX "CallTo16_%s:\n", profile );
+    fprintf( outfile, "\n\t.align 4\n" );
+    fprintf( outfile, "\t.globl " PREFIX "CallTo16_%s\n", profile );
+    fprintf( outfile, PREFIX "CallTo16_%s:\n", profile );
 
     /* Push code selector before return address to simulate a lcall */
 
-    printf( "\tpopl %%eax\n" );
-    printf( "\tpushl $0x%04x\n", WINE_CODE_SELECTOR );
-    printf( "\tpushl %%eax\n" );
+    fprintf( outfile, "\tpopl %%eax\n" );
+    fprintf( outfile, "\tpushl $0x%04x\n", WINE_CODE_SELECTOR );
+    fprintf( outfile, "\tpushl %%eax\n" );
 
     /* Entry code */
 
-    printf( "\tpushl %%ebp\n" );
-    printf( "\tmovl %%esp,%%ebp\n" );
+    fprintf( outfile, "\tpushl %%ebp\n" );
+    fprintf( outfile, "\tmovl %%esp,%%ebp\n" );
 
     /* Save the 32-bit registers */
 
-    printf( "\tpushl %%ebx\n" );
-    printf( "\tpushl %%ecx\n" );
-    printf( "\tpushl %%edx\n" );
-    printf( "\tpushl %%esi\n" );
-    printf( "\tpushl %%edi\n" );
+    fprintf( outfile, "\tpushl %%ebx\n" );
+    fprintf( outfile, "\tpushl %%ecx\n" );
+    fprintf( outfile, "\tpushl %%edx\n" );
+    fprintf( outfile, "\tpushl %%esi\n" );
+    fprintf( outfile, "\tpushl %%edi\n" );
 
     /* Save the 32-bit stack */
 
-    printf( "\tpushl " PREFIX "IF1632_Saved32_esp\n" );
-    printf( "\tmovl %%esp," PREFIX "IF1632_Saved32_esp\n" );
-    printf( "\tmovl %%ebp,%%ebx\n" );
+    fprintf( outfile, "\tpushl " PREFIX "IF1632_Saved32_esp\n" );
+    fprintf( outfile, "\tmovl %%esp," PREFIX "IF1632_Saved32_esp\n" );
+    fprintf( outfile, "\tmovl %%ebp,%%ebx\n" );
 
     /* Print debugging info */
 
     if (debugging)
     {
         /* Push the address of the first argument */
-        printf( "\tmovl %%ebx,%%eax\n" );
-        printf( "\taddl $12,%%eax\n" );
-        printf( "\tpushl $%d\n", reg_func ? 8 : strlen(args) );
-        printf( "\tpushl %%eax\n" );
-        printf( "\tcall " PREFIX "RELAY_DebugCallTo16\n" );
-        printf( "\tpopl %%eax\n" );
-        printf( "\tpopl %%eax\n" );
+        fprintf( outfile, "\tmovl %%ebx,%%eax\n" );
+        fprintf( outfile, "\taddl $12,%%eax\n" );
+        fprintf( outfile, "\tpushl $%d\n", reg_func ? 8 : strlen(args) );
+        fprintf( outfile, "\tpushl %%eax\n" );
+        fprintf( outfile, "\tcall " PREFIX "RELAY_DebugCallTo16\n" );
+        fprintf( outfile, "\tpopl %%eax\n" );
+        fprintf( outfile, "\tpopl %%eax\n" );
     }
 
     /* Switch to the 16-bit stack */
 
 #ifdef __svr4__
-    printf("\tdata16\n");
+    fprintf( outfile,"\tdata16\n");
 #endif
-    printf( "\tmovw " PREFIX "IF1632_Saved16_ss,%%ss\n" );
-    printf( "\tmovw " PREFIX "IF1632_Saved16_sp,%%sp\n" );
+    fprintf( outfile, "\tmovw " PREFIX "IF1632_Saved16_ss,%%ss\n" );
+    fprintf( outfile, "\tmovw " PREFIX "IF1632_Saved16_sp,%%sp\n" );
 
     /* Transfer the arguments */
 
     if (reg_func)
     {
         /* Get the registers. ebx is handled later on. */
-        printf( "\tpushw 20(%%ebx)\n" );
-        printf( "\tpopw %%es\n" );
-        printf( "\tmovl 24(%%ebx),%%ebp\n" );
-        printf( "\tmovl 28(%%ebx),%%eax\n" );
-        printf( "\tmovl 36(%%ebx),%%ecx\n" );
-        printf( "\tmovl 40(%%ebx),%%edx\n" );
-        printf( "\tmovl 44(%%ebx),%%esi\n" );
-        printf( "\tmovl 48(%%ebx),%%edi\n" );
+        fprintf( outfile, "\tpushw 20(%%ebx)\n" );
+        fprintf( outfile, "\tpopw %%es\n" );
+        fprintf( outfile, "\tmovl 24(%%ebx),%%ebp\n" );
+        fprintf( outfile, "\tmovl 28(%%ebx),%%eax\n" );
+        fprintf( outfile, "\tmovl 36(%%ebx),%%ecx\n" );
+        fprintf( outfile, "\tmovl 40(%%ebx),%%edx\n" );
+        fprintf( outfile, "\tmovl 44(%%ebx),%%esi\n" );
+        fprintf( outfile, "\tmovl 48(%%ebx),%%edi\n" );
     }
     else  /* not a register function */
     {
         int pos = 16;  /* first argument position */
 
         /* Make %bp point to the previous stackframe (built by CallFrom16) */
-        printf( "\tmovzwl %%sp,%%ebp\n" );
-        printf( "\taddw $16,%%bp\n" );
+        fprintf( outfile, "\tmovzwl %%sp,%%ebp\n" );
+        fprintf( outfile, "\taddw $16,%%bp\n" );
 
         while (*args)
         {
             switch(*args++)
             {
             case 'w': /* word */
-                printf( "\tpushw %d(%%ebx)\n", pos );
+                fprintf( outfile, "\tpushw %d(%%ebx)\n", pos );
                 break;
             case 'l': /* long */
-                printf( "\tpushl %d(%%ebx)\n", pos );
+                fprintf( outfile, "\tpushl %d(%%ebx)\n", pos );
                 break;
             }
             pos += 4;
@@ -1827,36 +1838,37 @@
 
     /* Push the return address */
 
-    printf( "\tpushl " PREFIX "CALLTO16_RetAddr_%s\n",
-            short_ret ? "word" : "long" );
+    fprintf( outfile, "\tpushl " PREFIX "CALLTO16_RetAddr_%s\n",
+             short_ret ? "word" : "long" );
 
     /* Push the called routine address */
 
-    printf( "\tpushl 12(%%ebx)\n" );
+    fprintf( outfile, "\tpushl 12(%%ebx)\n" );
 
     /* Get the 16-bit ds */
 
     if (reg_func)
     {
-        printf( "\tpushw 16(%%ebx)\n" );
-        printf( "\tmovl 32(%%ebx),%%ebx\n" ); /*Get ebx from the 32-bit stack*/
-        printf( "\tpopw %%ds\n" );
+        fprintf( outfile, "\tpushw 16(%%ebx)\n" );
+        /* Get ebx from the 32-bit stack */
+        fprintf( outfile, "\tmovl 32(%%ebx),%%ebx\n" );
+        fprintf( outfile, "\tpopw %%ds\n" );
     }
     else
     {
         /* Get previous ds from the 16-bit stack and */
         /* set ax equal to ds for window procedures. */
-        printf( "\tmovw -10(%%ebp),%%ax\n" );
+        fprintf( outfile, "\tmovw -10(%%ebp),%%ax\n" );
 #ifdef __svr4__
-        printf( "\tdata16\n");
+        fprintf( outfile, "\tdata16\n");
 #endif
-        printf( "\tmovw %%ax,%%ds\n" );
+        fprintf( outfile, "\tmovw %%ax,%%ds\n" );
     }
 
     /* Jump to the called routine */
 
-    printf( "\t.byte 0x66\n" );
-    printf( "\tlret\n" );
+    fprintf( outfile, "\t.byte 0x66\n" );
+    fprintf( outfile, "\tlret\n" );
 }
 
 
@@ -1865,61 +1877,61 @@
  *
  * Build the return code for 16-bit callbacks
  */
-static void BuildRet16Func()
+static void BuildRet16Func( FILE *outfile )
 {
-    printf( "\t.globl " PREFIX "CALLTO16_Ret_word\n" );
-    printf( "\t.globl " PREFIX "CALLTO16_Ret_long\n" );
+    fprintf( outfile, "\t.globl " PREFIX "CALLTO16_Ret_word\n" );
+    fprintf( outfile, "\t.globl " PREFIX "CALLTO16_Ret_long\n" );
 
     /* Put return value into eax */
 
-    printf( PREFIX "CALLTO16_Ret_long:\n" );
-    printf( "\tpushw %%dx\n" );
-    printf( "\tpushw %%ax\n" );
-    printf( "\tpopl %%eax\n" );
-    printf( PREFIX "CALLTO16_Ret_word:\n" );
+    fprintf( outfile, PREFIX "CALLTO16_Ret_long:\n" );
+    fprintf( outfile, "\tpushw %%dx\n" );
+    fprintf( outfile, "\tpushw %%ax\n" );
+    fprintf( outfile, "\tpopl %%eax\n" );
+    fprintf( outfile, PREFIX "CALLTO16_Ret_word:\n" );
 
     /* Restore 32-bit segment registers */
 
-    printf( "\tmovw $0x%04x,%%bx\n", WINE_DATA_SELECTOR );
+    fprintf( outfile, "\tmovw $0x%04x,%%bx\n", WINE_DATA_SELECTOR );
 #ifdef __svr4__
-    printf( "\tdata16\n");
+    fprintf( outfile, "\tdata16\n");
 #endif
-    printf( "\tmovw %%bx,%%ds\n" );
+    fprintf( outfile, "\tmovw %%bx,%%ds\n" );
 #ifdef __svr4__
-    printf( "\tdata16\n");
+    fprintf( outfile, "\tdata16\n");
 #endif
-    printf( "\tmovw %%bx,%%es\n" );
+    fprintf( outfile, "\tmovw %%bx,%%es\n" );
 #ifdef __svr4__
-    printf( "\tdata16\n");
+    fprintf( outfile, "\tdata16\n");
 #endif
-    printf( "\tmovw %%bx,%%ss\n" );
+    fprintf( outfile, "\tmovw %%bx,%%ss\n" );
 
     /* Restore the 32-bit stack */
 
-    printf( "\tmovl " PREFIX "IF1632_Saved32_esp,%%esp\n" );
-    printf( "\tpopl " PREFIX "IF1632_Saved32_esp\n" );
+    fprintf( outfile, "\tmovl " PREFIX "IF1632_Saved32_esp,%%esp\n" );
+    fprintf( outfile, "\tpopl " PREFIX "IF1632_Saved32_esp\n" );
 
     /* Restore the 32-bit registers */
 
-    printf( "\tpopl %%edi\n" );
-    printf( "\tpopl %%esi\n" );
-    printf( "\tpopl %%edx\n" );
-    printf( "\tpopl %%ecx\n" );
-    printf( "\tpopl %%ebx\n" );
+    fprintf( outfile, "\tpopl %%edi\n" );
+    fprintf( outfile, "\tpopl %%esi\n" );
+    fprintf( outfile, "\tpopl %%edx\n" );
+    fprintf( outfile, "\tpopl %%ecx\n" );
+    fprintf( outfile, "\tpopl %%ebx\n" );
 
     /* Return to caller */
 
-    printf( "\tpopl %%ebp\n" );
-    printf( "\tlret\n" );
+    fprintf( outfile, "\tpopl %%ebp\n" );
+    fprintf( outfile, "\tlret\n" );
 
     /* Declare the return address variables */
 
-    printf( "\t.data\n" );
-    printf( "\t.globl " PREFIX "CALLTO16_RetAddr_word\n" );
-    printf( "\t.globl " PREFIX "CALLTO16_RetAddr_long\n" );
-    printf( PREFIX "CALLTO16_RetAddr_word:\t.long 0\n" );
-    printf( PREFIX "CALLTO16_RetAddr_long:\t.long 0\n" );
-    printf( "\t.text\n" );
+    fprintf( outfile, "\t.data\n" );
+    fprintf( outfile, "\t.globl " PREFIX "CALLTO16_RetAddr_word\n" );
+    fprintf( outfile, "\t.globl " PREFIX "CALLTO16_RetAddr_long\n" );
+    fprintf( outfile, PREFIX "CALLTO16_RetAddr_word:\t.long 0\n" );
+    fprintf( outfile, PREFIX "CALLTO16_RetAddr_long:\t.long 0\n" );
+    fprintf( outfile, "\t.text\n" );
 }
 
 
@@ -1928,41 +1940,41 @@
  *
  * Build the context structure on the stack.
  */
-static void BuildContext32(void)
+static void BuildContext32( FILE *outfile )
 {
     /* Build the context structure */
 
-    printf( "\tpushfl\n" );
-    printf( "\tsubl $%d,%%esp\n", sizeof(CONTEXT) );
-    printf( "\tmovl %%eax,%d(%%esp)\n", CONTEXTOFFSET(Eax) );
-    printf( "\tmovl %%ebx,%d(%%esp)\n", CONTEXTOFFSET(Ebx) );
-    printf( "\tmovl %%ecx,%d(%%esp)\n", CONTEXTOFFSET(Ecx) );
-    printf( "\tmovl %%edx,%d(%%esp)\n", CONTEXTOFFSET(Edx) );
-    printf( "\tmovl %%esi,%d(%%esp)\n", CONTEXTOFFSET(Esi) );
-    printf( "\tmovl %%edi,%d(%%esp)\n", CONTEXTOFFSET(Edi) );
+    fprintf( outfile, "\tpushfl\n" );
+    fprintf( outfile, "\tsubl $%d,%%esp\n", sizeof(CONTEXT) );
+    fprintf( outfile, "\tmovl %%eax,%d(%%esp)\n", CONTEXTOFFSET(Eax) );
+    fprintf( outfile, "\tmovl %%ebx,%d(%%esp)\n", CONTEXTOFFSET(Ebx) );
+    fprintf( outfile, "\tmovl %%ecx,%d(%%esp)\n", CONTEXTOFFSET(Ecx) );
+    fprintf( outfile, "\tmovl %%edx,%d(%%esp)\n", CONTEXTOFFSET(Edx) );
+    fprintf( outfile, "\tmovl %%esi,%d(%%esp)\n", CONTEXTOFFSET(Esi) );
+    fprintf( outfile, "\tmovl %%edi,%d(%%esp)\n", CONTEXTOFFSET(Edi) );
 
-    printf( "\tmovl %d(%%esp),%%eax\n", sizeof(CONTEXT) );
-    printf( "\tmovl %%eax,%d(%%esp)\n", CONTEXTOFFSET(EFlags) );
+    fprintf( outfile, "\tmovl %d(%%esp),%%eax\n", sizeof(CONTEXT) );
+    fprintf( outfile, "\tmovl %%eax,%d(%%esp)\n", CONTEXTOFFSET(EFlags) );
 
-    printf( "\tmovl %%cs,%d(%%esp)\n", CONTEXTOFFSET(SegCs) );
-    printf( "\tmovl %%ds,%d(%%esp)\n", CONTEXTOFFSET(SegDs) );
-    printf( "\tmovl %%es,%d(%%esp)\n", CONTEXTOFFSET(SegEs) );
-    printf( "\tmovl %%fs,%d(%%esp)\n", CONTEXTOFFSET(SegFs) );
-    printf( "\tmovl %%gs,%d(%%esp)\n", CONTEXTOFFSET(SegGs) );
-    printf( "\tmovl %%ss,%d(%%esp)\n", CONTEXTOFFSET(SegSs) );
+    fprintf( outfile, "\tmovl %%cs,%d(%%esp)\n", CONTEXTOFFSET(SegCs) );
+    fprintf( outfile, "\tmovl %%ds,%d(%%esp)\n", CONTEXTOFFSET(SegDs) );
+    fprintf( outfile, "\tmovl %%es,%d(%%esp)\n", CONTEXTOFFSET(SegEs) );
+    fprintf( outfile, "\tmovl %%fs,%d(%%esp)\n", CONTEXTOFFSET(SegFs) );
+    fprintf( outfile, "\tmovl %%gs,%d(%%esp)\n", CONTEXTOFFSET(SegGs) );
+    fprintf( outfile, "\tmovl %%ss,%d(%%esp)\n", CONTEXTOFFSET(SegSs) );
 
-    printf( "\tfsave %d(%%esp)\n", CONTEXTOFFSET(FloatSave) );
+    fprintf( outfile, "\tfsave %d(%%esp)\n", CONTEXTOFFSET(FloatSave) );
 
-    printf( "\tmovl 4(%%ebp),%%eax\n" ); /* %eip at time of call */
-    printf( "\tmovl %%eax,%d(%%esp)\n", CONTEXTOFFSET(Eip) );
-    printf( "\tmovl 0(%%ebp),%%eax\n" ); /* %ebp at time of call */
-    printf( "\tmovl %%eax,%d(%%esp)\n", CONTEXTOFFSET(Ebp) );
-    printf( "\tleal 8(%%ebp),%%eax\n" ); /* %esp at time of call */
-    printf( "\tmovl %%eax,%d(%%esp)\n", CONTEXTOFFSET(Esp) );
+    fprintf( outfile, "\tmovl 4(%%ebp),%%eax\n" ); /* %eip at time of call */
+    fprintf( outfile, "\tmovl %%eax,%d(%%esp)\n", CONTEXTOFFSET(Eip) );
+    fprintf( outfile, "\tmovl 0(%%ebp),%%eax\n" ); /* %ebp at time of call */
+    fprintf( outfile, "\tmovl %%eax,%d(%%esp)\n", CONTEXTOFFSET(Ebp) );
+    fprintf( outfile, "\tleal 8(%%ebp),%%eax\n" ); /* %esp at time of call */
+    fprintf( outfile, "\tmovl %%eax,%d(%%esp)\n", CONTEXTOFFSET(Esp) );
 
     /* Push pointer to context */
 
-    printf( "\tpushl %%esp\n" );
+    fprintf( outfile, "\tpushl %%esp\n" );
 }
 
 
@@ -1971,40 +1983,40 @@
  *
  * Restore the registers from the context structure
  */
-static void RestoreContext32(void)
+static void RestoreContext32( FILE *outfile )
 {
     /* Restore the context structure */
 
-    printf( "\tleal %d(%%ebp),%%esp\n", -sizeof(CONTEXT)-12 );
-    printf( "\tfrstor %d(%%esp)\n", CONTEXTOFFSET(FloatSave) );
+    fprintf( outfile, "\tleal %d(%%ebp),%%esp\n", -sizeof(CONTEXT)-12 );
+    fprintf( outfile, "\tfrstor %d(%%esp)\n", CONTEXTOFFSET(FloatSave) );
 
-    printf( "\tmovl %d(%%esp),%%ebx\n", CONTEXTOFFSET(Ebx) );
-    printf( "\tmovl %d(%%esp),%%ecx\n", CONTEXTOFFSET(Ecx) );
-    printf( "\tmovl %d(%%esp),%%edx\n", CONTEXTOFFSET(Edx) );
-    printf( "\tmovl %d(%%esp),%%esi\n", CONTEXTOFFSET(Esi) );
-    printf( "\tmovl %d(%%esp),%%edi\n", CONTEXTOFFSET(Edi) );
+    fprintf( outfile, "\tmovl %d(%%esp),%%ebx\n", CONTEXTOFFSET(Ebx) );
+    fprintf( outfile, "\tmovl %d(%%esp),%%ecx\n", CONTEXTOFFSET(Ecx) );
+    fprintf( outfile, "\tmovl %d(%%esp),%%edx\n", CONTEXTOFFSET(Edx) );
+    fprintf( outfile, "\tmovl %d(%%esp),%%esi\n", CONTEXTOFFSET(Esi) );
+    fprintf( outfile, "\tmovl %d(%%esp),%%edi\n", CONTEXTOFFSET(Edi) );
 
-    printf( "\tmovl %d(%%esp),%%eax\n", CONTEXTOFFSET(EFlags) );
-    printf( "\tmovl %%eax,%d(%%esp)\n", sizeof(CONTEXT) );
+    fprintf( outfile, "\tmovl %d(%%esp),%%eax\n", CONTEXTOFFSET(EFlags) );
+    fprintf( outfile, "\tmovl %%eax,%d(%%esp)\n", sizeof(CONTEXT) );
 
-/*    printf( "\tmovl %d(%%esp),%%cs\n", CONTEXTOFFSET(SegCs) ); */
-    printf( "\tmovl %d(%%esp),%%ds\n", CONTEXTOFFSET(SegDs) );
-    printf( "\tmovl %d(%%esp),%%es\n", CONTEXTOFFSET(SegEs) );
-    printf( "\tmovl %d(%%esp),%%fs\n", CONTEXTOFFSET(SegFs) );
-    printf( "\tmovl %d(%%esp),%%gs\n", CONTEXTOFFSET(SegGs) );
+/*    fprintf( outfile, "\tmovl %d(%%esp),%%cs\n", CONTEXTOFFSET(SegCs) ); */
+    fprintf( outfile, "\tmovl %d(%%esp),%%ds\n", CONTEXTOFFSET(SegDs) );
+    fprintf( outfile, "\tmovl %d(%%esp),%%es\n", CONTEXTOFFSET(SegEs) );
+    fprintf( outfile, "\tmovl %d(%%esp),%%fs\n", CONTEXTOFFSET(SegFs) );
+    fprintf( outfile, "\tmovl %d(%%esp),%%gs\n", CONTEXTOFFSET(SegGs) );
 
-    printf( "\tmovl %d(%%esp),%%eax\n", CONTEXTOFFSET(Eip) );
-    printf( "\tmovl %%eax,4(%%ebp)\n" ); /* %eip at time of call */
-    printf( "\tmovl %d(%%esp),%%eax\n", CONTEXTOFFSET(Ebp) );
-    printf( "\tmovl %%eax,0(%%ebp)\n" ); /* %ebp at time of call */
+    fprintf( outfile, "\tmovl %d(%%esp),%%eax\n", CONTEXTOFFSET(Eip) );
+    fprintf( outfile, "\tmovl %%eax,4(%%ebp)\n" ); /* %eip at time of call */
+    fprintf( outfile, "\tmovl %d(%%esp),%%eax\n", CONTEXTOFFSET(Ebp) );
+    fprintf( outfile, "\tmovl %%eax,0(%%ebp)\n" ); /* %ebp at time of call */
 
-/*    printf( "\tmovl %d(%%esp),%%ss\n", CONTEXTOFFSET(SegSs) ); */
-/*    printf( "\tmovl %d(%%esp),%%eax\n", CONTEXTOFFSET(Esp) ); */
+/*    fprintf( outfile, "\tmovl %d(%%esp),%%ss\n", CONTEXTOFFSET(SegSs) ); */
+/*    fprintf( outfile, "\tmovl %d(%%esp),%%eax\n", CONTEXTOFFSET(Esp) ); */
 
-    printf( "\tmovl %d(%%esp),%%eax\n", CONTEXTOFFSET(Eax) );
+    fprintf( outfile, "\tmovl %d(%%esp),%%eax\n", CONTEXTOFFSET(Eax) );
 
-    printf( "\taddl $%d,%%esp\n", sizeof(CONTEXT) );
-    printf( "\tpopfl\n" );
+    fprintf( outfile, "\taddl $%d,%%esp\n", sizeof(CONTEXT) );
+    fprintf( outfile, "\tpopfl\n" );
 }
 
 
@@ -2023,7 +2035,7 @@
  * (ebp-4)   entry point
  * (ebp-8)   relay addr
  */
-static void BuildCallFrom32Func( const char *profile )
+static void BuildCallFrom32Func( FILE *outfile, const char *profile )
 {
     int args, stdcall, reg_func;
 
@@ -2045,76 +2057,74 @@
     }
     else
     {
-        fprintf( stderr, "Invalid function profile '%s'\n", profile );
+        fprintf( stderr, "Invalid function profile '%s', ignored\n", profile );
         return;
     }
 
     /* Function header */
 
-    printf( "/**********\n" );
-    printf( " * " PREFIX "CallFrom32_%s\n", profile );
-    printf( " **********/\n" );
-    printf( "\t.align 4\n" );
-    printf( "\t.globl " PREFIX "CallFrom32_%s\n\n", profile );
-    printf( PREFIX "CallFrom32_%s:\n", profile );
+    fprintf( outfile, "\n\t.align 4\n" );
+    fprintf( outfile, "\t.globl " PREFIX "CallFrom32_%s\n", profile );
+    fprintf( outfile, PREFIX "CallFrom32_%s:\n", profile );
 
     /* Entry code */
 
-    printf( "\tleal 8(%%esp),%%ebp\n" );
+    fprintf( outfile, "\tleal 8(%%esp),%%ebp\n" );
 
     /* Transfer the arguments */
 
-    if (reg_func) BuildContext32();
+    if (reg_func) BuildContext32( outfile );
 
     if (args)
     {
         int i;
-        for (i = args; i > 0; i--) printf( "\tpushl %d(%%ebp)\n", 4 * i + 4 );
+        for (i = args; i > 0; i--)
+            fprintf( outfile, "\tpushl %d(%%ebp)\n", 4 * i + 4 );
     }
     else if (!reg_func)
     {
         /* Push the address of the arguments. The called function will */
         /* ignore this if it really takes no arguments. */
-        printf( "\tleal 8(%%ebp),%%eax\n" );
-        printf( "\tpushl %%eax\n" );
+        fprintf( outfile, "\tleal 8(%%ebp),%%eax\n" );
+        fprintf( outfile, "\tpushl %%eax\n" );
     }
 
     /* Print the debugging info */
 
     if (debugging)
     {
-        printf( "\tpushl $%d\n", reg_func ? -1 : args );  /* Nb args */
-        printf( "\tpushl %%ebp\n" );
-        printf( "\tcall " PREFIX "RELAY_DebugCallFrom32\n" );
-        printf( "\tadd $8, %%esp\n" );
+        fprintf( outfile, "\tpushl $%d\n", reg_func ? -1 : args); /* Nb args */
+        fprintf( outfile, "\tpushl %%ebp\n" );
+        fprintf( outfile, "\tcall " PREFIX "RELAY_DebugCallFrom32\n" );
+        fprintf( outfile, "\tadd $8, %%esp\n" );
     }
 
     /* Call the function */
 
-    printf( "\tcall -4(%%ebp)\n" );
+    fprintf( outfile, "\tcall -4(%%ebp)\n" );
 
     /* Print the debugging info */
 
     if (debugging)
     {
-        printf( "\tpushl %%eax\n" );
-        printf( "\tpushl $%d\n", reg_func ? -1 : args );  /* Nb args */
-        printf( "\tpushl %%ebp\n" );
-        printf( "\tcall " PREFIX "RELAY_DebugCallFrom32Ret\n" );
-        printf( "\tpopl %%eax\n" );
-        printf( "\tpopl %%eax\n" );
-        printf( "\tpopl %%eax\n" );
+        fprintf( outfile, "\tpushl %%eax\n" );
+        fprintf( outfile, "\tpushl $%d\n", reg_func ? -1 : args); /* Nb args */
+        fprintf( outfile, "\tpushl %%ebp\n" );
+        fprintf( outfile, "\tcall " PREFIX "RELAY_DebugCallFrom32Ret\n" );
+        fprintf( outfile, "\tpopl %%eax\n" );
+        fprintf( outfile, "\tpopl %%eax\n" );
+        fprintf( outfile, "\tpopl %%eax\n" );
     }
 
-    if (reg_func) RestoreContext32();
+    if (reg_func) RestoreContext32( outfile );
 
-    printf( "\tmovl %%ebp,%%esp\n" );
-    printf( "\tpopl %%ebp\n" );
+    fprintf( outfile, "\tmovl %%ebp,%%esp\n" );
+    fprintf( outfile, "\tpopl %%ebp\n" );
 
     /* Return, removing arguments */
 
-    if (args && stdcall) printf( "\tret $%d\n", args * 4 );
-    else printf( "\tret\n" );
+    if (args && stdcall) fprintf( outfile, "\tret $%d\n", args * 4 );
+    else fprintf( outfile, "\tret\n" );
 }
 
 
@@ -2134,144 +2144,234 @@
  * Prototype for the CallTo32 functions:
  *   extern LONG CallTo32_nn( FARPROC32 func, args... );
  */
-static void BuildCallTo32Func( int args )
+static void BuildCallTo32Func( FILE *outfile, int args )
 {
     /* Function header */
 
-    printf( "/**********\n" );
-    printf( " * " PREFIX "CallTo32_%d\n", args );
-    printf( " **********/\n" );
-    printf( "\t.align 4\n" );
-    printf( "\t.globl " PREFIX "CallTo32_%d\n\n", args );
-    printf( PREFIX "CallTo32_%d:\n", args );
+    fprintf( outfile, "\n\t.align 4\n" );
+    fprintf( outfile, "\t.globl " PREFIX "CallTo32_%d\n", args );
+    fprintf( outfile, PREFIX "CallTo32_%d:\n", args );
 
     /* Entry code */
 
-    printf( "\tpushl %%ebp\n" );
-    printf( "\tmovl %%esp,%%ebp\n" );
+    fprintf( outfile, "\tpushl %%ebp\n" );
+    fprintf( outfile, "\tmovl %%esp,%%ebp\n" );
 
     /* Transfer arguments */
 
     if (args)
     {
         int i;
-        for (i = args; i > 0; i--) printf( "\tpushl %d(%%ebp)\n", 4 * i + 8 );
+        for (i = args; i > 0; i--)
+            fprintf( outfile, "\tpushl %d(%%ebp)\n", 4 * i + 8 );
     }
 
     /* Print the debugging output */
 
     if (debugging)
     {
-        printf( "\tpushl $%d\n", args );
-        printf( "\tpushl 8(%%ebp)\n" );
-        printf( "\tcall " PREFIX "RELAY_DebugCallTo32\n" );
-        printf( "\taddl $8,%%esp\n" );
+        fprintf( outfile, "\tpushl $%d\n", args );
+        fprintf( outfile, "\tpushl 8(%%ebp)\n" );
+        fprintf( outfile, "\tcall " PREFIX "RELAY_DebugCallTo32\n" );
+        fprintf( outfile, "\taddl $8,%%esp\n" );
     }
 
     /* Call the function */
 
-    printf( "\tcall 8(%%ebp)\n" );
+    fprintf( outfile, "\tcall 8(%%ebp)\n" );
 
     /* Return to Wine */
 
-    printf( "\tmovl %%ebp,%%esp\n" );
-    printf( "\tpopl %%ebp\n" );
-    printf( "\tret\n" );
+    fprintf( outfile, "\tmovl %%ebp,%%esp\n" );
+    fprintf( outfile, "\tpopl %%ebp\n" );
+    fprintf( outfile, "\tret\n" );
 }
 
 
+/*******************************************************************
+ *         BuildSpec
+ *
+ * Build the spec files
+ */
+static int BuildSpec( FILE *outfile, int argc, char *argv[] )
+{
+    int i;
+    for (i = 2; i < argc; i++)
+        if (BuildSpecFile( outfile, argv[i] ) < 0) return -1;
+    return 0;
+}
+
+
+/*******************************************************************
+ *         BuildCallFrom16
+ *
+ * Build the 16-bit-to-Wine callbacks
+ */
+static int BuildCallFrom16( FILE *outfile, int argc, char *argv[] )
+{
+    int i;
+
+    /* File header */
+
+    fprintf( outfile, "/* File generated automatically. Do not edit! */\n\n" );
+    fprintf( outfile, "\t.text\n" );
+
+    /* Build the 32-bit large stack callback */
+
+    BuildCall32LargeStack( outfile );
+
+    /* Build the callback functions */
+
+    for (i = 2; i < argc; i++) BuildCallFrom16Func( outfile, argv[i] );
+
+    /* Output the argument debugging strings */
+
+    if (debugging)
+    {
+        fprintf( outfile, "/* Argument strings */\n" );
+        for (i = 2; i < argc; i++)
+        {
+            fprintf( outfile, "Profile_%s:\n", argv[i] );
+            fprintf( outfile, "\t.ascii \"%s\\0\"\n", argv[i] + 5 );
+        }
+    }
+    return 0;
+}
+
+
+/*******************************************************************
+ *         BuildCallTo16
+ *
+ * Build the Wine-to-16-bit callbacks
+ */
+static int BuildCallTo16( FILE *outfile, int argc, char *argv[] )
+{
+    int i;
+
+    /* File header */
+
+    fprintf( outfile, "/* File generated automatically. Do not edit! */\n\n" );
+    fprintf( outfile, "\t.text\n" );
+    fprintf( outfile, "\t.globl " PREFIX "CALLTO16_Start\n" );
+    fprintf( outfile, PREFIX "CALLTO16_Start:\n" );
+
+    /* Build the callback functions */
+
+    for (i = 2; i < argc; i++) BuildCallTo16Func( outfile, argv[i] );
+
+    /* Output the 16-bit return code */
+
+    BuildRet16Func( outfile );
+
+    fprintf( outfile, "\t.globl " PREFIX "CALLTO16_End\n" );
+    fprintf( outfile, PREFIX "CALLTO16_End:\n" );
+    return 0;
+}
+
+
+/*******************************************************************
+ *         BuildCallFrom32
+ *
+ * Build the 32-bit-to-Wine callbacks
+ */
+static int BuildCallFrom32( FILE *outfile, int argc, char *argv[] )
+{
+    int i;
+
+    /* File header */
+
+    fprintf( outfile, "/* File generated automatically. Do not edit! */\n\n" );
+    fprintf( outfile, "\t.text\n" );
+
+    /* Build the callback functions */
+
+    for (i = 2; i < argc; i++) BuildCallFrom32Func( outfile, argv[i] );
+    return 0;
+}
+
+
+/*******************************************************************
+ *         BuildCallTo32
+ *
+ * Build the Wine-to-32-bit callbacks
+ */
+static int BuildCallTo32( FILE *outfile, int argc, char *argv[] )
+{
+    int i;
+
+    /* File header */
+
+    fprintf( outfile, "/* File generated automatically. Do not edit! */\n\n" );
+    fprintf( outfile, "\t.text\n" );
+
+    /* Build the callback functions */
+
+    for (i = 2; i < argc; i++) BuildCallTo32Func( outfile, atoi(argv[i]) );
+    return 0;
+}
+
+
+/*******************************************************************
+ *         usage
+ */
 static void usage(void)
 {
-    fprintf(stderr, "usage: build -spec SPECNAMES\n"
-                    "       build -callfrom16 FUNCTION_PROFILES\n"
-                    "       build -callto16 FUNCTION_PROFILES\n"
-                    "       build -callfrom32 FUNCTION_PROFILES\n"
-                    "       build -callto32 FUNCTION_PROFILES\n" );
+    fprintf(stderr, "usage: build [-o outfile] -spec SPECNAMES\n"
+                    "       build [-o outfile] -callfrom16 FUNCTION_PROFILES\n"
+                    "       build [-o outfile] -callto16 FUNCTION_PROFILES\n"
+                    "       build [-o outfile] -callfrom32 FUNCTION_PROFILES\n"
+                    "       build [-o outfile] -callto32 FUNCTION_PROFILES\n");
     exit(1);
 }
 
 
+/*******************************************************************
+ *         main
+ */
 int main(int argc, char **argv)
 {
-    int i;
+    char *outname = NULL;
+    FILE *outfile = stdout;
+    int res = -1;
 
     if (argc <= 2) usage();
 
-    if (!strcmp( argv[1], "-spec" ))
+    if (!strcmp( argv[1], "-o" ))
     {
-        for (i = 2; i < argc; i++) BuildSpecFiles( argv[i] );
-    }
-    else if (!strcmp( argv[1], "-callfrom16" ))  /* 16-bit-to-Wine callbacks */
-    {
-        /* File header */
-
-        printf( "/* File generated automatically. Do not edit! */\n\n" );
-        printf( "\t.text\n" );
-
-        /* Build the 32-bit large stack callback */
-
-        BuildCall32LargeStack();
-
-        /* Build the callback functions */
-
-        for (i = 2; i < argc; i++) BuildCallFrom16Func( argv[i] );
-
-        /* Output the argument debugging strings */
-
-        if (debugging)
+        outname = argv[2];
+        argv += 2;
+        argc -= 2;
+        if (argc <= 2) usage();
+        if (!(outfile = fopen( outname, "w" )))
         {
-            printf( "/* Argument strings */\n" );
-            for (i = 2; i < argc; i++)
-            {
-                printf( "Profile_%s:\n", argv[i] );
-                printf( "\t.ascii \"%s\\0\"\n", argv[i] + 5 );
-            }
+            fprintf( stderr, "Unable to create output file '%s'\n", outname );
+            exit(1);
         }
     }
-    else if (!strcmp( argv[1], "-callto16" ))  /* Wine-to-16-bit callbacks */
+
+    if (!strcmp( argv[1], "-spec" ))
+        res = BuildSpec( outfile, argc, argv );
+    else if (!strcmp( argv[1], "-callfrom16" ))
+        res = BuildCallFrom16( outfile, argc, argv );
+    else if (!strcmp( argv[1], "-callto16" ))
+        res = BuildCallTo16( outfile, argc, argv );
+    else if (!strcmp( argv[1], "-callfrom32" ))
+        res = BuildCallFrom32( outfile, argc, argv );
+    else if (!strcmp( argv[1], "-callto32" ))
+        res = BuildCallTo32( outfile, argc, argv );
+    else
     {
-        /* File header */
-
-        printf( "/* File generated automatically. Do not edit! */\n\n" );
-        printf( "\t.text\n" );
-        printf( "\t.globl " PREFIX "CALLTO16_Start\n" );
-        printf( PREFIX "CALLTO16_Start:\n" );
-
-        /* Build the callback functions */
-
-        for (i = 2; i < argc; i++) BuildCallTo16Func( argv[i] );
-
-        /* Output the 16-bit return code */
-
-        BuildRet16Func();
-
-        printf( "\t.globl " PREFIX "CALLTO16_End\n" );
-        printf( PREFIX "CALLTO16_End:\n" );
+        fclose( outfile );
+        unlink( outname );
+        usage();
     }
-    else if (!strcmp( argv[1], "-callfrom32" ))  /* 32-bit-to-Wine callbacks */
+
+    fclose( outfile );
+    if (res < 0)
     {
-        /* File header */
-
-        printf( "/* File generated automatically. Do not edit! */\n\n" );
-        printf( "\t.text\n" );
-
-        /* Build the callback functions */
-
-        for (i = 2; i < argc; i++) BuildCallFrom32Func( argv[i] );
+        unlink( outname );
+        return 1;
     }
-    else if (!strcmp( argv[1], "-callto32" ))  /* Wine-to-32-bit callbacks */
-    {
-        /* File header */
-
-        printf( "/* File generated automatically. Do not edit! */\n\n" );
-        printf( "\t.text\n" );
-
-        /* Build the callback functions */
-
-        for (i = 2; i < argc; i++) BuildCallTo32Func( atoi(argv[i]) );
-    }
-    else usage();
-
     return 0;
 }
 
diff --git a/tools/fnt2bdf.c b/tools/fnt2bdf.c
new file mode 100644
index 0000000..f391b79
--- /dev/null
+++ b/tools/fnt2bdf.c
@@ -0,0 +1,584 @@
+/************************************************
+ *
+ * Extract fonts from .fnt or Windows DLL files
+ * and convert them to the .bdf format.
+ *
+ * Copyright 1994-1996 Kevin Carothers and Alex Korobka
+ *
+ */
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include "windows.h"
+#include "fnt2bdf.h"
+#include "neexe.h"
+#include "module.h"
+
+#define MAP_BEG 118
+
+extern char*   g_lpstrFileName;
+extern char*   g_lpstrCharSet;
+
+#define FILE_ERROR	0
+#define FILE_DLL	1
+#define FILE_FNT	2
+
+/* global options */
+
+char*	g_lpstrFileName = NULL;
+char*	g_lpstrCharSet = NULL;
+char*   g_lpstrInputFile = NULL;
+
+static char*	errorDLLRead = "Unable to read Windows DLL.\n";
+static char*    errorFNTRead = "Unable to read .FNT file.\n";
+static char*    errorOpenFile = "Unable to open file.\n";
+static char*    errorMemory = "Memory allocation error.\n";
+static char*    errorFile = "Corrupt or invalid file.\n";
+static char*    errorFontData = "Unable to parse font data: Error ";
+static char*    errorEmpty = "No fonts found.\n";
+
+/* info */
+
+void usage()
+{
+    printf("Usage: font2bdf [-c charset] [-o basename] [input file]\n");
+    printf("  -c charset\tuse this charset name for OEM_CHARSET fonts\n");
+    printf("  -f basename\tbasic output filename\n");
+    printf("  input file\tMSWindows .fon, .fnt, .dll, or .exe file.\n");
+    printf("\nExample:\n  fnt2bdf -c winsys vgasys.fnt\n\n");
+    exit(-1);
+}
+
+/* convert big-endian value to the local format */
+
+int return_data_value(enum data_types dtype, void * pChr)
+{
+int   ret_val = 0;
+
+    switch(dtype) {
+        case (dfChar): 
+            ret_val = (int) *(unsigned char *)pChr;
+            break;
+            
+        case(dfShort): 
+            ret_val = *(unsigned char *)pChr;
+            ret_val += (*((unsigned char *)pChr + 1) << 8);
+            break;
+            
+        case(dfLong): {
+            int  i;
+
+            for(i=3; i >= 0; i--)  {
+                ret_val += *((unsigned char *)pChr + i) << (8*i);
+                }
+            break;
+            }
+	case(dfString):
+        } 
+    return ret_val;
+}
+
+int make_bdf_filename(char* name, fnt_fontS* cpe_font_struct, unsigned char* file_buffer)
+{
+int     l_nameoffset = return_data_value(dfLong, cpe_font_struct->hdr.dfFace);
+char*   lpChar;
+
+  if( !g_lpstrFileName )
+  {
+    if( !l_nameoffset || 
+         l_nameoffset > return_data_value(dfLong, cpe_font_struct->hdr.dfSize) + 1 )
+         return ERROR_DATA;
+    lpChar =  (char*)(file_buffer + l_nameoffset);
+  }
+    else lpChar = g_lpstrFileName;
+
+  strcpy( name, lpChar );
+
+  while( (lpChar = strchr( name, ' ')) ) 
+         *lpChar = '-';
+
+  /* construct a filename from the font typeface, slant, weight, and size */
+
+  if( cpe_font_struct->hdr.dfItalic[0] ) strcat(name, "_i" );
+  else strcat(name, "_r" );
+
+  lpChar = name + strlen( name );
+  sprintf(lpChar, "%d-%d.bdf", return_data_value(dfShort, cpe_font_struct->hdr.dfWeight),
+                               return_data_value(dfShort, cpe_font_struct->hdr.dfPoints) );
+  return 0;
+}
+
+/* parse FONT resource and write .bdf file */
+
+int parse_fnt_data(unsigned char* file_buffer, int length)
+{
+  fnt_fontS	cpe_font_struct; 
+  int     	ic=0, t;
+
+  bcopy(file_buffer, (char *) &cpe_font_struct.hdr, sizeof(fnt_hdrS));
+
+  /* check font header */
+
+  t = return_data_value(dfShort, cpe_font_struct.hdr.dfVersion);
+  if( t != 0x300 && t != 0x200) return ERROR_VERSION;
+
+  t = return_data_value(dfLong, cpe_font_struct.hdr.dfSize);
+  if( t > length ) return ERROR_SIZE;
+  else
+  {    	
+    /* set up the charWidth/charOffset  structure pairs (dfCharTable)... */
+
+    int l_fchar = return_data_value(dfChar, cpe_font_struct.hdr.dfFirstChar),
+        l_lchar = return_data_value(dfChar, cpe_font_struct.hdr.dfLastChar); 
+    int l_len   = l_lchar-l_fchar, l_ptr = MAP_BEG;
+
+    /* malloc size = (# chars) * sizeof(WinCharS) */
+
+    if((cpe_font_struct.dfCharTable = (WinCharS *) calloc(sizeof(WinCharS), l_len)) == NULL) 
+	return ERROR_MEMORY;
+
+    /* NOW, convert them all to UNIX (lton) notation... */
+
+    for(ic=0; ic < l_len; ic++) {
+   	cpe_font_struct.dfCharTable[ic].charWidth = return_data_value(dfShort, &file_buffer[l_ptr]);
+	l_ptr += 2;	/* bump by sizeof(short) */
+
+
+	if( return_data_value(dfShort, cpe_font_struct.hdr.dfVersion) == 0x200) {
+	    cpe_font_struct.dfCharTable[ic].charOffset = 
+			return_data_value(dfShort, &file_buffer[l_ptr]);
+	    l_ptr += 2;	/* bump by sizeof(long) */
+	    }
+	else { 	/*  Windows Version 3.0 type font */
+	    cpe_font_struct.dfCharTable[ic].charOffset = 
+			return_data_value(dfLong, &file_buffer[l_ptr]);
+	    l_ptr += 4;	/* bump by sizeof(long) */
+	    }
+	}
+    t = dump_bdf(&cpe_font_struct, file_buffer);
+    free( cpe_font_struct.dfCharTable );
+  }
+  return t;
+}
+
+int dump_bdf( fnt_fontS* cpe_font_struct, unsigned char* file_buffer)
+{
+  FILE*   fp;
+  int	  ic;
+  int     l_fchar = return_data_value(dfChar, cpe_font_struct->hdr.dfFirstChar), 
+          l_lchar = return_data_value(dfChar, cpe_font_struct->hdr.dfLastChar); 
+
+  int     l_len = l_lchar-l_fchar,
+          l_hgt = return_data_value(dfChar, cpe_font_struct->hdr.dfPixHeight); 
+  int	  l_ascent = return_data_value(dfShort, cpe_font_struct->hdr.dfAscent);
+  char    l_filename[256];
+
+    if( (ic = make_bdf_filename(l_filename, cpe_font_struct, file_buffer)) )
+	return ic;
+
+    if((fp = fopen(l_filename, "w")) == (FILE *) 0)   
+    {
+      fprintf(stderr, "Couldn't open \"%s\" for output.\n", l_filename);
+      return ERROR_FILE;
+    }
+
+    dump_bdf_hdr(fp, cpe_font_struct, file_buffer);
+
+    /* NOW, convert all chars to UNIX (lton) notation... */
+
+    for(ic=0; ic < l_len; ic++) {
+	int rowidx, l_span,		/* how many char-cols wide is char? */
+	    l_idx = cpe_font_struct->dfCharTable[ic].charOffset;
+
+	l_span = (int) (cpe_font_struct->dfCharTable[ic].charWidth-1)/8; 
+
+	fprintf(fp, "STARTCHAR %d  \n", ic);
+	fprintf(fp, "ENCODING %d\n",   l_fchar);
+	fprintf(fp, "SWIDTH    %d    %d \n", 
+		cpe_font_struct->dfCharTable[ic].charWidth*1000, 
+		0);
+
+	fprintf(fp, "DWIDTH    %d    %d \n", 
+		cpe_font_struct->dfCharTable[ic].charWidth, 0);
+
+	fprintf(fp, "BBX  %d  %d  %d   %d\n",
+		cpe_font_struct->dfCharTable[ic].charWidth, l_hgt, 0, 
+		l_ascent - l_hgt);
+
+	fprintf(fp, "BITMAP\n");
+	for(rowidx=0; rowidx < l_hgt; rowidx++) {
+	    switch(l_span) {
+		case(0):	/* 1-7 pixels wide font */
+		    {
+		    fprintf(fp, "%02X\n", (int) file_buffer[l_idx+rowidx]);
+		    break;
+		    }
+		
+		case(1):	/* 8-15 pixels wide font */
+		    {
+		    fprintf(fp, "%02X%02X", 
+			(int) file_buffer[l_idx+rowidx], file_buffer[l_idx+l_hgt+rowidx]);
+		    fprintf(fp, "\n");
+		    break;
+		    }
+
+		case(2):	/* 16-23 pixels wide font */
+		    {
+		    fprintf(fp, "%02X%02X%02X", 
+			file_buffer[l_idx+rowidx],
+		        file_buffer[l_idx+l_hgt+rowidx],
+		        file_buffer[l_idx+(2*l_hgt)+rowidx]);
+		    fprintf(fp, "\n");
+		    break;
+		    }
+
+		case(3):	/* 24-31 pixels wide font */
+		    {
+		    fprintf(fp, "%02X%02X%02X%02X", 
+			file_buffer[l_idx+rowidx],
+			file_buffer[l_idx+l_hgt+rowidx],
+			file_buffer[l_idx+(2*l_hgt)+rowidx],
+			file_buffer[l_idx+(3*l_hgt)+rowidx]);
+		    fprintf(fp, "\n");
+		    break;
+		    }
+		case(4):	/* 32-39 */
+		    {
+		    fprintf(fp, "%02X%02X%02X%02X%02X",
+			file_buffer[l_idx+rowidx],
+			file_buffer[l_idx+l_hgt+rowidx],
+                        file_buffer[l_idx+(2*l_hgt)+rowidx],
+                        file_buffer[l_idx+(3*l_hgt)+rowidx],
+			file_buffer[l_idx+(4*l_hgt)+rowidx]);
+		    fprintf(fp, "\n");
+                    break;
+                    }
+		default:
+		    fclose(fp);
+		    unlink(l_filename);
+		    return ERROR_DATA;
+		}
+	    }
+	fprintf(fp, "ENDCHAR\n");
+
+	l_fchar++;	/* Go to next one */
+	}
+fprintf(fp, "ENDFONT\n");
+fclose(fp);
+return 0;
+}
+
+
+int dump_bdf_hdr(FILE* fs, fnt_fontS* cpe_font_struct, unsigned char* file_buffer)
+{
+int     l_fchar = return_data_value(dfChar, cpe_font_struct->hdr.dfFirstChar), 
+        l_lchar = return_data_value(dfChar, cpe_font_struct->hdr.dfLastChar);
+int     l_len = l_lchar - l_fchar;
+int     l_nameoffset = return_data_value(dfLong, cpe_font_struct->hdr.dfFace);
+int 	l_cellheight = return_data_value(dfShort, cpe_font_struct->hdr.dfPixHeight);
+int     l_ascent = return_data_value(dfShort, cpe_font_struct->hdr.dfAscent);
+
+    fprintf(fs, "STARTFONT   2.1\n");
+
+    /* Compose font name */
+
+    if( l_nameoffset && 
+	l_nameoffset < return_data_value(dfLong, cpe_font_struct->hdr.dfSize) )
+    {
+      int     dpi, point_size;
+      char*   lpFace = (char*)(file_buffer + l_nameoffset), *lpChar;
+      short   tmWeight = return_data_value(dfShort, cpe_font_struct->hdr.dfWeight);
+
+      while((lpChar = strchr(lpFace, '-')) ) 
+	    *lpChar = ' ';
+
+      fprintf(fs, "FONT -windows-%s-", lpFace );
+
+      if( tmWeight == 0 )			/* weight */
+	  fputs("medium-", fs);
+      else if( tmWeight <= FW_LIGHT )
+	  fputs("light-", fs);
+      else if( tmWeight <= FW_MEDIUM )
+	  fputs("medium-", fs);
+      else if( tmWeight <= FW_DEMIBOLD )
+	  fputs("demibold-", fs);
+      else if( tmWeight <= FW_BOLD )
+	  fputs("bold-", fs);
+      else fputs("black-", fs);
+
+      if( cpe_font_struct->hdr.dfItalic[0] )	/* slant */
+	  fputs("i-", fs);
+      else fputs("r-", fs);
+
+      /* style */
+
+      if( (cpe_font_struct->hdr.dfPitchAndFamily[0] & 0xF0) == FF_SWISS )
+	  fputs("normal-sans-", fs);
+      else fputs("normal--", fs);	/* still can be -sans */
+
+      /* y extents */
+
+      point_size = 10 * return_data_value(dfShort, cpe_font_struct->hdr.dfPoints );
+      dpi = (l_cellheight * 720) / point_size;
+
+      fprintf(fs, "%d-%d-%d-%d-", l_cellheight, 10*l_cellheight, 72, 72);
+						/* point_size, dpi, dpi); */
+
+      /* spacing */
+
+      if( return_data_value(dfShort, cpe_font_struct->hdr.dfPixWidth) ) fputs("c-", fs);
+      else fputs("m-", fs);
+	
+      /* average width */
+
+      fprintf( fs, "%d-", 10 * return_data_value(dfShort, cpe_font_struct->hdr.dfAvgWidth) );
+
+      /* charset */
+
+      switch( cpe_font_struct->hdr.dfCharSet[0] )
+      {
+	case ANSI_CHARSET: fputs("ansi-0\n", fs); break;
+	default:
+	case DEFAULT_CHARSET: fputs("iso8859-1\n", fs); break;
+	case SYMBOL_CHARSET: fputs("misc-fontspecific\n", fs); break;
+	case SHIFTJIS_CHARSET: fputs("jisx0208.1983-0\n", fs); break;
+	case OEM_CHARSET: 
+		if( !g_lpstrCharSet ) 
+		{ fputs("Undefined OEM charset, use -c option.\n", stderr); 
+		  return ERROR_DATA; }
+	        fprintf(fs, "%s\n", g_lpstrCharSet);
+      }
+    }
+    else return ERROR_DATA;
+
+    fprintf(fs, "SIZE  %d  %d   %d\n",  
+	l_cellheight,
+	return_data_value(dfShort, cpe_font_struct->hdr.dfHorizRes),
+	return_data_value(dfShort, cpe_font_struct->hdr.dfVertRes));   /* dfVertRes[2] */
+
+    fprintf(fs, "FONTBOUNDINGBOX %d  %d  %d  %d\n",
+	return_data_value(dfShort, cpe_font_struct->hdr.dfMaxWidth),
+        return_data_value(dfChar, cpe_font_struct->hdr.dfPixHeight),
+   	0, l_ascent - l_cellheight );
+
+    fprintf(fs, "STARTPROPERTIES  4\n");
+
+    fprintf(fs, "FONT_ASCENT %d\n", l_ascent );                       /*  dfAscent[2] */
+    fprintf(fs, "FONT_DESCENT %d\n", l_cellheight - l_ascent );
+    fprintf(fs, "CAP_HEIGHT %d\n", l_ascent -
+                                   return_data_value(dfShort, cpe_font_struct->hdr.dfInternalLeading));
+    fprintf(fs, "DEFAULT_CHAR %d\n", return_data_value(dfShort, cpe_font_struct->hdr.dfDefaultChar));
+
+    fprintf(fs, "ENDPROPERTIES\n");
+
+    fprintf(fs, "CHARS  %d\n",  l_len);
+    return 0;
+}
+
+
+
+void parse_options(int argc, char **argv)
+{
+  int i;
+
+  switch( argc )
+  {
+    case 2:
+	 g_lpstrInputFile = argv[1];
+	 break;
+
+    case 3:
+    case 4:
+    case 5:
+    case 6:
+	 for( i = 1; i < argc - 1; i++ )
+	 {
+	   if( argv[i][0] != '-' ||
+	       strlen(argv[i]) != 2 ) break;
+
+	   if( argv[i][1] == 'c' ) { g_lpstrCharSet = argv[i+1]; }
+	   else 
+	   if( argv[i][1] == 'f' ) { g_lpstrFileName = argv[i+1]; }
+	   else
+	   usage();
+
+	   i++;
+	 } 
+	 if( i == argc - 1 )
+	 {
+	   g_lpstrInputFile = argv[i];
+	   break;
+	 }
+    default: usage();
+  }
+    
+}
+
+/* read file data and return file type */
+
+int get_resource_table(int fd, unsigned char** lpdata, int fsize)
+{
+  struct mz_header_s mz_header;
+  struct ne_header_s ne_header;
+  short		     s, offset, size, retval;
+
+ 
+  lseek( fd, 0, SEEK_SET );
+
+  if( read(fd, &mz_header, sizeof(mz_header)) != sizeof(mz_header) ) 
+      return FILE_ERROR;
+
+  s = return_data_value(dfShort, &mz_header.mz_magic);
+
+  if( s == MZ_SIGNATURE) 		/* looks like .dll file so far... */
+  {
+    s = return_data_value(dfShort, &mz_header.ne_offset);
+    lseek( fd, s, SEEK_SET );
+
+    if( read(fd, &ne_header, sizeof(ne_header)) != sizeof(ne_header) )
+	return FILE_ERROR;
+
+    s = return_data_value(dfShort, &ne_header.ne_magic);
+
+    if( s == PE_SIGNATURE)
+    {
+       fprintf( stderr, "Do not know how to handle 32-bit Windows DLLs.\n");
+       return FILE_ERROR; 
+    }
+    else if ( s != NE_SIGNATURE) return FILE_ERROR;
+
+    s = return_data_value(dfShort, &ne_header.resource_tab_offset);
+    size = return_data_value(dfShort, &ne_header.rname_tab_offset);
+
+    if( size > fsize ) return FILE_ERROR;
+
+    size -= s;
+    offset = s + return_data_value(dfShort, &mz_header.ne_offset);
+
+    if( size <= sizeof(NE_TYPEINFO) ) return FILE_ERROR;
+    retval = FILE_DLL;
+  }
+  else if( s == 0x300 || s == 0x200 )		/* maybe .fnt ? */
+  {
+    size = return_data_value(dfLong, &mz_header.dont_care);
+
+    if( size != fsize ) return FILE_ERROR;
+    offset  = 0;
+    retval = FILE_FNT; 
+  }
+  else return FILE_ERROR;
+
+  *lpdata = (unsigned char*)malloc(size);
+
+  if( *lpdata )
+  {
+    lseek( fd, offset, SEEK_SET );
+    if( read(fd, *lpdata, size) != size )
+           { free( *lpdata ); *lpdata = NULL; }
+  }
+  return retval;
+}
+
+
+/* entry point */
+
+int main(int argc, char **argv)
+{
+  unsigned char* lpdata = NULL;
+  int 		 fd;
+
+  parse_options( argc, argv);
+
+  if( (fd = open( g_lpstrInputFile, O_RDONLY)) ) 
+  {
+    int    i;
+    struct stat file_stat;
+
+    fstat( fd, &file_stat);
+    i = get_resource_table( fd, &lpdata, file_stat.st_size );
+
+    switch(i)
+    {
+	case FILE_DLL:
+	     if( lpdata )
+	     {
+	       int	    j, count = 0;
+	       NE_TYPEINFO* pTInfo = (NE_TYPEINFO*)(lpdata + 2);
+	       NE_NAMEINFO* pFontStorage = NULL;
+
+	       while( (i = return_data_value(dfShort, &pTInfo->type_id)) ) 
+	       {
+		  j = return_data_value(dfShort, &pTInfo->count);
+		  if( i == NE_RSCTYPE_FONT )
+		  {
+		    count = j;
+		    pFontStorage = (NE_NAMEINFO*)(pTInfo + 1);
+		  }
+
+		  pTInfo = (NE_TYPEINFO *)((char*)(pTInfo+1) + j*sizeof(NE_NAMEINFO));
+	       }
+	       if( pFontStorage && count )
+	       {
+		 unsigned short		size_shift = return_data_value(dfShort, lpdata);
+		 unsigned char*		lpfont = NULL;
+		 unsigned		offset;
+		 unsigned		length;
+
+		 for( j = 0; j < count; j++, pFontStorage++ )
+		 {
+		    length = return_data_value(dfShort, &pFontStorage->length) << size_shift;
+		    offset = return_data_value(dfShort, &pFontStorage->offset) << size_shift;
+		    
+		    if( !(lpfont = (unsigned char*) realloc( lpfont, length )) )
+		    {
+			fprintf(stderr, errorMemory );
+			free(lpdata);
+			return -1;
+		    }
+
+		    lseek( fd, offset, SEEK_SET );
+		    if( read(fd, lpfont, length) != length )
+		    {
+			fprintf(stderr, errorDLLRead );
+			free(lpdata); free(lpfont);
+			return -1;
+		    }
+
+		    if( (i = parse_fnt_data( lpfont, length )) )
+			fprintf(stderr, "%s%d\n", errorFontData, i );
+		 }
+		 free(lpfont); free(lpdata);
+		 return 0;
+	       }
+	       else fprintf(stderr, errorEmpty );
+	       free( lpdata );
+	     }
+	     else fprintf(stderr, errorDLLRead);
+	     break;
+
+	case FILE_FNT:
+	     if( lpdata )
+	     {
+	       if( (i = parse_fnt_data( lpdata, file_stat.st_size )) )
+		   fprintf(stderr, "%s%d\n", errorFontData, i );
+
+	       free( lpdata );
+	     }
+	     else fprintf(stderr, errorFNTRead);
+	     break;
+
+	case FILE_ERROR:
+	     fprintf(stderr, errorFile );
+ 
+    }
+    close(fd);
+  }
+  else fprintf(stderr, errorOpenFile );
+  return -1;
+}
diff --git a/tools/fnt2bdf.h b/tools/fnt2bdf.h
new file mode 100644
index 0000000..e40dbad
--- /dev/null
+++ b/tools/fnt2bdf.h
@@ -0,0 +1,74 @@
+#include <stdio.h>
+
+enum data_types {dfChar, dfShort, dfLong, dfString};
+
+#define ERROR_DATA	1
+#define ERROR_VERSION	2
+#define ERROR_SIZE	3
+#define ERROR_MEMORY	4
+#define ERROR_FILE	5
+
+typedef struct tagFontHeader 
+{
+    unsigned char dfVersion[2]; 	/* Version (always 0x3000) */ 
+    unsigned char dfSize[4];            /* Total File Size */
+    unsigned char dfCopyright[60];      /* Copyright notice */
+    unsigned char dfType[2];            /* Vector or bitmap font */
+    unsigned char dfPoints[2];          /* Nominal point size */
+    unsigned char dfVertRes[2]; 	/* Vertical Resolution */
+    unsigned char dfHorizRes[2];        /* Horizontal Resolutionchar */  
+    unsigned char dfAscent[2];          /* Character ascent in pixels */ 
+    unsigned char dfInternalLeading[2]; /* Leading included in character defn */
+    unsigned char dfExternalLeading[2]; /* Leading to be added by Windows */
+    unsigned char dfItalic[1];             /* 1=Italic font */
+    unsigned char dfUnderline[1];          /* 1=underlined font */
+    unsigned char dfStrikeOut[1];          /* 1=strike-out font */
+    unsigned char dfWeight[2];          /* Weight: 400=normal */
+    unsigned char dfCharSet[1];            /* Character Set for this font */
+    unsigned char dfPixWidth[2];        /* Character width (0 for proportional) */
+    unsigned char dfPixHeight[2];       /* Character height */
+    unsigned char dfPitchAndFamily[1];     /* Font Pitch and family */
+    unsigned char dfAvgWidth[2];        /* Average character width */
+    unsigned char dfMaxWidth[2];        /* Maximum character width */
+    unsigned char dfFirstChar[1];          /* Firwst character of the font */
+    unsigned char dfLastChar[1];           /* Last character of the font */
+    unsigned char dfDefaultChar[1];        /* Missing character */
+    unsigned char dfBreakChar[1];          /* Character to indicate word breaks */
+    unsigned char dfWidthBytes[2];      /* Number of bytes in each row */
+    unsigned char dfDevice[4];          /* Offset to device name */
+    unsigned char dfFace[4];            /* Offset to type face name */
+    unsigned char dfBitsPointer[4];
+    unsigned char dfBitsOffset[4];      /* Offset to bitmaps */
+    unsigned char dfReserved[1];
+    unsigned char dfFlags[4];           /* Bitmapped flags */
+    unsigned char dfAspace[2];
+    unsigned char dfBspace[2];
+    unsigned char dfCspace[2];
+    unsigned char dfColorTable[2];      /* Offset to Color table */
+    unsigned char dfReserved1[4];
+} fnt_hdrS;
+
+typedef struct WinCharStruct
+{
+    unsigned int charWidth;
+    unsigned int charOffset;
+} WinCharS;
+ 
+typedef struct fntFontStruct
+{
+    fnt_hdrS 	 	hdr;
+    WinCharS 		*dfCharTable;
+    unsigned char	*dfDeviceP;
+    unsigned char 	*dfFaceP;
+    unsigned char 	*dfBitsPointerP;
+    unsigned char 	*dfBitsOffsetP;
+    short 		*dfColorTableP;
+} fnt_fontS;
+
+extern	int return_data_value(enum data_types, void *);
+ 
+extern	int dump_bdf(fnt_fontS*, unsigned char* );
+extern	int dump_bdf_hdr(FILE* fp,fnt_fontS*, unsigned char* );
+
+extern	int parse_fnt_data(unsigned char* file_buffer, int length);
+