Added function to build the Windows numeric language ID from language,
[wine] / misc / main.c
1 /*
2  * Main function.
3  *
4  * Copyright 1994 Alexandre Julliard
5  */
6
7 #include <stdlib.h>
8 #include <string.h>
9 #include <unistd.h>
10 #include <ctype.h>
11 /* #include <locale.h> */
12 #ifdef MALLOC_DEBUGGING
13 #include <malloc.h>
14 #endif
15 #include "ts_xlib.h"
16 #include "ts_xresource.h"
17 #include "ts_xutil.h"
18 #include <X11/Xlocale.h>
19 #include <X11/cursorfont.h>
20 #include "winsock.h"
21 #include "heap.h"
22 #include "message.h"
23 #include "msdos.h"
24 #include "windows.h"
25 #include "color.h"
26 #include "options.h"
27 #include "desktop.h"
28 #include "process.h"
29 #include "shell.h"
30 #include "winbase.h"
31 #include "debug.h"
32 #include "debugdefs.h"
33 #include "xmalloc.h"
34 #include "version.h"
35 #include "winnls.h"
36
37 /* when adding new languages look at ole/ole2nls.c 
38  * for proper iso name and Windows code (add 0x0400 
39  * to the code listed there)
40  */
41 const WINE_LANGUAGE_DEF Languages[] =
42 {
43     {"En",0x0409},      /* LANG_En */
44     {"Es",0x040A},      /* LANG_Es */
45     {"De",0x0407},      /* LANG_De */
46     {"No",0x0414},      /* LANG_No */
47     {"Fr",0x040C},      /* LANG_Fr */
48     {"Fi",0x040B},      /* LANG_Fi */
49     {"Da",0x0406},      /* LANG_Da */
50     {"Cs",0x0405},      /* LANG_Cs */
51     {"Eo",0x048f},      /* LANG_Eo */
52     {"It",0x0410},      /* LANG_It */
53     {"Ko",0x0412},      /* LANG_Ko */
54     {"Hu",0x040e},      /* LANG_Hu */
55     {"Pl",0x0415},      /* LANG_Pl */
56     {"Pt",0x0416},      /* LANG_Pt */
57     {"Sv",0x041d},      /* LANG_Sv */
58     {"Ca",0x0403},      /* LANG_Ca */
59 /* for compatibility whith non-iso names previously used */
60     {"Sw",0x041d},      /* LANG_Sv */
61     {"Cz",0x0405},      /* LANG_Cs */
62     {"Po",0x0416},      /* LANG_Pt */
63     {NULL,0}
64 };
65
66 WORD WINE_LanguageId = 0;
67
68 #define WINE_CLASS    "Wine"    /* Class name for resources */
69
70 #define WINE_APP_DEFAULTS "/usr/lib/X11/app-defaults/Wine"
71
72 Display *display;
73 Screen *screen;
74 Window rootWindow;
75 int screenWidth = 0, screenHeight = 0;  /* Desktop window dimensions */
76 int screenDepth = 0;  /* Screen depth to use */
77
78 struct options Options =
79 {  /* default options */
80     NULL,           /* desktopGeometry */
81     NULL,           /* programName */
82     NULL,           /* argv0 */
83     NULL,           /* dllFlags */
84     FALSE,          /* usePrivateMap */
85     FALSE,          /* useFixedMap */
86     FALSE,          /* synchronous */
87     FALSE,          /* backing store */
88     SW_SHOWNORMAL,  /* cmdShow */
89     FALSE,
90     FALSE,          /* failReadOnly */
91     MODE_ENHANCED,  /* Enhanced mode */
92 #ifdef DEFAULT_LANG
93     DEFAULT_LANG,   /* Default language */
94 #else
95     LANG_En,
96 #endif
97     FALSE,          /* Managed windows */
98     FALSE,          /* Perfect graphics */
99     NULL            /* Alternate config file name */
100 };
101
102
103 static XrmOptionDescRec optionsTable[] =
104 {
105     { "-backingstore",  ".backingstore",    XrmoptionNoArg,  (caddr_t)"on" },
106     { "-desktop",       ".desktop",         XrmoptionSepArg, (caddr_t)NULL },
107     { "-depth",         ".depth",           XrmoptionSepArg, (caddr_t)NULL },
108     { "-display",       ".display",         XrmoptionSepArg, (caddr_t)NULL },
109     { "-iconic",        ".iconic",          XrmoptionNoArg,  (caddr_t)"on" },
110     { "-language",      ".language",        XrmoptionSepArg, (caddr_t)"En" },
111     { "-name",          ".name",            XrmoptionSepArg, (caddr_t)NULL },
112     { "-perfect",       ".perfect",         XrmoptionNoArg,  (caddr_t)"on" },
113     { "-privatemap",    ".privatemap",      XrmoptionNoArg,  (caddr_t)"on" },
114     { "-fixedmap",      ".fixedmap",        XrmoptionNoArg,  (caddr_t)"on" },
115     { "-synchronous",   ".synchronous",     XrmoptionNoArg,  (caddr_t)"on" },
116     { "-debug",         ".debug",           XrmoptionNoArg,  (caddr_t)"on" },
117     { "-debugmsg",      ".debugmsg",        XrmoptionSepArg, (caddr_t)NULL },
118     { "-dll",           ".dll",             XrmoptionSepArg, (caddr_t)NULL },
119     { "-failreadonly",  ".failreadonly",    XrmoptionNoArg,  (caddr_t)"on" },
120     { "-mode",          ".mode",            XrmoptionSepArg, (caddr_t)NULL },
121     { "-managed",       ".managed",         XrmoptionNoArg,  (caddr_t)"off"},
122     { "-winver",        ".winver",          XrmoptionSepArg, (caddr_t)NULL },
123     { "-config",        ".config",          XrmoptionSepArg, (caddr_t)NULL }
124 };
125
126 #define NB_OPTIONS  (sizeof(optionsTable) / sizeof(optionsTable[0]))
127
128 #define USAGE \
129   "%s\n" \
130   "Usage:  %s [options] \"program_name [arguments]\"\n" \
131   "\n" \
132   "Options:\n" \
133   "    -backingstore   Turn on backing store\n" \
134   "    -config name    Specify config file to use\n" \
135   "    -debug          Enter debugger before starting application\n" \
136   "    -debugmsg name  Turn debugging-messages on or off\n" \
137   "    -depth n        Change the depth to use for multiple-depth screens\n" \
138   "    -desktop geom   Use a desktop window of the given geometry\n" \
139   "    -display name   Use the specified display\n" \
140   "    -dll name       Enable or disable built-in DLLs\n" \
141   "    -failreadonly   Read only files may not be opened in write mode\n" \
142   "    -fixedmap       Use a \"standard\" color map\n" \
143   "    -help           Show this help message\n" \
144   "    -iconic         Start as an icon\n" \
145   "    -language xx    Set the language (one of Ca,Cs,Da,De,En,Eo,Es,Fi,Fr,Hu,It,\n                    Ko,No,Pl,Pt,Sv)\n" \
146   "    -managed        Allow the window manager to manage created windows\n" \
147   "    -mode mode      Start Wine in a particular mode (standard or enhanced)\n" \
148   "    -name name      Set the application name\n" \
149   "    -perfect        Favor correctness over speed for graphical operations\n" \
150   "    -privatemap     Use a private color map\n" \
151   "    -synchronous    Turn on synchronous display mode\n" \
152   "    -version        Display the Wine version\n" \
153   "    -winver         Version to imitate (one of win31,win95,nt351,nt40)\n"
154
155
156
157 /***********************************************************************
158  *           MAIN_Usage
159  */
160 void MAIN_Usage( char *name )
161 {
162     MSG( USAGE, WINE_RELEASE_INFO, name );
163     exit(1);
164 }
165
166
167 /***********************************************************************
168  *           MAIN_GetProgramName
169  *
170  * Get the program name. The name is specified by (in order of precedence):
171  * - the option '-name'.
172  * - the environment variable 'WINE_NAME'.
173  * - the last component of argv[0].
174  */
175 static char *MAIN_GetProgramName( int argc, char *argv[] )
176 {
177     int i;
178     char *p;
179
180     for (i = 1; i < argc-1; i++)
181         if (!strcmp( argv[i], "-name" )) return argv[i+1];
182     if ((p = getenv( "WINE_NAME" )) != NULL) return p;
183     if ((p = strrchr( argv[0], '/' )) != NULL) return p+1;
184     return argv[0];
185 }
186
187
188 /***********************************************************************
189  *           MAIN_GetResource
190  *
191  * Fetch the value of resource 'name' using the correct instance name.
192  * 'name' must begin with '.' or '*'
193  */
194 static int MAIN_GetResource( XrmDatabase db, char *name, XrmValue *value )
195 {
196     char *buff_instance, *buff_class;
197     char *dummy;
198     int retval;
199
200     buff_instance = (char *)xmalloc(strlen(Options.programName)+strlen(name)+1);
201     buff_class    = (char *)xmalloc( strlen(WINE_CLASS) + strlen(name) + 1 );
202
203     strcpy( buff_instance, Options.programName );
204     strcat( buff_instance, name );
205     strcpy( buff_class, WINE_CLASS );
206     strcat( buff_class, name );
207     retval = TSXrmGetResource( db, buff_instance, buff_class, &dummy, value );
208     free( buff_instance );
209     free( buff_class );
210     return retval;
211 }
212
213
214 /***********************************************************************
215  *          MAIN_ParseDebugOptions
216  *
217  *  Turns specific debug messages on or off, according to "options".
218  *  
219  *  RETURNS
220  *    TRUE if parsing was successful
221  */
222 static BOOL32 MAIN_ParseDebugOptions(char *options)
223 {
224   /* defined in relay32/relay386.c */
225   extern char **debug_relay_includelist;
226   extern char **debug_relay_excludelist;
227   /* defined in relay32/snoop.c */
228   extern char **debug_snoop_includelist;
229   extern char **debug_snoop_excludelist;
230
231   int l, cls;
232   if (strlen(options)<3)
233     return FALSE;
234   do
235   {
236     if ((*options!='+')&&(*options!='-')){
237       int j;
238
239       for(j=0; j<DEBUG_CLASS_COUNT; j++)
240         if(!lstrncmpi32A(options, debug_cl_name[j], strlen(debug_cl_name[j])))
241           break;
242       if(j==DEBUG_CLASS_COUNT)
243         return FALSE;
244       options += strlen(debug_cl_name[j]);
245       if ((*options!='+')&&(*options!='-'))
246         return FALSE;
247       cls = j;
248     }
249     else
250       cls = -1; /* all classes */
251
252     if (strchr(options,','))
253       l=strchr(options,',')-options;
254     else
255       l=strlen(options);
256
257     if (!lstrncmpi32A(options+1,"all",l-1))
258       {
259         int i, j;
260         for (i=0; i<DEBUG_CHANNEL_COUNT; i++)
261           for(j=0; j<DEBUG_CLASS_COUNT; j++)
262             if(cls == -1 || cls == j)
263               debug_msg_enabled[i][j]=(*options=='+');
264       }
265     else if (!lstrncmpi32A(options+1, "relay=", 6) ||
266              !lstrncmpi32A(options+1, "snoop=", 6))
267       {
268         int i, j;
269         char *s, *s2, ***output, c;
270
271         for (i=0; i<DEBUG_CHANNEL_COUNT; i++)
272           if (debug_ch_name && (!lstrncmpi32A(debug_ch_name[i],options+1,5))){
273             for(j=0; j<DEBUG_CLASS_COUNT; j++)
274               if(cls == -1 || cls == j)
275                 debug_msg_enabled[i][j]=TRUE;
276             break;
277           }
278         /* should never happen, maybe assert(i!=DEBUG_CHANNEL_COUNT)? */
279         if (i==DEBUG_CHANNEL_COUNT)
280           return FALSE;
281         output = (*options == '+') ?
282                         ((*(options+1) == 'r') ?
283                                 &debug_relay_includelist :
284                                 &debug_snoop_includelist) :
285                         ((*(options+1) == 'r') ?
286                                 &debug_relay_excludelist :
287                                 &debug_snoop_excludelist);
288         s = options + 7;
289         i = 1;
290         while((s = strchr(s, ':'))) i++, s++;
291         *output = malloc(sizeof(char **) * i + 1);
292         i = 0;
293         s = options + 7;
294         while((s2 = strchr(s, ':'))) {
295           c = *s2;
296           *s2 = '\0';
297           *((*output)+i) = strdup(s);
298           *s2 = c;
299           s = s2 + 1;
300           i++;
301         }
302         c = *(options + l);
303         *(options + l) = '\0';
304         *((*output)+i) = strdup(s);
305         *(options + l) = c;
306         *((*output)+i+1) = NULL;
307       }
308     else
309       {
310         int i, j;
311         for (i=0; i<DEBUG_CHANNEL_COUNT; i++)
312           if (debug_ch_name && (!lstrncmpi32A(options+1,debug_ch_name[i],l-1))){
313             for(j=0; j<DEBUG_CLASS_COUNT; j++)
314               if(cls == -1 || cls == j)
315                 debug_msg_enabled[i][j]=(*options=='+');
316             break;
317           }
318         if (i==DEBUG_CHANNEL_COUNT)
319           return FALSE;
320       }
321     options+=l;
322   }
323   while((*options==',')&&(*(++options)));
324   if (*options)
325     return FALSE;
326   else
327     return TRUE;
328 }
329
330 /***********************************************************************
331  *           MAIN_GetLanguageID
332  *
333  * INPUT:
334  *      Lang: a string whose two first chars are the iso name of a language.
335  *      Country: a string whose two first chars are the iso name of country
336  *      Charset: a string defining the chossen charset encoding
337  *      Dialect: a string defining a variation of the locale
338  *
339  *      all those values are from the standardized format of locale
340  *      name in unix which is: Lang[_Country][.Charset][@Dialect]
341  *
342  * RETURNS:
343  *      the numeric code of the language used by Windows (or 0x00)
344  */
345 int MAIN_GetLanguageID(char *Lang, char *Country, char *Charset, char *Dialect)
346 {
347     char lang[3]="??", country[3]={0,0,0};
348     char *charset=NULL, *dialect=NULL;
349     int i,j,ret=0;
350
351     if (Lang==NULL) return 0x00;
352     if (Lang[0]) lang[0]=tolower(Lang[0]);
353     if (Lang[1]) lang[1]=tolower(Lang[1]);
354
355     if (Country!=NULL) {
356         if (Country[0]) country[0]=toupper(Country[0]);
357         if (Country[1]) country[1]=toupper(Country[1]);
358     }
359
360     if (Charset!=NULL) {
361         j=strlen(Charset);
362         charset=(char*)malloc(j+1);
363         for (i=0;i<j;i++)
364             charset[i]=toupper(Charset[i]);
365         charset[i]='\0';
366     }
367
368     if (Dialect!=NULL) {
369         j=strlen(Dialect);
370         dialect=(char*)malloc(j+1);
371         for (i=0;i<j;i++)
372             dialect[i]=tolower(Dialect[i]);
373         dialect[i]='\0';
374     }
375
376 #define LANG_ENTRY_BEGIN(x,y)   if(!strcmp(lang, x )) { \
377                                     if (!country[0]) { \
378                                         ret=LANG_##y ; \
379                                         goto end_MAIN_GetLanguageID; \
380                                     }
381 #define LANG_SUB_ENTRY(x,y,z)       if (!strcmp(country, x )) \
382                                         ret = MAKELANGID( LANG_##y , SUBLANG_##z ); \
383                                         goto end_MAIN_GetLanguageID;
384 #define LANG_DIALECT_ENTRY(x,y)     { ret = MAKELANGID(LANG_##x , SUBLANG_##y ); \
385                                     goto end_MAIN_GetLanguageID; }
386 #define LANG_ENTRY_END(x)           ret = MAKELANGID(LANG_##x , SUBLANG_DEFAULT); \
387                                     goto end_MAIN_GetLanguageID; \
388                                 }
389
390 /*x01*/ LANG_ENTRY_BEGIN( "ar", ARABIC )
391         LANG_SUB_ENTRY( "SA", ARABIC, ARABIC)
392         LANG_SUB_ENTRY( "IQ", ARABIC, ARABIC_IRAQ )
393         LANG_SUB_ENTRY( "EG", ARABIC, ARABIC_EGYPT )
394         LANG_SUB_ENTRY( "LY", ARABIC, ARABIC_LIBYA )
395         LANG_SUB_ENTRY( "DZ", ARABIC, ARABIC_ALGERIA )
396         LANG_SUB_ENTRY( "MA", ARABIC, ARABIC_MOROCCO )
397         LANG_SUB_ENTRY( "TN", ARABIC, ARABIC_TUNISIA )
398         LANG_SUB_ENTRY( "OM", ARABIC, ARABIC_OMAN )
399         LANG_SUB_ENTRY( "YE", ARABIC, ARABIC_YEMEN )
400         LANG_SUB_ENTRY( "SY", ARABIC, ARABIC_SYRIA )
401         LANG_SUB_ENTRY( "JO", ARABIC, ARABIC_JORDAN )
402         LANG_SUB_ENTRY( "LB", ARABIC, ARABIC_LEBANON )
403         LANG_SUB_ENTRY( "KW", ARABIC, ARABIC_KUWAIT )
404         LANG_SUB_ENTRY( "AE", ARABIC, ARABIC_UAE )
405         LANG_SUB_ENTRY( "BH", ARABIC, ARABIC_BAHRAIN )
406         LANG_SUB_ENTRY( "QA", ARABIC, ARABIC_QATAR )
407         LANG_ENTRY_END( ARABIC )
408 /*x02*/ LANG_ENTRY_BEGIN( "bu", BULGARIAN )
409         LANG_ENTRY_END( BULGARIAN )
410 /*x03*/ LANG_ENTRY_BEGIN( "ca", CATALAN )
411         LANG_ENTRY_END( CATALAN )
412 /*x04*/ LANG_ENTRY_BEGIN( "zh", CHINESE )
413         LANG_SUB_ENTRY( "TW", CHINESE, CHINESE_TRADITIONAL )
414         LANG_SUB_ENTRY( "CN", CHINESE, CHINESE_SIMPLIFIED )
415         LANG_SUB_ENTRY( "HK", CHINESE, CHINESE_HONGKONG )
416         LANG_SUB_ENTRY( "SG", CHINESE, CHINESE_SINGAPORE )
417         LANG_SUB_ENTRY( "MO", CHINESE, CHINESE_MACAU )
418         LANG_ENTRY_END( CHINESE )
419 /*x05*/ LANG_ENTRY_BEGIN( "cs", CZECH )
420         LANG_ENTRY_END( CZECH )
421 /*x06*/ LANG_ENTRY_BEGIN( "da", DANISH )
422         LANG_ENTRY_END( DANISH )
423 /*x07*/ LANG_ENTRY_BEGIN( "de", GERMAN )
424         LANG_SUB_ENTRY( "DE", GERMAN, GERMAN )
425         LANG_SUB_ENTRY( "CH", GERMAN, GERMAN_SWISS )
426         LANG_SUB_ENTRY( "AT", GERMAN, GERMAN_AUSTRIAN )
427         LANG_SUB_ENTRY( "LU", GERMAN, GERMAN_LUXEMBOURG )
428         LANG_SUB_ENTRY( "LI", GERMAN, GERMAN_LIECHTENSTEIN )
429         LANG_ENTRY_END( GERMAN )
430 /*x08*/ LANG_ENTRY_BEGIN( "el", GREEK )
431         LANG_ENTRY_END( GREEK )
432 /*x09*/ LANG_ENTRY_BEGIN( "en", ENGLISH )
433         LANG_SUB_ENTRY( "US", ENGLISH, ENGLISH_US )
434         LANG_SUB_ENTRY( "UK", ENGLISH, ENGLISH_UK )
435         LANG_SUB_ENTRY( "AU", ENGLISH, ENGLISH_AUS )
436         LANG_SUB_ENTRY( "CA", ENGLISH, ENGLISH_CAN )
437         LANG_SUB_ENTRY( "NZ", ENGLISH, ENGLISH_NZ )
438         LANG_SUB_ENTRY( "EI", ENGLISH, ENGLISH_EIRE )
439         LANG_SUB_ENTRY( "ZA", ENGLISH, ENGLISH_SAFRICA )
440         LANG_SUB_ENTRY( "JM", ENGLISH, ENGLISH_JAMAICA )
441      /* LANG_SUB_ENTRY( "AG", ENGLISH, ENGLISH_CARIBBEAN ) */
442         LANG_SUB_ENTRY( "BZ", ENGLISH, ENGLISH_BELIZE )
443         LANG_SUB_ENTRY( "TT", ENGLISH, ENGLISH_TRINIDAD )
444         LANG_SUB_ENTRY( "ZW", ENGLISH, ENGLISH_ZIMBABWE )
445         LANG_SUB_ENTRY( "PH", ENGLISH, ENGLISH_PHILIPPINES )
446         LANG_ENTRY_END( ENGLISH )
447 /*x0a*/ LANG_ENTRY_BEGIN( "es", SPANISH )
448         /* traditional sorting */
449         if (!strcmp(dialect,"tradicional"))
450                 LANG_DIALECT_ENTRY( SPANISH, SPANISH )
451         LANG_SUB_ENTRY( "MX", SPANISH, SPANISH_MEXICAN )
452         LANG_SUB_ENTRY( "ES", SPANISH, SPANISH_MODERN )
453         LANG_SUB_ENTRY( "GT", SPANISH, SPANISH_GUATEMALA )
454         LANG_SUB_ENTRY( "CR", SPANISH, SPANISH_COSTARICA )
455         LANG_SUB_ENTRY( "PA", SPANISH, SPANISH_PANAMA )
456         LANG_SUB_ENTRY( "DO", SPANISH, SPANISH_DOMINICAN )
457         LANG_SUB_ENTRY( "VE", SPANISH, SPANISH_VENEZUELA )
458         LANG_SUB_ENTRY( "CO", SPANISH, SPANISH_COLOMBIA )
459         LANG_SUB_ENTRY( "PE", SPANISH, SPANISH_PERU )
460         LANG_SUB_ENTRY( "AR", SPANISH, SPANISH_ARGENTINA )
461         LANG_SUB_ENTRY( "EC", SPANISH, SPANISH_ECUADOR )
462         LANG_SUB_ENTRY( "CL", SPANISH, SPANISH_CHILE )
463         LANG_SUB_ENTRY( "UY", SPANISH, SPANISH_URUGUAY )
464         LANG_SUB_ENTRY( "PY", SPANISH, SPANISH_PARAGUAY )
465         LANG_SUB_ENTRY( "BO", SPANISH, SPANISH_BOLIVIA )
466         LANG_SUB_ENTRY( "HN", SPANISH, SPANISH_HONDURAS )
467         LANG_SUB_ENTRY( "NI", SPANISH, SPANISH_NICARAGUA )
468         LANG_SUB_ENTRY( "PR", SPANISH, SPANISH_PUERTO_RICO )
469         LANG_ENTRY_END( SPANISH )
470 /*x0b*/ LANG_ENTRY_BEGIN( "fi", FINNISH )
471         LANG_ENTRY_END( FINNISH )
472 /*x0c*/ LANG_ENTRY_BEGIN( "fr", FRENCH )
473         LANG_SUB_ENTRY( "FR", FRENCH, FRENCH )
474         LANG_SUB_ENTRY( "BE", FRENCH, FRENCH_BELGIAN )
475         LANG_SUB_ENTRY( "CA", FRENCH, FRENCH_CANADIAN )
476         LANG_SUB_ENTRY( "CH", FRENCH, FRENCH_SWISS )
477         LANG_SUB_ENTRY( "LU", FRENCH, FRENCH_LUXEMBOURG )
478         LANG_SUB_ENTRY( "MC", FRENCH, FRENCH_MONACO )
479         LANG_ENTRY_END( FRENCH )
480 /*x0d*/ LANG_ENTRY_BEGIN( "iw", HEBREW )
481         LANG_ENTRY_END( HEBREW )
482 /*x0e*/ LANG_ENTRY_BEGIN( "hu", HUNGARIAN )
483         LANG_ENTRY_END( HUNGARIAN )
484 /*x0f*/ LANG_ENTRY_BEGIN( "ic", ICELANDIC )
485         LANG_ENTRY_END( ICELANDIC )
486 /*x10*/ LANG_ENTRY_BEGIN( "it", ITALIAN )
487         LANG_SUB_ENTRY( "IT", ITALIAN, ITALIAN )
488         LANG_SUB_ENTRY( "CH", ITALIAN, ITALIAN_SWISS )
489         LANG_ENTRY_END( ITALIAN )
490 /*x11*/ LANG_ENTRY_BEGIN( "ja", JAPANESE )
491         LANG_ENTRY_END( JAPANESE )
492 /*x12*/ LANG_ENTRY_BEGIN( "ko", KOREAN )
493         /* JOHAB encoding */
494         if (!strcmp(charset,"JOHAB"))
495                 LANG_DIALECT_ENTRY( KOREAN, KOREAN_JOHAB )
496         else
497                 LANG_DIALECT_ENTRY( KOREAN, KOREAN )
498         LANG_ENTRY_END( KOREAN )
499 /*x13*/ LANG_ENTRY_BEGIN( "nl", DUTCH )
500         LANG_SUB_ENTRY( "NL", DUTCH, DUTCH )
501         LANG_SUB_ENTRY( "BE", DUTCH, DUTCH_BELGIAN )
502         LANG_SUB_ENTRY( "SR", DUTCH, DUTCH_SURINAM )
503         LANG_ENTRY_END( DUTCH )
504 /*x14*/ LANG_ENTRY_BEGIN( "no", NORWEGIAN )
505         /* nynorsk */
506         if (!strcmp(dialect,"nynorsk"))
507                 LANG_DIALECT_ENTRY( NORWEGIAN, NORWEGIAN_NYNORSK )
508         else
509                 LANG_DIALECT_ENTRY( NORWEGIAN, NORWEGIAN_BOKMAL )
510         LANG_ENTRY_END( NORWEGIAN )
511 /*x15*/ LANG_ENTRY_BEGIN( "pl", POLISH )
512         LANG_ENTRY_END( POLISH )
513 /*x16*/ LANG_ENTRY_BEGIN( "pt", PORTUGUESE )
514         LANG_SUB_ENTRY( "BR", PORTUGUESE, PORTUGUESE_BRAZILIAN )
515         LANG_SUB_ENTRY( "PT", PORTUGUESE, PORTUGUESE )
516         LANG_ENTRY_END( PORTUGUESE )
517 /*x17*/ LANG_ENTRY_BEGIN( "rm", RHAETO_ROMANCE )
518         LANG_ENTRY_END( RHAETO_ROMANCE )
519 /*x18*/ LANG_ENTRY_BEGIN( "ro", ROMANIAN )
520         LANG_SUB_ENTRY( "RO", ROMANIAN, ROMANIAN )
521         LANG_SUB_ENTRY( "MD", ROMANIAN, ROMANIAN_MOLDAVIA )
522         LANG_ENTRY_END( ROMANIAN )
523 /*x19*/ LANG_ENTRY_BEGIN( "ru", RUSSIAN )
524         LANG_SUB_ENTRY( "RU", RUSSIAN, RUSSIAN )
525         LANG_SUB_ENTRY( "MD", RUSSIAN, RUSSIAN_MOLDAVIA )
526         LANG_ENTRY_END( RUSSIAN )
527 /*x1a*/ if (!strcmp(lang,"sh") || !strcmp(lang,"hr") || !strcmp(lang,"sr")) {
528             if (!country[0]) 
529                 LANG_DIALECT_ENTRY( SERBO_CROATIAN, NEUTRAL)
530             if (!strcmp(charset,"ISO-8859-5"))
531                 LANG_DIALECT_ENTRY( SERBO_CROATIAN, SERBIAN )
532             LANG_SUB_ENTRY( "HR", SERBO_CROATIAN, CROATIAN )
533             if (!strcmp(country,"YU") && !strcmp(charset,"ISO-8859-2"))
534                 LANG_DIALECT_ENTRY( SERBO_CROATIAN, SERBIAN_LATIN )
535             LANG_SUB_ENTRY( "YU", SERBO_CROATIAN, SERBIAN )
536             LANG_DIALECT_ENTRY( SERBO_CROATIAN, SERBIAN_LATIN )
537         }
538 /*x1b*/ LANG_ENTRY_BEGIN( "sk", SLOVAK )
539         LANG_ENTRY_END( SLOVAK )
540 /*x1c*/ LANG_ENTRY_BEGIN( "sq", ALBANIAN )
541         LANG_ENTRY_END( ALBANIAN )
542 /*x1d*/ LANG_ENTRY_BEGIN( "sv", SWEDISH )
543         LANG_SUB_ENTRY( "SE", SWEDISH, SWEDISH )
544         LANG_SUB_ENTRY( "FI", SWEDISH, SWEDISH_FINLAND )
545         LANG_ENTRY_END( SWEDISH )
546 /*x1e*/ LANG_ENTRY_BEGIN( "th", THAI )
547         LANG_ENTRY_END( THAI )
548 /*x1f*/ LANG_ENTRY_BEGIN( "tr", TURKISH )
549         LANG_ENTRY_END( TURKISH )
550 /*x20*/ LANG_ENTRY_BEGIN( "ur", URDU )
551         LANG_ENTRY_END( URDU )
552 /*x21*/ LANG_ENTRY_BEGIN( "in", INDONESIAN )
553         LANG_ENTRY_END( INDONESIAN )
554 /*x22*/ LANG_ENTRY_BEGIN( "uk", UKRAINIAN )
555         LANG_ENTRY_END( UKRAINIAN )
556 /*x23*/ LANG_ENTRY_BEGIN( "be", BYELORUSSIAN )
557         LANG_ENTRY_END( BYELORUSSIAN )
558 /*x24*/ LANG_ENTRY_BEGIN( "sl", SLOVENIAN )
559         LANG_ENTRY_END( SLOVENIAN )
560 /*x25*/ LANG_ENTRY_BEGIN( "et", ESTONIAN )
561         LANG_ENTRY_END( ESTONIAN )
562 /*x26*/ LANG_ENTRY_BEGIN( "lv", LATVIAN )
563         LANG_ENTRY_END( LATVIAN )
564 /*x27*/ LANG_ENTRY_BEGIN( "lt", LITHUANIAN )
565         /* traditional sorting ? */
566         if (!strcmp(dialect,"classic") || !strcmp(dialect,"traditional"))
567                 LANG_DIALECT_ENTRY( LITHUANIAN, LITHUANIAN_CLASSIC )
568         else
569                 LANG_DIALECT_ENTRY( LITHUANIAN, LITHUANIAN )
570         LANG_ENTRY_END( LITHUANIAN )
571 /*x28*/ LANG_ENTRY_BEGIN( "mi", MAORI )
572         LANG_ENTRY_END( MAORI )
573 /*x29*/ LANG_ENTRY_BEGIN( "fa", FARSI )
574         LANG_ENTRY_END( FARSI )
575 /*x2a*/ LANG_ENTRY_BEGIN( "vi", VIETNAMESE )
576         LANG_ENTRY_END( VIETNAMESE )
577 /*x2b*/ LANG_ENTRY_BEGIN( "hy", ARMENIAN )
578         LANG_ENTRY_END( ARMENIAN )
579 /*x2c*/ LANG_ENTRY_BEGIN( "az", AZERI )
580         /* Cyrillic */
581         if (strstr(charset,"KOI8") || !strcmp(charset,"ISO-8859-5"))
582                 LANG_DIALECT_ENTRY( AZERI, AZERI_CYRILLIC )
583         else
584                 LANG_DIALECT_ENTRY( AZERI, AZERI )
585         LANG_ENTRY_END( AZERI )
586 /*x2d*/ LANG_ENTRY_BEGIN( "eu", BASQUE )
587         LANG_ENTRY_END( BASQUE )
588 /*x2e*/ /*LANG_ENTRY_BEGIN( "??", SORBIAN )
589         LANG_ENTRY_END( SORBIAN ) */
590 /*x2f*/ LANG_ENTRY_BEGIN( "mk", MACEDONIAN )
591         LANG_ENTRY_END( MACEDONIAN )
592 /*x30*/ /*LANG_ENTRY_BEGIN( "??", SUTU )
593         LANG_ENTRY_END( SUTU ) */
594 /*x31*/ LANG_ENTRY_BEGIN( "ts", TSONGA )
595         LANG_ENTRY_END( TSONGA )
596 /*x32*/ /*LANG_ENTRY_BEGIN( "??", TSWANA )
597         LANG_ENTRY_END( TSWANA ) */
598 /*x33*/ /*LANG_ENTRY_BEGIN( "??", VENDA )
599         LANG_ENTRY_END( VENDA ) */
600 /*x34*/ LANG_ENTRY_BEGIN( "xh", XHOSA )
601         LANG_ENTRY_END( XHOSA )
602 /*x35*/ LANG_ENTRY_BEGIN( "zu", ZULU )
603         LANG_ENTRY_END( ZULU )
604 /*x36*/ LANG_ENTRY_BEGIN( "af", AFRIKAANS )
605         LANG_ENTRY_END( AFRIKAANS )
606 /*x37*/ LANG_ENTRY_BEGIN( "ka", GEORGIAN )
607         LANG_ENTRY_END( GEORGIAN )
608 /*x38*/ LANG_ENTRY_BEGIN( "fo", FAEROESE )
609         LANG_ENTRY_END( FAEROESE )
610 /*x39*/ LANG_ENTRY_BEGIN( "hi", HINDI )
611         LANG_ENTRY_END( HINDI )
612 /*x3a*/ LANG_ENTRY_BEGIN( "mt", MALTESE )
613         LANG_ENTRY_END( MALTESE )
614 /*x3b*/ /*LANG_ENTRY_BEGIN( "??", SAAMI )
615         LANG_ENTRY_END( SAAMI ) */
616 /*x3c*/ LANG_ENTRY_BEGIN( "ga", GAELIC )
617         LANG_DIALECT_ENTRY( GAELIC, GAELIC )
618         LANG_ENTRY_END( GAELIC )
619 /*x3c*/ LANG_ENTRY_BEGIN( "gd", GAELIC )
620         LANG_DIALECT_ENTRY( GAELIC, GAELIC_SCOTTISH )
621         LANG_ENTRY_END( GAELIC )
622 // 0x3d
623 /*x3e*/ LANG_ENTRY_BEGIN( "ms", MALAY )
624         LANG_SUB_ENTRY( "MY", MALAY, MALAY )
625         LANG_SUB_ENTRY( "BN", MALAY, MALAY_BRUNEI_DARUSSALAM )
626         LANG_ENTRY_END( MALAY )
627 /*x3f*/ LANG_ENTRY_BEGIN( "kk", KAZAKH )
628         LANG_ENTRY_END( KAZAKH )
629 // 0x40
630 /*x41*/ LANG_ENTRY_BEGIN( "sw", SWAHILI )
631         LANG_ENTRY_END( SWAHILI )
632 // 0x42
633 /*x43*/ LANG_ENTRY_BEGIN( "uz", UZBEK )
634         /* Cyrillic */
635         if (strstr(charset,"KOI8") || !strcmp(charset,"ISO-8859-5"))
636                 LANG_DIALECT_ENTRY( UZBEK, UZBEK_CYRILLIC )
637         else
638                 LANG_DIALECT_ENTRY( UZBEK, UZBEK )
639         LANG_ENTRY_END( UZBEK )
640 /*x44*/ LANG_ENTRY_BEGIN( "tt", TATAR )
641         LANG_ENTRY_END( TATAR )
642 /*x45*/ LANG_ENTRY_BEGIN( "bn", BENGALI )
643         LANG_ENTRY_END( BENGALI )
644 /*x46*/ LANG_ENTRY_BEGIN( "pa", PUNJABI )
645         LANG_ENTRY_END( PUNJABI )
646 /*x47*/ LANG_ENTRY_BEGIN( "gu", GUJARATI )
647         LANG_ENTRY_END( GUJARATI )
648 /*x48*/ LANG_ENTRY_BEGIN( "or", ORIYA )
649         LANG_ENTRY_END( ORIYA )
650 /*x49*/ LANG_ENTRY_BEGIN( "ta", TAMIL )
651         LANG_ENTRY_END( TAMIL )
652 /*x4a*/ LANG_ENTRY_BEGIN( "te", TELUGU )
653         LANG_ENTRY_END( TELUGU )
654 /*x4b*/ LANG_ENTRY_BEGIN( "kn", KANNADA )
655         LANG_ENTRY_END( KANNADA )
656 /*x4c*/ LANG_ENTRY_BEGIN( "ml", MALAYALAM )
657         LANG_ENTRY_END( MALAYALAM )
658 /*x4d*/ LANG_ENTRY_BEGIN( "as", ASSAMESE )
659         LANG_ENTRY_END( ASSAMESE )
660 /*x4e*/ LANG_ENTRY_BEGIN( "mr", MARATHI )
661         LANG_ENTRY_END( MARATHI )
662 /*x4f*/ LANG_ENTRY_BEGIN( "sa", SANSKRIT )
663         LANG_ENTRY_END( SANSKRIT )
664 // 0x50 -> 0x56
665 /*x57*/ /*LANG_ENTRY_BEGIN( "??", KONKANI )
666         LANG_ENTRY_END( KONKANI ) */
667 // 0x58 -> ...
668         LANG_ENTRY_BEGIN( "eo", ESPERANTO ) /* not official */
669         LANG_ENTRY_END( ESPERANTO )
670
671         ret = LANG_NEUTRAL;
672
673 end_MAIN_GetLanguageID:
674         if (Charset) free(Charset);
675         if (Dialect) free(Dialect);
676
677         return ret;
678 }
679
680 /***********************************************************************
681  *           MAIN_ParseLanguageOption
682  *
683  * Parse -language option.
684  */
685 static void MAIN_ParseLanguageOption( char *arg )
686 {
687     const WINE_LANGUAGE_DEF *p = Languages;
688
689     Options.language = LANG_En;  /* First language */
690     for (;p->name;p++)
691     {
692         if (!lstrcmpi32A( p->name, arg ))
693         {
694             WINE_LanguageId = p->langid;
695             return;
696         }
697         Options.language++;
698     }
699     MSG( "Invalid language specified '%s'. Supported languages are: ", arg );
700     for (p = Languages; p->name; p++) MSG( "%s ", p->name );
701     MSG( "\n" );
702     exit(1);
703 }
704
705
706 /***********************************************************************
707  *           MAIN_ParseModeOption
708  *
709  * Parse -mode option.
710  */
711 static void MAIN_ParseModeOption( char *arg )
712 {
713     if (!lstrcmpi32A("enhanced", arg)) Options.mode = MODE_ENHANCED;
714     else if (!lstrcmpi32A("standard", arg)) Options.mode = MODE_STANDARD;
715     else
716     {
717         MSG( "Invalid mode '%s' specified.\n", arg);
718         MSG( "Valid modes are: 'standard', 'enhanced' (default).\n");
719         exit(1);
720     }
721 }
722
723 /***********************************************************************
724  *           MAIN_ParseOptions
725  *
726  * Parse command line options and open display.
727  */
728 static void MAIN_ParseOptions( int *argc, char *argv[] )
729 {
730     char *display_name = NULL;
731     XrmValue value;
732     XrmDatabase db = TSXrmGetFileDatabase(WINE_APP_DEFAULTS);
733     int i;
734     char *xrm_string;
735
736     Options.programName = MAIN_GetProgramName( *argc, argv );
737     Options.argv0 = argv[0];
738
739       /* Get display name from command line */
740     for (i = 1; i < *argc; i++)
741     {
742         if (!strcmp( argv[i], "-display" )) display_name = argv[i+1];
743         if (!strcmp( argv[i], "-v" ) || !strcmp( argv[i], "-version" ))
744         {
745             MSG( "%s\n", WINE_RELEASE_INFO );
746             exit(0);
747         }
748         if (!strcmp( argv[i], "-h" ) || !strcmp( argv[i], "-help" ))
749         {
750             MAIN_Usage(argv[0]);
751             exit(0);
752         }
753     }
754
755       /* Open display */
756
757     if (display_name == NULL &&
758         MAIN_GetResource( db, ".display", &value )) display_name = value.addr;
759
760     if (!(display = TSXOpenDisplay( display_name )))
761     {
762         MSG( "%s: Can't open display: %s\n",
763                  argv[0], display_name ? display_name : "(none specified)" );
764         exit(1);
765     }
766
767     /* tell the libX11 that we will do input method handling ourselves
768      * that keep libX11 from doing anything whith dead keys, allowing Wine
769      * to have total control over dead keys, that is this line allows
770      * them to work in Wine, even whith a libX11 including the dead key
771      * patches from Th.Quinot (http://Web.FdN.FR/~tquinot/dead-keys.en.html)
772      */
773     TSXOpenIM(display,NULL,NULL,NULL);
774
775       /* Merge file and screen databases */
776     if ((xrm_string = TSXResourceManagerString( display )) != NULL)
777     {
778         XrmDatabase display_db = TSXrmGetStringDatabase( xrm_string );
779         TSXrmMergeDatabases( display_db, &db );
780     }
781
782       /* Parse command line */
783     TSXrmParseCommand( &db, optionsTable, NB_OPTIONS,
784                      Options.programName, argc, argv );
785
786       /* Get all options */
787     if (MAIN_GetResource( db, ".iconic", &value ))
788         Options.cmdShow = SW_SHOWMINIMIZED;
789     if (MAIN_GetResource( db, ".privatemap", &value ))
790         Options.usePrivateMap = TRUE;
791     if (MAIN_GetResource( db, ".fixedmap", &value ))
792         Options.useFixedMap = TRUE;
793     if (MAIN_GetResource( db, ".synchronous", &value ))
794         Options.synchronous = TRUE;
795     if (MAIN_GetResource( db, ".backingstore", &value ))
796         Options.backingstore = TRUE;    
797     if (MAIN_GetResource( db, ".debug", &value ))
798         Options.debug = TRUE;
799     if (MAIN_GetResource( db, ".failreadonly", &value ))
800         Options.failReadOnly = TRUE;
801     if (MAIN_GetResource( db, ".perfect", &value ))
802         Options.perfectGraphics = TRUE;
803     if (MAIN_GetResource( db, ".depth", &value))
804         screenDepth = atoi( value.addr );
805     if (MAIN_GetResource( db, ".desktop", &value))
806         Options.desktopGeometry = value.addr;
807     if (MAIN_GetResource( db, ".language", &value))
808         MAIN_ParseLanguageOption( (char *)value.addr );
809     if (MAIN_GetResource( db, ".managed", &value))
810         Options.managed = TRUE;
811     if (MAIN_GetResource( db, ".mode", &value))
812         MAIN_ParseModeOption( (char *)value.addr );
813     if (MAIN_GetResource( db, ".debugoptions", &value))
814         MAIN_ParseDebugOptions((char*)value.addr);
815     if (MAIN_GetResource( db, ".debugmsg", &value))
816       {
817 #ifndef DEBUG_RUNTIME
818         MSG("%s: Option \"-debugmsg\" not implemented.\n" \
819           "    Recompile with DEBUG_RUNTIME in include/debugtools.h defined.\n",
820           argv[0]);
821         exit(1);
822 #else
823         if (MAIN_ParseDebugOptions((char*)value.addr)==FALSE)
824           {
825             int i;
826             MSG("%s: Syntax: -debugmsg [class]+xxx,...  or "
827                     "-debugmsg [class]-xxx,...\n",argv[0]);
828             MSG("Example: -debugmsg +all,warn-heap\n"
829                     "  turn on all messages except warning heap messages\n");
830             MSG("Special case: -debugmsg +relay=DLL:DLL.###:FuncName\n"
831                 "  turn on -debugmsg +relay only as specified\n"
832                 "Special case: -debugmsg -relay=DLL:DLL.###:FuncName\n"
833                 "  turn on -debugmsg +relay except as specified\n"
834                 "Also permitted, +snoop=..., -snoop=... as with relay.\n\n");
835
836             MSG("Available message classes:\n");
837             for(i=0;i<DEBUG_CLASS_COUNT;i++)
838               MSG( "%-9s", debug_cl_name[i]);
839             MSG("\n\n");
840
841             MSG("Available message types:\n");
842             MSG("%-9s ","all");
843             for(i=0;i<DEBUG_CHANNEL_COUNT;i++)
844               if(debug_ch_name[i])
845                 MSG("%-9s%c",debug_ch_name[i],
846                         (((i+2)%8==0)?'\n':' '));
847             MSG("\n\n");
848             exit(1);
849           }
850 #endif
851       }
852
853       if (MAIN_GetResource( db, ".dll", &value))
854       {
855           /* Hack: store option value in Options to be retrieved */
856           /* later on inside the emulator code. */
857           if (!__winelib) Options.dllFlags = xstrdup((char *)value.addr);
858           else
859           {
860               MSG("-dll not supported in Winelib\n" );
861               exit(1);
862           }
863       }
864
865       if (MAIN_GetResource( db, ".winver", &value))
866           VERSION_ParseVersion( (char*)value.addr );
867       if (MAIN_GetResource( db, ".config", &value))
868          Options.configFileName = xstrdup((char *)value.addr);
869 }
870
871
872 /***********************************************************************
873  *           MAIN_CreateDesktop
874  */
875 static void MAIN_CreateDesktop( int argc, char *argv[] )
876 {
877     int x, y, flags;
878     unsigned int width = 640, height = 480;  /* Default size = 640x480 */
879     char *name = "Wine desktop";
880     XSizeHints *size_hints;
881     XWMHints   *wm_hints;
882     XClassHint *class_hints;
883     XSetWindowAttributes win_attr;
884     XTextProperty window_name;
885     Atom XA_WM_DELETE_WINDOW;
886
887     flags = TSXParseGeometry( Options.desktopGeometry, &x, &y, &width, &height );
888     screenWidth  = width;
889     screenHeight = height;
890
891       /* Create window */
892
893     win_attr.background_pixel = BlackPixel(display,0);
894     win_attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
895                          PointerMotionMask | ButtonPressMask |
896                          ButtonReleaseMask | EnterWindowMask;
897     win_attr.cursor = TSXCreateFontCursor( display, XC_top_left_arrow );
898
899     rootWindow = TSXCreateWindow( display, DefaultRootWindow(display),
900                                 x, y, width, height, 0,
901                                 CopyFromParent, InputOutput, CopyFromParent,
902                                 CWBackPixel | CWEventMask | CWCursor, &win_attr );
903
904       /* Set window manager properties */
905
906     size_hints  = TSXAllocSizeHints();
907     wm_hints    = TSXAllocWMHints();
908     class_hints = TSXAllocClassHint();
909     if (!size_hints || !wm_hints || !class_hints)
910     {
911         MSG("Not enough memory for window manager hints.\n" );
912         exit(1);
913     }
914     size_hints->min_width = size_hints->max_width = width;
915     size_hints->min_height = size_hints->max_height = height;
916     size_hints->flags = PMinSize | PMaxSize;
917     if (flags & (XValue | YValue)) size_hints->flags |= USPosition;
918     if (flags & (WidthValue | HeightValue)) size_hints->flags |= USSize;
919     else size_hints->flags |= PSize;
920
921     wm_hints->flags = InputHint | StateHint;
922     wm_hints->input = True;
923     wm_hints->initial_state = NormalState;
924     class_hints->res_name = argv[0];
925     class_hints->res_class = "Wine";
926
927     TSXStringListToTextProperty( &name, 1, &window_name );
928     TSXSetWMProperties( display, rootWindow, &window_name, &window_name,
929                       argv, argc, size_hints, wm_hints, class_hints );
930     XA_WM_DELETE_WINDOW = TSXInternAtom( display, "WM_DELETE_WINDOW", False );
931     TSXSetWMProtocols( display, rootWindow, &XA_WM_DELETE_WINDOW, 1 );
932     TSXFree( size_hints );
933     TSXFree( wm_hints );
934     TSXFree( class_hints );
935
936       /* Map window */
937
938     TSXMapWindow( display, rootWindow );
939 }
940
941
942 XKeyboardState keyboard_state;
943
944 /***********************************************************************
945  *           MAIN_SaveSetup
946  */
947 static void MAIN_SaveSetup(void)
948 {
949     TSXGetKeyboardControl(display, &keyboard_state);
950 }
951
952 /***********************************************************************
953  *           MAIN_RestoreSetup
954  */
955 static void MAIN_RestoreSetup(void)
956 {
957     XKeyboardControl keyboard_value;
958
959     keyboard_value.key_click_percent    = keyboard_state.key_click_percent;
960     keyboard_value.bell_percent         = keyboard_state.bell_percent;
961     keyboard_value.bell_pitch           = keyboard_state.bell_pitch;
962     keyboard_value.bell_duration        = keyboard_state.bell_duration;
963     keyboard_value.auto_repeat_mode     = keyboard_state.global_auto_repeat;
964
965     XChangeKeyboardControl(display, KBKeyClickPercent | KBBellPercent | 
966         KBBellPitch | KBBellDuration | KBAutoRepeatMode, &keyboard_value);
967 }
968
969
970 /***********************************************************************
971  *           called_at_exit
972  */
973 static void called_at_exit(void)
974 {
975     MAIN_RestoreSetup();
976     COLOR_Cleanup();
977     WINSOCK_Shutdown();
978     /* FIXME: should check for other processes or threads */
979     DeleteCriticalSection( HEAP_SystemLock );
980 }
981
982 /***********************************************************************
983  *           MAIN_WineInit
984  *
985  * Wine initialisation and command-line parsing
986  */
987 BOOL32 MAIN_WineInit( int *argc, char *argv[] )
988 {    
989     int depth_count, i;
990     int *depth_list;
991     struct timeval tv;
992
993 #ifdef MALLOC_DEBUGGING
994     char *trace;
995
996     mcheck(NULL);
997     if (!(trace = getenv("MALLOC_TRACE")))
998     {       
999         MSG( "MALLOC_TRACE not set. No trace generated\n" );
1000     }
1001     else
1002     {
1003         MSG( "malloc trace goes to %s\n", trace );
1004         mtrace();
1005     }
1006 #endif
1007
1008     setbuf(stdout,NULL);
1009     setbuf(stderr,NULL);
1010
1011     setlocale(LC_CTYPE,"");
1012     gettimeofday( &tv, NULL);
1013     MSG_WineStartTicks = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
1014
1015     /* We need this before calling any Xlib function */
1016     InitializeCriticalSection( &X11DRV_CritSection );
1017
1018     TSXrmInitialize();
1019
1020     putenv("XKB_DISABLE="); /* Disable XKB extension if present. */
1021
1022     MAIN_ParseOptions( argc, argv );
1023
1024     if (Options.desktopGeometry && Options.managed)
1025     {
1026 #if 0
1027         MSG( "%s: -managed and -desktop options cannot be used together\n",
1028                  Options.programName );
1029         exit(1);
1030 #else
1031         Options.managed = FALSE;
1032 #endif
1033     }
1034
1035     screen       = DefaultScreenOfDisplay( display );
1036     screenWidth  = WidthOfScreen( screen );
1037     screenHeight = HeightOfScreen( screen );
1038     if (screenDepth)  /* -depth option specified */
1039     {
1040         depth_list = TSXListDepths(display,DefaultScreen(display),&depth_count);
1041         for (i = 0; i < depth_count; i++)
1042             if (depth_list[i] == screenDepth) break;
1043         TSXFree( depth_list );
1044         if (i >= depth_count)
1045         {
1046             MSG( "%s: Depth %d not supported on this screen.\n",
1047                               Options.programName, screenDepth );
1048             exit(1);
1049         }
1050     }
1051     else screenDepth  = DefaultDepthOfScreen( screen );
1052     if (Options.synchronous) TSXSynchronize( display, True );
1053     if (Options.desktopGeometry) MAIN_CreateDesktop( *argc, argv );
1054     else rootWindow = DefaultRootWindow( display );
1055
1056     MAIN_SaveSetup();
1057     atexit(called_at_exit);
1058     return TRUE;
1059 }
1060
1061
1062 /***********************************************************************
1063  *           MessageBeep16   (USER.104)
1064  */
1065 void WINAPI MessageBeep16( UINT16 i )
1066 {
1067     MessageBeep32( i );
1068 }
1069
1070
1071 /***********************************************************************
1072  *           MessageBeep32   (USER32.390)
1073  */
1074 BOOL32 WINAPI MessageBeep32( UINT32 i )
1075 {
1076     TSXBell( display, 0 );
1077     return TRUE;
1078 }
1079
1080
1081 /***********************************************************************
1082  *           Beep   (KERNEL32.11)
1083  */
1084 BOOL32 WINAPI Beep( DWORD dwFreq, DWORD dwDur )
1085 {
1086     /* dwFreq and dwDur are ignored by Win95 */
1087     TSXBell(display, 0);
1088     return TRUE;
1089 }
1090
1091
1092 /***********************************************************************
1093  *      GetTimerResolution (USER.14)
1094  */
1095 LONG WINAPI GetTimerResolution(void)
1096 {
1097         return (1000);
1098 }
1099
1100 /***********************************************************************
1101  *      SystemParametersInfo32A   (USER32.540)
1102  */
1103 BOOL32 WINAPI SystemParametersInfo32A( UINT32 uAction, UINT32 uParam,
1104                                        LPVOID lpvParam, UINT32 fuWinIni )
1105 {
1106         int timeout, temp;
1107         XKeyboardState          keyboard_state;
1108
1109         switch (uAction) {
1110         case SPI_GETBEEP:
1111                 TSXGetKeyboardControl(display, &keyboard_state);
1112                 if (keyboard_state.bell_percent == 0)
1113                         *(BOOL32 *) lpvParam = FALSE;
1114                 else
1115                         *(BOOL32 *) lpvParam = TRUE;
1116                 break;
1117
1118         case SPI_GETBORDER:
1119                 *(INT32 *)lpvParam = GetSystemMetrics32( SM_CXFRAME );
1120                 break;
1121
1122         case SPI_GETFASTTASKSWITCH:
1123                 if ( GetProfileInt32A( "windows", "CoolSwitch", 1 ) == 1 )
1124                         *(BOOL32 *) lpvParam = TRUE;
1125                 else
1126                         *(BOOL32 *) lpvParam = FALSE;
1127                 break;
1128
1129         case SPI_GETDRAGFULLWINDOWS:
1130           *(BOOL32 *) lpvParam = FALSE;
1131                 
1132         case SPI_GETGRIDGRANULARITY:
1133                 *(INT32*)lpvParam=GetProfileInt32A("desktop","GridGranularity",1);
1134                 break;
1135
1136         case SPI_GETICONTITLEWRAP:
1137                 *(BOOL32*)lpvParam=GetProfileInt32A("desktop","IconTitleWrap",TRUE);
1138                 break;
1139
1140         case SPI_GETKEYBOARDDELAY:
1141                 *(INT32*)lpvParam=GetProfileInt32A("keyboard","KeyboardDelay",1);
1142                 break;
1143
1144         case SPI_GETKEYBOARDSPEED:
1145                 *(DWORD*)lpvParam=GetProfileInt32A("keyboard","KeyboardSpeed",30);
1146                 break;
1147
1148         case SPI_GETMENUDROPALIGNMENT:
1149                 *(BOOL32*)lpvParam=GetSystemMetrics32(SM_MENUDROPALIGNMENT); /* XXX check this */
1150                 break;
1151
1152         case SPI_GETSCREENSAVEACTIVE:
1153                 if ( GetProfileInt32A( "windows", "ScreenSaveActive", 1 ) == 1 )
1154                         *(BOOL32*)lpvParam = TRUE;
1155                 else
1156                         *(BOOL32*)lpvParam = FALSE;
1157                 break;
1158
1159         case SPI_GETSCREENSAVETIMEOUT:
1160         /* FIXME GetProfileInt( "windows", "ScreenSaveTimeout", 300 ); */
1161                 TSXGetScreenSaver(display, &timeout, &temp,&temp,&temp);
1162                 *(INT32 *) lpvParam = timeout * 1000;
1163                 break;
1164
1165         case SPI_ICONHORIZONTALSPACING:
1166                 /* FIXME Get/SetProfileInt */
1167                 if (lpvParam == NULL)
1168                         /*SetSystemMetrics( SM_CXICONSPACING, uParam )*/ ;
1169                 else
1170                         *(INT32*)lpvParam=GetSystemMetrics32(SM_CXICONSPACING);
1171                 break;
1172
1173         case SPI_ICONVERTICALSPACING:
1174                 /* FIXME Get/SetProfileInt */
1175                 if (lpvParam == NULL)
1176                         /*SetSystemMetrics( SM_CYICONSPACING, uParam )*/ ;
1177                 else
1178                         *(INT32*)lpvParam=GetSystemMetrics32(SM_CYICONSPACING);
1179                 break;
1180
1181         case SPI_GETICONTITLELOGFONT: {
1182                 LPLOGFONT32A lpLogFont = (LPLOGFONT32A)lpvParam;
1183
1184                 /* from now on we always have an alias for MS Sans Serif */
1185
1186                 GetProfileString32A("Desktop", "IconTitleFaceName", "MS Sans Serif", 
1187                         lpLogFont->lfFaceName, LF_FACESIZE );
1188                 lpLogFont->lfHeight = -GetProfileInt32A("Desktop","IconTitleSize", 8);
1189                 lpLogFont->lfWidth = 0;
1190                 lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
1191                 lpLogFont->lfWeight = FW_NORMAL;
1192                 lpLogFont->lfItalic = FALSE;
1193                 lpLogFont->lfStrikeOut = FALSE;
1194                 lpLogFont->lfUnderline = FALSE;
1195                 lpLogFont->lfCharSet = ANSI_CHARSET;
1196                 lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
1197                 lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
1198                 lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
1199                 break;
1200         }
1201         case SPI_GETWORKAREA:
1202                 SetRect32( (RECT32 *)lpvParam, 0, 0,
1203                         GetSystemMetrics32( SM_CXSCREEN ),
1204                         GetSystemMetrics32( SM_CYSCREEN )
1205                 );
1206                 break;
1207         case SPI_GETNONCLIENTMETRICS: 
1208
1209 #define lpnm ((LPNONCLIENTMETRICS32A)lpvParam)
1210                 
1211                 if( lpnm->cbSize == sizeof(NONCLIENTMETRICS32A) )
1212                 {
1213                     /* FIXME: initialize geometry entries */
1214
1215                     SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
1216                                                         (LPVOID)&(lpnm->lfCaptionFont),0);
1217                     lpnm->lfCaptionFont.lfWeight = FW_BOLD;
1218                     SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
1219                                                         (LPVOID)&(lpnm->lfMenuFont),0);
1220                     SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
1221                                                         (LPVOID)&(lpnm->lfStatusFont),0);
1222                     SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
1223                                                         (LPVOID)&(lpnm->lfMessageFont),0);
1224                 }
1225 #undef lpnm
1226                 break;
1227
1228         case SPI_GETANIMATION: {
1229                 LPANIMATIONINFO lpAnimInfo = (LPANIMATIONINFO)lpvParam;
1230  
1231                 /* Tell it "disabled" */
1232                 lpAnimInfo->cbSize = sizeof(ANIMATIONINFO);
1233                 uParam = sizeof(ANIMATIONINFO);
1234                 lpAnimInfo->iMinAnimate = 0; /* Minimise and restore animation is disabled (nonzero == enabled) */
1235                 break;
1236         }
1237  
1238         case SPI_SETANIMATION: {
1239                 LPANIMATIONINFO lpAnimInfo = (LPANIMATIONINFO)lpvParam;
1240  
1241                 /* Do nothing */
1242                 WARN(system, "SPI_SETANIMATION ignored.\n");
1243                 lpAnimInfo->cbSize = sizeof(ANIMATIONINFO);
1244                 uParam = sizeof(ANIMATIONINFO);
1245                 break;
1246         }
1247
1248         case SPI_GETHIGHCONTRAST:
1249         {
1250                 LPHIGHCONTRASTA lpHighContrastA = (LPHIGHCONTRASTA)lpvParam;
1251
1252                 FIXME(system,"SPI_GETHIGHCONTRAST not fully implemented\n");
1253
1254                 if ( lpHighContrastA->cbSize == sizeof( HIGHCONTRASTA ) )
1255                 {
1256                         /* Indicate that there is no high contrast available */
1257                         lpHighContrastA->dwFlags = 0;
1258                         lpHighContrastA->lpszDefaultScheme = NULL;
1259                 }
1260                 else
1261                 {
1262                         return FALSE;
1263                 }
1264
1265                 break;
1266         }
1267
1268         default:
1269                 return SystemParametersInfo16(uAction,uParam,lpvParam,fuWinIni);
1270         }
1271         return TRUE;
1272 }
1273
1274
1275 /***********************************************************************
1276  *      SystemParametersInfo16   (USER.483)
1277  */
1278 BOOL16 WINAPI SystemParametersInfo16( UINT16 uAction, UINT16 uParam,
1279                                       LPVOID lpvParam, UINT16 fuWinIni )
1280 {
1281         int timeout, temp;
1282         char buffer[256];
1283         XKeyboardState          keyboard_state;
1284         XKeyboardControl        keyboard_value;
1285
1286
1287         switch (uAction)
1288         {
1289                 case SPI_GETBEEP:
1290                         TSXGetKeyboardControl(display, &keyboard_state);
1291                         if (keyboard_state.bell_percent == 0)
1292                                 *(BOOL16 *) lpvParam = FALSE;
1293                         else
1294                                 *(BOOL16 *) lpvParam = TRUE;
1295                         break;
1296                 
1297                 case SPI_GETBORDER:
1298                         *(INT16 *)lpvParam = GetSystemMetrics16( SM_CXFRAME );
1299                         break;
1300
1301                 case SPI_GETFASTTASKSWITCH:
1302                     if ( GetProfileInt32A( "windows", "CoolSwitch", 1 ) == 1 )
1303                           *(BOOL16 *) lpvParam = TRUE;
1304                         else
1305                           *(BOOL16 *) lpvParam = FALSE;
1306                         break;
1307
1308                 case SPI_GETGRIDGRANULARITY:
1309                     *(INT16 *) lpvParam = GetProfileInt32A( "desktop", 
1310                                                           "GridGranularity",
1311                                                           1 );
1312                     break;
1313
1314                 case SPI_GETICONTITLEWRAP:
1315                     *(BOOL16 *) lpvParam = GetProfileInt32A( "desktop",
1316                                                            "IconTitleWrap",
1317                                                            TRUE );
1318                     break;
1319
1320                 case SPI_GETKEYBOARDDELAY:
1321                     *(INT16 *) lpvParam = GetProfileInt32A( "keyboard",
1322                                                           "KeyboardDelay", 1 );
1323                     break;
1324
1325                 case SPI_GETKEYBOARDSPEED:
1326                     *(WORD *) lpvParam = GetProfileInt32A( "keyboard",
1327                                                            "KeyboardSpeed",
1328                                                            30 );
1329                     break;
1330
1331                 case SPI_GETMENUDROPALIGNMENT:
1332                         *(BOOL16 *) lpvParam = GetSystemMetrics16( SM_MENUDROPALIGNMENT ); /* XXX check this */
1333                         break;
1334
1335                 case SPI_GETSCREENSAVEACTIVE:
1336                     if ( GetProfileInt32A( "windows", "ScreenSaveActive", 1 ) == 1 )
1337                         *(BOOL16 *) lpvParam = TRUE;
1338                     else
1339                         *(BOOL16 *) lpvParam = FALSE;
1340                     break;
1341
1342                 case SPI_GETSCREENSAVETIMEOUT:
1343                         /* FIXME GetProfileInt( "windows", "ScreenSaveTimeout", 300 ); */
1344                         TSXGetScreenSaver(display, &timeout, &temp,&temp,&temp);
1345                         *(INT16 *) lpvParam = timeout;
1346                         break;
1347
1348                 case SPI_ICONHORIZONTALSPACING:
1349                     /* FIXME Get/SetProfileInt */
1350                         if (lpvParam == NULL)
1351                             /*SetSystemMetrics( SM_CXICONSPACING, uParam )*/ ;
1352                         else
1353                             *(INT16 *)lpvParam = GetSystemMetrics16( SM_CXICONSPACING );
1354                         break;
1355
1356                 case SPI_ICONVERTICALSPACING:
1357                     /* FIXME Get/SetProfileInt */
1358                     if (lpvParam == NULL)
1359                         /*SetSystemMetrics( SM_CYICONSPACING, uParam )*/ ;
1360                     else
1361                         *(INT16 *)lpvParam = GetSystemMetrics16(SM_CYICONSPACING);
1362                     break;
1363
1364                 case SPI_SETBEEP:
1365                         if (uParam == TRUE)
1366                                 keyboard_value.bell_percent = -1;
1367                         else
1368                                 keyboard_value.bell_percent = 0;                        
1369                         TSXChangeKeyboardControl(display, KBBellPercent, 
1370                                                         &keyboard_value);
1371                         break;
1372
1373                 case SPI_SETSCREENSAVEACTIVE:
1374                         if (uParam == TRUE)
1375                                 TSXActivateScreenSaver(display);
1376                         else
1377                                 TSXResetScreenSaver(display);
1378                         break;
1379
1380                 case SPI_SETSCREENSAVETIMEOUT:
1381                         TSXSetScreenSaver(display, uParam, 60, DefaultBlanking, 
1382                                                         DefaultExposures);
1383                         break;
1384
1385                 case SPI_SETDESKWALLPAPER:
1386                         return (SetDeskWallPaper32((LPSTR) lpvParam));
1387                         break;
1388
1389                 case SPI_SETDESKPATTERN:
1390                         if ((INT16)uParam == -1) {
1391                                 GetProfileString32A("Desktop", "Pattern", 
1392                                                 "170 85 170 85 170 85 170 85", 
1393                                                 buffer, sizeof(buffer) );
1394                                 return (DESKTOP_SetPattern((LPSTR) buffer));
1395                         } else
1396                                 return (DESKTOP_SetPattern((LPSTR) lpvParam));
1397                         break;
1398
1399                 case SPI_GETICONTITLELOGFONT: 
1400                 {
1401                     LPLOGFONT16 lpLogFont = (LPLOGFONT16)lpvParam;
1402
1403                     GetProfileString32A("Desktop", "IconTitleFaceName", "MS Sans Serif", 
1404                                         lpLogFont->lfFaceName, LF_FACESIZE );
1405                     lpLogFont->lfHeight = -GetProfileInt32A("Desktop","IconTitleSize", 8);
1406                     lpLogFont->lfWidth = 0;
1407                     lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
1408                     lpLogFont->lfWeight = FW_NORMAL;
1409                     lpLogFont->lfItalic = FALSE;
1410                     lpLogFont->lfStrikeOut = FALSE;
1411                     lpLogFont->lfUnderline = FALSE;
1412                     lpLogFont->lfCharSet = ANSI_CHARSET;
1413                     lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
1414                     lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
1415                     lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
1416                     break;
1417                 }
1418                 case SPI_GETNONCLIENTMETRICS:
1419
1420 #define lpnm ((LPNONCLIENTMETRICS16)lpvParam)
1421                     if( lpnm->cbSize == sizeof(NONCLIENTMETRICS16) )
1422                     {
1423                         /* FIXME: initialize geometry entries */
1424                         SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0, 
1425                                                         (LPVOID)&(lpnm->lfCaptionFont),0);
1426                         lpnm->lfCaptionFont.lfWeight = FW_BOLD;
1427                         SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
1428                                                         (LPVOID)&(lpnm->lfMenuFont),0);
1429                         SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
1430                                                         (LPVOID)&(lpnm->lfStatusFont),0);
1431                         SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
1432                                                         (LPVOID)&(lpnm->lfMessageFont),0);
1433                     }
1434                     else /* winfile 95 sets sbSize to 340 */
1435                         SystemParametersInfo32A( uAction, uParam, lpvParam, fuWinIni );
1436 #undef lpnm
1437                     break;
1438
1439                 case SPI_LANGDRIVER:
1440                 case SPI_SETBORDER:
1441                 case SPI_SETDOUBLECLKHEIGHT:
1442                 case SPI_SETDOUBLECLICKTIME:
1443                 case SPI_SETDOUBLECLKWIDTH:
1444                 case SPI_SETFASTTASKSWITCH:
1445                 case SPI_SETKEYBOARDDELAY:
1446                 case SPI_SETKEYBOARDSPEED:
1447                         WARN(system, "Option %d ignored.\n", uAction);
1448                         break;
1449
1450                 case SPI_GETWORKAREA:
1451                     SetRect16( (RECT16 *)lpvParam, 0, 0,
1452                                GetSystemMetrics16( SM_CXSCREEN ),
1453                                GetSystemMetrics16( SM_CYSCREEN ) );
1454                     break;
1455
1456                 default:
1457                         WARN(system, "Unknown option %d.\n", uAction);
1458                         break;
1459         }
1460         return 1;
1461 }
1462
1463 /***********************************************************************
1464  *      SystemParametersInfo32W   (USER32.541)
1465  */
1466 BOOL32 WINAPI SystemParametersInfo32W( UINT32 uAction, UINT32 uParam,
1467                                        LPVOID lpvParam, UINT32 fuWinIni )
1468 {
1469     char buffer[256];
1470
1471     switch (uAction)
1472     {
1473     case SPI_SETDESKWALLPAPER:
1474         if (lpvParam)
1475         {
1476             lstrcpynWtoA(buffer,(LPWSTR)lpvParam,sizeof(buffer));
1477             return SetDeskWallPaper32(buffer);
1478         }
1479         return SetDeskWallPaper32(NULL);
1480
1481     case SPI_SETDESKPATTERN:
1482         if ((INT32) uParam == -1)
1483         {
1484             GetProfileString32A("Desktop", "Pattern", 
1485                                 "170 85 170 85 170 85 170 85", 
1486                                 buffer, sizeof(buffer) );
1487             return (DESKTOP_SetPattern((LPSTR) buffer));
1488         }
1489         if (lpvParam)
1490         {
1491             lstrcpynWtoA(buffer,(LPWSTR)lpvParam,sizeof(buffer));
1492             return DESKTOP_SetPattern(buffer);
1493         }
1494         return DESKTOP_SetPattern(NULL);
1495
1496     case SPI_GETICONTITLELOGFONT:
1497         {
1498             /* FIXME GetProfileString32A( "?", "?", "?" ) */
1499             LPLOGFONT32W lpLogFont = (LPLOGFONT32W)lpvParam;
1500             lpLogFont->lfHeight = 10;
1501             lpLogFont->lfWidth = 0;
1502             lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
1503             lpLogFont->lfWeight = FW_NORMAL;
1504             lpLogFont->lfItalic = lpLogFont->lfStrikeOut = lpLogFont->lfUnderline = FALSE;
1505             lpLogFont->lfCharSet = ANSI_CHARSET;
1506             lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
1507             lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
1508             lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
1509         }
1510         break;
1511     case SPI_GETNONCLIENTMETRICS: {
1512         /* FIXME: implement correctly */
1513         LPNONCLIENTMETRICS32W   lpnm=(LPNONCLIENTMETRICS32W)lpvParam;
1514
1515         SystemParametersInfo32W(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfCaptionFont),0);
1516         lpnm->lfCaptionFont.lfWeight = FW_BOLD;
1517         SystemParametersInfo32W(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfMenuFont),0);
1518         SystemParametersInfo32W(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfStatusFont),0);
1519         SystemParametersInfo32W(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfMessageFont),0);
1520         break;
1521     }
1522
1523     case SPI_GETHIGHCONTRAST:
1524     {
1525        LPHIGHCONTRASTW lpHighContrastW = (LPHIGHCONTRASTW)lpvParam;
1526
1527        FIXME(system,"SPI_GETHIGHCONTRAST not fully implemented\n");
1528
1529        if ( lpHighContrastW->cbSize == sizeof( HIGHCONTRASTW ) )
1530        {
1531           /* Indicate that there is no high contrast available */
1532           lpHighContrastW->dwFlags = 0;
1533           lpHighContrastW->lpszDefaultScheme = NULL;
1534        }
1535        else
1536        {
1537           return FALSE;
1538        }
1539
1540        break;
1541     }
1542
1543     default:
1544         return SystemParametersInfo32A(uAction,uParam,lpvParam,fuWinIni);
1545         
1546     }
1547     return TRUE;
1548 }
1549
1550
1551 /***********************************************************************
1552 *       FileCDR (KERNEL.130)
1553 */
1554 FARPROC16 WINAPI FileCDR(FARPROC16 x)
1555 {
1556         FIXME(file,"(0x%8x): stub\n", (int) x);
1557         return (FARPROC16)TRUE;
1558 }