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