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