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