Avoid calling the *Rect USER functions from inside GDI.
[wine] / misc / main.c
1 /*
2  * Main function.
3  *
4  * Copyright 1994 Alexandre Julliard
5  */
6
7 #include "config.h"
8
9 #ifndef X_DISPLAY_MISSING
10 #include "x11drv.h"
11 #else /* !defined(X_DISPLAY_MISSING) */
12 #include "ttydrv.h"
13 #endif /* !defined(X_DISPLAY_MISSING) */
14
15 #include <locale.h>
16 #include <ctype.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <unistd.h>
20 #ifdef MALLOC_DEBUGGING
21 # include <malloc.h>
22 #endif
23
24 #include "winbase.h"
25 #include "winsock.h"
26 #include "heap.h"
27 #include "message.h"
28 #include "msdos.h"
29 #include "color.h"
30 #include "options.h"
31 #include "desktop.h"
32 #include "builtin32.h"
33 #include "debugtools.h"
34 #include "debugdefs.h"
35 #include "xmalloc.h"
36 #include "module.h"
37 #include "version.h"
38 #include "winnls.h"
39 #include "console.h"
40 #include "monitor.h"
41 #include "keyboard.h"
42 #include "gdi.h"
43 #include "user.h"
44 #include "windef.h"
45 #include "wingdi.h"
46 #include "wine/winuser16.h"
47 #include "tweak.h"
48 #include "winerror.h"
49
50 /**********************************************************************/
51
52 USER_DRIVER *USER_Driver = NULL;
53
54 /* when adding new languages look at ole/ole2nls.c 
55  * for proper iso name and Windows code (add 0x0400 
56  * to the code listed there)
57  */
58 const WINE_LANGUAGE_DEF Languages[] =
59 {
60     {"En",0x0409},      /* LANG_En */
61     {"Es",0x040A},      /* LANG_Es */
62     {"De",0x0407},      /* LANG_De */
63     {"No",0x0414},      /* LANG_No */
64     {"Fr",0x040C},      /* LANG_Fr */
65     {"Fi",0x040B},      /* LANG_Fi */
66     {"Da",0x0406},      /* LANG_Da */
67     {"Cs",0x0405},      /* LANG_Cs */
68     {"Eo",0x048f},      /* LANG_Eo */
69     {"It",0x0410},      /* LANG_It */
70     {"Ko",0x0412},      /* LANG_Ko */
71     {"Hu",0x040e},      /* LANG_Hu */
72     {"Pl",0x0415},      /* LANG_Pl */
73     {"Pt",0x0416},      /* LANG_Pt */
74     {"Sk",0x041b},      /* LANG_Sk */
75     {"Sv",0x041d},      /* LANG_Sv */
76     {"Ca",0x0403},      /* LANG_Ca */
77     {"Nl",0x0413},      /* LANG_Nl */
78     {"Ru",0x0419},      /* LANG_Ru */
79     {"Wa",0x0490},      /* LANG_Wa */
80     {"Ga",0x043c},      /* LANG_Ga */
81     {"Gd",0x083c},      /* LANG_Gd */
82     {"Gv",0x0c3c},      /* LANG_Gv */
83     {"Kw",0x0491},      /* LANG_Kw */
84     {"Cy",0x0492},      /* LANG_Cy */
85     {"Br",0x0493},      /* LANG_Br  */
86     {"Ja",0x0411},      /* LANG_Ja */
87     {NULL,0}
88 };
89
90 WORD WINE_LanguageId = 0x409;   /* english as default */
91
92 struct options Options =
93 {  /* default options */
94     0,              /* argc */
95     NULL,           /* argv */
96     NULL,           /* desktopGeometry */
97     NULL,           /* display */
98     NULL,           /* dllFlags */
99     FALSE,          /* synchronous */
100     FALSE,          /* debug */
101     FALSE,          /* failReadOnly */
102     0,              /* language */
103     FALSE,          /* Managed windows */
104     NULL            /* Alternate config file name */
105 };
106
107 const char *argv0;
108
109 /***********************************************************************
110  *          MAIN_ParseDebugOptions
111  *
112  *  Turns specific debug messages on or off, according to "options".
113  */
114 void MAIN_ParseDebugOptions( const char *arg )
115 {
116   /* defined in relay32/relay386.c */
117   extern char **debug_relay_includelist;
118   extern char **debug_relay_excludelist;
119   /* defined in relay32/snoop.c */
120   extern char **debug_snoop_includelist;
121   extern char **debug_snoop_excludelist;
122
123   int i;
124   int l, cls, dotracerelay = TRACE_ON(relay);
125
126   char *options = strdup(arg);
127
128   l = strlen(options);
129   if (l<2) goto error;
130
131   if (options[l-1]=='\n') options[l-1]='\0';
132   do
133   {
134     if ((*options!='+')&&(*options!='-')){
135       int j;
136
137       for(j=0; j<DEBUG_CLASS_COUNT; j++)
138         if(!lstrncmpiA(options, debug_cl_name[j], strlen(debug_cl_name[j])))
139           break;
140       if(j==DEBUG_CLASS_COUNT)
141         goto error;
142       options += strlen(debug_cl_name[j]);
143       if ((*options!='+')&&(*options!='-'))
144         goto error;
145       cls = j;
146     }
147     else
148       cls = -1; /* all classes */
149
150     if (strchr(options,','))
151       l=strchr(options,',')-options;
152     else
153       l=strlen(options);
154
155     if (!lstrncmpiA(options+1,"all",l-1))
156       {
157         int i, j;
158         for (i=0; i<DEBUG_CHANNEL_COUNT; i++)
159           for(j=0; j<DEBUG_CLASS_COUNT; j++)
160             if(cls == -1 || cls == j)
161                 __SET_DEBUGGING( j, debug_channels[i], (*options=='+') );
162       }
163     else if (!lstrncmpiA(options+1, "relay=", 6) ||
164              !lstrncmpiA(options+1, "snoop=", 6))
165       {
166         int i, j;
167         char *s, *s2, ***output, c;
168
169         for (i=0; i<DEBUG_CHANNEL_COUNT; i++)
170           if (!strncasecmp( debug_channels[i] + 1, options + 1, 5))
171           {
172             for(j=0; j<DEBUG_CLASS_COUNT; j++)
173               if(cls == -1 || cls == j)
174                   __SET_DEBUGGING( j, debug_channels[i], 1 );
175             break;
176           }
177         /* should never happen, maybe assert(i!=DEBUG_CHANNEL_COUNT)? */
178         if (i==DEBUG_CHANNEL_COUNT)
179           goto error;
180         output = (*options == '+') ?
181                         ((*(options+1) == 'r') ?
182                                 &debug_relay_includelist :
183                                 &debug_snoop_includelist) :
184                         ((*(options+1) == 'r') ?
185                                 &debug_relay_excludelist :
186                                 &debug_snoop_excludelist);
187         s = options + 7;
188         /* if there are n ':', there are n+1 modules, and we need n+2 slots
189          * last one being for the sentinel (NULL) */
190         i = 2;  
191         while((s = strchr(s, ':'))) i++, s++;
192         *output = malloc(sizeof(char **) * i);
193         i = 0;
194         s = options + 7;
195         while((s2 = strchr(s, ':'))) {
196           c = *s2;
197           *s2 = '\0';
198           *((*output)+i) = CharUpperA(strdup(s));
199           *s2 = c;
200           s = s2 + 1;
201           i++;
202         }
203         c = *(options + l);
204         *(options + l) = '\0';
205         *((*output)+i) = CharUpperA(strdup(s));
206         *(options + l) = c;
207         *((*output)+i+1) = NULL;
208       }
209     else
210       {
211         int i, j;
212         for (i=0; i<DEBUG_CHANNEL_COUNT; i++)
213           if (!strncasecmp( debug_channels[i] + 1, options + 1, l - 1) && !debug_channels[i][l])
214           {
215             for(j=0; j<DEBUG_CLASS_COUNT; j++)
216               if(cls == -1 || cls == j)
217                   __SET_DEBUGGING( j, debug_channels[i], (*options=='+') );
218             break;
219           }
220         if (i==DEBUG_CHANNEL_COUNT)
221           goto error;
222       }
223     options+=l;
224   }
225   while((*options==',')&&(*(++options)));
226
227   /* special handling for relay debugging */
228   if (dotracerelay != TRACE_ON(relay))
229         BUILTIN32_SwitchRelayDebug( TRACE_ON(relay) );
230
231   if (!*options) return;
232
233  error:  
234   MESSAGE("%s: Syntax: -debugmsg [class]+xxx,...  or "
235       "-debugmsg [class]-xxx,...\n",argv0);
236   MESSAGE("Example: -debugmsg +all,warn-heap\n"
237       "  turn on all messages except warning heap messages\n");
238   MESSAGE("Special case: -debugmsg +relay=DLL:DLL.###:FuncName\n"
239       "  turn on -debugmsg +relay only as specified\n"
240       "Special case: -debugmsg -relay=DLL:DLL.###:FuncName\n"
241       "  turn on -debugmsg +relay except as specified\n"
242       "Also permitted, +snoop=..., -snoop=... as with relay.\n\n");
243   
244   MESSAGE("Available message classes:\n");
245   for(i=0;i<DEBUG_CLASS_COUNT;i++)
246     MESSAGE( "%-9s", debug_cl_name[i]);
247   MESSAGE("\n\n");
248   
249   MESSAGE("Available message types:\n");
250   MESSAGE("%-9s ","all");
251   for(i=0;i<DEBUG_CHANNEL_COUNT;i++)
252       MESSAGE("%-9s%c",debug_channels[i] + 1,
253           (((i+2)%8==0)?'\n':' '));
254   MESSAGE("\n\n");
255   ExitProcess(1);
256 }
257
258 /***********************************************************************
259  *           MAIN_GetLanguageID
260  *
261  * INPUT:
262  *      Lang: a string whose two first chars are the iso name of a language.
263  *      Country: a string whose two first chars are the iso name of country
264  *      Charset: a string defining the chossen charset encoding
265  *      Dialect: a string defining a variation of the locale
266  *
267  *      all those values are from the standardized format of locale
268  *      name in unix which is: Lang[_Country][.Charset][@Dialect]
269  *
270  * RETURNS:
271  *      the numeric code of the language used by Windows (or 0x00)
272  */
273 int MAIN_GetLanguageID(LPCSTR Lang,LPCSTR Country,LPCSTR Charset,LPCSTR Dialect)
274 {
275     char lang[3]="??", country[3]={0,0,0};
276     char *charset=NULL, *dialect=NULL;
277     int i,j,ret=0;
278
279     if (Lang==NULL) return 0x00;
280     if (Lang[0]) lang[0]=tolower(Lang[0]);
281     if (Lang[1]) lang[1]=tolower(Lang[1]);
282
283     if (Country!=NULL) {
284         if (Country[0]) country[0]=toupper(Country[0]);
285         if (Country[1]) country[1]=toupper(Country[1]);
286     }
287
288     if (Charset!=NULL) {
289         j=strlen(Charset);
290         charset=(char*)malloc(j+1);
291         for (i=0;i<j;i++)
292             charset[i]=toupper(Charset[i]);
293         charset[i]='\0';
294     }
295
296     if (Dialect!=NULL) {
297         j=strlen(Dialect);
298         dialect=(char*)malloc(j+1);
299         for (i=0;i<j;i++)
300             dialect[i]=tolower(Dialect[i]);
301         dialect[i]='\0';
302     } else {
303         dialect = malloc(1);
304         dialect[0] = '\0';
305     }
306
307 #define LANG_ENTRY_BEGIN(x,y)   if(!strcmp(lang, x )) { \
308                                     if (!country[0]) { \
309                                         ret=LANG_##y ; \
310                                         goto end_MAIN_GetLanguageID; \
311                                     }
312 #define LANG_SUB_ENTRY(x,y,z)       if (!strcmp(country, x )) \
313                                         ret = MAKELANGID( LANG_##y , SUBLANG_##z ); \
314                                         goto end_MAIN_GetLanguageID;
315 #define LANG_DIALECT_ENTRY(x,y)     { ret = MAKELANGID(LANG_##x , SUBLANG_##y ); \
316                                     goto end_MAIN_GetLanguageID; }
317 #define LANG_ENTRY_END(x)           ret = MAKELANGID(LANG_##x , SUBLANG_DEFAULT); \
318                                     goto end_MAIN_GetLanguageID; \
319                                 }
320
321 /*x01*/ LANG_ENTRY_BEGIN( "ar", ARABIC )
322         LANG_SUB_ENTRY( "SA", ARABIC, ARABIC)
323         LANG_SUB_ENTRY( "IQ", ARABIC, ARABIC_IRAQ )
324         LANG_SUB_ENTRY( "EG", ARABIC, ARABIC_EGYPT )
325         LANG_SUB_ENTRY( "LY", ARABIC, ARABIC_LIBYA )
326         LANG_SUB_ENTRY( "DZ", ARABIC, ARABIC_ALGERIA )
327         LANG_SUB_ENTRY( "MA", ARABIC, ARABIC_MOROCCO )
328         LANG_SUB_ENTRY( "TN", ARABIC, ARABIC_TUNISIA )
329         LANG_SUB_ENTRY( "OM", ARABIC, ARABIC_OMAN )
330         LANG_SUB_ENTRY( "YE", ARABIC, ARABIC_YEMEN )
331         LANG_SUB_ENTRY( "SY", ARABIC, ARABIC_SYRIA )
332         LANG_SUB_ENTRY( "JO", ARABIC, ARABIC_JORDAN )
333         LANG_SUB_ENTRY( "LB", ARABIC, ARABIC_LEBANON )
334         LANG_SUB_ENTRY( "KW", ARABIC, ARABIC_KUWAIT )
335         LANG_SUB_ENTRY( "AE", ARABIC, ARABIC_UAE )
336         LANG_SUB_ENTRY( "BH", ARABIC, ARABIC_BAHRAIN )
337         LANG_SUB_ENTRY( "QA", ARABIC, ARABIC_QATAR )
338         LANG_ENTRY_END( ARABIC )
339 /*x02*/ LANG_ENTRY_BEGIN( "bu", BULGARIAN )
340         LANG_ENTRY_END( BULGARIAN )
341 /*x03*/ LANG_ENTRY_BEGIN( "ca", CATALAN )
342         LANG_ENTRY_END( CATALAN )
343 /*x04*/ LANG_ENTRY_BEGIN( "zh", CHINESE )
344         LANG_SUB_ENTRY( "TW", CHINESE, CHINESE_TRADITIONAL )
345         LANG_SUB_ENTRY( "CN", CHINESE, CHINESE_SIMPLIFIED )
346         LANG_SUB_ENTRY( "HK", CHINESE, CHINESE_HONGKONG )
347         LANG_SUB_ENTRY( "SG", CHINESE, CHINESE_SINGAPORE )
348         LANG_SUB_ENTRY( "MO", CHINESE, CHINESE_MACAU )
349         LANG_ENTRY_END( CHINESE )
350 /*x05*/ LANG_ENTRY_BEGIN( "cs", CZECH )
351         LANG_ENTRY_END( CZECH )
352 /*x06*/ LANG_ENTRY_BEGIN( "da", DANISH )
353         LANG_ENTRY_END( DANISH )
354 /*x07*/ LANG_ENTRY_BEGIN( "de", GERMAN )
355         LANG_SUB_ENTRY( "DE", GERMAN, GERMAN )
356         LANG_SUB_ENTRY( "CH", GERMAN, GERMAN_SWISS )
357         LANG_SUB_ENTRY( "AT", GERMAN, GERMAN_AUSTRIAN )
358         LANG_SUB_ENTRY( "LU", GERMAN, GERMAN_LUXEMBOURG )
359         LANG_SUB_ENTRY( "LI", GERMAN, GERMAN_LIECHTENSTEIN )
360         LANG_ENTRY_END( GERMAN )
361 /*x08*/ LANG_ENTRY_BEGIN( "el", GREEK )
362         LANG_ENTRY_END( GREEK )
363 /*x09*/ LANG_ENTRY_BEGIN( "en", ENGLISH )
364         LANG_SUB_ENTRY( "US", ENGLISH, ENGLISH_US )
365         LANG_SUB_ENTRY( "UK", ENGLISH, ENGLISH_UK )
366         LANG_SUB_ENTRY( "AU", ENGLISH, ENGLISH_AUS )
367         LANG_SUB_ENTRY( "CA", ENGLISH, ENGLISH_CAN )
368         LANG_SUB_ENTRY( "NZ", ENGLISH, ENGLISH_NZ )
369         LANG_SUB_ENTRY( "EI", ENGLISH, ENGLISH_EIRE )
370         LANG_SUB_ENTRY( "ZA", ENGLISH, ENGLISH_SAFRICA )
371         LANG_SUB_ENTRY( "JM", ENGLISH, ENGLISH_JAMAICA )
372      /* LANG_SUB_ENTRY( "AG", ENGLISH, ENGLISH_CARIBBEAN ) */
373         LANG_SUB_ENTRY( "BZ", ENGLISH, ENGLISH_BELIZE )
374         LANG_SUB_ENTRY( "TT", ENGLISH, ENGLISH_TRINIDAD )
375         LANG_SUB_ENTRY( "ZW", ENGLISH, ENGLISH_ZIMBABWE )
376         LANG_SUB_ENTRY( "PH", ENGLISH, ENGLISH_PHILIPPINES )
377         LANG_ENTRY_END( ENGLISH )
378 /*x0a*/ LANG_ENTRY_BEGIN( "es", SPANISH )
379         /* traditional sorting */
380         if (!strcmp(dialect,"tradicional"))
381                 LANG_DIALECT_ENTRY( SPANISH, SPANISH )
382         LANG_SUB_ENTRY( "MX", SPANISH, SPANISH_MEXICAN )
383         LANG_SUB_ENTRY( "ES", SPANISH, SPANISH_MODERN )
384         LANG_SUB_ENTRY( "GT", SPANISH, SPANISH_GUATEMALA )
385         LANG_SUB_ENTRY( "CR", SPANISH, SPANISH_COSTARICA )
386         LANG_SUB_ENTRY( "PA", SPANISH, SPANISH_PANAMA )
387         LANG_SUB_ENTRY( "DO", SPANISH, SPANISH_DOMINICAN )
388         LANG_SUB_ENTRY( "VE", SPANISH, SPANISH_VENEZUELA )
389         LANG_SUB_ENTRY( "CO", SPANISH, SPANISH_COLOMBIA )
390         LANG_SUB_ENTRY( "PE", SPANISH, SPANISH_PERU )
391         LANG_SUB_ENTRY( "AR", SPANISH, SPANISH_ARGENTINA )
392         LANG_SUB_ENTRY( "EC", SPANISH, SPANISH_ECUADOR )
393         LANG_SUB_ENTRY( "CL", SPANISH, SPANISH_CHILE )
394         LANG_SUB_ENTRY( "UY", SPANISH, SPANISH_URUGUAY )
395         LANG_SUB_ENTRY( "PY", SPANISH, SPANISH_PARAGUAY )
396         LANG_SUB_ENTRY( "BO", SPANISH, SPANISH_BOLIVIA )
397         LANG_SUB_ENTRY( "HN", SPANISH, SPANISH_HONDURAS )
398         LANG_SUB_ENTRY( "NI", SPANISH, SPANISH_NICARAGUA )
399         LANG_SUB_ENTRY( "PR", SPANISH, SPANISH_PUERTO_RICO )
400         LANG_ENTRY_END( SPANISH )
401 /*x0b*/ LANG_ENTRY_BEGIN( "fi", FINNISH )
402         LANG_ENTRY_END( FINNISH )
403 /*x0c*/ LANG_ENTRY_BEGIN( "fr", FRENCH )
404         LANG_SUB_ENTRY( "FR", FRENCH, FRENCH )
405         LANG_SUB_ENTRY( "BE", FRENCH, FRENCH_BELGIAN )
406         LANG_SUB_ENTRY( "CA", FRENCH, FRENCH_CANADIAN )
407         LANG_SUB_ENTRY( "CH", FRENCH, FRENCH_SWISS )
408         LANG_SUB_ENTRY( "LU", FRENCH, FRENCH_LUXEMBOURG )
409         LANG_SUB_ENTRY( "MC", FRENCH, FRENCH_MONACO )
410         LANG_ENTRY_END( FRENCH )
411 /*x0d*/ LANG_ENTRY_BEGIN( "iw", HEBREW )
412         LANG_ENTRY_END( HEBREW )
413 /*x0e*/ LANG_ENTRY_BEGIN( "hu", HUNGARIAN )
414         LANG_ENTRY_END( HUNGARIAN )
415 /*x0f*/ LANG_ENTRY_BEGIN( "ic", ICELANDIC )
416         LANG_ENTRY_END( ICELANDIC )
417 /*x10*/ LANG_ENTRY_BEGIN( "it", ITALIAN )
418         LANG_SUB_ENTRY( "IT", ITALIAN, ITALIAN )
419         LANG_SUB_ENTRY( "CH", ITALIAN, ITALIAN_SWISS )
420         LANG_ENTRY_END( ITALIAN )
421 /*x11*/ LANG_ENTRY_BEGIN( "ja", JAPANESE )
422         LANG_ENTRY_END( JAPANESE )
423 /*x12*/ LANG_ENTRY_BEGIN( "ko", KOREAN )
424         /* JOHAB encoding */
425         if (!strcmp(charset,"JOHAB"))
426                 LANG_DIALECT_ENTRY( KOREAN, KOREAN_JOHAB )
427         else
428                 LANG_DIALECT_ENTRY( KOREAN, KOREAN )
429         LANG_ENTRY_END( KOREAN )
430 /*x13*/ LANG_ENTRY_BEGIN( "nl", DUTCH )
431         LANG_SUB_ENTRY( "NL", DUTCH, DUTCH )
432         LANG_SUB_ENTRY( "BE", DUTCH, DUTCH_BELGIAN )
433         LANG_SUB_ENTRY( "SR", DUTCH, DUTCH_SURINAM )
434         LANG_ENTRY_END( DUTCH )
435 /*x14*/ LANG_ENTRY_BEGIN( "no", NORWEGIAN )
436         /* nynorsk */
437         if (!strcmp(dialect,"nynorsk"))
438                 LANG_DIALECT_ENTRY( NORWEGIAN, NORWEGIAN_NYNORSK )
439         else
440                 LANG_DIALECT_ENTRY( NORWEGIAN, NORWEGIAN_BOKMAL )
441         LANG_ENTRY_END( NORWEGIAN )
442 /*x15*/ LANG_ENTRY_BEGIN( "pl", POLISH )
443         LANG_ENTRY_END( POLISH )
444 /*x16*/ LANG_ENTRY_BEGIN( "pt", PORTUGUESE )
445         LANG_SUB_ENTRY( "BR", PORTUGUESE, PORTUGUESE_BRAZILIAN )
446         LANG_SUB_ENTRY( "PT", PORTUGUESE, PORTUGUESE )
447         LANG_ENTRY_END( PORTUGUESE )
448 /*x17*/ LANG_ENTRY_BEGIN( "rm", RHAETO_ROMANCE )
449         LANG_ENTRY_END( RHAETO_ROMANCE )
450 /*x18*/ LANG_ENTRY_BEGIN( "ro", ROMANIAN )
451         LANG_SUB_ENTRY( "RO", ROMANIAN, ROMANIAN )
452         LANG_SUB_ENTRY( "MD", ROMANIAN, ROMANIAN_MOLDAVIA )
453         LANG_ENTRY_END( ROMANIAN )
454 /*x19*/ LANG_ENTRY_BEGIN( "ru", RUSSIAN )
455         LANG_SUB_ENTRY( "RU", RUSSIAN, RUSSIAN )
456         LANG_SUB_ENTRY( "MD", RUSSIAN, RUSSIAN_MOLDAVIA )
457         LANG_ENTRY_END( RUSSIAN )
458 /*x1a*/ if (!strcmp(lang,"sh") || !strcmp(lang,"hr") || !strcmp(lang,"sr")) {
459             if (!country[0]) 
460                 LANG_DIALECT_ENTRY( SERBO_CROATIAN, NEUTRAL)
461             if (!strcmp(charset,"ISO-8859-5"))
462                 LANG_DIALECT_ENTRY( SERBO_CROATIAN, SERBIAN )
463             LANG_SUB_ENTRY( "HR", SERBO_CROATIAN, CROATIAN )
464             if (!strcmp(country,"YU") && !strcmp(charset,"ISO-8859-2"))
465                 LANG_DIALECT_ENTRY( SERBO_CROATIAN, SERBIAN_LATIN )
466             LANG_SUB_ENTRY( "YU", SERBO_CROATIAN, SERBIAN )
467             LANG_DIALECT_ENTRY( SERBO_CROATIAN, SERBIAN_LATIN )
468         }
469 /*x1b*/ LANG_ENTRY_BEGIN( "sk", SLOVAK )
470         LANG_ENTRY_END( SLOVAK )
471 /*x1c*/ LANG_ENTRY_BEGIN( "sq", ALBANIAN )
472         LANG_ENTRY_END( ALBANIAN )
473 /*x1d*/ LANG_ENTRY_BEGIN( "sv", SWEDISH )
474         LANG_SUB_ENTRY( "SE", SWEDISH, SWEDISH )
475         LANG_SUB_ENTRY( "FI", SWEDISH, SWEDISH_FINLAND )
476         LANG_ENTRY_END( SWEDISH )
477 /*x1e*/ LANG_ENTRY_BEGIN( "th", THAI )
478         LANG_ENTRY_END( THAI )
479 /*x1f*/ LANG_ENTRY_BEGIN( "tr", TURKISH )
480         LANG_ENTRY_END( TURKISH )
481 /*x20*/ LANG_ENTRY_BEGIN( "ur", URDU )
482         LANG_ENTRY_END( URDU )
483 /*x21*/ LANG_ENTRY_BEGIN( "in", INDONESIAN )
484         LANG_ENTRY_END( INDONESIAN )
485 /*x22*/ LANG_ENTRY_BEGIN( "uk", UKRAINIAN )
486         LANG_ENTRY_END( UKRAINIAN )
487 /*x23*/ LANG_ENTRY_BEGIN( "be", BYELORUSSIAN )
488         LANG_ENTRY_END( BYELORUSSIAN )
489 /*x24*/ LANG_ENTRY_BEGIN( "sl", SLOVENIAN )
490         LANG_ENTRY_END( SLOVENIAN )
491 /*x25*/ LANG_ENTRY_BEGIN( "et", ESTONIAN )
492         LANG_ENTRY_END( ESTONIAN )
493 /*x26*/ LANG_ENTRY_BEGIN( "lv", LATVIAN )
494         LANG_ENTRY_END( LATVIAN )
495 /*x27*/ LANG_ENTRY_BEGIN( "lt", LITHUANIAN )
496         /* traditional sorting ? */
497         if (!strcmp(dialect,"classic") || !strcmp(dialect,"traditional"))
498                 LANG_DIALECT_ENTRY( LITHUANIAN, LITHUANIAN_CLASSIC )
499         else
500                 LANG_DIALECT_ENTRY( LITHUANIAN, LITHUANIAN )
501         LANG_ENTRY_END( LITHUANIAN )
502 /*x28*/ LANG_ENTRY_BEGIN( "mi", MAORI )
503         LANG_ENTRY_END( MAORI )
504 /*x29*/ LANG_ENTRY_BEGIN( "fa", FARSI )
505         LANG_ENTRY_END( FARSI )
506 /*x2a*/ LANG_ENTRY_BEGIN( "vi", VIETNAMESE )
507         LANG_ENTRY_END( VIETNAMESE )
508 /*x2b*/ LANG_ENTRY_BEGIN( "hy", ARMENIAN )
509         LANG_ENTRY_END( ARMENIAN )
510 /*x2c*/ LANG_ENTRY_BEGIN( "az", AZERI )
511         /* Cyrillic */
512         if (strstr(charset,"KOI8") || !strcmp(charset,"ISO-8859-5"))
513                 LANG_DIALECT_ENTRY( AZERI, AZERI_CYRILLIC )
514         else
515                 LANG_DIALECT_ENTRY( AZERI, AZERI )
516         LANG_ENTRY_END( AZERI )
517 /*x2d*/ LANG_ENTRY_BEGIN( "eu", BASQUE )
518         LANG_ENTRY_END( BASQUE )
519 /*x2e*/ /*LANG_ENTRY_BEGIN( "??", SORBIAN )
520         LANG_ENTRY_END( SORBIAN ) */
521 /*x2f*/ LANG_ENTRY_BEGIN( "mk", MACEDONIAN )
522         LANG_ENTRY_END( MACEDONIAN )
523 /*x30*/ /*LANG_ENTRY_BEGIN( "??", SUTU )
524         LANG_ENTRY_END( SUTU ) */
525 /*x31*/ LANG_ENTRY_BEGIN( "ts", TSONGA )
526         LANG_ENTRY_END( TSONGA )
527 /*x32*/ /*LANG_ENTRY_BEGIN( "??", TSWANA )
528         LANG_ENTRY_END( TSWANA ) */
529 /*x33*/ /*LANG_ENTRY_BEGIN( "??", VENDA )
530         LANG_ENTRY_END( VENDA ) */
531 /*x34*/ LANG_ENTRY_BEGIN( "xh", XHOSA )
532         LANG_ENTRY_END( XHOSA )
533 /*x35*/ LANG_ENTRY_BEGIN( "zu", ZULU )
534         LANG_ENTRY_END( ZULU )
535 /*x36*/ LANG_ENTRY_BEGIN( "af", AFRIKAANS )
536         LANG_ENTRY_END( AFRIKAANS )
537 /*x37*/ LANG_ENTRY_BEGIN( "ka", GEORGIAN )
538         LANG_ENTRY_END( GEORGIAN )
539 /*x38*/ LANG_ENTRY_BEGIN( "fo", FAEROESE )
540         LANG_ENTRY_END( FAEROESE )
541 /*x39*/ LANG_ENTRY_BEGIN( "hi", HINDI )
542         LANG_ENTRY_END( HINDI )
543 /*x3a*/ LANG_ENTRY_BEGIN( "mt", MALTESE )
544         LANG_ENTRY_END( MALTESE )
545 /*x3b*/ /*LANG_ENTRY_BEGIN( "??", SAAMI )
546         LANG_ENTRY_END( SAAMI ) */
547 /*x3c*/ LANG_ENTRY_BEGIN( "ga", GAELIC )
548         LANG_DIALECT_ENTRY( GAELIC, GAELIC )
549         LANG_ENTRY_END( GAELIC )
550 /*x3c*/ LANG_ENTRY_BEGIN( "gd", GAELIC )
551         LANG_DIALECT_ENTRY( GAELIC, GAELIC_SCOTTISH )
552         LANG_ENTRY_END( GAELIC )
553 /* 0x3d */
554 /*x3e*/ LANG_ENTRY_BEGIN( "ms", MALAY )
555         LANG_SUB_ENTRY( "MY", MALAY, MALAY )
556         LANG_SUB_ENTRY( "BN", MALAY, MALAY_BRUNEI_DARUSSALAM )
557         LANG_ENTRY_END( MALAY )
558 /*x3f*/ LANG_ENTRY_BEGIN( "kk", KAZAKH )
559         LANG_ENTRY_END( KAZAKH )
560 /* 0x40 */
561 /*x41*/ LANG_ENTRY_BEGIN( "sw", SWAHILI )
562         LANG_ENTRY_END( SWAHILI )
563 /* 0x42 */
564 /*x43*/ LANG_ENTRY_BEGIN( "uz", UZBEK )
565         /* Cyrillic */
566         if (strstr(charset,"KOI8") || !strcmp(charset,"ISO-8859-5"))
567                 LANG_DIALECT_ENTRY( UZBEK, UZBEK_CYRILLIC )
568         else
569                 LANG_DIALECT_ENTRY( UZBEK, UZBEK )
570         LANG_ENTRY_END( UZBEK )
571 /*x44*/ LANG_ENTRY_BEGIN( "tt", TATAR )
572         LANG_ENTRY_END( TATAR )
573 /*x45*/ LANG_ENTRY_BEGIN( "bn", BENGALI )
574         LANG_ENTRY_END( BENGALI )
575 /*x46*/ LANG_ENTRY_BEGIN( "pa", PUNJABI )
576         LANG_ENTRY_END( PUNJABI )
577 /*x47*/ LANG_ENTRY_BEGIN( "gu", GUJARATI )
578         LANG_ENTRY_END( GUJARATI )
579 /*x48*/ LANG_ENTRY_BEGIN( "or", ORIYA )
580         LANG_ENTRY_END( ORIYA )
581 /*x49*/ LANG_ENTRY_BEGIN( "ta", TAMIL )
582         LANG_ENTRY_END( TAMIL )
583 /*x4a*/ LANG_ENTRY_BEGIN( "te", TELUGU )
584         LANG_ENTRY_END( TELUGU )
585 /*x4b*/ LANG_ENTRY_BEGIN( "kn", KANNADA )
586         LANG_ENTRY_END( KANNADA )
587 /*x4c*/ LANG_ENTRY_BEGIN( "ml", MALAYALAM )
588         LANG_ENTRY_END( MALAYALAM )
589 /*x4d*/ LANG_ENTRY_BEGIN( "as", ASSAMESE )
590         LANG_ENTRY_END( ASSAMESE )
591 /*x4e*/ LANG_ENTRY_BEGIN( "mr", MARATHI )
592         LANG_ENTRY_END( MARATHI )
593 /*x4f*/ LANG_ENTRY_BEGIN( "sa", SANSKRIT )
594         LANG_ENTRY_END( SANSKRIT )
595 /* 0x50 -> 0x56 */
596 /*x57*/ /*LANG_ENTRY_BEGIN( "??", KONKANI )
597         LANG_ENTRY_END( KONKANI ) */
598 /* 0x58 -> ... */
599         LANG_ENTRY_BEGIN( "eo", ESPERANTO ) /* not official */
600         LANG_ENTRY_END( ESPERANTO )
601         LANG_ENTRY_BEGIN( "wa", WALON ) /* not official */ 
602         LANG_ENTRY_END( WALON )
603
604         ret = LANG_ENGLISH;
605
606 end_MAIN_GetLanguageID:
607         if (Charset) free(charset);
608         free(dialect);
609
610         return ret;
611 }
612
613 /***********************************************************************
614  *           MAIN_ParseLanguageOption
615  *
616  * Parse -language option.
617  */
618 void MAIN_ParseLanguageOption( const char *arg )
619 {
620     const WINE_LANGUAGE_DEF *p = Languages;
621
622     Options.language = LANG_Xx;  /* First (dummy) language */
623     for (;p->name;p++)
624     {
625         if (!lstrcmpiA( p->name, arg ))
626         {
627             WINE_LanguageId = p->langid;
628             return;
629         }
630         Options.language++;
631     }
632     MESSAGE( "Invalid language specified '%s'. Supported languages are: ", arg );
633     for (p = Languages; p->name; p++) MESSAGE( "%s ", p->name );
634     MESSAGE( "\n" );
635     ExitProcess(1);
636 }
637
638
639 /***********************************************************************
640  *           called_at_exit
641  */
642 static void called_at_exit(void)
643 {
644     if (GDI_Driver)
645         GDI_Driver->pFinalize();
646     if (USER_Driver)
647         USER_Driver->pFinalize();
648
649     CONSOLE_Close();
650 }
651
652 /***********************************************************************
653  *           MAIN_WineInit
654  *
655  * Wine initialisation and command-line parsing
656  */
657 BOOL MAIN_WineInit( int *argc, char *argv[] )
658 {    
659     struct timeval tv;
660
661 #ifdef MALLOC_DEBUGGING
662     char *trace;
663
664     mcheck(NULL);
665     if (!(trace = getenv("MALLOC_TRACE")))
666     {       
667         MESSAGE( "MALLOC_TRACE not set. No trace generated\n" );
668     }
669     else
670     {
671         MESSAGE( "malloc trace goes to %s\n", trace );
672         mtrace();
673     }
674 #endif
675
676     setbuf(stdout,NULL);
677     setbuf(stderr,NULL);
678
679     setlocale(LC_CTYPE,"");
680     gettimeofday( &tv, NULL);
681     MSG_WineStartTicks = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
682     
683     OPTIONS_ParseOptions( *argc, argv );
684
685 #ifndef X_DISPLAY_MISSING
686     USER_Driver = &X11DRV_USER_Driver;
687 #else /* !defined(X_DISPLAY_MISSING) */
688     USER_Driver = &TTYDRV_USER_Driver;
689 #endif /* !defined(X_DISPLAY_MISSING) */
690
691     USER_Driver->pInitialize();
692
693     MONITOR_Initialize(&MONITOR_PrimaryMonitor);
694
695     atexit(called_at_exit);
696     return TRUE;
697 }
698
699 /***********************************************************************
700  *           MessageBeep16   (USER.104)
701  */
702 void WINAPI MessageBeep16( UINT16 i )
703 {
704     MessageBeep( i );
705 }
706
707
708 /***********************************************************************
709  *           MessageBeep32   (USER32.390)
710  */
711 BOOL WINAPI MessageBeep( UINT i )
712 {
713     KEYBOARD_Beep();
714     return TRUE;
715 }
716
717
718 /***********************************************************************
719  *           Beep   (KERNEL32.11)
720  */
721 BOOL WINAPI Beep( DWORD dwFreq, DWORD dwDur )
722 {
723     /* dwFreq and dwDur are ignored by Win95 */
724     KEYBOARD_Beep();
725     return TRUE;
726 }
727
728
729 /***********************************************************************
730 *       FileCDR (KERNEL.130)
731 */
732 FARPROC16 WINAPI FileCDR16(FARPROC16 x)
733 {
734         FIXME_(file)("(0x%8x): stub\n", (int) x);
735         return (FARPROC16)TRUE;
736 }
737
738 /***********************************************************************
739  *           GetTickCount   (USER.13) (KERNEL32.299)
740  *
741  * Returns the number of milliseconds, modulo 2^32, since the start
742  * of the current session.
743  */
744 DWORD WINAPI GetTickCount(void)
745 {
746     struct timeval t;
747     gettimeofday( &t, NULL );
748     return ((t.tv_sec * 1000) + (t.tv_usec / 1000)) - MSG_WineStartTicks;
749 }