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