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