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