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