Check for drivers==NULL before trying to delete them at exit. This
[wine] / misc / main.c
1 /*
2  * Main function.
3  *
4  * Copyright 1994 Alexandre Julliard
5  */
6
7 #include "config.h"
8
9 #ifndef X_DISPLAY_MISSING
10 #include "x11drv.h"
11 #else /* !defined(X_DISPLAY_MISSING) */
12 #include "ttydrv.h"
13 #endif /* !defined(X_DISPLAY_MISSING) */
14
15 #include <locale.h>
16 #include <ctype.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <unistd.h>
20 #ifdef MALLOC_DEBUGGING
21 # include <malloc.h>
22 #endif
23
24 #include "winbase.h"
25 #include "winsock.h"
26 #include "heap.h"
27 #include "message.h"
28 #include "msdos.h"
29 #include "color.h"
30 #include "options.h"
31 #include "desktop.h"
32 #include "builtin32.h"
33 #include "debug.h"
34 #include "debugdefs.h"
35 #include "xmalloc.h"
36 #include "module.h"
37 #include "version.h"
38 #include "winnls.h"
39 #include "console.h"
40 #include "monitor.h"
41 #include "keyboard.h"
42 #include "gdi.h"
43 #include "user.h"
44 #include "wine/winuser16.h"
45
46 /**********************************************************************/
47
48 USER_DRIVER *USER_Driver = NULL;
49
50 /* when adding new languages look at ole/ole2nls.c 
51  * for proper iso name and Windows code (add 0x0400 
52  * to the code listed there)
53  */
54 const WINE_LANGUAGE_DEF Languages[] =
55 {
56     {"En",0x0409},      /* LANG_En */
57     {"Es",0x040A},      /* LANG_Es */
58     {"De",0x0407},      /* LANG_De */
59     {"No",0x0414},      /* LANG_No */
60     {"Fr",0x040C},      /* LANG_Fr */
61     {"Fi",0x040B},      /* LANG_Fi */
62     {"Da",0x0406},      /* LANG_Da */
63     {"Cs",0x0405},      /* LANG_Cs */
64     {"Eo",0x048f},      /* LANG_Eo */
65     {"It",0x0410},      /* LANG_It */
66     {"Ko",0x0412},      /* LANG_Ko */
67     {"Hu",0x040e},      /* LANG_Hu */
68     {"Pl",0x0415},      /* LANG_Pl */
69     {"Pt",0x0416},      /* LANG_Pt */
70     {"Sv",0x041d},      /* LANG_Sv */
71     {"Ca",0x0403},      /* LANG_Ca */
72     {"Nl",0x0413},      /* LANG_Nl */
73     {"Ru",0x0419},      /* LANG_Ru */
74     {NULL,0}
75 };
76
77 WORD WINE_LanguageId = 0x409;   /* english as default */
78
79 struct options Options =
80 {  /* default options */
81     0,              /* argc */
82     NULL,           /* argv */
83     NULL,           /* desktopGeometry */
84     NULL,           /* programName */
85     NULL,           /* argv0 */
86     NULL,           /* dllFlags */
87     FALSE,          /* usePrivateMap */
88     FALSE,          /* useFixedMap */
89     FALSE,          /* synchronous */
90     FALSE,          /* backing store */
91     SW_SHOWNORMAL,  /* cmdShow */
92     FALSE,
93     FALSE,          /* failReadOnly */
94     MODE_ENHANCED,  /* Enhanced mode */
95 #ifdef DEFAULT_LANG
96     DEFAULT_LANG,   /* Default language */
97 #else
98     LANG_En,
99 #endif
100     FALSE,          /* Managed windows */
101     FALSE,          /* Perfect graphics */
102     FALSE,          /* No DGA */
103     NULL,           /* Alternate config file name */
104     0               /* screenDepth */
105 };
106
107 static char szUsage[] =
108   "%s\n"
109   "Usage:  %s [options] \"program_name [arguments]\"\n"
110   "\n"
111   "Options:\n"
112   "    -backingstore   Turn on backing store\n"
113   "    -config name    Specify config file to use\n"
114   "    -console driver Select which driver(s) to use for the console\n"
115   "    -debug          Enter debugger before starting application\n"
116   "    -debugmsg name  Turn debugging-messages on or off\n"
117   "    -depth n        Change the depth to use for multiple-depth screens\n"
118   "    -desktop geom   Use a desktop window of the given geometry\n"
119   "    -display name   Use the specified display\n"
120   "    -dll name       Enable or disable built-in DLLs\n"
121   "    -failreadonly   Read only files may not be opened in write mode\n"
122   "    -fixedmap       Use a \"standard\" color map\n"
123   "    -help           Show this help message\n"
124   "    -iconic         Start as an icon\n"
125   "    -language xx    Set the language (one of Ca,Cs,Da,De,En,Eo,Es,Fi,Fr,Hu,It,\n"
126   "                    Ko,Nl,No,Pl,Pt,Sv,Ru)\n"
127   "    -managed        Allow the window manager to manage created windows\n"
128   "    -mode mode      Start Wine in a particular mode (standard or enhanced)\n"
129   "    -name name      Set the application name\n"
130   "    -nodga          Disable XFree86 DGA extensions\n"
131   "    -perfect        Favor correctness over speed for graphical operations\n"
132   "    -privatemap     Use a private color map\n"
133   "    -synchronous    Turn on synchronous display mode\n"
134   "    -version        Display the Wine version\n"
135   "    -winver         Version to imitate (one of win31,win95,nt351,nt40)\n"
136   "    -dosver         DOS version to imitate (x.xx, e.g. 6.22). Only valid with -winver win31\n"
137   ;
138
139 /***********************************************************************
140  *           MAIN_Usage
141  */
142 void MAIN_Usage( char *name )
143 {
144     MSG( szUsage, WINE_RELEASE_INFO, name );
145     exit(1);
146 }
147
148 /***********************************************************************
149  *           MAIN_GetProgramName
150  *
151  * Get the program name. The name is specified by (in order of precedence):
152  * - the option '-name'.
153  * - the environment variable 'WINE_NAME'.
154  * - the last component of argv[0].
155  */
156 static char *MAIN_GetProgramName( int argc, char *argv[] )
157 {
158     int i;
159     char *p;
160
161     for (i = 1; i < argc-1; i++)
162         if (!strcmp( argv[i], "-name" )) return argv[i+1];
163     if ((p = getenv( "WINE_NAME" )) != NULL) return p;
164     if ((p = strrchr( argv[0], '/' )) != NULL) return p+1;
165     return argv[0];
166 }
167
168 /***********************************************************************
169  *          MAIN_ParseDebugOptions
170  *
171  *  Turns specific debug messages on or off, according to "options".
172  *  
173  *  RETURNS
174  *    TRUE if parsing was successful
175  */
176 BOOL MAIN_ParseDebugOptions(char *options)
177 {
178   /* defined in relay32/relay386.c */
179   extern char **debug_relay_includelist;
180   extern char **debug_relay_excludelist;
181   /* defined in relay32/snoop.c */
182   extern char **debug_snoop_includelist;
183   extern char **debug_snoop_excludelist;
184
185   int i;
186   int l, cls, dotracerelay = TRACE_ON(relay);
187
188   l = strlen(options);
189   if (l<3)
190     return FALSE;
191   if (options[l-1]=='\n') options[l-1]='\0';
192   do
193   {
194     if ((*options!='+')&&(*options!='-')){
195       int j;
196
197       for(j=0; j<DEBUG_CLASS_COUNT; j++)
198         if(!lstrncmpiA(options, debug_cl_name[j], strlen(debug_cl_name[j])))
199           break;
200       if(j==DEBUG_CLASS_COUNT)
201         goto error;
202       options += strlen(debug_cl_name[j]);
203       if ((*options!='+')&&(*options!='-'))
204         goto error;
205       cls = j;
206     }
207     else
208       cls = -1; /* all classes */
209
210     if (strchr(options,','))
211       l=strchr(options,',')-options;
212     else
213       l=strlen(options);
214
215     if (!lstrncmpiA(options+1,"all",l-1))
216       {
217         int i, j;
218         for (i=0; i<DEBUG_CHANNEL_COUNT; i++)
219           for(j=0; j<DEBUG_CLASS_COUNT; j++)
220             if(cls == -1 || cls == j)
221               debug_msg_enabled[i][j]=(*options=='+');
222       }
223     else if (!lstrncmpiA(options+1, "relay=", 6) ||
224              !lstrncmpiA(options+1, "snoop=", 6))
225       {
226         int i, j;
227         char *s, *s2, ***output, c;
228
229         for (i=0; i<DEBUG_CHANNEL_COUNT; i++)
230           if (debug_ch_name && (!lstrncmpiA(debug_ch_name[i],options+1,5))){
231             for(j=0; j<DEBUG_CLASS_COUNT; j++)
232               if(cls == -1 || cls == j)
233                 debug_msg_enabled[i][j]=TRUE;
234             break;
235           }
236         /* should never happen, maybe assert(i!=DEBUG_CHANNEL_COUNT)? */
237         if (i==DEBUG_CHANNEL_COUNT)
238           goto error;
239         output = (*options == '+') ?
240                         ((*(options+1) == 'r') ?
241                                 &debug_relay_includelist :
242                                 &debug_snoop_includelist) :
243                         ((*(options+1) == 'r') ?
244                                 &debug_relay_excludelist :
245                                 &debug_snoop_excludelist);
246         s = options + 7;
247         i = 1;
248         while((s = strchr(s, ':'))) i++, s++;
249         *output = malloc(sizeof(char **) * i + 1);
250         i = 0;
251         s = options + 7;
252         while((s2 = strchr(s, ':'))) {
253           c = *s2;
254           *s2 = '\0';
255           *((*output)+i) = strdup(s);
256           *s2 = c;
257           s = s2 + 1;
258           i++;
259         }
260         c = *(options + l);
261         *(options + l) = '\0';
262         *((*output)+i) = strdup(s);
263         *(options + l) = c;
264         *((*output)+i+1) = NULL;
265       }
266     else
267       {
268         int i, j;
269         for (i=0; i<DEBUG_CHANNEL_COUNT; i++)
270           if (debug_ch_name && (!lstrncmpiA(options+1,debug_ch_name[i],l-1))){
271             for(j=0; j<DEBUG_CLASS_COUNT; j++)
272               if(cls == -1 || cls == j)
273                 debug_msg_enabled[i][j]=(*options=='+');
274             break;
275           }
276         if (i==DEBUG_CHANNEL_COUNT)
277           goto error;
278       }
279     options+=l;
280   }
281   while((*options==',')&&(*(++options)));
282
283   /* special handling for relay debugging */
284   if (dotracerelay != TRACE_ON(relay))
285         BUILTIN32_SwitchRelayDebug( TRACE_ON(relay) );
286
287   if (!*options)
288     return TRUE;
289
290  error:  
291   MSG("%s: Syntax: -debugmsg [class]+xxx,...  or "
292       "-debugmsg [class]-xxx,...\n",Options.argv[0]);
293   MSG("Example: -debugmsg +all,warn-heap\n"
294       "  turn on all messages except warning heap messages\n");
295   MSG("Special case: -debugmsg +relay=DLL:DLL.###:FuncName\n"
296       "  turn on -debugmsg +relay only as specified\n"
297       "Special case: -debugmsg -relay=DLL:DLL.###:FuncName\n"
298       "  turn on -debugmsg +relay except as specified\n"
299       "Also permitted, +snoop=..., -snoop=... as with relay.\n\n");
300   
301   MSG("Available message classes:\n");
302   for(i=0;i<DEBUG_CLASS_COUNT;i++)
303     MSG( "%-9s", debug_cl_name[i]);
304   MSG("\n\n");
305   
306   MSG("Available message types:\n");
307   MSG("%-9s ","all");
308   for(i=0;i<DEBUG_CHANNEL_COUNT;i++)
309     if(debug_ch_name[i])
310       MSG("%-9s%c",debug_ch_name[i],
311           (((i+2)%8==0)?'\n':' '));
312   MSG("\n\n");
313   exit(1);
314 }
315
316 /***********************************************************************
317  *           MAIN_GetLanguageID
318  *
319  * INPUT:
320  *      Lang: a string whose two first chars are the iso name of a language.
321  *      Country: a string whose two first chars are the iso name of country
322  *      Charset: a string defining the chossen charset encoding
323  *      Dialect: a string defining a variation of the locale
324  *
325  *      all those values are from the standardized format of locale
326  *      name in unix which is: Lang[_Country][.Charset][@Dialect]
327  *
328  * RETURNS:
329  *      the numeric code of the language used by Windows (or 0x00)
330  */
331 int MAIN_GetLanguageID(LPCSTR Lang,LPCSTR Country,LPCSTR Charset,LPCSTR Dialect)
332 {
333     char lang[3]="??", country[3]={0,0,0};
334     char *charset=NULL, *dialect=NULL;
335     int i,j,ret=0;
336
337     if (Lang==NULL) return 0x00;
338     if (Lang[0]) lang[0]=tolower(Lang[0]);
339     if (Lang[1]) lang[1]=tolower(Lang[1]);
340
341     if (Country!=NULL) {
342         if (Country[0]) country[0]=toupper(Country[0]);
343         if (Country[1]) country[1]=toupper(Country[1]);
344     }
345
346     if (Charset!=NULL) {
347         j=strlen(Charset);
348         charset=(char*)malloc(j+1);
349         for (i=0;i<j;i++)
350             charset[i]=toupper(Charset[i]);
351         charset[i]='\0';
352     }
353
354     if (Dialect!=NULL) {
355         j=strlen(Dialect);
356         dialect=(char*)malloc(j+1);
357         for (i=0;i<j;i++)
358             dialect[i]=tolower(Dialect[i]);
359         dialect[i]='\0';
360     } else {
361         dialect = malloc(1);
362         dialect[0] = '\0';
363     }
364
365 #define LANG_ENTRY_BEGIN(x,y)   if(!strcmp(lang, x )) { \
366                                     if (!country[0]) { \
367                                         ret=LANG_##y ; \
368                                         goto end_MAIN_GetLanguageID; \
369                                     }
370 #define LANG_SUB_ENTRY(x,y,z)       if (!strcmp(country, x )) \
371                                         ret = MAKELANGID( LANG_##y , SUBLANG_##z ); \
372                                         goto end_MAIN_GetLanguageID;
373 #define LANG_DIALECT_ENTRY(x,y)     { ret = MAKELANGID(LANG_##x , SUBLANG_##y ); \
374                                     goto end_MAIN_GetLanguageID; }
375 #define LANG_ENTRY_END(x)           ret = MAKELANGID(LANG_##x , SUBLANG_DEFAULT); \
376                                     goto end_MAIN_GetLanguageID; \
377                                 }
378
379 /*x01*/ LANG_ENTRY_BEGIN( "ar", ARABIC )
380         LANG_SUB_ENTRY( "SA", ARABIC, ARABIC)
381         LANG_SUB_ENTRY( "IQ", ARABIC, ARABIC_IRAQ )
382         LANG_SUB_ENTRY( "EG", ARABIC, ARABIC_EGYPT )
383         LANG_SUB_ENTRY( "LY", ARABIC, ARABIC_LIBYA )
384         LANG_SUB_ENTRY( "DZ", ARABIC, ARABIC_ALGERIA )
385         LANG_SUB_ENTRY( "MA", ARABIC, ARABIC_MOROCCO )
386         LANG_SUB_ENTRY( "TN", ARABIC, ARABIC_TUNISIA )
387         LANG_SUB_ENTRY( "OM", ARABIC, ARABIC_OMAN )
388         LANG_SUB_ENTRY( "YE", ARABIC, ARABIC_YEMEN )
389         LANG_SUB_ENTRY( "SY", ARABIC, ARABIC_SYRIA )
390         LANG_SUB_ENTRY( "JO", ARABIC, ARABIC_JORDAN )
391         LANG_SUB_ENTRY( "LB", ARABIC, ARABIC_LEBANON )
392         LANG_SUB_ENTRY( "KW", ARABIC, ARABIC_KUWAIT )
393         LANG_SUB_ENTRY( "AE", ARABIC, ARABIC_UAE )
394         LANG_SUB_ENTRY( "BH", ARABIC, ARABIC_BAHRAIN )
395         LANG_SUB_ENTRY( "QA", ARABIC, ARABIC_QATAR )
396         LANG_ENTRY_END( ARABIC )
397 /*x02*/ LANG_ENTRY_BEGIN( "bu", BULGARIAN )
398         LANG_ENTRY_END( BULGARIAN )
399 /*x03*/ LANG_ENTRY_BEGIN( "ca", CATALAN )
400         LANG_ENTRY_END( CATALAN )
401 /*x04*/ LANG_ENTRY_BEGIN( "zh", CHINESE )
402         LANG_SUB_ENTRY( "TW", CHINESE, CHINESE_TRADITIONAL )
403         LANG_SUB_ENTRY( "CN", CHINESE, CHINESE_SIMPLIFIED )
404         LANG_SUB_ENTRY( "HK", CHINESE, CHINESE_HONGKONG )
405         LANG_SUB_ENTRY( "SG", CHINESE, CHINESE_SINGAPORE )
406         LANG_SUB_ENTRY( "MO", CHINESE, CHINESE_MACAU )
407         LANG_ENTRY_END( CHINESE )
408 /*x05*/ LANG_ENTRY_BEGIN( "cs", CZECH )
409         LANG_ENTRY_END( CZECH )
410 /*x06*/ LANG_ENTRY_BEGIN( "da", DANISH )
411         LANG_ENTRY_END( DANISH )
412 /*x07*/ LANG_ENTRY_BEGIN( "de", GERMAN )
413         LANG_SUB_ENTRY( "DE", GERMAN, GERMAN )
414         LANG_SUB_ENTRY( "CH", GERMAN, GERMAN_SWISS )
415         LANG_SUB_ENTRY( "AT", GERMAN, GERMAN_AUSTRIAN )
416         LANG_SUB_ENTRY( "LU", GERMAN, GERMAN_LUXEMBOURG )
417         LANG_SUB_ENTRY( "LI", GERMAN, GERMAN_LIECHTENSTEIN )
418         LANG_ENTRY_END( GERMAN )
419 /*x08*/ LANG_ENTRY_BEGIN( "el", GREEK )
420         LANG_ENTRY_END( GREEK )
421 /*x09*/ LANG_ENTRY_BEGIN( "en", ENGLISH )
422         LANG_SUB_ENTRY( "US", ENGLISH, ENGLISH_US )
423         LANG_SUB_ENTRY( "UK", ENGLISH, ENGLISH_UK )
424         LANG_SUB_ENTRY( "AU", ENGLISH, ENGLISH_AUS )
425         LANG_SUB_ENTRY( "CA", ENGLISH, ENGLISH_CAN )
426         LANG_SUB_ENTRY( "NZ", ENGLISH, ENGLISH_NZ )
427         LANG_SUB_ENTRY( "EI", ENGLISH, ENGLISH_EIRE )
428         LANG_SUB_ENTRY( "ZA", ENGLISH, ENGLISH_SAFRICA )
429         LANG_SUB_ENTRY( "JM", ENGLISH, ENGLISH_JAMAICA )
430      /* LANG_SUB_ENTRY( "AG", ENGLISH, ENGLISH_CARIBBEAN ) */
431         LANG_SUB_ENTRY( "BZ", ENGLISH, ENGLISH_BELIZE )
432         LANG_SUB_ENTRY( "TT", ENGLISH, ENGLISH_TRINIDAD )
433         LANG_SUB_ENTRY( "ZW", ENGLISH, ENGLISH_ZIMBABWE )
434         LANG_SUB_ENTRY( "PH", ENGLISH, ENGLISH_PHILIPPINES )
435         LANG_ENTRY_END( ENGLISH )
436 /*x0a*/ LANG_ENTRY_BEGIN( "es", SPANISH )
437         /* traditional sorting */
438         if (!strcmp(dialect,"tradicional"))
439                 LANG_DIALECT_ENTRY( SPANISH, SPANISH )
440         LANG_SUB_ENTRY( "MX", SPANISH, SPANISH_MEXICAN )
441         LANG_SUB_ENTRY( "ES", SPANISH, SPANISH_MODERN )
442         LANG_SUB_ENTRY( "GT", SPANISH, SPANISH_GUATEMALA )
443         LANG_SUB_ENTRY( "CR", SPANISH, SPANISH_COSTARICA )
444         LANG_SUB_ENTRY( "PA", SPANISH, SPANISH_PANAMA )
445         LANG_SUB_ENTRY( "DO", SPANISH, SPANISH_DOMINICAN )
446         LANG_SUB_ENTRY( "VE", SPANISH, SPANISH_VENEZUELA )
447         LANG_SUB_ENTRY( "CO", SPANISH, SPANISH_COLOMBIA )
448         LANG_SUB_ENTRY( "PE", SPANISH, SPANISH_PERU )
449         LANG_SUB_ENTRY( "AR", SPANISH, SPANISH_ARGENTINA )
450         LANG_SUB_ENTRY( "EC", SPANISH, SPANISH_ECUADOR )
451         LANG_SUB_ENTRY( "CL", SPANISH, SPANISH_CHILE )
452         LANG_SUB_ENTRY( "UY", SPANISH, SPANISH_URUGUAY )
453         LANG_SUB_ENTRY( "PY", SPANISH, SPANISH_PARAGUAY )
454         LANG_SUB_ENTRY( "BO", SPANISH, SPANISH_BOLIVIA )
455         LANG_SUB_ENTRY( "HN", SPANISH, SPANISH_HONDURAS )
456         LANG_SUB_ENTRY( "NI", SPANISH, SPANISH_NICARAGUA )
457         LANG_SUB_ENTRY( "PR", SPANISH, SPANISH_PUERTO_RICO )
458         LANG_ENTRY_END( SPANISH )
459 /*x0b*/ LANG_ENTRY_BEGIN( "fi", FINNISH )
460         LANG_ENTRY_END( FINNISH )
461 /*x0c*/ LANG_ENTRY_BEGIN( "fr", FRENCH )
462         LANG_SUB_ENTRY( "FR", FRENCH, FRENCH )
463         LANG_SUB_ENTRY( "BE", FRENCH, FRENCH_BELGIAN )
464         LANG_SUB_ENTRY( "CA", FRENCH, FRENCH_CANADIAN )
465         LANG_SUB_ENTRY( "CH", FRENCH, FRENCH_SWISS )
466         LANG_SUB_ENTRY( "LU", FRENCH, FRENCH_LUXEMBOURG )
467         LANG_SUB_ENTRY( "MC", FRENCH, FRENCH_MONACO )
468         LANG_ENTRY_END( FRENCH )
469 /*x0d*/ LANG_ENTRY_BEGIN( "iw", HEBREW )
470         LANG_ENTRY_END( HEBREW )
471 /*x0e*/ LANG_ENTRY_BEGIN( "hu", HUNGARIAN )
472         LANG_ENTRY_END( HUNGARIAN )
473 /*x0f*/ LANG_ENTRY_BEGIN( "ic", ICELANDIC )
474         LANG_ENTRY_END( ICELANDIC )
475 /*x10*/ LANG_ENTRY_BEGIN( "it", ITALIAN )
476         LANG_SUB_ENTRY( "IT", ITALIAN, ITALIAN )
477         LANG_SUB_ENTRY( "CH", ITALIAN, ITALIAN_SWISS )
478         LANG_ENTRY_END( ITALIAN )
479 /*x11*/ LANG_ENTRY_BEGIN( "ja", JAPANESE )
480         LANG_ENTRY_END( JAPANESE )
481 /*x12*/ LANG_ENTRY_BEGIN( "ko", KOREAN )
482         /* JOHAB encoding */
483         if (!strcmp(charset,"JOHAB"))
484                 LANG_DIALECT_ENTRY( KOREAN, KOREAN_JOHAB )
485         else
486                 LANG_DIALECT_ENTRY( KOREAN, KOREAN )
487         LANG_ENTRY_END( KOREAN )
488 /*x13*/ LANG_ENTRY_BEGIN( "nl", DUTCH )
489         LANG_SUB_ENTRY( "NL", DUTCH, DUTCH )
490         LANG_SUB_ENTRY( "BE", DUTCH, DUTCH_BELGIAN )
491         LANG_SUB_ENTRY( "SR", DUTCH, DUTCH_SURINAM )
492         LANG_ENTRY_END( DUTCH )
493 /*x14*/ LANG_ENTRY_BEGIN( "no", NORWEGIAN )
494         /* nynorsk */
495         if (!strcmp(dialect,"nynorsk"))
496                 LANG_DIALECT_ENTRY( NORWEGIAN, NORWEGIAN_NYNORSK )
497         else
498                 LANG_DIALECT_ENTRY( NORWEGIAN, NORWEGIAN_BOKMAL )
499         LANG_ENTRY_END( NORWEGIAN )
500 /*x15*/ LANG_ENTRY_BEGIN( "pl", POLISH )
501         LANG_ENTRY_END( POLISH )
502 /*x16*/ LANG_ENTRY_BEGIN( "pt", PORTUGUESE )
503         LANG_SUB_ENTRY( "BR", PORTUGUESE, PORTUGUESE_BRAZILIAN )
504         LANG_SUB_ENTRY( "PT", PORTUGUESE, PORTUGUESE )
505         LANG_ENTRY_END( PORTUGUESE )
506 /*x17*/ LANG_ENTRY_BEGIN( "rm", RHAETO_ROMANCE )
507         LANG_ENTRY_END( RHAETO_ROMANCE )
508 /*x18*/ LANG_ENTRY_BEGIN( "ro", ROMANIAN )
509         LANG_SUB_ENTRY( "RO", ROMANIAN, ROMANIAN )
510         LANG_SUB_ENTRY( "MD", ROMANIAN, ROMANIAN_MOLDAVIA )
511         LANG_ENTRY_END( ROMANIAN )
512 /*x19*/ LANG_ENTRY_BEGIN( "ru", RUSSIAN )
513         LANG_SUB_ENTRY( "RU", RUSSIAN, RUSSIAN )
514         LANG_SUB_ENTRY( "MD", RUSSIAN, RUSSIAN_MOLDAVIA )
515         LANG_ENTRY_END( RUSSIAN )
516 /*x1a*/ if (!strcmp(lang,"sh") || !strcmp(lang,"hr") || !strcmp(lang,"sr")) {
517             if (!country[0]) 
518                 LANG_DIALECT_ENTRY( SERBO_CROATIAN, NEUTRAL)
519             if (!strcmp(charset,"ISO-8859-5"))
520                 LANG_DIALECT_ENTRY( SERBO_CROATIAN, SERBIAN )
521             LANG_SUB_ENTRY( "HR", SERBO_CROATIAN, CROATIAN )
522             if (!strcmp(country,"YU") && !strcmp(charset,"ISO-8859-2"))
523                 LANG_DIALECT_ENTRY( SERBO_CROATIAN, SERBIAN_LATIN )
524             LANG_SUB_ENTRY( "YU", SERBO_CROATIAN, SERBIAN )
525             LANG_DIALECT_ENTRY( SERBO_CROATIAN, SERBIAN_LATIN )
526         }
527 /*x1b*/ LANG_ENTRY_BEGIN( "sk", SLOVAK )
528         LANG_ENTRY_END( SLOVAK )
529 /*x1c*/ LANG_ENTRY_BEGIN( "sq", ALBANIAN )
530         LANG_ENTRY_END( ALBANIAN )
531 /*x1d*/ LANG_ENTRY_BEGIN( "sv", SWEDISH )
532         LANG_SUB_ENTRY( "SE", SWEDISH, SWEDISH )
533         LANG_SUB_ENTRY( "FI", SWEDISH, SWEDISH_FINLAND )
534         LANG_ENTRY_END( SWEDISH )
535 /*x1e*/ LANG_ENTRY_BEGIN( "th", THAI )
536         LANG_ENTRY_END( THAI )
537 /*x1f*/ LANG_ENTRY_BEGIN( "tr", TURKISH )
538         LANG_ENTRY_END( TURKISH )
539 /*x20*/ LANG_ENTRY_BEGIN( "ur", URDU )
540         LANG_ENTRY_END( URDU )
541 /*x21*/ LANG_ENTRY_BEGIN( "in", INDONESIAN )
542         LANG_ENTRY_END( INDONESIAN )
543 /*x22*/ LANG_ENTRY_BEGIN( "uk", UKRAINIAN )
544         LANG_ENTRY_END( UKRAINIAN )
545 /*x23*/ LANG_ENTRY_BEGIN( "be", BYELORUSSIAN )
546         LANG_ENTRY_END( BYELORUSSIAN )
547 /*x24*/ LANG_ENTRY_BEGIN( "sl", SLOVENIAN )
548         LANG_ENTRY_END( SLOVENIAN )
549 /*x25*/ LANG_ENTRY_BEGIN( "et", ESTONIAN )
550         LANG_ENTRY_END( ESTONIAN )
551 /*x26*/ LANG_ENTRY_BEGIN( "lv", LATVIAN )
552         LANG_ENTRY_END( LATVIAN )
553 /*x27*/ LANG_ENTRY_BEGIN( "lt", LITHUANIAN )
554         /* traditional sorting ? */
555         if (!strcmp(dialect,"classic") || !strcmp(dialect,"traditional"))
556                 LANG_DIALECT_ENTRY( LITHUANIAN, LITHUANIAN_CLASSIC )
557         else
558                 LANG_DIALECT_ENTRY( LITHUANIAN, LITHUANIAN )
559         LANG_ENTRY_END( LITHUANIAN )
560 /*x28*/ LANG_ENTRY_BEGIN( "mi", MAORI )
561         LANG_ENTRY_END( MAORI )
562 /*x29*/ LANG_ENTRY_BEGIN( "fa", FARSI )
563         LANG_ENTRY_END( FARSI )
564 /*x2a*/ LANG_ENTRY_BEGIN( "vi", VIETNAMESE )
565         LANG_ENTRY_END( VIETNAMESE )
566 /*x2b*/ LANG_ENTRY_BEGIN( "hy", ARMENIAN )
567         LANG_ENTRY_END( ARMENIAN )
568 /*x2c*/ LANG_ENTRY_BEGIN( "az", AZERI )
569         /* Cyrillic */
570         if (strstr(charset,"KOI8") || !strcmp(charset,"ISO-8859-5"))
571                 LANG_DIALECT_ENTRY( AZERI, AZERI_CYRILLIC )
572         else
573                 LANG_DIALECT_ENTRY( AZERI, AZERI )
574         LANG_ENTRY_END( AZERI )
575 /*x2d*/ LANG_ENTRY_BEGIN( "eu", BASQUE )
576         LANG_ENTRY_END( BASQUE )
577 /*x2e*/ /*LANG_ENTRY_BEGIN( "??", SORBIAN )
578         LANG_ENTRY_END( SORBIAN ) */
579 /*x2f*/ LANG_ENTRY_BEGIN( "mk", MACEDONIAN )
580         LANG_ENTRY_END( MACEDONIAN )
581 /*x30*/ /*LANG_ENTRY_BEGIN( "??", SUTU )
582         LANG_ENTRY_END( SUTU ) */
583 /*x31*/ LANG_ENTRY_BEGIN( "ts", TSONGA )
584         LANG_ENTRY_END( TSONGA )
585 /*x32*/ /*LANG_ENTRY_BEGIN( "??", TSWANA )
586         LANG_ENTRY_END( TSWANA ) */
587 /*x33*/ /*LANG_ENTRY_BEGIN( "??", VENDA )
588         LANG_ENTRY_END( VENDA ) */
589 /*x34*/ LANG_ENTRY_BEGIN( "xh", XHOSA )
590         LANG_ENTRY_END( XHOSA )
591 /*x35*/ LANG_ENTRY_BEGIN( "zu", ZULU )
592         LANG_ENTRY_END( ZULU )
593 /*x36*/ LANG_ENTRY_BEGIN( "af", AFRIKAANS )
594         LANG_ENTRY_END( AFRIKAANS )
595 /*x37*/ LANG_ENTRY_BEGIN( "ka", GEORGIAN )
596         LANG_ENTRY_END( GEORGIAN )
597 /*x38*/ LANG_ENTRY_BEGIN( "fo", FAEROESE )
598         LANG_ENTRY_END( FAEROESE )
599 /*x39*/ LANG_ENTRY_BEGIN( "hi", HINDI )
600         LANG_ENTRY_END( HINDI )
601 /*x3a*/ LANG_ENTRY_BEGIN( "mt", MALTESE )
602         LANG_ENTRY_END( MALTESE )
603 /*x3b*/ /*LANG_ENTRY_BEGIN( "??", SAAMI )
604         LANG_ENTRY_END( SAAMI ) */
605 /*x3c*/ LANG_ENTRY_BEGIN( "ga", GAELIC )
606         LANG_DIALECT_ENTRY( GAELIC, GAELIC )
607         LANG_ENTRY_END( GAELIC )
608 /*x3c*/ LANG_ENTRY_BEGIN( "gd", GAELIC )
609         LANG_DIALECT_ENTRY( GAELIC, GAELIC_SCOTTISH )
610         LANG_ENTRY_END( GAELIC )
611 /* 0x3d */
612 /*x3e*/ LANG_ENTRY_BEGIN( "ms", MALAY )
613         LANG_SUB_ENTRY( "MY", MALAY, MALAY )
614         LANG_SUB_ENTRY( "BN", MALAY, MALAY_BRUNEI_DARUSSALAM )
615         LANG_ENTRY_END( MALAY )
616 /*x3f*/ LANG_ENTRY_BEGIN( "kk", KAZAKH )
617         LANG_ENTRY_END( KAZAKH )
618 /* 0x40 */
619 /*x41*/ LANG_ENTRY_BEGIN( "sw", SWAHILI )
620         LANG_ENTRY_END( SWAHILI )
621 /* 0x42 */
622 /*x43*/ LANG_ENTRY_BEGIN( "uz", UZBEK )
623         /* Cyrillic */
624         if (strstr(charset,"KOI8") || !strcmp(charset,"ISO-8859-5"))
625                 LANG_DIALECT_ENTRY( UZBEK, UZBEK_CYRILLIC )
626         else
627                 LANG_DIALECT_ENTRY( UZBEK, UZBEK )
628         LANG_ENTRY_END( UZBEK )
629 /*x44*/ LANG_ENTRY_BEGIN( "tt", TATAR )
630         LANG_ENTRY_END( TATAR )
631 /*x45*/ LANG_ENTRY_BEGIN( "bn", BENGALI )
632         LANG_ENTRY_END( BENGALI )
633 /*x46*/ LANG_ENTRY_BEGIN( "pa", PUNJABI )
634         LANG_ENTRY_END( PUNJABI )
635 /*x47*/ LANG_ENTRY_BEGIN( "gu", GUJARATI )
636         LANG_ENTRY_END( GUJARATI )
637 /*x48*/ LANG_ENTRY_BEGIN( "or", ORIYA )
638         LANG_ENTRY_END( ORIYA )
639 /*x49*/ LANG_ENTRY_BEGIN( "ta", TAMIL )
640         LANG_ENTRY_END( TAMIL )
641 /*x4a*/ LANG_ENTRY_BEGIN( "te", TELUGU )
642         LANG_ENTRY_END( TELUGU )
643 /*x4b*/ LANG_ENTRY_BEGIN( "kn", KANNADA )
644         LANG_ENTRY_END( KANNADA )
645 /*x4c*/ LANG_ENTRY_BEGIN( "ml", MALAYALAM )
646         LANG_ENTRY_END( MALAYALAM )
647 /*x4d*/ LANG_ENTRY_BEGIN( "as", ASSAMESE )
648         LANG_ENTRY_END( ASSAMESE )
649 /*x4e*/ LANG_ENTRY_BEGIN( "mr", MARATHI )
650         LANG_ENTRY_END( MARATHI )
651 /*x4f*/ LANG_ENTRY_BEGIN( "sa", SANSKRIT )
652         LANG_ENTRY_END( SANSKRIT )
653 /* 0x50 -> 0x56 */
654 /*x57*/ /*LANG_ENTRY_BEGIN( "??", KONKANI )
655         LANG_ENTRY_END( KONKANI ) */
656 /* 0x58 -> ... */
657         LANG_ENTRY_BEGIN( "eo", ESPERANTO ) /* not official */
658         LANG_ENTRY_END( ESPERANTO )
659
660         ret = LANG_ENGLISH;
661
662 end_MAIN_GetLanguageID:
663         if (Charset) free(charset);
664         free(dialect);
665
666         return ret;
667 }
668
669 /***********************************************************************
670  *           MAIN_ParseLanguageOption
671  *
672  * Parse -language option.
673  */
674 void MAIN_ParseLanguageOption( char *arg )
675 {
676     const WINE_LANGUAGE_DEF *p = Languages;
677
678 /* for compatibility whith non-iso names previously used */
679     if (!strcmp("Sw",arg)) { strcpy(arg,"Sv"); FIXME(system,"use 'Sv' instead of 'Sw'\n");}
680     if (!strcmp("Cz",arg)) { strcpy(arg,"Cs"); FIXME(system,"use 'Cs' instead of 'Cz'\n");}
681     if (!strcmp("Po",arg)) { strcpy(arg,"Pt"); FIXME(system,"use 'Pt' instead of 'Po'\n");}
682
683     Options.language = LANG_Xx;  /* First (dummy) language */
684     for (;p->name;p++)
685     {
686         if (!lstrcmpiA( p->name, arg ))
687         {
688             WINE_LanguageId = p->langid;
689             return;
690         }
691         Options.language++;
692     }
693     MSG( "Invalid language specified '%s'. Supported languages are: ", arg );
694     for (p = Languages; p->name; p++) MSG( "%s ", p->name );
695     MSG( "\n" );
696     exit(1);
697 }
698
699
700 /***********************************************************************
701  *           MAIN_ParseModeOption
702  *
703  * Parse -mode option.
704  */
705 void MAIN_ParseModeOption( char *arg )
706 {
707     if (!lstrcmpiA("enhanced", arg)) Options.mode = MODE_ENHANCED;
708     else if (!lstrcmpiA("standard", arg)) Options.mode = MODE_STANDARD;
709     else
710     {
711         MSG( "Invalid mode '%s' specified.\n", arg);
712         MSG( "Valid modes are: 'standard', 'enhanced' (default).\n");
713         exit(1);
714     }
715 }
716
717 /***********************************************************************
718  *           MAIN_ParseOptions
719  *
720  * Parse command line options and open display.
721  */
722 static void MAIN_ParseOptions( int *argc, char *argv[] )
723 {
724     int i;
725     char *pcDot;
726
727     Options.argc = argc;
728     Options.argv = argv;
729     Options.programName = MAIN_GetProgramName( *argc, argv );
730     Options.argv0 = argv[0];
731
732     /* initialise Options.language to 0 to tell "no language choosen yet" */
733     Options.language = 0;
734   
735     /* make sure there is no "." in Options.programName to confuse the X
736        resource database lookups */
737     if ((pcDot = strchr(Options.programName, '.'))) *pcDot = '\0';
738
739     for (i = 1; i < *argc; i++)
740     {
741         if (!strcmp( argv[i], "-v" ) || !strcmp( argv[i], "-version" ))
742         {
743             MSG( "%s\n", WINE_RELEASE_INFO );
744             exit(0);
745         }
746         if (!strcmp( argv[i], "-h" ) || !strcmp( argv[i], "-help" ))
747         {
748             MAIN_Usage(argv[0]);
749             exit(0);
750         }
751     }
752 }
753
754 /***********************************************************************
755  *           called_at_exit
756  */
757 static void called_at_exit(void)
758 {
759     if (GDI_Driver)
760         GDI_Driver->pFinalize();
761     if (USER_Driver)
762         USER_Driver->pFinalize();
763
764     WINSOCK_Shutdown();
765     CONSOLE_Close();
766 }
767
768 /***********************************************************************
769  *           MAIN_WineInit
770  *
771  * Wine initialisation and command-line parsing
772  */
773 BOOL MAIN_WineInit( int *argc, char *argv[] )
774 {    
775     struct timeval tv;
776
777 #ifdef MALLOC_DEBUGGING
778     char *trace;
779
780     mcheck(NULL);
781     if (!(trace = getenv("MALLOC_TRACE")))
782     {       
783         MSG( "MALLOC_TRACE not set. No trace generated\n" );
784     }
785     else
786     {
787         MSG( "malloc trace goes to %s\n", trace );
788         mtrace();
789     }
790 #endif
791
792     setbuf(stdout,NULL);
793     setbuf(stderr,NULL);
794
795     setlocale(LC_CTYPE,"");
796     gettimeofday( &tv, NULL);
797     MSG_WineStartTicks = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
798     
799     MAIN_ParseOptions(argc, argv);
800
801 #ifndef X_DISPLAY_MISSING
802     USER_Driver = &X11DRV_USER_Driver;
803 #else /* !defined(X_DISPLAY_MISSING) */
804     USER_Driver = &TTYDRV_USER_Driver;
805 #endif /* !defined(X_DISPLAY_MISSING) */
806
807     USER_Driver->pInitialize();
808
809     MONITOR_Initialize(&MONITOR_PrimaryMonitor);
810
811     if (Options.dllFlags)
812         BUILTIN32_ParseDLLOptions( Options.dllFlags );
813         /* if (__winelib && errors ) print_error_message_like_misc_main(); */
814
815     atexit(called_at_exit);
816     return TRUE;
817 }
818
819 /***********************************************************************
820  *           MessageBeep16   (USER.104)
821  */
822 void WINAPI MessageBeep16( UINT16 i )
823 {
824     MessageBeep( i );
825 }
826
827
828 /***********************************************************************
829  *           MessageBeep32   (USER32.390)
830  */
831 BOOL WINAPI MessageBeep( UINT i )
832 {
833     KEYBOARD_Beep();
834     return TRUE;
835 }
836
837
838 /***********************************************************************
839  *           Beep   (KERNEL32.11)
840  */
841 BOOL WINAPI Beep( DWORD dwFreq, DWORD dwDur )
842 {
843     /* dwFreq and dwDur are ignored by Win95 */
844     KEYBOARD_Beep();
845     return TRUE;
846 }
847
848
849 /***********************************************************************
850  *      GetTimerResolution (USER.14)
851  */
852 LONG WINAPI GetTimerResolution16(void)
853 {
854         return (1000);
855 }
856
857 /***********************************************************************
858  *      SystemParametersInfo32A   (USER32.540)
859  */
860 BOOL WINAPI SystemParametersInfoA( UINT uAction, UINT uParam,
861                                        LPVOID lpvParam, UINT fuWinIni )
862 {
863         int timeout;
864
865         switch (uAction) {
866         case SPI_GETBEEP:
867                 *(BOOL *) lpvParam = KEYBOARD_GetBeepActive();
868                 break;
869         case SPI_SETBEEP:
870                KEYBOARD_SetBeepActive(uParam);
871                break;
872
873         case SPI_GETBORDER:
874                 *(INT *)lpvParam = GetSystemMetrics( SM_CXFRAME );
875                 break;
876
877         case SPI_GETDRAGFULLWINDOWS:
878                 *(BOOL *) lpvParam = FALSE;
879                 break;
880
881         case SPI_SETDRAGFULLWINDOWS:
882                 break;
883
884         case SPI_GETFASTTASKSWITCH:
885                 if ( GetProfileIntA( "windows", "CoolSwitch", 1 ) == 1 )
886                         *(BOOL *) lpvParam = TRUE;
887                 else
888                         *(BOOL *) lpvParam = FALSE;
889                 break;
890                 
891         case SPI_GETGRIDGRANULARITY:
892                 *(INT*)lpvParam=GetProfileIntA("desktop","GridGranularity",1);
893                 break;
894
895         case SPI_GETICONTITLEWRAP:
896                 *(BOOL*)lpvParam=GetProfileIntA("desktop","IconTitleWrap",TRUE);
897                 break;
898
899         case SPI_GETKEYBOARDDELAY:
900                 *(INT*)lpvParam=GetProfileIntA("keyboard","KeyboardDelay",1);
901                 break;
902
903         case SPI_GETKEYBOARDSPEED:
904                 *(DWORD*)lpvParam=GetProfileIntA("keyboard","KeyboardSpeed",30);
905                 break;
906
907         case SPI_GETMENUDROPALIGNMENT:
908                 *(BOOL*)lpvParam=GetSystemMetrics(SM_MENUDROPALIGNMENT); /* XXX check this */
909                 break;
910
911         case SPI_GETSCREENSAVEACTIVE:           
912                if(MONITOR_GetScreenSaveActive(&MONITOR_PrimaryMonitor) || 
913                   GetProfileIntA( "windows", "ScreenSaveActive", 1 ) == 1)
914                         *(BOOL*)lpvParam = TRUE;
915                 else
916                         *(BOOL*)lpvParam = FALSE;
917                 break;
918
919         case SPI_GETSCREENSAVETIMEOUT:
920                 timeout = MONITOR_GetScreenSaveTimeout(&MONITOR_PrimaryMonitor);
921                 if(!timeout)
922                         timeout = GetProfileIntA( "windows", "ScreenSaveTimeout", 300 );
923                 *(INT *) lpvParam = timeout * 1000;
924                 break;
925
926         case SPI_ICONHORIZONTALSPACING:
927                 /* FIXME Get/SetProfileInt */
928                 if (lpvParam == NULL)
929                         /*SetSystemMetrics( SM_CXICONSPACING, uParam )*/ ;
930                 else
931                         *(INT*)lpvParam=GetSystemMetrics(SM_CXICONSPACING);
932                 break;
933
934         case SPI_ICONVERTICALSPACING:
935                 /* FIXME Get/SetProfileInt */
936                 if (lpvParam == NULL)
937                         /*SetSystemMetrics( SM_CYICONSPACING, uParam )*/ ;
938                 else
939                         *(INT*)lpvParam=GetSystemMetrics(SM_CYICONSPACING);
940                 break;
941
942         case SPI_GETICONTITLELOGFONT: {
943                 LPLOGFONTA lpLogFont = (LPLOGFONTA)lpvParam;
944
945                 /* from now on we always have an alias for MS Sans Serif */
946
947                 GetProfileStringA("Desktop", "IconTitleFaceName", "MS Sans Serif", 
948                         lpLogFont->lfFaceName, LF_FACESIZE );
949                 lpLogFont->lfHeight = -GetProfileIntA("Desktop","IconTitleSize", 8);
950                 lpLogFont->lfWidth = 0;
951                 lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
952                 lpLogFont->lfWeight = FW_NORMAL;
953                 lpLogFont->lfItalic = FALSE;
954                 lpLogFont->lfStrikeOut = FALSE;
955                 lpLogFont->lfUnderline = FALSE;
956                 lpLogFont->lfCharSet = ANSI_CHARSET;
957                 lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
958                 lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
959                 lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
960                 break;
961         }
962         case SPI_GETWORKAREA:
963                 SetRect( (RECT *)lpvParam, 0, 0,
964                         GetSystemMetrics( SM_CXSCREEN ),
965                         GetSystemMetrics( SM_CYSCREEN )
966                 );
967                 break;
968         case SPI_GETNONCLIENTMETRICS: 
969
970 #define lpnm ((LPNONCLIENTMETRICSA)lpvParam)
971                 
972                 if( lpnm->cbSize == sizeof(NONCLIENTMETRICSA) )
973                 {
974                     /* FIXME: initialize geometry entries */
975
976                     SystemParametersInfoA(SPI_GETICONTITLELOGFONT, 0,
977                                                         (LPVOID)&(lpnm->lfCaptionFont),0);
978                     lpnm->lfCaptionFont.lfWeight = FW_BOLD;
979                     SystemParametersInfoA(SPI_GETICONTITLELOGFONT, 0,
980                                                         (LPVOID)&(lpnm->lfSmCaptionFont),0);
981                     SystemParametersInfoA(SPI_GETICONTITLELOGFONT, 0,
982                                                         (LPVOID)&(lpnm->lfMenuFont),0);
983                     SystemParametersInfoA(SPI_GETICONTITLELOGFONT, 0,
984                                                         (LPVOID)&(lpnm->lfStatusFont),0);
985                     SystemParametersInfoA(SPI_GETICONTITLELOGFONT, 0,
986                                                         (LPVOID)&(lpnm->lfMessageFont),0);
987                 }
988 #undef lpnm
989                 break;
990
991         case SPI_GETANIMATION: {
992                 LPANIMATIONINFO lpAnimInfo = (LPANIMATIONINFO)lpvParam;
993  
994                 /* Tell it "disabled" */
995                 lpAnimInfo->cbSize = sizeof(ANIMATIONINFO);
996                 uParam = sizeof(ANIMATIONINFO);
997                 lpAnimInfo->iMinAnimate = 0; /* Minimise and restore animation is disabled (nonzero == enabled) */
998                 break;
999         }
1000  
1001         case SPI_SETANIMATION: {
1002                 LPANIMATIONINFO lpAnimInfo = (LPANIMATIONINFO)lpvParam;
1003  
1004                 /* Do nothing */
1005                 WARN(system, "SPI_SETANIMATION ignored.\n");
1006                 lpAnimInfo->cbSize = sizeof(ANIMATIONINFO);
1007                 uParam = sizeof(ANIMATIONINFO);
1008                 break;
1009         }
1010
1011         case SPI_GETHIGHCONTRAST:
1012         {
1013                 LPHIGHCONTRASTA lpHighContrastA = (LPHIGHCONTRASTA)lpvParam;
1014
1015                 FIXME(system,"SPI_GETHIGHCONTRAST not fully implemented\n");
1016
1017                 if ( lpHighContrastA->cbSize == sizeof( HIGHCONTRASTA ) )
1018                 {
1019                         /* Indicate that there is no high contrast available */
1020                         lpHighContrastA->dwFlags = 0;
1021                         lpHighContrastA->lpszDefaultScheme = NULL;
1022                 }
1023                 else
1024                 {
1025                         return FALSE;
1026                 }
1027
1028                 break;
1029         }
1030
1031         default:
1032                 return SystemParametersInfo16(uAction,uParam,lpvParam,fuWinIni);
1033         }
1034         return TRUE;
1035 }
1036
1037
1038 /***********************************************************************
1039  *      SystemParametersInfo16   (USER.483)
1040  */
1041 BOOL16 WINAPI SystemParametersInfo16( UINT16 uAction, UINT16 uParam,
1042                                       LPVOID lpvParam, UINT16 fuWinIni )
1043 {
1044         int timeout; 
1045         char buffer[256];
1046
1047         switch (uAction)
1048         {
1049                 case SPI_GETBEEP:
1050                         *(BOOL *) lpvParam = KEYBOARD_GetBeepActive();
1051                         break;
1052                 
1053                 case SPI_GETBORDER:
1054                         *(INT16 *)lpvParam = GetSystemMetrics16( SM_CXFRAME );
1055                         break;
1056
1057                 case SPI_GETFASTTASKSWITCH:
1058                     if ( GetProfileIntA( "windows", "CoolSwitch", 1 ) == 1 )
1059                           *(BOOL16 *) lpvParam = TRUE;
1060                         else
1061                           *(BOOL16 *) lpvParam = FALSE;
1062                         break;
1063
1064                 case SPI_GETGRIDGRANULARITY:
1065                     *(INT16 *) lpvParam = GetProfileIntA( "desktop", 
1066                                                           "GridGranularity",
1067                                                           1 );
1068                     break;
1069
1070                 case SPI_GETICONTITLEWRAP:
1071                     *(BOOL16 *) lpvParam = GetProfileIntA( "desktop",
1072                                                            "IconTitleWrap",
1073                                                            TRUE );
1074                     break;
1075
1076                 case SPI_GETKEYBOARDDELAY:
1077                     *(INT16 *) lpvParam = GetProfileIntA( "keyboard",
1078                                                           "KeyboardDelay", 1 );
1079                     break;
1080
1081                 case SPI_GETKEYBOARDSPEED:
1082                     *(WORD *) lpvParam = GetProfileIntA( "keyboard",
1083                                                            "KeyboardSpeed",
1084                                                            30 );
1085                     break;
1086
1087                 case SPI_GETMENUDROPALIGNMENT:
1088                         *(BOOL16 *) lpvParam = GetSystemMetrics16( SM_MENUDROPALIGNMENT ); /* XXX check this */
1089                         break;
1090
1091                 case SPI_GETSCREENSAVEACTIVE:
1092                   if(MONITOR_GetScreenSaveActive(&MONITOR_PrimaryMonitor) ||
1093                      GetProfileIntA( "windows", "ScreenSaveActive", 1 ) == 1)
1094                         *(BOOL16 *) lpvParam = TRUE;
1095                     else
1096                         *(BOOL16 *) lpvParam = FALSE;
1097                     break;
1098
1099                 case SPI_GETSCREENSAVETIMEOUT:
1100                         timeout = MONITOR_GetScreenSaveTimeout(&MONITOR_PrimaryMonitor);
1101                         if(!timeout)
1102                             timeout = GetProfileIntA( "windows", "ScreenSaveTimeout", 300 );
1103                         *(INT16 *) lpvParam = timeout;
1104                         break;
1105
1106                 case SPI_ICONHORIZONTALSPACING:
1107                     /* FIXME Get/SetProfileInt */
1108                         if (lpvParam == NULL)
1109                             /*SetSystemMetrics( SM_CXICONSPACING, uParam )*/ ;
1110                         else
1111                             *(INT16 *)lpvParam = GetSystemMetrics16( SM_CXICONSPACING );
1112                         break;
1113
1114                 case SPI_ICONVERTICALSPACING:
1115                     /* FIXME Get/SetProfileInt */
1116                     if (lpvParam == NULL)
1117                         /*SetSystemMetrics( SM_CYICONSPACING, uParam )*/ ;
1118                     else
1119                         *(INT16 *)lpvParam = GetSystemMetrics16(SM_CYICONSPACING);
1120                     break;
1121
1122                 case SPI_SETBEEP:
1123                         KEYBOARD_SetBeepActive(uParam);
1124                         break;
1125
1126                 case SPI_SETSCREENSAVEACTIVE:
1127                         MONITOR_SetScreenSaveActive(&MONITOR_PrimaryMonitor, uParam);
1128                         break;
1129
1130                 case SPI_SETSCREENSAVETIMEOUT:
1131                         MONITOR_SetScreenSaveTimeout(&MONITOR_PrimaryMonitor, uParam);
1132                         break;
1133
1134                 case SPI_SETDESKWALLPAPER:
1135                         return (SetDeskWallPaper((LPSTR) lpvParam));
1136                         break;
1137
1138                 case SPI_SETDESKPATTERN:
1139                         if ((INT16)uParam == -1) {
1140                                 GetProfileStringA("Desktop", "Pattern", 
1141                                                 "170 85 170 85 170 85 170 85", 
1142                                                 buffer, sizeof(buffer) );
1143                                 return (DESKTOP_SetPattern((LPSTR) buffer));
1144                         } else
1145                                 return (DESKTOP_SetPattern((LPSTR) lpvParam));
1146                         break;
1147
1148                 case SPI_GETICONTITLELOGFONT: 
1149                 {
1150                     LPLOGFONT16 lpLogFont = (LPLOGFONT16)lpvParam;
1151
1152                     GetProfileStringA("Desktop", "IconTitleFaceName", "MS Sans Serif", 
1153                                         lpLogFont->lfFaceName, LF_FACESIZE );
1154                     lpLogFont->lfHeight = -GetProfileIntA("Desktop","IconTitleSize", 8);
1155                     lpLogFont->lfWidth = 0;
1156                     lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
1157                     lpLogFont->lfWeight = FW_NORMAL;
1158                     lpLogFont->lfItalic = FALSE;
1159                     lpLogFont->lfStrikeOut = FALSE;
1160                     lpLogFont->lfUnderline = FALSE;
1161                     lpLogFont->lfCharSet = ANSI_CHARSET;
1162                     lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
1163                     lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
1164                     lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
1165                     break;
1166                 }
1167                 case SPI_GETNONCLIENTMETRICS:
1168
1169 #define lpnm ((LPNONCLIENTMETRICS16)lpvParam)
1170                     if( lpnm->cbSize == sizeof(NONCLIENTMETRICS16) )
1171                     {
1172                         /* FIXME: initialize geometry entries */
1173                         SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0, 
1174                                                         (LPVOID)&(lpnm->lfCaptionFont),0);
1175                         lpnm->lfCaptionFont.lfWeight = FW_BOLD;
1176                         SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
1177                                                         (LPVOID)&(lpnm->lfSmCaptionFont),0);
1178                         SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
1179                                                         (LPVOID)&(lpnm->lfMenuFont),0);
1180                         SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
1181                                                         (LPVOID)&(lpnm->lfStatusFont),0);
1182                         SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
1183                                                         (LPVOID)&(lpnm->lfMessageFont),0);
1184                     }
1185                     else /* winfile 95 sets sbSize to 340 */
1186                         SystemParametersInfoA( uAction, uParam, lpvParam, fuWinIni );
1187 #undef lpnm
1188                     break;
1189
1190                 case SPI_LANGDRIVER:
1191                 case SPI_SETBORDER:
1192                 case SPI_SETDOUBLECLKHEIGHT:
1193                 case SPI_SETDOUBLECLICKTIME:
1194                 case SPI_SETDOUBLECLKWIDTH:
1195                 case SPI_SETFASTTASKSWITCH:
1196                 case SPI_SETKEYBOARDDELAY:
1197                 case SPI_SETKEYBOARDSPEED:
1198                         WARN(system, "Option %d ignored.\n", uAction);
1199                         break;
1200
1201                 case SPI_GETWORKAREA:
1202                     SetRect16( (RECT16 *)lpvParam, 0, 0,
1203                                GetSystemMetrics16( SM_CXSCREEN ),
1204                                GetSystemMetrics16( SM_CYSCREEN ) );
1205                     break;
1206
1207                 default:
1208                         WARN(system, "Unknown option %d.\n", uAction);
1209                         break;
1210         }
1211         return 1;
1212 }
1213
1214 /***********************************************************************
1215  *      SystemParametersInfo32W   (USER32.541)
1216  */
1217 BOOL WINAPI SystemParametersInfoW( UINT uAction, UINT uParam,
1218                                        LPVOID lpvParam, UINT fuWinIni )
1219 {
1220     char buffer[256];
1221
1222     switch (uAction)
1223     {
1224     case SPI_SETDESKWALLPAPER:
1225         if (lpvParam)
1226         {
1227             lstrcpynWtoA(buffer,(LPWSTR)lpvParam,sizeof(buffer));
1228             return SetDeskWallPaper(buffer);
1229         }
1230         return SetDeskWallPaper(NULL);
1231
1232     case SPI_SETDESKPATTERN:
1233         if ((INT) uParam == -1)
1234         {
1235             GetProfileStringA("Desktop", "Pattern", 
1236                                 "170 85 170 85 170 85 170 85", 
1237                                 buffer, sizeof(buffer) );
1238             return (DESKTOP_SetPattern((LPSTR) buffer));
1239         }
1240         if (lpvParam)
1241         {
1242             lstrcpynWtoA(buffer,(LPWSTR)lpvParam,sizeof(buffer));
1243             return DESKTOP_SetPattern(buffer);
1244         }
1245         return DESKTOP_SetPattern(NULL);
1246
1247     case SPI_GETICONTITLELOGFONT:
1248         {
1249             LPLOGFONTW lpLogFont = (LPLOGFONTW)lpvParam;
1250             GetProfileStringA("Desktop", "IconTitleFaceName", "MS Sans Serif", 
1251                          buffer, sizeof(buffer) );
1252             lstrcpynAtoW(lpLogFont->lfFaceName, buffer ,LF_FACESIZE);
1253             lpLogFont->lfHeight = 10;
1254             lpLogFont->lfWidth = 0;
1255             lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
1256             lpLogFont->lfWeight = FW_NORMAL;
1257             lpLogFont->lfItalic = lpLogFont->lfStrikeOut = lpLogFont->lfUnderline = FALSE;
1258             lpLogFont->lfCharSet = ANSI_CHARSET;
1259             lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
1260             lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
1261             lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
1262         }
1263         break;
1264     case SPI_GETNONCLIENTMETRICS: {
1265         /* FIXME: implement correctly */
1266         LPNONCLIENTMETRICSW     lpnm=(LPNONCLIENTMETRICSW)lpvParam;
1267
1268         SystemParametersInfoW(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfCaptionFont),0);
1269         lpnm->lfCaptionFont.lfWeight = FW_BOLD;
1270         SystemParametersInfoW(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfSmCaptionFont),0);
1271         SystemParametersInfoW(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfMenuFont),0);
1272         SystemParametersInfoW(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfStatusFont),0);
1273         SystemParametersInfoW(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfMessageFont),0);
1274         break;
1275     }
1276
1277     case SPI_GETHIGHCONTRAST:
1278     {
1279        LPHIGHCONTRASTW lpHighContrastW = (LPHIGHCONTRASTW)lpvParam;
1280
1281        FIXME(system,"SPI_GETHIGHCONTRAST not fully implemented\n");
1282
1283        if ( lpHighContrastW->cbSize == sizeof( HIGHCONTRASTW ) )
1284        {
1285           /* Indicate that there is no high contrast available */
1286           lpHighContrastW->dwFlags = 0;
1287           lpHighContrastW->lpszDefaultScheme = NULL;
1288        }
1289        else
1290        {
1291           return FALSE;
1292        }
1293
1294        break;
1295     }
1296
1297     default:
1298         return SystemParametersInfoA(uAction,uParam,lpvParam,fuWinIni);
1299         
1300     }
1301     return TRUE;
1302 }
1303
1304
1305 /***********************************************************************
1306 *       FileCDR (KERNEL.130)
1307 */
1308 FARPROC16 WINAPI FileCDR16(FARPROC16 x)
1309 {
1310         FIXME(file,"(0x%8x): stub\n", (int) x);
1311         return (FARPROC16)TRUE;
1312 }