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