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