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