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