Removed references to obsolete msdos/cdrom.c file.
[wine/wine64.git] / misc / main.c
blob4445d9738262f3550232257a31f201546a286f36
1 /*
2 * Main function.
4 * Copyright 1994 Alexandre Julliard
5 */
7 #include <signal.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <unistd.h>
11 #include <ctype.h>
12 #ifdef MALLOC_DEBUGGING
13 # include <malloc.h>
14 #endif
15 #include "ts_xlib.h"
16 #include "ts_xresource.h"
17 #include "ts_xutil.h"
18 #include <X11/Xlocale.h>
19 #include <X11/cursorfont.h>
20 #include "winsock.h"
21 #include "heap.h"
22 #include "message.h"
23 #include "msdos.h"
24 #include "windows.h"
25 #include "color.h"
26 #include "options.h"
27 #include "desktop.h"
28 #include "process.h"
29 #include "shell.h"
30 #include "winbase.h"
31 #include "builtin32.h"
32 #include "debug.h"
33 #include "debugdefs.h"
34 #include "xmalloc.h"
35 #include "version.h"
36 #include "winnls.h"
37 #include "x11drv.h"
38 #include "console.h"
40 /* when adding new languages look at ole/ole2nls.c
41 * for proper iso name and Windows code (add 0x0400
42 * to the code listed there)
44 const WINE_LANGUAGE_DEF Languages[] =
46 {"En",0x0409}, /* LANG_En */
47 {"Es",0x040A}, /* LANG_Es */
48 {"De",0x0407}, /* LANG_De */
49 {"No",0x0414}, /* LANG_No */
50 {"Fr",0x040C}, /* LANG_Fr */
51 {"Fi",0x040B}, /* LANG_Fi */
52 {"Da",0x0406}, /* LANG_Da */
53 {"Cs",0x0405}, /* LANG_Cs */
54 {"Eo",0x048f}, /* LANG_Eo */
55 {"It",0x0410}, /* LANG_It */
56 {"Ko",0x0412}, /* LANG_Ko */
57 {"Hu",0x040e}, /* LANG_Hu */
58 {"Pl",0x0415}, /* LANG_Pl */
59 {"Pt",0x0416}, /* LANG_Pt */
60 {"Sv",0x041d}, /* LANG_Sv */
61 {"Ca",0x0403}, /* LANG_Ca */
62 {NULL,0}
65 WORD WINE_LanguageId = 0x409; /* english as default */
67 #define WINE_CLASS "Wine" /* Class name for resources */
69 #define WINE_APP_DEFAULTS "/usr/lib/X11/app-defaults/Wine"
71 Display *display;
72 Screen *screen;
73 Window rootWindow;
74 int screenWidth = 0, screenHeight = 0; /* Desktop window dimensions */
75 int screenDepth = 0; /* Screen depth to use */
77 struct options Options =
78 { /* default options */
79 NULL, /* desktopGeometry */
80 NULL, /* programName */
81 NULL, /* argv0 */
82 NULL, /* dllFlags */
83 FALSE, /* usePrivateMap */
84 FALSE, /* useFixedMap */
85 FALSE, /* synchronous */
86 FALSE, /* backing store */
87 SW_SHOWNORMAL, /* cmdShow */
88 FALSE,
89 FALSE, /* failReadOnly */
90 MODE_ENHANCED, /* Enhanced mode */
91 #ifdef DEFAULT_LANG
92 DEFAULT_LANG, /* Default language */
93 #else
94 LANG_En,
95 #endif
96 FALSE, /* Managed windows */
97 FALSE, /* Perfect graphics */
98 FALSE, /* No DGA */
99 NULL, /* Alternate config file name */
100 NULL /* Console driver list */
104 static XrmOptionDescRec optionsTable[] =
106 { "-backingstore", ".backingstore", XrmoptionNoArg, (caddr_t)"on" },
107 { "-desktop", ".desktop", XrmoptionSepArg, (caddr_t)NULL },
108 { "-depth", ".depth", XrmoptionSepArg, (caddr_t)NULL },
109 { "-display", ".display", XrmoptionSepArg, (caddr_t)NULL },
110 { "-iconic", ".iconic", XrmoptionNoArg, (caddr_t)"on" },
111 { "-language", ".language", XrmoptionSepArg, (caddr_t)"En" },
112 { "-name", ".name", XrmoptionSepArg, (caddr_t)NULL },
113 { "-perfect", ".perfect", XrmoptionNoArg, (caddr_t)"on" },
114 { "-privatemap", ".privatemap", XrmoptionNoArg, (caddr_t)"on" },
115 { "-fixedmap", ".fixedmap", XrmoptionNoArg, (caddr_t)"on" },
116 { "-synchronous", ".synchronous", XrmoptionNoArg, (caddr_t)"on" },
117 { "-debug", ".debug", XrmoptionNoArg, (caddr_t)"on" },
118 { "-debugmsg", ".debugmsg", XrmoptionSepArg, (caddr_t)NULL },
119 { "-dll", ".dll", XrmoptionSepArg, (caddr_t)NULL },
120 { "-failreadonly", ".failreadonly", XrmoptionNoArg, (caddr_t)"on" },
121 { "-mode", ".mode", XrmoptionSepArg, (caddr_t)NULL },
122 { "-managed", ".managed", XrmoptionNoArg, (caddr_t)"off"},
123 { "-winver", ".winver", XrmoptionSepArg, (caddr_t)NULL },
124 { "-config", ".config", XrmoptionSepArg, (caddr_t)NULL },
125 { "-nodga", ".nodga", XrmoptionNoArg, (caddr_t)"off"},
126 { "-console", ".console", XrmoptionSepArg, (caddr_t)NULL },
127 { "-dosver", ".dosver", XrmoptionSepArg, (caddr_t)NULL }
130 #define NB_OPTIONS (sizeof(optionsTable) / sizeof(optionsTable[0]))
132 #define USAGE \
133 "%s\n" \
134 "Usage: %s [options] \"program_name [arguments]\"\n" \
135 "\n" \
136 "Options:\n" \
137 " -backingstore Turn on backing store\n" \
138 " -config name Specify config file to use\n" \
139 " -console driver Select which driver(s) to use for the console\n" \
140 " -debug Enter debugger before starting application\n" \
141 " -debugmsg name Turn debugging-messages on or off\n" \
142 " -depth n Change the depth to use for multiple-depth screens\n" \
143 " -desktop geom Use a desktop window of the given geometry\n" \
144 " -display name Use the specified display\n" \
145 " -dll name Enable or disable built-in DLLs\n" \
146 " -failreadonly Read only files may not be opened in write mode\n" \
147 " -fixedmap Use a \"standard\" color map\n" \
148 " -help Show this help message\n" \
149 " -iconic Start as an icon\n" \
150 " -language xx Set the language (one of Ca,Cs,Da,De,En,Eo,Es,Fi,Fr,Hu,It,\n Ko,No,Pl,Pt,Sv)\n" \
151 " -managed Allow the window manager to manage created windows\n" \
152 " -mode mode Start Wine in a particular mode (standard or enhanced)\n" \
153 " -name name Set the application name\n" \
154 " -nodga Disable XFree86 DGA extensions\n" \
155 " -perfect Favor correctness over speed for graphical operations\n" \
156 " -privatemap Use a private color map\n" \
157 " -synchronous Turn on synchronous display mode\n" \
158 " -version Display the Wine version\n" \
159 " -winver Windows version to imitate (one of win31,win95,nt351,nt40)\n" \
160 " -dosver DOS version to imitate (x.xx, e.g. 6.22). Only valid with -winver win31\n"
164 /***********************************************************************
165 * MAIN_Usage
167 void MAIN_Usage( char *name )
169 MSG( USAGE, WINE_RELEASE_INFO, name );
170 exit(1);
174 /***********************************************************************
175 * MAIN_GetProgramName
177 * Get the program name. The name is specified by (in order of precedence):
178 * - the option '-name'.
179 * - the environment variable 'WINE_NAME'.
180 * - the last component of argv[0].
182 static char *MAIN_GetProgramName( int argc, char *argv[] )
184 int i;
185 char *p;
187 for (i = 1; i < argc-1; i++)
188 if (!strcmp( argv[i], "-name" )) return argv[i+1];
189 if ((p = getenv( "WINE_NAME" )) != NULL) return p;
190 if ((p = strrchr( argv[0], '/' )) != NULL) return p+1;
191 return argv[0];
195 /***********************************************************************
196 * MAIN_GetResource
198 * Fetch the value of resource 'name' using the correct instance name.
199 * 'name' must begin with '.' or '*'
201 static int MAIN_GetResource( XrmDatabase db, char *name, XrmValue *value )
203 char *buff_instance, *buff_class;
204 char *dummy;
205 int retval;
207 buff_instance = (char *)xmalloc(strlen(Options.programName)+strlen(name)+1);
208 buff_class = (char *)xmalloc( strlen(WINE_CLASS) + strlen(name) + 1 );
210 strcpy( buff_instance, Options.programName );
211 strcat( buff_instance, name );
212 strcpy( buff_class, WINE_CLASS );
213 strcat( buff_class, name );
214 retval = TSXrmGetResource( db, buff_instance, buff_class, &dummy, value );
215 free( buff_instance );
216 free( buff_class );
217 return retval;
221 /***********************************************************************
222 * MAIN_ParseDebugOptions
224 * Turns specific debug messages on or off, according to "options".
226 * RETURNS
227 * TRUE if parsing was successful
229 BOOL32 MAIN_ParseDebugOptions(char *options)
231 /* defined in relay32/relay386.c */
232 extern char **debug_relay_includelist;
233 extern char **debug_relay_excludelist;
234 /* defined in relay32/snoop.c */
235 extern char **debug_snoop_includelist;
236 extern char **debug_snoop_excludelist;
238 int l, cls, dotracerelay = TRACE_ON(relay);
240 l = strlen(options);
241 if (l<3)
242 return FALSE;
243 if (options[l-1]=='\n') options[l-1]='\0';
246 if ((*options!='+')&&(*options!='-')){
247 int j;
249 for(j=0; j<DEBUG_CLASS_COUNT; j++)
250 if(!lstrncmpi32A(options, debug_cl_name[j], strlen(debug_cl_name[j])))
251 break;
252 if(j==DEBUG_CLASS_COUNT)
253 return FALSE;
254 options += strlen(debug_cl_name[j]);
255 if ((*options!='+')&&(*options!='-'))
256 return FALSE;
257 cls = j;
259 else
260 cls = -1; /* all classes */
262 if (strchr(options,','))
263 l=strchr(options,',')-options;
264 else
265 l=strlen(options);
267 if (!lstrncmpi32A(options+1,"all",l-1))
269 int i, j;
270 for (i=0; i<DEBUG_CHANNEL_COUNT; i++)
271 for(j=0; j<DEBUG_CLASS_COUNT; j++)
272 if(cls == -1 || cls == j)
273 debug_msg_enabled[i][j]=(*options=='+');
275 else if (!lstrncmpi32A(options+1, "relay=", 6) ||
276 !lstrncmpi32A(options+1, "snoop=", 6))
278 int i, j;
279 char *s, *s2, ***output, c;
281 for (i=0; i<DEBUG_CHANNEL_COUNT; i++)
282 if (debug_ch_name && (!lstrncmpi32A(debug_ch_name[i],options+1,5))){
283 for(j=0; j<DEBUG_CLASS_COUNT; j++)
284 if(cls == -1 || cls == j)
285 debug_msg_enabled[i][j]=TRUE;
286 break;
288 /* should never happen, maybe assert(i!=DEBUG_CHANNEL_COUNT)? */
289 if (i==DEBUG_CHANNEL_COUNT)
290 return FALSE;
291 output = (*options == '+') ?
292 ((*(options+1) == 'r') ?
293 &debug_relay_includelist :
294 &debug_snoop_includelist) :
295 ((*(options+1) == 'r') ?
296 &debug_relay_excludelist :
297 &debug_snoop_excludelist);
298 s = options + 7;
299 i = 1;
300 while((s = strchr(s, ':'))) i++, s++;
301 *output = malloc(sizeof(char **) * i + 1);
302 i = 0;
303 s = options + 7;
304 while((s2 = strchr(s, ':'))) {
305 c = *s2;
306 *s2 = '\0';
307 *((*output)+i) = strdup(s);
308 *s2 = c;
309 s = s2 + 1;
310 i++;
312 c = *(options + l);
313 *(options + l) = '\0';
314 *((*output)+i) = strdup(s);
315 *(options + l) = c;
316 *((*output)+i+1) = NULL;
318 else
320 int i, j;
321 for (i=0; i<DEBUG_CHANNEL_COUNT; i++)
322 if (debug_ch_name && (!lstrncmpi32A(options+1,debug_ch_name[i],l-1))){
323 for(j=0; j<DEBUG_CLASS_COUNT; j++)
324 if(cls == -1 || cls == j)
325 debug_msg_enabled[i][j]=(*options=='+');
326 break;
328 if (i==DEBUG_CHANNEL_COUNT)
329 return FALSE;
331 options+=l;
333 while((*options==',')&&(*(++options)));
335 /* special handling for relay debugging */
336 if (dotracerelay != TRACE_ON(relay))
337 BUILTIN32_SwitchRelayDebug( TRACE_ON(relay) );
339 if (*options)
340 return FALSE;
341 else
342 return TRUE;
345 /***********************************************************************
346 * MAIN_GetLanguageID
348 * INPUT:
349 * Lang: a string whose two first chars are the iso name of a language.
350 * Country: a string whose two first chars are the iso name of country
351 * Charset: a string defining the chossen charset encoding
352 * Dialect: a string defining a variation of the locale
354 * all those values are from the standardized format of locale
355 * name in unix which is: Lang[_Country][.Charset][@Dialect]
357 * RETURNS:
358 * the numeric code of the language used by Windows (or 0x00)
360 int MAIN_GetLanguageID(LPCSTR Lang,LPCSTR Country,LPCSTR Charset,LPCSTR Dialect)
362 char lang[3]="??", country[3]={0,0,0};
363 char *charset=NULL, *dialect=NULL;
364 int i,j,ret=0;
366 if (Lang==NULL) return 0x00;
367 if (Lang[0]) lang[0]=tolower(Lang[0]);
368 if (Lang[1]) lang[1]=tolower(Lang[1]);
370 if (Country!=NULL) {
371 if (Country[0]) country[0]=toupper(Country[0]);
372 if (Country[1]) country[1]=toupper(Country[1]);
375 if (Charset!=NULL) {
376 j=strlen(Charset);
377 charset=(char*)malloc(j+1);
378 for (i=0;i<j;i++)
379 charset[i]=toupper(Charset[i]);
380 charset[i]='\0';
383 if (Dialect!=NULL) {
384 j=strlen(Dialect);
385 dialect=(char*)malloc(j+1);
386 for (i=0;i<j;i++)
387 dialect[i]=tolower(Dialect[i]);
388 dialect[i]='\0';
391 #define LANG_ENTRY_BEGIN(x,y) if(!strcmp(lang, x )) { \
392 if (!country[0]) { \
393 ret=LANG_##y ; \
394 goto end_MAIN_GetLanguageID; \
396 #define LANG_SUB_ENTRY(x,y,z) if (!strcmp(country, x )) \
397 ret = MAKELANGID( LANG_##y , SUBLANG_##z ); \
398 goto end_MAIN_GetLanguageID;
399 #define LANG_DIALECT_ENTRY(x,y) { ret = MAKELANGID(LANG_##x , SUBLANG_##y ); \
400 goto end_MAIN_GetLanguageID; }
401 #define LANG_ENTRY_END(x) ret = MAKELANGID(LANG_##x , SUBLANG_DEFAULT); \
402 goto end_MAIN_GetLanguageID; \
405 /*x01*/ LANG_ENTRY_BEGIN( "ar", ARABIC )
406 LANG_SUB_ENTRY( "SA", ARABIC, ARABIC)
407 LANG_SUB_ENTRY( "IQ", ARABIC, ARABIC_IRAQ )
408 LANG_SUB_ENTRY( "EG", ARABIC, ARABIC_EGYPT )
409 LANG_SUB_ENTRY( "LY", ARABIC, ARABIC_LIBYA )
410 LANG_SUB_ENTRY( "DZ", ARABIC, ARABIC_ALGERIA )
411 LANG_SUB_ENTRY( "MA", ARABIC, ARABIC_MOROCCO )
412 LANG_SUB_ENTRY( "TN", ARABIC, ARABIC_TUNISIA )
413 LANG_SUB_ENTRY( "OM", ARABIC, ARABIC_OMAN )
414 LANG_SUB_ENTRY( "YE", ARABIC, ARABIC_YEMEN )
415 LANG_SUB_ENTRY( "SY", ARABIC, ARABIC_SYRIA )
416 LANG_SUB_ENTRY( "JO", ARABIC, ARABIC_JORDAN )
417 LANG_SUB_ENTRY( "LB", ARABIC, ARABIC_LEBANON )
418 LANG_SUB_ENTRY( "KW", ARABIC, ARABIC_KUWAIT )
419 LANG_SUB_ENTRY( "AE", ARABIC, ARABIC_UAE )
420 LANG_SUB_ENTRY( "BH", ARABIC, ARABIC_BAHRAIN )
421 LANG_SUB_ENTRY( "QA", ARABIC, ARABIC_QATAR )
422 LANG_ENTRY_END( ARABIC )
423 /*x02*/ LANG_ENTRY_BEGIN( "bu", BULGARIAN )
424 LANG_ENTRY_END( BULGARIAN )
425 /*x03*/ LANG_ENTRY_BEGIN( "ca", CATALAN )
426 LANG_ENTRY_END( CATALAN )
427 /*x04*/ LANG_ENTRY_BEGIN( "zh", CHINESE )
428 LANG_SUB_ENTRY( "TW", CHINESE, CHINESE_TRADITIONAL )
429 LANG_SUB_ENTRY( "CN", CHINESE, CHINESE_SIMPLIFIED )
430 LANG_SUB_ENTRY( "HK", CHINESE, CHINESE_HONGKONG )
431 LANG_SUB_ENTRY( "SG", CHINESE, CHINESE_SINGAPORE )
432 LANG_SUB_ENTRY( "MO", CHINESE, CHINESE_MACAU )
433 LANG_ENTRY_END( CHINESE )
434 /*x05*/ LANG_ENTRY_BEGIN( "cs", CZECH )
435 LANG_ENTRY_END( CZECH )
436 /*x06*/ LANG_ENTRY_BEGIN( "da", DANISH )
437 LANG_ENTRY_END( DANISH )
438 /*x07*/ LANG_ENTRY_BEGIN( "de", GERMAN )
439 LANG_SUB_ENTRY( "DE", GERMAN, GERMAN )
440 LANG_SUB_ENTRY( "CH", GERMAN, GERMAN_SWISS )
441 LANG_SUB_ENTRY( "AT", GERMAN, GERMAN_AUSTRIAN )
442 LANG_SUB_ENTRY( "LU", GERMAN, GERMAN_LUXEMBOURG )
443 LANG_SUB_ENTRY( "LI", GERMAN, GERMAN_LIECHTENSTEIN )
444 LANG_ENTRY_END( GERMAN )
445 /*x08*/ LANG_ENTRY_BEGIN( "el", GREEK )
446 LANG_ENTRY_END( GREEK )
447 /*x09*/ LANG_ENTRY_BEGIN( "en", ENGLISH )
448 LANG_SUB_ENTRY( "US", ENGLISH, ENGLISH_US )
449 LANG_SUB_ENTRY( "UK", ENGLISH, ENGLISH_UK )
450 LANG_SUB_ENTRY( "AU", ENGLISH, ENGLISH_AUS )
451 LANG_SUB_ENTRY( "CA", ENGLISH, ENGLISH_CAN )
452 LANG_SUB_ENTRY( "NZ", ENGLISH, ENGLISH_NZ )
453 LANG_SUB_ENTRY( "EI", ENGLISH, ENGLISH_EIRE )
454 LANG_SUB_ENTRY( "ZA", ENGLISH, ENGLISH_SAFRICA )
455 LANG_SUB_ENTRY( "JM", ENGLISH, ENGLISH_JAMAICA )
456 /* LANG_SUB_ENTRY( "AG", ENGLISH, ENGLISH_CARIBBEAN ) */
457 LANG_SUB_ENTRY( "BZ", ENGLISH, ENGLISH_BELIZE )
458 LANG_SUB_ENTRY( "TT", ENGLISH, ENGLISH_TRINIDAD )
459 LANG_SUB_ENTRY( "ZW", ENGLISH, ENGLISH_ZIMBABWE )
460 LANG_SUB_ENTRY( "PH", ENGLISH, ENGLISH_PHILIPPINES )
461 LANG_ENTRY_END( ENGLISH )
462 /*x0a*/ LANG_ENTRY_BEGIN( "es", SPANISH )
463 /* traditional sorting */
464 if (!strcmp(dialect,"tradicional"))
465 LANG_DIALECT_ENTRY( SPANISH, SPANISH )
466 LANG_SUB_ENTRY( "MX", SPANISH, SPANISH_MEXICAN )
467 LANG_SUB_ENTRY( "ES", SPANISH, SPANISH_MODERN )
468 LANG_SUB_ENTRY( "GT", SPANISH, SPANISH_GUATEMALA )
469 LANG_SUB_ENTRY( "CR", SPANISH, SPANISH_COSTARICA )
470 LANG_SUB_ENTRY( "PA", SPANISH, SPANISH_PANAMA )
471 LANG_SUB_ENTRY( "DO", SPANISH, SPANISH_DOMINICAN )
472 LANG_SUB_ENTRY( "VE", SPANISH, SPANISH_VENEZUELA )
473 LANG_SUB_ENTRY( "CO", SPANISH, SPANISH_COLOMBIA )
474 LANG_SUB_ENTRY( "PE", SPANISH, SPANISH_PERU )
475 LANG_SUB_ENTRY( "AR", SPANISH, SPANISH_ARGENTINA )
476 LANG_SUB_ENTRY( "EC", SPANISH, SPANISH_ECUADOR )
477 LANG_SUB_ENTRY( "CL", SPANISH, SPANISH_CHILE )
478 LANG_SUB_ENTRY( "UY", SPANISH, SPANISH_URUGUAY )
479 LANG_SUB_ENTRY( "PY", SPANISH, SPANISH_PARAGUAY )
480 LANG_SUB_ENTRY( "BO", SPANISH, SPANISH_BOLIVIA )
481 LANG_SUB_ENTRY( "HN", SPANISH, SPANISH_HONDURAS )
482 LANG_SUB_ENTRY( "NI", SPANISH, SPANISH_NICARAGUA )
483 LANG_SUB_ENTRY( "PR", SPANISH, SPANISH_PUERTO_RICO )
484 LANG_ENTRY_END( SPANISH )
485 /*x0b*/ LANG_ENTRY_BEGIN( "fi", FINNISH )
486 LANG_ENTRY_END( FINNISH )
487 /*x0c*/ LANG_ENTRY_BEGIN( "fr", FRENCH )
488 LANG_SUB_ENTRY( "FR", FRENCH, FRENCH )
489 LANG_SUB_ENTRY( "BE", FRENCH, FRENCH_BELGIAN )
490 LANG_SUB_ENTRY( "CA", FRENCH, FRENCH_CANADIAN )
491 LANG_SUB_ENTRY( "CH", FRENCH, FRENCH_SWISS )
492 LANG_SUB_ENTRY( "LU", FRENCH, FRENCH_LUXEMBOURG )
493 LANG_SUB_ENTRY( "MC", FRENCH, FRENCH_MONACO )
494 LANG_ENTRY_END( FRENCH )
495 /*x0d*/ LANG_ENTRY_BEGIN( "iw", HEBREW )
496 LANG_ENTRY_END( HEBREW )
497 /*x0e*/ LANG_ENTRY_BEGIN( "hu", HUNGARIAN )
498 LANG_ENTRY_END( HUNGARIAN )
499 /*x0f*/ LANG_ENTRY_BEGIN( "ic", ICELANDIC )
500 LANG_ENTRY_END( ICELANDIC )
501 /*x10*/ LANG_ENTRY_BEGIN( "it", ITALIAN )
502 LANG_SUB_ENTRY( "IT", ITALIAN, ITALIAN )
503 LANG_SUB_ENTRY( "CH", ITALIAN, ITALIAN_SWISS )
504 LANG_ENTRY_END( ITALIAN )
505 /*x11*/ LANG_ENTRY_BEGIN( "ja", JAPANESE )
506 LANG_ENTRY_END( JAPANESE )
507 /*x12*/ LANG_ENTRY_BEGIN( "ko", KOREAN )
508 /* JOHAB encoding */
509 if (!strcmp(charset,"JOHAB"))
510 LANG_DIALECT_ENTRY( KOREAN, KOREAN_JOHAB )
511 else
512 LANG_DIALECT_ENTRY( KOREAN, KOREAN )
513 LANG_ENTRY_END( KOREAN )
514 /*x13*/ LANG_ENTRY_BEGIN( "nl", DUTCH )
515 LANG_SUB_ENTRY( "NL", DUTCH, DUTCH )
516 LANG_SUB_ENTRY( "BE", DUTCH, DUTCH_BELGIAN )
517 LANG_SUB_ENTRY( "SR", DUTCH, DUTCH_SURINAM )
518 LANG_ENTRY_END( DUTCH )
519 /*x14*/ LANG_ENTRY_BEGIN( "no", NORWEGIAN )
520 /* nynorsk */
521 if (!strcmp(dialect,"nynorsk"))
522 LANG_DIALECT_ENTRY( NORWEGIAN, NORWEGIAN_NYNORSK )
523 else
524 LANG_DIALECT_ENTRY( NORWEGIAN, NORWEGIAN_BOKMAL )
525 LANG_ENTRY_END( NORWEGIAN )
526 /*x15*/ LANG_ENTRY_BEGIN( "pl", POLISH )
527 LANG_ENTRY_END( POLISH )
528 /*x16*/ LANG_ENTRY_BEGIN( "pt", PORTUGUESE )
529 LANG_SUB_ENTRY( "BR", PORTUGUESE, PORTUGUESE_BRAZILIAN )
530 LANG_SUB_ENTRY( "PT", PORTUGUESE, PORTUGUESE )
531 LANG_ENTRY_END( PORTUGUESE )
532 /*x17*/ LANG_ENTRY_BEGIN( "rm", RHAETO_ROMANCE )
533 LANG_ENTRY_END( RHAETO_ROMANCE )
534 /*x18*/ LANG_ENTRY_BEGIN( "ro", ROMANIAN )
535 LANG_SUB_ENTRY( "RO", ROMANIAN, ROMANIAN )
536 LANG_SUB_ENTRY( "MD", ROMANIAN, ROMANIAN_MOLDAVIA )
537 LANG_ENTRY_END( ROMANIAN )
538 /*x19*/ LANG_ENTRY_BEGIN( "ru", RUSSIAN )
539 LANG_SUB_ENTRY( "RU", RUSSIAN, RUSSIAN )
540 LANG_SUB_ENTRY( "MD", RUSSIAN, RUSSIAN_MOLDAVIA )
541 LANG_ENTRY_END( RUSSIAN )
542 /*x1a*/ if (!strcmp(lang,"sh") || !strcmp(lang,"hr") || !strcmp(lang,"sr")) {
543 if (!country[0])
544 LANG_DIALECT_ENTRY( SERBO_CROATIAN, NEUTRAL)
545 if (!strcmp(charset,"ISO-8859-5"))
546 LANG_DIALECT_ENTRY( SERBO_CROATIAN, SERBIAN )
547 LANG_SUB_ENTRY( "HR", SERBO_CROATIAN, CROATIAN )
548 if (!strcmp(country,"YU") && !strcmp(charset,"ISO-8859-2"))
549 LANG_DIALECT_ENTRY( SERBO_CROATIAN, SERBIAN_LATIN )
550 LANG_SUB_ENTRY( "YU", SERBO_CROATIAN, SERBIAN )
551 LANG_DIALECT_ENTRY( SERBO_CROATIAN, SERBIAN_LATIN )
553 /*x1b*/ LANG_ENTRY_BEGIN( "sk", SLOVAK )
554 LANG_ENTRY_END( SLOVAK )
555 /*x1c*/ LANG_ENTRY_BEGIN( "sq", ALBANIAN )
556 LANG_ENTRY_END( ALBANIAN )
557 /*x1d*/ LANG_ENTRY_BEGIN( "sv", SWEDISH )
558 LANG_SUB_ENTRY( "SE", SWEDISH, SWEDISH )
559 LANG_SUB_ENTRY( "FI", SWEDISH, SWEDISH_FINLAND )
560 LANG_ENTRY_END( SWEDISH )
561 /*x1e*/ LANG_ENTRY_BEGIN( "th", THAI )
562 LANG_ENTRY_END( THAI )
563 /*x1f*/ LANG_ENTRY_BEGIN( "tr", TURKISH )
564 LANG_ENTRY_END( TURKISH )
565 /*x20*/ LANG_ENTRY_BEGIN( "ur", URDU )
566 LANG_ENTRY_END( URDU )
567 /*x21*/ LANG_ENTRY_BEGIN( "in", INDONESIAN )
568 LANG_ENTRY_END( INDONESIAN )
569 /*x22*/ LANG_ENTRY_BEGIN( "uk", UKRAINIAN )
570 LANG_ENTRY_END( UKRAINIAN )
571 /*x23*/ LANG_ENTRY_BEGIN( "be", BYELORUSSIAN )
572 LANG_ENTRY_END( BYELORUSSIAN )
573 /*x24*/ LANG_ENTRY_BEGIN( "sl", SLOVENIAN )
574 LANG_ENTRY_END( SLOVENIAN )
575 /*x25*/ LANG_ENTRY_BEGIN( "et", ESTONIAN )
576 LANG_ENTRY_END( ESTONIAN )
577 /*x26*/ LANG_ENTRY_BEGIN( "lv", LATVIAN )
578 LANG_ENTRY_END( LATVIAN )
579 /*x27*/ LANG_ENTRY_BEGIN( "lt", LITHUANIAN )
580 /* traditional sorting ? */
581 if (!strcmp(dialect,"classic") || !strcmp(dialect,"traditional"))
582 LANG_DIALECT_ENTRY( LITHUANIAN, LITHUANIAN_CLASSIC )
583 else
584 LANG_DIALECT_ENTRY( LITHUANIAN, LITHUANIAN )
585 LANG_ENTRY_END( LITHUANIAN )
586 /*x28*/ LANG_ENTRY_BEGIN( "mi", MAORI )
587 LANG_ENTRY_END( MAORI )
588 /*x29*/ LANG_ENTRY_BEGIN( "fa", FARSI )
589 LANG_ENTRY_END( FARSI )
590 /*x2a*/ LANG_ENTRY_BEGIN( "vi", VIETNAMESE )
591 LANG_ENTRY_END( VIETNAMESE )
592 /*x2b*/ LANG_ENTRY_BEGIN( "hy", ARMENIAN )
593 LANG_ENTRY_END( ARMENIAN )
594 /*x2c*/ LANG_ENTRY_BEGIN( "az", AZERI )
595 /* Cyrillic */
596 if (strstr(charset,"KOI8") || !strcmp(charset,"ISO-8859-5"))
597 LANG_DIALECT_ENTRY( AZERI, AZERI_CYRILLIC )
598 else
599 LANG_DIALECT_ENTRY( AZERI, AZERI )
600 LANG_ENTRY_END( AZERI )
601 /*x2d*/ LANG_ENTRY_BEGIN( "eu", BASQUE )
602 LANG_ENTRY_END( BASQUE )
603 /*x2e*/ /*LANG_ENTRY_BEGIN( "??", SORBIAN )
604 LANG_ENTRY_END( SORBIAN ) */
605 /*x2f*/ LANG_ENTRY_BEGIN( "mk", MACEDONIAN )
606 LANG_ENTRY_END( MACEDONIAN )
607 /*x30*/ /*LANG_ENTRY_BEGIN( "??", SUTU )
608 LANG_ENTRY_END( SUTU ) */
609 /*x31*/ LANG_ENTRY_BEGIN( "ts", TSONGA )
610 LANG_ENTRY_END( TSONGA )
611 /*x32*/ /*LANG_ENTRY_BEGIN( "??", TSWANA )
612 LANG_ENTRY_END( TSWANA ) */
613 /*x33*/ /*LANG_ENTRY_BEGIN( "??", VENDA )
614 LANG_ENTRY_END( VENDA ) */
615 /*x34*/ LANG_ENTRY_BEGIN( "xh", XHOSA )
616 LANG_ENTRY_END( XHOSA )
617 /*x35*/ LANG_ENTRY_BEGIN( "zu", ZULU )
618 LANG_ENTRY_END( ZULU )
619 /*x36*/ LANG_ENTRY_BEGIN( "af", AFRIKAANS )
620 LANG_ENTRY_END( AFRIKAANS )
621 /*x37*/ LANG_ENTRY_BEGIN( "ka", GEORGIAN )
622 LANG_ENTRY_END( GEORGIAN )
623 /*x38*/ LANG_ENTRY_BEGIN( "fo", FAEROESE )
624 LANG_ENTRY_END( FAEROESE )
625 /*x39*/ LANG_ENTRY_BEGIN( "hi", HINDI )
626 LANG_ENTRY_END( HINDI )
627 /*x3a*/ LANG_ENTRY_BEGIN( "mt", MALTESE )
628 LANG_ENTRY_END( MALTESE )
629 /*x3b*/ /*LANG_ENTRY_BEGIN( "??", SAAMI )
630 LANG_ENTRY_END( SAAMI ) */
631 /*x3c*/ LANG_ENTRY_BEGIN( "ga", GAELIC )
632 LANG_DIALECT_ENTRY( GAELIC, GAELIC )
633 LANG_ENTRY_END( GAELIC )
634 /*x3c*/ LANG_ENTRY_BEGIN( "gd", GAELIC )
635 LANG_DIALECT_ENTRY( GAELIC, GAELIC_SCOTTISH )
636 LANG_ENTRY_END( GAELIC )
637 /* 0x3d */
638 /*x3e*/ LANG_ENTRY_BEGIN( "ms", MALAY )
639 LANG_SUB_ENTRY( "MY", MALAY, MALAY )
640 LANG_SUB_ENTRY( "BN", MALAY, MALAY_BRUNEI_DARUSSALAM )
641 LANG_ENTRY_END( MALAY )
642 /*x3f*/ LANG_ENTRY_BEGIN( "kk", KAZAKH )
643 LANG_ENTRY_END( KAZAKH )
644 /* 0x40 */
645 /*x41*/ LANG_ENTRY_BEGIN( "sw", SWAHILI )
646 LANG_ENTRY_END( SWAHILI )
647 /* 0x42 */
648 /*x43*/ LANG_ENTRY_BEGIN( "uz", UZBEK )
649 /* Cyrillic */
650 if (strstr(charset,"KOI8") || !strcmp(charset,"ISO-8859-5"))
651 LANG_DIALECT_ENTRY( UZBEK, UZBEK_CYRILLIC )
652 else
653 LANG_DIALECT_ENTRY( UZBEK, UZBEK )
654 LANG_ENTRY_END( UZBEK )
655 /*x44*/ LANG_ENTRY_BEGIN( "tt", TATAR )
656 LANG_ENTRY_END( TATAR )
657 /*x45*/ LANG_ENTRY_BEGIN( "bn", BENGALI )
658 LANG_ENTRY_END( BENGALI )
659 /*x46*/ LANG_ENTRY_BEGIN( "pa", PUNJABI )
660 LANG_ENTRY_END( PUNJABI )
661 /*x47*/ LANG_ENTRY_BEGIN( "gu", GUJARATI )
662 LANG_ENTRY_END( GUJARATI )
663 /*x48*/ LANG_ENTRY_BEGIN( "or", ORIYA )
664 LANG_ENTRY_END( ORIYA )
665 /*x49*/ LANG_ENTRY_BEGIN( "ta", TAMIL )
666 LANG_ENTRY_END( TAMIL )
667 /*x4a*/ LANG_ENTRY_BEGIN( "te", TELUGU )
668 LANG_ENTRY_END( TELUGU )
669 /*x4b*/ LANG_ENTRY_BEGIN( "kn", KANNADA )
670 LANG_ENTRY_END( KANNADA )
671 /*x4c*/ LANG_ENTRY_BEGIN( "ml", MALAYALAM )
672 LANG_ENTRY_END( MALAYALAM )
673 /*x4d*/ LANG_ENTRY_BEGIN( "as", ASSAMESE )
674 LANG_ENTRY_END( ASSAMESE )
675 /*x4e*/ LANG_ENTRY_BEGIN( "mr", MARATHI )
676 LANG_ENTRY_END( MARATHI )
677 /*x4f*/ LANG_ENTRY_BEGIN( "sa", SANSKRIT )
678 LANG_ENTRY_END( SANSKRIT )
679 /* 0x50 -> 0x56 */
680 /*x57*/ /*LANG_ENTRY_BEGIN( "??", KONKANI )
681 LANG_ENTRY_END( KONKANI ) */
682 /* 0x58 -> ... */
683 LANG_ENTRY_BEGIN( "eo", ESPERANTO ) /* not official */
684 LANG_ENTRY_END( ESPERANTO )
686 ret = LANG_ENGLISH;
688 end_MAIN_GetLanguageID:
689 if (Charset) free(charset);
690 if (Dialect) free(dialect);
692 return ret;
695 /***********************************************************************
696 * MAIN_ParseLanguageOption
698 * Parse -language option.
700 static void MAIN_ParseLanguageOption( char *arg )
702 const WINE_LANGUAGE_DEF *p = Languages;
704 /* for compatibility whith non-iso names previously used */
705 if (!strcmp("Sw",arg)) { strcpy(arg,"Sv"); FIXME(system,"use 'Sv' instead of 'Sw'\n");}
706 if (!strcmp("Cz",arg)) { strcpy(arg,"Cs"); FIXME(system,"use 'Cs' instead of 'Cz'\n");}
707 if (!strcmp("Po",arg)) { strcpy(arg,"Pt"); FIXME(system,"use 'Pt' instead of 'Po'\n");}
709 Options.language = LANG_Xx; /* First (dummy) language */
710 for (;p->name;p++)
712 if (!lstrcmpi32A( p->name, arg ))
714 WINE_LanguageId = p->langid;
715 return;
717 Options.language++;
719 MSG( "Invalid language specified '%s'. Supported languages are: ", arg );
720 for (p = Languages; p->name; p++) MSG( "%s ", p->name );
721 MSG( "\n" );
722 exit(1);
726 /***********************************************************************
727 * MAIN_ParseModeOption
729 * Parse -mode option.
731 static void MAIN_ParseModeOption( char *arg )
733 if (!lstrcmpi32A("enhanced", arg)) Options.mode = MODE_ENHANCED;
734 else if (!lstrcmpi32A("standard", arg)) Options.mode = MODE_STANDARD;
735 else
737 MSG( "Invalid mode '%s' specified.\n", arg);
738 MSG( "Valid modes are: 'standard', 'enhanced' (default).\n");
739 exit(1);
743 /***********************************************************************
744 * MAIN_ParseOptions
746 * Parse command line options and open display.
748 static void MAIN_ParseOptions( int *argc, char *argv[] )
750 char *display_name = NULL;
751 XrmValue value;
752 XrmDatabase db = TSXrmGetFileDatabase(WINE_APP_DEFAULTS);
753 int i;
754 char *xrm_string;
756 Options.programName = MAIN_GetProgramName( *argc, argv );
757 Options.argv0 = argv[0];
759 /* initialise Options.language to 0 to tell "no language choosen yet" */
760 Options.language = 0;
762 /* Get display name from command line */
763 for (i = 1; i < *argc; i++)
765 if (!strcmp( argv[i], "-display" )) display_name = argv[i+1];
766 if (!strcmp( argv[i], "-v" ) || !strcmp( argv[i], "-version" ))
768 MSG( "%s\n", WINE_RELEASE_INFO );
769 exit(0);
771 if (!strcmp( argv[i], "-h" ) || !strcmp( argv[i], "-help" ))
773 MAIN_Usage(argv[0]);
774 exit(0);
778 /* Open display */
780 if (display_name == NULL &&
781 MAIN_GetResource( db, ".display", &value )) display_name = value.addr;
783 if (!(display = TSXOpenDisplay( display_name )))
785 MSG( "%s: Can't open display: %s\n",
786 argv[0], display_name ? display_name : "(none specified)" );
787 exit(1);
790 /* tell the libX11 that we will do input method handling ourselves
791 * that keep libX11 from doing anything whith dead keys, allowing Wine
792 * to have total control over dead keys, that is this line allows
793 * them to work in Wine, even whith a libX11 including the dead key
794 * patches from Th.Quinot (http://Web.FdN.FR/~tquinot/dead-keys.en.html)
796 TSXOpenIM(display,NULL,NULL,NULL);
798 /* Merge file and screen databases */
799 if ((xrm_string = TSXResourceManagerString( display )) != NULL)
801 XrmDatabase display_db = TSXrmGetStringDatabase( xrm_string );
802 TSXrmMergeDatabases( display_db, &db );
805 /* Parse command line */
806 TSXrmParseCommand( &db, optionsTable, NB_OPTIONS,
807 Options.programName, argc, argv );
809 /* Get all options */
810 if (MAIN_GetResource( db, ".iconic", &value ))
811 Options.cmdShow = SW_SHOWMINIMIZED;
812 if (MAIN_GetResource( db, ".privatemap", &value ))
813 Options.usePrivateMap = TRUE;
814 if (MAIN_GetResource( db, ".fixedmap", &value ))
815 Options.useFixedMap = TRUE;
816 if (MAIN_GetResource( db, ".synchronous", &value ))
817 Options.synchronous = TRUE;
818 if (MAIN_GetResource( db, ".backingstore", &value ))
819 Options.backingstore = TRUE;
820 if (MAIN_GetResource( db, ".debug", &value ))
821 Options.debug = TRUE;
822 if (MAIN_GetResource( db, ".failreadonly", &value ))
823 Options.failReadOnly = TRUE;
824 if (MAIN_GetResource( db, ".perfect", &value ))
825 Options.perfectGraphics = TRUE;
826 if (MAIN_GetResource( db, ".depth", &value))
827 screenDepth = atoi( value.addr );
828 if (MAIN_GetResource( db, ".desktop", &value))
829 Options.desktopGeometry = value.addr;
830 if (MAIN_GetResource( db, ".language", &value))
831 MAIN_ParseLanguageOption( (char *)value.addr );
832 if (MAIN_GetResource( db, ".managed", &value))
833 Options.managed = TRUE;
834 if (MAIN_GetResource( db, ".mode", &value))
835 MAIN_ParseModeOption( (char *)value.addr );
836 if (MAIN_GetResource( db, ".debugoptions", &value))
837 MAIN_ParseDebugOptions((char*)value.addr);
838 if (MAIN_GetResource( db, ".debugmsg", &value))
840 #ifndef DEBUG_RUNTIME
841 MSG("%s: Option \"-debugmsg\" not implemented.\n" \
842 " Recompile with DEBUG_RUNTIME in include/debugtools.h defined.\n",
843 argv[0]);
844 exit(1);
845 #else
846 if (MAIN_ParseDebugOptions((char*)value.addr)==FALSE)
848 int i;
849 MSG("%s: Syntax: -debugmsg [class]+xxx,... or "
850 "-debugmsg [class]-xxx,...\n",argv[0]);
851 MSG("Example: -debugmsg +all,warn-heap\n"
852 " turn on all messages except warning heap messages\n");
853 MSG("Special case: -debugmsg +relay=DLL:DLL.###:FuncName\n"
854 " turn on -debugmsg +relay only as specified\n"
855 "Special case: -debugmsg -relay=DLL:DLL.###:FuncName\n"
856 " turn on -debugmsg +relay except as specified\n"
857 "Also permitted, +snoop=..., -snoop=... as with relay.\n\n");
859 MSG("Available message classes:\n");
860 for(i=0;i<DEBUG_CLASS_COUNT;i++)
861 MSG( "%-9s", debug_cl_name[i]);
862 MSG("\n\n");
864 MSG("Available message types:\n");
865 MSG("%-9s ","all");
866 for(i=0;i<DEBUG_CHANNEL_COUNT;i++)
867 if(debug_ch_name[i])
868 MSG("%-9s%c",debug_ch_name[i],
869 (((i+2)%8==0)?'\n':' '));
870 MSG("\n\n");
871 exit(1);
873 #endif
876 if (MAIN_GetResource( db, ".dll", &value))
878 /* Hack: store option value in Options to be retrieved */
879 /* later on inside the emulator code. */
880 if (!__winelib)
882 if (Options.dllFlags)
884 /* don't overwrite previous value. Should we
885 * automatically add the ',' between multiple DLLs ?
887 MSG("Only one -dll flag is allowed. Use ',' between multiple DLLs\n");
889 else
891 Options.dllFlags = xstrdup((char *)value.addr);
894 else
896 MSG("-dll not supported in Winelib\n" );
897 exit(1);
901 if (MAIN_GetResource( db, ".winver", &value))
902 VERSION_ParseWinVersion( (char*)value.addr );
903 if (MAIN_GetResource( db, ".dosver", &value))
904 VERSION_ParseDosVersion( (char*)value.addr );
905 if (MAIN_GetResource( db, ".config", &value))
906 Options.configFileName = xstrdup((char *)value.addr);
907 if (MAIN_GetResource( db, ".nodga", &value))
908 Options.noDGA = TRUE;
909 if (MAIN_GetResource( db, ".console", &value))
910 Options.consoleDrivers = xstrdup((char *)value.addr);
911 else
912 Options.consoleDrivers = CONSOLE_DEFAULT_DRIVER;
914 CONSOLE_Init(Options.consoleDrivers);
918 /***********************************************************************
919 * MAIN_CreateDesktop
921 static void MAIN_CreateDesktop( int argc, char *argv[] )
923 int x, y, flags;
924 unsigned int width = 640, height = 480; /* Default size = 640x480 */
925 char *name = "Wine desktop";
926 XSizeHints *size_hints;
927 XWMHints *wm_hints;
928 XClassHint *class_hints;
929 XSetWindowAttributes win_attr;
930 XTextProperty window_name;
931 Atom XA_WM_DELETE_WINDOW;
933 flags = TSXParseGeometry( Options.desktopGeometry, &x, &y, &width, &height );
934 screenWidth = width;
935 screenHeight = height;
937 /* Create window */
939 win_attr.background_pixel = BlackPixel(display,0);
940 win_attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
941 PointerMotionMask | ButtonPressMask |
942 ButtonReleaseMask | EnterWindowMask;
943 win_attr.cursor = TSXCreateFontCursor( display, XC_top_left_arrow );
945 rootWindow = TSXCreateWindow( display, DefaultRootWindow(display),
946 x, y, width, height, 0,
947 CopyFromParent, InputOutput, CopyFromParent,
948 CWBackPixel | CWEventMask | CWCursor, &win_attr );
950 /* Set window manager properties */
952 size_hints = TSXAllocSizeHints();
953 wm_hints = TSXAllocWMHints();
954 class_hints = TSXAllocClassHint();
955 if (!size_hints || !wm_hints || !class_hints)
957 MSG("Not enough memory for window manager hints.\n" );
958 exit(1);
960 size_hints->min_width = size_hints->max_width = width;
961 size_hints->min_height = size_hints->max_height = height;
962 size_hints->flags = PMinSize | PMaxSize;
963 if (flags & (XValue | YValue)) size_hints->flags |= USPosition;
964 if (flags & (WidthValue | HeightValue)) size_hints->flags |= USSize;
965 else size_hints->flags |= PSize;
967 wm_hints->flags = InputHint | StateHint;
968 wm_hints->input = True;
969 wm_hints->initial_state = NormalState;
970 class_hints->res_name = argv[0];
971 class_hints->res_class = "Wine";
973 TSXStringListToTextProperty( &name, 1, &window_name );
974 TSXSetWMProperties( display, rootWindow, &window_name, &window_name,
975 argv, argc, size_hints, wm_hints, class_hints );
976 XA_WM_DELETE_WINDOW = TSXInternAtom( display, "WM_DELETE_WINDOW", False );
977 TSXSetWMProtocols( display, rootWindow, &XA_WM_DELETE_WINDOW, 1 );
978 TSXFree( size_hints );
979 TSXFree( wm_hints );
980 TSXFree( class_hints );
982 /* Map window */
984 TSXMapWindow( display, rootWindow );
988 XKeyboardState keyboard_state;
990 /***********************************************************************
991 * MAIN_SaveSetup
993 static void MAIN_SaveSetup(void)
995 TSXGetKeyboardControl(display, &keyboard_state);
998 /***********************************************************************
999 * MAIN_RestoreSetup
1001 static void MAIN_RestoreSetup(void)
1003 XKeyboardControl keyboard_value;
1005 keyboard_value.key_click_percent = keyboard_state.key_click_percent;
1006 keyboard_value.bell_percent = keyboard_state.bell_percent;
1007 keyboard_value.bell_pitch = keyboard_state.bell_pitch;
1008 keyboard_value.bell_duration = keyboard_state.bell_duration;
1009 keyboard_value.auto_repeat_mode = keyboard_state.global_auto_repeat;
1011 XChangeKeyboardControl(display, KBKeyClickPercent | KBBellPercent |
1012 KBBellPitch | KBBellDuration | KBAutoRepeatMode, &keyboard_value);
1016 /***********************************************************************
1017 * called_at_exit
1019 static void called_at_exit(void)
1021 MAIN_RestoreSetup();
1022 COLOR_Cleanup();
1023 WINSOCK_Shutdown();
1024 /* FIXME: should check for other processes or threads */
1025 DeleteCriticalSection( HEAP_SystemLock );
1026 CONSOLE_Close();
1029 static int WINE_X11_ErrorHandler(Display *display,XErrorEvent *error_evt)
1031 kill( getpid(), SIGHUP ); /* force an entry in the debugger */
1032 return 0;
1035 /***********************************************************************
1036 * MAIN_WineInit
1038 * Wine initialisation and command-line parsing
1040 BOOL32 MAIN_WineInit( int *argc, char *argv[] )
1042 int depth_count, i;
1043 int *depth_list;
1044 struct timeval tv;
1046 #ifdef MALLOC_DEBUGGING
1047 char *trace;
1049 mcheck(NULL);
1050 if (!(trace = getenv("MALLOC_TRACE")))
1052 MSG( "MALLOC_TRACE not set. No trace generated\n" );
1054 else
1056 MSG( "malloc trace goes to %s\n", trace );
1057 mtrace();
1059 #endif
1061 setbuf(stdout,NULL);
1062 setbuf(stderr,NULL);
1064 setlocale(LC_CTYPE,"");
1065 gettimeofday( &tv, NULL);
1066 MSG_WineStartTicks = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
1068 /* We need this before calling any Xlib function */
1069 InitializeCriticalSection( &X11DRV_CritSection );
1070 MakeCriticalSectionGlobal( &X11DRV_CritSection );
1072 TSXrmInitialize();
1074 putenv("XKB_DISABLE="); /* Disable XKB extension if present. */
1076 MAIN_ParseOptions( argc, argv );
1078 if (Options.synchronous) XSetErrorHandler( WINE_X11_ErrorHandler );
1080 if (Options.desktopGeometry && Options.managed)
1082 #if 0
1083 MSG( "%s: -managed and -desktop options cannot be used together\n",
1084 Options.programName );
1085 exit(1);
1086 #else
1087 Options.managed = FALSE;
1088 #endif
1091 screen = DefaultScreenOfDisplay( display );
1092 screenWidth = WidthOfScreen( screen );
1093 screenHeight = HeightOfScreen( screen );
1094 if (screenDepth) /* -depth option specified */
1096 depth_list = TSXListDepths(display,DefaultScreen(display),&depth_count);
1097 for (i = 0; i < depth_count; i++)
1098 if (depth_list[i] == screenDepth) break;
1099 TSXFree( depth_list );
1100 if (i >= depth_count)
1102 MSG( "%s: Depth %d not supported on this screen.\n",
1103 Options.programName, screenDepth );
1104 exit(1);
1107 else screenDepth = DefaultDepthOfScreen( screen );
1108 if (Options.synchronous) TSXSynchronize( display, True );
1109 if (Options.desktopGeometry) MAIN_CreateDesktop( *argc, argv );
1110 else rootWindow = DefaultRootWindow( display );
1112 MAIN_SaveSetup();
1113 atexit(called_at_exit);
1114 return TRUE;
1118 /***********************************************************************
1119 * MessageBeep16 (USER.104)
1121 void WINAPI MessageBeep16( UINT16 i )
1123 MessageBeep32( i );
1127 /***********************************************************************
1128 * MessageBeep32 (USER32.390)
1130 BOOL32 WINAPI MessageBeep32( UINT32 i )
1132 TSXBell( display, 0 );
1133 return TRUE;
1137 /***********************************************************************
1138 * Beep (KERNEL32.11)
1140 BOOL32 WINAPI Beep( DWORD dwFreq, DWORD dwDur )
1142 /* dwFreq and dwDur are ignored by Win95 */
1143 TSXBell(display, 0);
1144 return TRUE;
1148 /***********************************************************************
1149 * GetTimerResolution (USER.14)
1151 LONG WINAPI GetTimerResolution(void)
1153 return (1000);
1156 /***********************************************************************
1157 * SystemParametersInfo32A (USER32.540)
1159 BOOL32 WINAPI SystemParametersInfo32A( UINT32 uAction, UINT32 uParam,
1160 LPVOID lpvParam, UINT32 fuWinIni )
1162 int timeout, temp;
1163 XKeyboardState keyboard_state;
1165 switch (uAction) {
1166 case SPI_GETBEEP:
1167 TSXGetKeyboardControl(display, &keyboard_state);
1168 if (keyboard_state.bell_percent == 0)
1169 *(BOOL32 *) lpvParam = FALSE;
1170 else
1171 *(BOOL32 *) lpvParam = TRUE;
1172 break;
1174 case SPI_GETBORDER:
1175 *(INT32 *)lpvParam = GetSystemMetrics32( SM_CXFRAME );
1176 break;
1178 case SPI_GETDRAGFULLWINDOWS:
1179 *(BOOL32 *) lpvParam = FALSE;
1180 break;
1182 case SPI_SETDRAGFULLWINDOWS:
1183 break;
1185 case SPI_GETFASTTASKSWITCH:
1186 if ( GetProfileInt32A( "windows", "CoolSwitch", 1 ) == 1 )
1187 *(BOOL32 *) lpvParam = TRUE;
1188 else
1189 *(BOOL32 *) lpvParam = FALSE;
1190 break;
1192 case SPI_GETGRIDGRANULARITY:
1193 *(INT32*)lpvParam=GetProfileInt32A("desktop","GridGranularity",1);
1194 break;
1196 case SPI_GETICONTITLEWRAP:
1197 *(BOOL32*)lpvParam=GetProfileInt32A("desktop","IconTitleWrap",TRUE);
1198 break;
1200 case SPI_GETKEYBOARDDELAY:
1201 *(INT32*)lpvParam=GetProfileInt32A("keyboard","KeyboardDelay",1);
1202 break;
1204 case SPI_GETKEYBOARDSPEED:
1205 *(DWORD*)lpvParam=GetProfileInt32A("keyboard","KeyboardSpeed",30);
1206 break;
1208 case SPI_GETMENUDROPALIGNMENT:
1209 *(BOOL32*)lpvParam=GetSystemMetrics32(SM_MENUDROPALIGNMENT); /* XXX check this */
1210 break;
1212 case SPI_GETSCREENSAVEACTIVE:
1213 if ( GetProfileInt32A( "windows", "ScreenSaveActive", 1 ) == 1 )
1214 *(BOOL32*)lpvParam = TRUE;
1215 else
1216 *(BOOL32*)lpvParam = FALSE;
1217 break;
1219 case SPI_GETSCREENSAVETIMEOUT:
1220 /* FIXME GetProfileInt( "windows", "ScreenSaveTimeout", 300 ); */
1221 TSXGetScreenSaver(display, &timeout, &temp,&temp,&temp);
1222 *(INT32 *) lpvParam = timeout * 1000;
1223 break;
1225 case SPI_ICONHORIZONTALSPACING:
1226 /* FIXME Get/SetProfileInt */
1227 if (lpvParam == NULL)
1228 /*SetSystemMetrics( SM_CXICONSPACING, uParam )*/ ;
1229 else
1230 *(INT32*)lpvParam=GetSystemMetrics32(SM_CXICONSPACING);
1231 break;
1233 case SPI_ICONVERTICALSPACING:
1234 /* FIXME Get/SetProfileInt */
1235 if (lpvParam == NULL)
1236 /*SetSystemMetrics( SM_CYICONSPACING, uParam )*/ ;
1237 else
1238 *(INT32*)lpvParam=GetSystemMetrics32(SM_CYICONSPACING);
1239 break;
1241 case SPI_GETICONTITLELOGFONT: {
1242 LPLOGFONT32A lpLogFont = (LPLOGFONT32A)lpvParam;
1244 /* from now on we always have an alias for MS Sans Serif */
1246 GetProfileString32A("Desktop", "IconTitleFaceName", "MS Sans Serif",
1247 lpLogFont->lfFaceName, LF_FACESIZE );
1248 lpLogFont->lfHeight = -GetProfileInt32A("Desktop","IconTitleSize", 8);
1249 lpLogFont->lfWidth = 0;
1250 lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
1251 lpLogFont->lfWeight = FW_NORMAL;
1252 lpLogFont->lfItalic = FALSE;
1253 lpLogFont->lfStrikeOut = FALSE;
1254 lpLogFont->lfUnderline = FALSE;
1255 lpLogFont->lfCharSet = ANSI_CHARSET;
1256 lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
1257 lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
1258 lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
1259 break;
1261 case SPI_GETWORKAREA:
1262 SetRect32( (RECT32 *)lpvParam, 0, 0,
1263 GetSystemMetrics32( SM_CXSCREEN ),
1264 GetSystemMetrics32( SM_CYSCREEN )
1266 break;
1267 case SPI_GETNONCLIENTMETRICS:
1269 #define lpnm ((LPNONCLIENTMETRICS32A)lpvParam)
1271 if( lpnm->cbSize == sizeof(NONCLIENTMETRICS32A) )
1273 /* FIXME: initialize geometry entries */
1275 SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
1276 (LPVOID)&(lpnm->lfCaptionFont),0);
1277 lpnm->lfCaptionFont.lfWeight = FW_BOLD;
1278 SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
1279 (LPVOID)&(lpnm->lfSmCaptionFont),0);
1280 SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
1281 (LPVOID)&(lpnm->lfMenuFont),0);
1282 SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
1283 (LPVOID)&(lpnm->lfStatusFont),0);
1284 SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
1285 (LPVOID)&(lpnm->lfMessageFont),0);
1287 #undef lpnm
1288 break;
1290 case SPI_GETANIMATION: {
1291 LPANIMATIONINFO lpAnimInfo = (LPANIMATIONINFO)lpvParam;
1293 /* Tell it "disabled" */
1294 lpAnimInfo->cbSize = sizeof(ANIMATIONINFO);
1295 uParam = sizeof(ANIMATIONINFO);
1296 lpAnimInfo->iMinAnimate = 0; /* Minimise and restore animation is disabled (nonzero == enabled) */
1297 break;
1300 case SPI_SETANIMATION: {
1301 LPANIMATIONINFO lpAnimInfo = (LPANIMATIONINFO)lpvParam;
1303 /* Do nothing */
1304 WARN(system, "SPI_SETANIMATION ignored.\n");
1305 lpAnimInfo->cbSize = sizeof(ANIMATIONINFO);
1306 uParam = sizeof(ANIMATIONINFO);
1307 break;
1310 case SPI_GETHIGHCONTRAST:
1312 LPHIGHCONTRASTA lpHighContrastA = (LPHIGHCONTRASTA)lpvParam;
1314 FIXME(system,"SPI_GETHIGHCONTRAST not fully implemented\n");
1316 if ( lpHighContrastA->cbSize == sizeof( HIGHCONTRASTA ) )
1318 /* Indicate that there is no high contrast available */
1319 lpHighContrastA->dwFlags = 0;
1320 lpHighContrastA->lpszDefaultScheme = NULL;
1322 else
1324 return FALSE;
1327 break;
1330 default:
1331 return SystemParametersInfo16(uAction,uParam,lpvParam,fuWinIni);
1333 return TRUE;
1337 /***********************************************************************
1338 * SystemParametersInfo16 (USER.483)
1340 BOOL16 WINAPI SystemParametersInfo16( UINT16 uAction, UINT16 uParam,
1341 LPVOID lpvParam, UINT16 fuWinIni )
1343 int timeout, temp;
1344 char buffer[256];
1345 XKeyboardState keyboard_state;
1346 XKeyboardControl keyboard_value;
1349 switch (uAction)
1351 case SPI_GETBEEP:
1352 TSXGetKeyboardControl(display, &keyboard_state);
1353 if (keyboard_state.bell_percent == 0)
1354 *(BOOL16 *) lpvParam = FALSE;
1355 else
1356 *(BOOL16 *) lpvParam = TRUE;
1357 break;
1359 case SPI_GETBORDER:
1360 *(INT16 *)lpvParam = GetSystemMetrics16( SM_CXFRAME );
1361 break;
1363 case SPI_GETFASTTASKSWITCH:
1364 if ( GetProfileInt32A( "windows", "CoolSwitch", 1 ) == 1 )
1365 *(BOOL16 *) lpvParam = TRUE;
1366 else
1367 *(BOOL16 *) lpvParam = FALSE;
1368 break;
1370 case SPI_GETGRIDGRANULARITY:
1371 *(INT16 *) lpvParam = GetProfileInt32A( "desktop",
1372 "GridGranularity",
1373 1 );
1374 break;
1376 case SPI_GETICONTITLEWRAP:
1377 *(BOOL16 *) lpvParam = GetProfileInt32A( "desktop",
1378 "IconTitleWrap",
1379 TRUE );
1380 break;
1382 case SPI_GETKEYBOARDDELAY:
1383 *(INT16 *) lpvParam = GetProfileInt32A( "keyboard",
1384 "KeyboardDelay", 1 );
1385 break;
1387 case SPI_GETKEYBOARDSPEED:
1388 *(WORD *) lpvParam = GetProfileInt32A( "keyboard",
1389 "KeyboardSpeed",
1390 30 );
1391 break;
1393 case SPI_GETMENUDROPALIGNMENT:
1394 *(BOOL16 *) lpvParam = GetSystemMetrics16( SM_MENUDROPALIGNMENT ); /* XXX check this */
1395 break;
1397 case SPI_GETSCREENSAVEACTIVE:
1398 if ( GetProfileInt32A( "windows", "ScreenSaveActive", 1 ) == 1 )
1399 *(BOOL16 *) lpvParam = TRUE;
1400 else
1401 *(BOOL16 *) lpvParam = FALSE;
1402 break;
1404 case SPI_GETSCREENSAVETIMEOUT:
1405 /* FIXME GetProfileInt( "windows", "ScreenSaveTimeout", 300 ); */
1406 TSXGetScreenSaver(display, &timeout, &temp,&temp,&temp);
1407 *(INT16 *) lpvParam = timeout;
1408 break;
1410 case SPI_ICONHORIZONTALSPACING:
1411 /* FIXME Get/SetProfileInt */
1412 if (lpvParam == NULL)
1413 /*SetSystemMetrics( SM_CXICONSPACING, uParam )*/ ;
1414 else
1415 *(INT16 *)lpvParam = GetSystemMetrics16( SM_CXICONSPACING );
1416 break;
1418 case SPI_ICONVERTICALSPACING:
1419 /* FIXME Get/SetProfileInt */
1420 if (lpvParam == NULL)
1421 /*SetSystemMetrics( SM_CYICONSPACING, uParam )*/ ;
1422 else
1423 *(INT16 *)lpvParam = GetSystemMetrics16(SM_CYICONSPACING);
1424 break;
1426 case SPI_SETBEEP:
1427 if (uParam == TRUE)
1428 keyboard_value.bell_percent = -1;
1429 else
1430 keyboard_value.bell_percent = 0;
1431 TSXChangeKeyboardControl(display, KBBellPercent,
1432 &keyboard_value);
1433 break;
1435 case SPI_SETSCREENSAVEACTIVE:
1436 if (uParam == TRUE)
1437 TSXActivateScreenSaver(display);
1438 else
1439 TSXResetScreenSaver(display);
1440 break;
1442 case SPI_SETSCREENSAVETIMEOUT:
1443 TSXSetScreenSaver(display, uParam, 60, DefaultBlanking,
1444 DefaultExposures);
1445 break;
1447 case SPI_SETDESKWALLPAPER:
1448 return (SetDeskWallPaper32((LPSTR) lpvParam));
1449 break;
1451 case SPI_SETDESKPATTERN:
1452 if ((INT16)uParam == -1) {
1453 GetProfileString32A("Desktop", "Pattern",
1454 "170 85 170 85 170 85 170 85",
1455 buffer, sizeof(buffer) );
1456 return (DESKTOP_SetPattern((LPSTR) buffer));
1457 } else
1458 return (DESKTOP_SetPattern((LPSTR) lpvParam));
1459 break;
1461 case SPI_GETICONTITLELOGFONT:
1463 LPLOGFONT16 lpLogFont = (LPLOGFONT16)lpvParam;
1465 GetProfileString32A("Desktop", "IconTitleFaceName", "MS Sans Serif",
1466 lpLogFont->lfFaceName, LF_FACESIZE );
1467 lpLogFont->lfHeight = -GetProfileInt32A("Desktop","IconTitleSize", 8);
1468 lpLogFont->lfWidth = 0;
1469 lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
1470 lpLogFont->lfWeight = FW_NORMAL;
1471 lpLogFont->lfItalic = FALSE;
1472 lpLogFont->lfStrikeOut = FALSE;
1473 lpLogFont->lfUnderline = FALSE;
1474 lpLogFont->lfCharSet = ANSI_CHARSET;
1475 lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
1476 lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
1477 lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
1478 break;
1480 case SPI_GETNONCLIENTMETRICS:
1482 #define lpnm ((LPNONCLIENTMETRICS16)lpvParam)
1483 if( lpnm->cbSize == sizeof(NONCLIENTMETRICS16) )
1485 /* FIXME: initialize geometry entries */
1486 SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
1487 (LPVOID)&(lpnm->lfCaptionFont),0);
1488 lpnm->lfCaptionFont.lfWeight = FW_BOLD;
1489 SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
1490 (LPVOID)&(lpnm->lfSmCaptionFont),0);
1491 SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
1492 (LPVOID)&(lpnm->lfMenuFont),0);
1493 SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
1494 (LPVOID)&(lpnm->lfStatusFont),0);
1495 SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
1496 (LPVOID)&(lpnm->lfMessageFont),0);
1498 else /* winfile 95 sets sbSize to 340 */
1499 SystemParametersInfo32A( uAction, uParam, lpvParam, fuWinIni );
1500 #undef lpnm
1501 break;
1503 case SPI_LANGDRIVER:
1504 case SPI_SETBORDER:
1505 case SPI_SETDOUBLECLKHEIGHT:
1506 case SPI_SETDOUBLECLICKTIME:
1507 case SPI_SETDOUBLECLKWIDTH:
1508 case SPI_SETFASTTASKSWITCH:
1509 case SPI_SETKEYBOARDDELAY:
1510 case SPI_SETKEYBOARDSPEED:
1511 WARN(system, "Option %d ignored.\n", uAction);
1512 break;
1514 case SPI_GETWORKAREA:
1515 SetRect16( (RECT16 *)lpvParam, 0, 0,
1516 GetSystemMetrics16( SM_CXSCREEN ),
1517 GetSystemMetrics16( SM_CYSCREEN ) );
1518 break;
1520 default:
1521 WARN(system, "Unknown option %d.\n", uAction);
1522 break;
1524 return 1;
1527 /***********************************************************************
1528 * SystemParametersInfo32W (USER32.541)
1530 BOOL32 WINAPI SystemParametersInfo32W( UINT32 uAction, UINT32 uParam,
1531 LPVOID lpvParam, UINT32 fuWinIni )
1533 char buffer[256];
1535 switch (uAction)
1537 case SPI_SETDESKWALLPAPER:
1538 if (lpvParam)
1540 lstrcpynWtoA(buffer,(LPWSTR)lpvParam,sizeof(buffer));
1541 return SetDeskWallPaper32(buffer);
1543 return SetDeskWallPaper32(NULL);
1545 case SPI_SETDESKPATTERN:
1546 if ((INT32) uParam == -1)
1548 GetProfileString32A("Desktop", "Pattern",
1549 "170 85 170 85 170 85 170 85",
1550 buffer, sizeof(buffer) );
1551 return (DESKTOP_SetPattern((LPSTR) buffer));
1553 if (lpvParam)
1555 lstrcpynWtoA(buffer,(LPWSTR)lpvParam,sizeof(buffer));
1556 return DESKTOP_SetPattern(buffer);
1558 return DESKTOP_SetPattern(NULL);
1560 case SPI_GETICONTITLELOGFONT:
1562 LPLOGFONT32W lpLogFont = (LPLOGFONT32W)lpvParam;
1563 GetProfileString32A("Desktop", "IconTitleFaceName", "MS Sans Serif",
1564 buffer, sizeof(buffer) );
1565 lstrcpynAtoW(lpLogFont->lfFaceName, buffer ,LF_FACESIZE);
1566 lpLogFont->lfHeight = 10;
1567 lpLogFont->lfWidth = 0;
1568 lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
1569 lpLogFont->lfWeight = FW_NORMAL;
1570 lpLogFont->lfItalic = lpLogFont->lfStrikeOut = lpLogFont->lfUnderline = FALSE;
1571 lpLogFont->lfCharSet = ANSI_CHARSET;
1572 lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
1573 lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
1574 lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
1576 break;
1577 case SPI_GETNONCLIENTMETRICS: {
1578 /* FIXME: implement correctly */
1579 LPNONCLIENTMETRICS32W lpnm=(LPNONCLIENTMETRICS32W)lpvParam;
1581 SystemParametersInfo32W(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfCaptionFont),0);
1582 lpnm->lfCaptionFont.lfWeight = FW_BOLD;
1583 SystemParametersInfo32W(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfSmCaptionFont),0);
1584 SystemParametersInfo32W(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfMenuFont),0);
1585 SystemParametersInfo32W(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfStatusFont),0);
1586 SystemParametersInfo32W(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfMessageFont),0);
1587 break;
1590 case SPI_GETHIGHCONTRAST:
1592 LPHIGHCONTRASTW lpHighContrastW = (LPHIGHCONTRASTW)lpvParam;
1594 FIXME(system,"SPI_GETHIGHCONTRAST not fully implemented\n");
1596 if ( lpHighContrastW->cbSize == sizeof( HIGHCONTRASTW ) )
1598 /* Indicate that there is no high contrast available */
1599 lpHighContrastW->dwFlags = 0;
1600 lpHighContrastW->lpszDefaultScheme = NULL;
1602 else
1604 return FALSE;
1607 break;
1610 default:
1611 return SystemParametersInfo32A(uAction,uParam,lpvParam,fuWinIni);
1614 return TRUE;
1618 /***********************************************************************
1619 * FileCDR (KERNEL.130)
1621 FARPROC16 WINAPI FileCDR(FARPROC16 x)
1623 FIXME(file,"(0x%8x): stub\n", (int) x);
1624 return (FARPROC16)TRUE;