Use proper system directory.
[wine/multimedia.git] / misc / main.c
blobf148a5b1c42ab7b3dda89b83627b11becd230adf
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 "debug.h"
32 #include "debugdefs.h"
33 #include "xmalloc.h"
34 #include "version.h"
35 #include "winnls.h"
36 #include "x11drv.h"
37 #include "console.h"
39 /* when adding new languages look at ole/ole2nls.c
40 * for proper iso name and Windows code (add 0x0400
41 * to the code listed there)
43 const WINE_LANGUAGE_DEF Languages[] =
45 {"En",0x0409}, /* LANG_En */
46 {"Es",0x040A}, /* LANG_Es */
47 {"De",0x0407}, /* LANG_De */
48 {"No",0x0414}, /* LANG_No */
49 {"Fr",0x040C}, /* LANG_Fr */
50 {"Fi",0x040B}, /* LANG_Fi */
51 {"Da",0x0406}, /* LANG_Da */
52 {"Cs",0x0405}, /* LANG_Cs */
53 {"Eo",0x048f}, /* LANG_Eo */
54 {"It",0x0410}, /* LANG_It */
55 {"Ko",0x0412}, /* LANG_Ko */
56 {"Hu",0x040e}, /* LANG_Hu */
57 {"Pl",0x0415}, /* LANG_Pl */
58 {"Pt",0x0416}, /* LANG_Pt */
59 {"Sv",0x041d}, /* LANG_Sv */
60 {"Ca",0x0403}, /* LANG_Ca */
61 {NULL,0}
64 WORD WINE_LanguageId = 0x409; /* english as default */
66 #define WINE_CLASS "Wine" /* Class name for resources */
68 #define WINE_APP_DEFAULTS "/usr/lib/X11/app-defaults/Wine"
70 Display *display;
71 Screen *screen;
72 Window rootWindow;
73 int screenWidth = 0, screenHeight = 0; /* Desktop window dimensions */
74 int screenDepth = 0; /* Screen depth to use */
76 struct options Options =
77 { /* default options */
78 NULL, /* desktopGeometry */
79 NULL, /* programName */
80 NULL, /* argv0 */
81 NULL, /* dllFlags */
82 FALSE, /* usePrivateMap */
83 FALSE, /* useFixedMap */
84 FALSE, /* synchronous */
85 FALSE, /* backing store */
86 SW_SHOWNORMAL, /* cmdShow */
87 FALSE,
88 FALSE, /* failReadOnly */
89 MODE_ENHANCED, /* Enhanced mode */
90 #ifdef DEFAULT_LANG
91 DEFAULT_LANG, /* Default language */
92 #else
93 LANG_En,
94 #endif
95 FALSE, /* Managed windows */
96 FALSE, /* Perfect graphics */
97 FALSE, /* No DGA */
98 NULL, /* Alternate config file name */
99 NULL /* Console driver list */
103 static XrmOptionDescRec optionsTable[] =
105 { "-backingstore", ".backingstore", XrmoptionNoArg, (caddr_t)"on" },
106 { "-desktop", ".desktop", XrmoptionSepArg, (caddr_t)NULL },
107 { "-depth", ".depth", XrmoptionSepArg, (caddr_t)NULL },
108 { "-display", ".display", XrmoptionSepArg, (caddr_t)NULL },
109 { "-iconic", ".iconic", XrmoptionNoArg, (caddr_t)"on" },
110 { "-language", ".language", XrmoptionSepArg, (caddr_t)"En" },
111 { "-name", ".name", XrmoptionSepArg, (caddr_t)NULL },
112 { "-perfect", ".perfect", XrmoptionNoArg, (caddr_t)"on" },
113 { "-privatemap", ".privatemap", XrmoptionNoArg, (caddr_t)"on" },
114 { "-fixedmap", ".fixedmap", XrmoptionNoArg, (caddr_t)"on" },
115 { "-synchronous", ".synchronous", XrmoptionNoArg, (caddr_t)"on" },
116 { "-debug", ".debug", XrmoptionNoArg, (caddr_t)"on" },
117 { "-debugmsg", ".debugmsg", XrmoptionSepArg, (caddr_t)NULL },
118 { "-dll", ".dll", XrmoptionSepArg, (caddr_t)NULL },
119 { "-failreadonly", ".failreadonly", XrmoptionNoArg, (caddr_t)"on" },
120 { "-mode", ".mode", XrmoptionSepArg, (caddr_t)NULL },
121 { "-managed", ".managed", XrmoptionNoArg, (caddr_t)"off"},
122 { "-winver", ".winver", XrmoptionSepArg, (caddr_t)NULL },
123 { "-config", ".config", XrmoptionSepArg, (caddr_t)NULL },
124 { "-nodga", ".nodga", XrmoptionNoArg, (caddr_t)"off"},
125 { "-console", ".console", XrmoptionSepArg, (caddr_t)NULL }
128 #define NB_OPTIONS (sizeof(optionsTable) / sizeof(optionsTable[0]))
130 #define USAGE \
131 "%s\n" \
132 "Usage: %s [options] \"program_name [arguments]\"\n" \
133 "\n" \
134 "Options:\n" \
135 " -backingstore Turn on backing store\n" \
136 " -config name Specify config file to use\n" \
137 " -console driver Select which driver(s) to use for the console\n" \
138 " -debug Enter debugger before starting application\n" \
139 " -debugmsg name Turn debugging-messages on or off\n" \
140 " -depth n Change the depth to use for multiple-depth screens\n" \
141 " -desktop geom Use a desktop window of the given geometry\n" \
142 " -display name Use the specified display\n" \
143 " -dll name Enable or disable built-in DLLs\n" \
144 " -failreadonly Read only files may not be opened in write mode\n" \
145 " -fixedmap Use a \"standard\" color map\n" \
146 " -help Show this help message\n" \
147 " -iconic Start as an icon\n" \
148 " -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" \
149 " -managed Allow the window manager to manage created windows\n" \
150 " -mode mode Start Wine in a particular mode (standard or enhanced)\n" \
151 " -name name Set the application name\n" \
152 " -nodga Disable XFree86 DGA extensions\n" \
153 " -perfect Favor correctness over speed for graphical operations\n" \
154 " -privatemap Use a private color map\n" \
155 " -synchronous Turn on synchronous display mode\n" \
156 " -version Display the Wine version\n" \
157 " -winver Version to imitate (one of win31,win95,nt351,nt40)\n"
161 /***********************************************************************
162 * MAIN_Usage
164 void MAIN_Usage( char *name )
166 MSG( USAGE, WINE_RELEASE_INFO, name );
167 exit(1);
171 /***********************************************************************
172 * MAIN_GetProgramName
174 * Get the program name. The name is specified by (in order of precedence):
175 * - the option '-name'.
176 * - the environment variable 'WINE_NAME'.
177 * - the last component of argv[0].
179 static char *MAIN_GetProgramName( int argc, char *argv[] )
181 int i;
182 char *p;
184 for (i = 1; i < argc-1; i++)
185 if (!strcmp( argv[i], "-name" )) return argv[i+1];
186 if ((p = getenv( "WINE_NAME" )) != NULL) return p;
187 if ((p = strrchr( argv[0], '/' )) != NULL) return p+1;
188 return argv[0];
192 /***********************************************************************
193 * MAIN_GetResource
195 * Fetch the value of resource 'name' using the correct instance name.
196 * 'name' must begin with '.' or '*'
198 static int MAIN_GetResource( XrmDatabase db, char *name, XrmValue *value )
200 char *buff_instance, *buff_class;
201 char *dummy;
202 int retval;
204 buff_instance = (char *)xmalloc(strlen(Options.programName)+strlen(name)+1);
205 buff_class = (char *)xmalloc( strlen(WINE_CLASS) + strlen(name) + 1 );
207 strcpy( buff_instance, Options.programName );
208 strcat( buff_instance, name );
209 strcpy( buff_class, WINE_CLASS );
210 strcat( buff_class, name );
211 retval = TSXrmGetResource( db, buff_instance, buff_class, &dummy, value );
212 free( buff_instance );
213 free( buff_class );
214 return retval;
218 /***********************************************************************
219 * MAIN_ParseDebugOptions
221 * Turns specific debug messages on or off, according to "options".
223 * RETURNS
224 * TRUE if parsing was successful
226 static BOOL32 MAIN_ParseDebugOptions(char *options)
228 /* defined in relay32/relay386.c */
229 extern char **debug_relay_includelist;
230 extern char **debug_relay_excludelist;
231 /* defined in relay32/snoop.c */
232 extern char **debug_snoop_includelist;
233 extern char **debug_snoop_excludelist;
235 int l, cls;
236 if (strlen(options)<3)
237 return FALSE;
240 if ((*options!='+')&&(*options!='-')){
241 int j;
243 for(j=0; j<DEBUG_CLASS_COUNT; j++)
244 if(!lstrncmpi32A(options, debug_cl_name[j], strlen(debug_cl_name[j])))
245 break;
246 if(j==DEBUG_CLASS_COUNT)
247 return FALSE;
248 options += strlen(debug_cl_name[j]);
249 if ((*options!='+')&&(*options!='-'))
250 return FALSE;
251 cls = j;
253 else
254 cls = -1; /* all classes */
256 if (strchr(options,','))
257 l=strchr(options,',')-options;
258 else
259 l=strlen(options);
261 if (!lstrncmpi32A(options+1,"all",l-1))
263 int i, j;
264 for (i=0; i<DEBUG_CHANNEL_COUNT; i++)
265 for(j=0; j<DEBUG_CLASS_COUNT; j++)
266 if(cls == -1 || cls == j)
267 debug_msg_enabled[i][j]=(*options=='+');
269 else if (!lstrncmpi32A(options+1, "relay=", 6) ||
270 !lstrncmpi32A(options+1, "snoop=", 6))
272 int i, j;
273 char *s, *s2, ***output, c;
275 for (i=0; i<DEBUG_CHANNEL_COUNT; i++)
276 if (debug_ch_name && (!lstrncmpi32A(debug_ch_name[i],options+1,5))){
277 for(j=0; j<DEBUG_CLASS_COUNT; j++)
278 if(cls == -1 || cls == j)
279 debug_msg_enabled[i][j]=TRUE;
280 break;
282 /* should never happen, maybe assert(i!=DEBUG_CHANNEL_COUNT)? */
283 if (i==DEBUG_CHANNEL_COUNT)
284 return FALSE;
285 output = (*options == '+') ?
286 ((*(options+1) == 'r') ?
287 &debug_relay_includelist :
288 &debug_snoop_includelist) :
289 ((*(options+1) == 'r') ?
290 &debug_relay_excludelist :
291 &debug_snoop_excludelist);
292 s = options + 7;
293 i = 1;
294 while((s = strchr(s, ':'))) i++, s++;
295 *output = malloc(sizeof(char **) * i + 1);
296 i = 0;
297 s = options + 7;
298 while((s2 = strchr(s, ':'))) {
299 c = *s2;
300 *s2 = '\0';
301 *((*output)+i) = strdup(s);
302 *s2 = c;
303 s = s2 + 1;
304 i++;
306 c = *(options + l);
307 *(options + l) = '\0';
308 *((*output)+i) = strdup(s);
309 *(options + l) = c;
310 *((*output)+i+1) = NULL;
312 else
314 int i, j;
315 for (i=0; i<DEBUG_CHANNEL_COUNT; i++)
316 if (debug_ch_name && (!lstrncmpi32A(options+1,debug_ch_name[i],l-1))){
317 for(j=0; j<DEBUG_CLASS_COUNT; j++)
318 if(cls == -1 || cls == j)
319 debug_msg_enabled[i][j]=(*options=='+');
320 break;
322 if (i==DEBUG_CHANNEL_COUNT)
323 return FALSE;
325 options+=l;
327 while((*options==',')&&(*(++options)));
328 if (*options)
329 return FALSE;
330 else
331 return TRUE;
334 /***********************************************************************
335 * MAIN_GetLanguageID
337 * INPUT:
338 * Lang: a string whose two first chars are the iso name of a language.
339 * Country: a string whose two first chars are the iso name of country
340 * Charset: a string defining the chossen charset encoding
341 * Dialect: a string defining a variation of the locale
343 * all those values are from the standardized format of locale
344 * name in unix which is: Lang[_Country][.Charset][@Dialect]
346 * RETURNS:
347 * the numeric code of the language used by Windows (or 0x00)
349 int MAIN_GetLanguageID(LPCSTR Lang,LPCSTR Country,LPCSTR Charset,LPCSTR Dialect)
351 char lang[3]="??", country[3]={0,0,0};
352 char *charset=NULL, *dialect=NULL;
353 int i,j,ret=0;
355 if (Lang==NULL) return 0x00;
356 if (Lang[0]) lang[0]=tolower(Lang[0]);
357 if (Lang[1]) lang[1]=tolower(Lang[1]);
359 if (Country!=NULL) {
360 if (Country[0]) country[0]=toupper(Country[0]);
361 if (Country[1]) country[1]=toupper(Country[1]);
364 if (Charset!=NULL) {
365 j=strlen(Charset);
366 charset=(char*)malloc(j+1);
367 for (i=0;i<j;i++)
368 charset[i]=toupper(Charset[i]);
369 charset[i]='\0';
372 if (Dialect!=NULL) {
373 j=strlen(Dialect);
374 dialect=(char*)malloc(j+1);
375 for (i=0;i<j;i++)
376 dialect[i]=tolower(Dialect[i]);
377 dialect[i]='\0';
380 #define LANG_ENTRY_BEGIN(x,y) if(!strcmp(lang, x )) { \
381 if (!country[0]) { \
382 ret=LANG_##y ; \
383 goto end_MAIN_GetLanguageID; \
385 #define LANG_SUB_ENTRY(x,y,z) if (!strcmp(country, x )) \
386 ret = MAKELANGID( LANG_##y , SUBLANG_##z ); \
387 goto end_MAIN_GetLanguageID;
388 #define LANG_DIALECT_ENTRY(x,y) { ret = MAKELANGID(LANG_##x , SUBLANG_##y ); \
389 goto end_MAIN_GetLanguageID; }
390 #define LANG_ENTRY_END(x) ret = MAKELANGID(LANG_##x , SUBLANG_DEFAULT); \
391 goto end_MAIN_GetLanguageID; \
394 /*x01*/ LANG_ENTRY_BEGIN( "ar", ARABIC )
395 LANG_SUB_ENTRY( "SA", ARABIC, ARABIC)
396 LANG_SUB_ENTRY( "IQ", ARABIC, ARABIC_IRAQ )
397 LANG_SUB_ENTRY( "EG", ARABIC, ARABIC_EGYPT )
398 LANG_SUB_ENTRY( "LY", ARABIC, ARABIC_LIBYA )
399 LANG_SUB_ENTRY( "DZ", ARABIC, ARABIC_ALGERIA )
400 LANG_SUB_ENTRY( "MA", ARABIC, ARABIC_MOROCCO )
401 LANG_SUB_ENTRY( "TN", ARABIC, ARABIC_TUNISIA )
402 LANG_SUB_ENTRY( "OM", ARABIC, ARABIC_OMAN )
403 LANG_SUB_ENTRY( "YE", ARABIC, ARABIC_YEMEN )
404 LANG_SUB_ENTRY( "SY", ARABIC, ARABIC_SYRIA )
405 LANG_SUB_ENTRY( "JO", ARABIC, ARABIC_JORDAN )
406 LANG_SUB_ENTRY( "LB", ARABIC, ARABIC_LEBANON )
407 LANG_SUB_ENTRY( "KW", ARABIC, ARABIC_KUWAIT )
408 LANG_SUB_ENTRY( "AE", ARABIC, ARABIC_UAE )
409 LANG_SUB_ENTRY( "BH", ARABIC, ARABIC_BAHRAIN )
410 LANG_SUB_ENTRY( "QA", ARABIC, ARABIC_QATAR )
411 LANG_ENTRY_END( ARABIC )
412 /*x02*/ LANG_ENTRY_BEGIN( "bu", BULGARIAN )
413 LANG_ENTRY_END( BULGARIAN )
414 /*x03*/ LANG_ENTRY_BEGIN( "ca", CATALAN )
415 LANG_ENTRY_END( CATALAN )
416 /*x04*/ LANG_ENTRY_BEGIN( "zh", CHINESE )
417 LANG_SUB_ENTRY( "TW", CHINESE, CHINESE_TRADITIONAL )
418 LANG_SUB_ENTRY( "CN", CHINESE, CHINESE_SIMPLIFIED )
419 LANG_SUB_ENTRY( "HK", CHINESE, CHINESE_HONGKONG )
420 LANG_SUB_ENTRY( "SG", CHINESE, CHINESE_SINGAPORE )
421 LANG_SUB_ENTRY( "MO", CHINESE, CHINESE_MACAU )
422 LANG_ENTRY_END( CHINESE )
423 /*x05*/ LANG_ENTRY_BEGIN( "cs", CZECH )
424 LANG_ENTRY_END( CZECH )
425 /*x06*/ LANG_ENTRY_BEGIN( "da", DANISH )
426 LANG_ENTRY_END( DANISH )
427 /*x07*/ LANG_ENTRY_BEGIN( "de", GERMAN )
428 LANG_SUB_ENTRY( "DE", GERMAN, GERMAN )
429 LANG_SUB_ENTRY( "CH", GERMAN, GERMAN_SWISS )
430 LANG_SUB_ENTRY( "AT", GERMAN, GERMAN_AUSTRIAN )
431 LANG_SUB_ENTRY( "LU", GERMAN, GERMAN_LUXEMBOURG )
432 LANG_SUB_ENTRY( "LI", GERMAN, GERMAN_LIECHTENSTEIN )
433 LANG_ENTRY_END( GERMAN )
434 /*x08*/ LANG_ENTRY_BEGIN( "el", GREEK )
435 LANG_ENTRY_END( GREEK )
436 /*x09*/ LANG_ENTRY_BEGIN( "en", ENGLISH )
437 LANG_SUB_ENTRY( "US", ENGLISH, ENGLISH_US )
438 LANG_SUB_ENTRY( "UK", ENGLISH, ENGLISH_UK )
439 LANG_SUB_ENTRY( "AU", ENGLISH, ENGLISH_AUS )
440 LANG_SUB_ENTRY( "CA", ENGLISH, ENGLISH_CAN )
441 LANG_SUB_ENTRY( "NZ", ENGLISH, ENGLISH_NZ )
442 LANG_SUB_ENTRY( "EI", ENGLISH, ENGLISH_EIRE )
443 LANG_SUB_ENTRY( "ZA", ENGLISH, ENGLISH_SAFRICA )
444 LANG_SUB_ENTRY( "JM", ENGLISH, ENGLISH_JAMAICA )
445 /* LANG_SUB_ENTRY( "AG", ENGLISH, ENGLISH_CARIBBEAN ) */
446 LANG_SUB_ENTRY( "BZ", ENGLISH, ENGLISH_BELIZE )
447 LANG_SUB_ENTRY( "TT", ENGLISH, ENGLISH_TRINIDAD )
448 LANG_SUB_ENTRY( "ZW", ENGLISH, ENGLISH_ZIMBABWE )
449 LANG_SUB_ENTRY( "PH", ENGLISH, ENGLISH_PHILIPPINES )
450 LANG_ENTRY_END( ENGLISH )
451 /*x0a*/ LANG_ENTRY_BEGIN( "es", SPANISH )
452 /* traditional sorting */
453 if (!strcmp(dialect,"tradicional"))
454 LANG_DIALECT_ENTRY( SPANISH, SPANISH )
455 LANG_SUB_ENTRY( "MX", SPANISH, SPANISH_MEXICAN )
456 LANG_SUB_ENTRY( "ES", SPANISH, SPANISH_MODERN )
457 LANG_SUB_ENTRY( "GT", SPANISH, SPANISH_GUATEMALA )
458 LANG_SUB_ENTRY( "CR", SPANISH, SPANISH_COSTARICA )
459 LANG_SUB_ENTRY( "PA", SPANISH, SPANISH_PANAMA )
460 LANG_SUB_ENTRY( "DO", SPANISH, SPANISH_DOMINICAN )
461 LANG_SUB_ENTRY( "VE", SPANISH, SPANISH_VENEZUELA )
462 LANG_SUB_ENTRY( "CO", SPANISH, SPANISH_COLOMBIA )
463 LANG_SUB_ENTRY( "PE", SPANISH, SPANISH_PERU )
464 LANG_SUB_ENTRY( "AR", SPANISH, SPANISH_ARGENTINA )
465 LANG_SUB_ENTRY( "EC", SPANISH, SPANISH_ECUADOR )
466 LANG_SUB_ENTRY( "CL", SPANISH, SPANISH_CHILE )
467 LANG_SUB_ENTRY( "UY", SPANISH, SPANISH_URUGUAY )
468 LANG_SUB_ENTRY( "PY", SPANISH, SPANISH_PARAGUAY )
469 LANG_SUB_ENTRY( "BO", SPANISH, SPANISH_BOLIVIA )
470 LANG_SUB_ENTRY( "HN", SPANISH, SPANISH_HONDURAS )
471 LANG_SUB_ENTRY( "NI", SPANISH, SPANISH_NICARAGUA )
472 LANG_SUB_ENTRY( "PR", SPANISH, SPANISH_PUERTO_RICO )
473 LANG_ENTRY_END( SPANISH )
474 /*x0b*/ LANG_ENTRY_BEGIN( "fi", FINNISH )
475 LANG_ENTRY_END( FINNISH )
476 /*x0c*/ LANG_ENTRY_BEGIN( "fr", FRENCH )
477 LANG_SUB_ENTRY( "FR", FRENCH, FRENCH )
478 LANG_SUB_ENTRY( "BE", FRENCH, FRENCH_BELGIAN )
479 LANG_SUB_ENTRY( "CA", FRENCH, FRENCH_CANADIAN )
480 LANG_SUB_ENTRY( "CH", FRENCH, FRENCH_SWISS )
481 LANG_SUB_ENTRY( "LU", FRENCH, FRENCH_LUXEMBOURG )
482 LANG_SUB_ENTRY( "MC", FRENCH, FRENCH_MONACO )
483 LANG_ENTRY_END( FRENCH )
484 /*x0d*/ LANG_ENTRY_BEGIN( "iw", HEBREW )
485 LANG_ENTRY_END( HEBREW )
486 /*x0e*/ LANG_ENTRY_BEGIN( "hu", HUNGARIAN )
487 LANG_ENTRY_END( HUNGARIAN )
488 /*x0f*/ LANG_ENTRY_BEGIN( "ic", ICELANDIC )
489 LANG_ENTRY_END( ICELANDIC )
490 /*x10*/ LANG_ENTRY_BEGIN( "it", ITALIAN )
491 LANG_SUB_ENTRY( "IT", ITALIAN, ITALIAN )
492 LANG_SUB_ENTRY( "CH", ITALIAN, ITALIAN_SWISS )
493 LANG_ENTRY_END( ITALIAN )
494 /*x11*/ LANG_ENTRY_BEGIN( "ja", JAPANESE )
495 LANG_ENTRY_END( JAPANESE )
496 /*x12*/ LANG_ENTRY_BEGIN( "ko", KOREAN )
497 /* JOHAB encoding */
498 if (!strcmp(charset,"JOHAB"))
499 LANG_DIALECT_ENTRY( KOREAN, KOREAN_JOHAB )
500 else
501 LANG_DIALECT_ENTRY( KOREAN, KOREAN )
502 LANG_ENTRY_END( KOREAN )
503 /*x13*/ LANG_ENTRY_BEGIN( "nl", DUTCH )
504 LANG_SUB_ENTRY( "NL", DUTCH, DUTCH )
505 LANG_SUB_ENTRY( "BE", DUTCH, DUTCH_BELGIAN )
506 LANG_SUB_ENTRY( "SR", DUTCH, DUTCH_SURINAM )
507 LANG_ENTRY_END( DUTCH )
508 /*x14*/ LANG_ENTRY_BEGIN( "no", NORWEGIAN )
509 /* nynorsk */
510 if (!strcmp(dialect,"nynorsk"))
511 LANG_DIALECT_ENTRY( NORWEGIAN, NORWEGIAN_NYNORSK )
512 else
513 LANG_DIALECT_ENTRY( NORWEGIAN, NORWEGIAN_BOKMAL )
514 LANG_ENTRY_END( NORWEGIAN )
515 /*x15*/ LANG_ENTRY_BEGIN( "pl", POLISH )
516 LANG_ENTRY_END( POLISH )
517 /*x16*/ LANG_ENTRY_BEGIN( "pt", PORTUGUESE )
518 LANG_SUB_ENTRY( "BR", PORTUGUESE, PORTUGUESE_BRAZILIAN )
519 LANG_SUB_ENTRY( "PT", PORTUGUESE, PORTUGUESE )
520 LANG_ENTRY_END( PORTUGUESE )
521 /*x17*/ LANG_ENTRY_BEGIN( "rm", RHAETO_ROMANCE )
522 LANG_ENTRY_END( RHAETO_ROMANCE )
523 /*x18*/ LANG_ENTRY_BEGIN( "ro", ROMANIAN )
524 LANG_SUB_ENTRY( "RO", ROMANIAN, ROMANIAN )
525 LANG_SUB_ENTRY( "MD", ROMANIAN, ROMANIAN_MOLDAVIA )
526 LANG_ENTRY_END( ROMANIAN )
527 /*x19*/ LANG_ENTRY_BEGIN( "ru", RUSSIAN )
528 LANG_SUB_ENTRY( "RU", RUSSIAN, RUSSIAN )
529 LANG_SUB_ENTRY( "MD", RUSSIAN, RUSSIAN_MOLDAVIA )
530 LANG_ENTRY_END( RUSSIAN )
531 /*x1a*/ if (!strcmp(lang,"sh") || !strcmp(lang,"hr") || !strcmp(lang,"sr")) {
532 if (!country[0])
533 LANG_DIALECT_ENTRY( SERBO_CROATIAN, NEUTRAL)
534 if (!strcmp(charset,"ISO-8859-5"))
535 LANG_DIALECT_ENTRY( SERBO_CROATIAN, SERBIAN )
536 LANG_SUB_ENTRY( "HR", SERBO_CROATIAN, CROATIAN )
537 if (!strcmp(country,"YU") && !strcmp(charset,"ISO-8859-2"))
538 LANG_DIALECT_ENTRY( SERBO_CROATIAN, SERBIAN_LATIN )
539 LANG_SUB_ENTRY( "YU", SERBO_CROATIAN, SERBIAN )
540 LANG_DIALECT_ENTRY( SERBO_CROATIAN, SERBIAN_LATIN )
542 /*x1b*/ LANG_ENTRY_BEGIN( "sk", SLOVAK )
543 LANG_ENTRY_END( SLOVAK )
544 /*x1c*/ LANG_ENTRY_BEGIN( "sq", ALBANIAN )
545 LANG_ENTRY_END( ALBANIAN )
546 /*x1d*/ LANG_ENTRY_BEGIN( "sv", SWEDISH )
547 LANG_SUB_ENTRY( "SE", SWEDISH, SWEDISH )
548 LANG_SUB_ENTRY( "FI", SWEDISH, SWEDISH_FINLAND )
549 LANG_ENTRY_END( SWEDISH )
550 /*x1e*/ LANG_ENTRY_BEGIN( "th", THAI )
551 LANG_ENTRY_END( THAI )
552 /*x1f*/ LANG_ENTRY_BEGIN( "tr", TURKISH )
553 LANG_ENTRY_END( TURKISH )
554 /*x20*/ LANG_ENTRY_BEGIN( "ur", URDU )
555 LANG_ENTRY_END( URDU )
556 /*x21*/ LANG_ENTRY_BEGIN( "in", INDONESIAN )
557 LANG_ENTRY_END( INDONESIAN )
558 /*x22*/ LANG_ENTRY_BEGIN( "uk", UKRAINIAN )
559 LANG_ENTRY_END( UKRAINIAN )
560 /*x23*/ LANG_ENTRY_BEGIN( "be", BYELORUSSIAN )
561 LANG_ENTRY_END( BYELORUSSIAN )
562 /*x24*/ LANG_ENTRY_BEGIN( "sl", SLOVENIAN )
563 LANG_ENTRY_END( SLOVENIAN )
564 /*x25*/ LANG_ENTRY_BEGIN( "et", ESTONIAN )
565 LANG_ENTRY_END( ESTONIAN )
566 /*x26*/ LANG_ENTRY_BEGIN( "lv", LATVIAN )
567 LANG_ENTRY_END( LATVIAN )
568 /*x27*/ LANG_ENTRY_BEGIN( "lt", LITHUANIAN )
569 /* traditional sorting ? */
570 if (!strcmp(dialect,"classic") || !strcmp(dialect,"traditional"))
571 LANG_DIALECT_ENTRY( LITHUANIAN, LITHUANIAN_CLASSIC )
572 else
573 LANG_DIALECT_ENTRY( LITHUANIAN, LITHUANIAN )
574 LANG_ENTRY_END( LITHUANIAN )
575 /*x28*/ LANG_ENTRY_BEGIN( "mi", MAORI )
576 LANG_ENTRY_END( MAORI )
577 /*x29*/ LANG_ENTRY_BEGIN( "fa", FARSI )
578 LANG_ENTRY_END( FARSI )
579 /*x2a*/ LANG_ENTRY_BEGIN( "vi", VIETNAMESE )
580 LANG_ENTRY_END( VIETNAMESE )
581 /*x2b*/ LANG_ENTRY_BEGIN( "hy", ARMENIAN )
582 LANG_ENTRY_END( ARMENIAN )
583 /*x2c*/ LANG_ENTRY_BEGIN( "az", AZERI )
584 /* Cyrillic */
585 if (strstr(charset,"KOI8") || !strcmp(charset,"ISO-8859-5"))
586 LANG_DIALECT_ENTRY( AZERI, AZERI_CYRILLIC )
587 else
588 LANG_DIALECT_ENTRY( AZERI, AZERI )
589 LANG_ENTRY_END( AZERI )
590 /*x2d*/ LANG_ENTRY_BEGIN( "eu", BASQUE )
591 LANG_ENTRY_END( BASQUE )
592 /*x2e*/ /*LANG_ENTRY_BEGIN( "??", SORBIAN )
593 LANG_ENTRY_END( SORBIAN ) */
594 /*x2f*/ LANG_ENTRY_BEGIN( "mk", MACEDONIAN )
595 LANG_ENTRY_END( MACEDONIAN )
596 /*x30*/ /*LANG_ENTRY_BEGIN( "??", SUTU )
597 LANG_ENTRY_END( SUTU ) */
598 /*x31*/ LANG_ENTRY_BEGIN( "ts", TSONGA )
599 LANG_ENTRY_END( TSONGA )
600 /*x32*/ /*LANG_ENTRY_BEGIN( "??", TSWANA )
601 LANG_ENTRY_END( TSWANA ) */
602 /*x33*/ /*LANG_ENTRY_BEGIN( "??", VENDA )
603 LANG_ENTRY_END( VENDA ) */
604 /*x34*/ LANG_ENTRY_BEGIN( "xh", XHOSA )
605 LANG_ENTRY_END( XHOSA )
606 /*x35*/ LANG_ENTRY_BEGIN( "zu", ZULU )
607 LANG_ENTRY_END( ZULU )
608 /*x36*/ LANG_ENTRY_BEGIN( "af", AFRIKAANS )
609 LANG_ENTRY_END( AFRIKAANS )
610 /*x37*/ LANG_ENTRY_BEGIN( "ka", GEORGIAN )
611 LANG_ENTRY_END( GEORGIAN )
612 /*x38*/ LANG_ENTRY_BEGIN( "fo", FAEROESE )
613 LANG_ENTRY_END( FAEROESE )
614 /*x39*/ LANG_ENTRY_BEGIN( "hi", HINDI )
615 LANG_ENTRY_END( HINDI )
616 /*x3a*/ LANG_ENTRY_BEGIN( "mt", MALTESE )
617 LANG_ENTRY_END( MALTESE )
618 /*x3b*/ /*LANG_ENTRY_BEGIN( "??", SAAMI )
619 LANG_ENTRY_END( SAAMI ) */
620 /*x3c*/ LANG_ENTRY_BEGIN( "ga", GAELIC )
621 LANG_DIALECT_ENTRY( GAELIC, GAELIC )
622 LANG_ENTRY_END( GAELIC )
623 /*x3c*/ LANG_ENTRY_BEGIN( "gd", GAELIC )
624 LANG_DIALECT_ENTRY( GAELIC, GAELIC_SCOTTISH )
625 LANG_ENTRY_END( GAELIC )
626 /* 0x3d */
627 /*x3e*/ LANG_ENTRY_BEGIN( "ms", MALAY )
628 LANG_SUB_ENTRY( "MY", MALAY, MALAY )
629 LANG_SUB_ENTRY( "BN", MALAY, MALAY_BRUNEI_DARUSSALAM )
630 LANG_ENTRY_END( MALAY )
631 /*x3f*/ LANG_ENTRY_BEGIN( "kk", KAZAKH )
632 LANG_ENTRY_END( KAZAKH )
633 /* 0x40 */
634 /*x41*/ LANG_ENTRY_BEGIN( "sw", SWAHILI )
635 LANG_ENTRY_END( SWAHILI )
636 /* 0x42 */
637 /*x43*/ LANG_ENTRY_BEGIN( "uz", UZBEK )
638 /* Cyrillic */
639 if (strstr(charset,"KOI8") || !strcmp(charset,"ISO-8859-5"))
640 LANG_DIALECT_ENTRY( UZBEK, UZBEK_CYRILLIC )
641 else
642 LANG_DIALECT_ENTRY( UZBEK, UZBEK )
643 LANG_ENTRY_END( UZBEK )
644 /*x44*/ LANG_ENTRY_BEGIN( "tt", TATAR )
645 LANG_ENTRY_END( TATAR )
646 /*x45*/ LANG_ENTRY_BEGIN( "bn", BENGALI )
647 LANG_ENTRY_END( BENGALI )
648 /*x46*/ LANG_ENTRY_BEGIN( "pa", PUNJABI )
649 LANG_ENTRY_END( PUNJABI )
650 /*x47*/ LANG_ENTRY_BEGIN( "gu", GUJARATI )
651 LANG_ENTRY_END( GUJARATI )
652 /*x48*/ LANG_ENTRY_BEGIN( "or", ORIYA )
653 LANG_ENTRY_END( ORIYA )
654 /*x49*/ LANG_ENTRY_BEGIN( "ta", TAMIL )
655 LANG_ENTRY_END( TAMIL )
656 /*x4a*/ LANG_ENTRY_BEGIN( "te", TELUGU )
657 LANG_ENTRY_END( TELUGU )
658 /*x4b*/ LANG_ENTRY_BEGIN( "kn", KANNADA )
659 LANG_ENTRY_END( KANNADA )
660 /*x4c*/ LANG_ENTRY_BEGIN( "ml", MALAYALAM )
661 LANG_ENTRY_END( MALAYALAM )
662 /*x4d*/ LANG_ENTRY_BEGIN( "as", ASSAMESE )
663 LANG_ENTRY_END( ASSAMESE )
664 /*x4e*/ LANG_ENTRY_BEGIN( "mr", MARATHI )
665 LANG_ENTRY_END( MARATHI )
666 /*x4f*/ LANG_ENTRY_BEGIN( "sa", SANSKRIT )
667 LANG_ENTRY_END( SANSKRIT )
668 /* 0x50 -> 0x56 */
669 /*x57*/ /*LANG_ENTRY_BEGIN( "??", KONKANI )
670 LANG_ENTRY_END( KONKANI ) */
671 /* 0x58 -> ... */
672 LANG_ENTRY_BEGIN( "eo", ESPERANTO ) /* not official */
673 LANG_ENTRY_END( ESPERANTO )
675 ret = LANG_ENGLISH;
677 end_MAIN_GetLanguageID:
678 if (Charset) free(charset);
679 if (Dialect) free(dialect);
681 return ret;
684 /***********************************************************************
685 * MAIN_ParseLanguageOption
687 * Parse -language option.
689 static void MAIN_ParseLanguageOption( char *arg )
691 const WINE_LANGUAGE_DEF *p = Languages;
693 /* for compatibility whith non-iso names previously used */
694 if (!strcmp("Sw",arg)) { strcpy(arg,"Sv"); FIXME(system,"use 'Sv' instead of 'Sw'\n");}
695 if (!strcmp("Cz",arg)) { strcpy(arg,"Cs"); FIXME(system,"use 'Cs' instead of 'Cz'\n");}
696 if (!strcmp("Po",arg)) { strcpy(arg,"Pt"); FIXME(system,"use 'Pt' instead of 'Po'\n");}
698 Options.language = LANG_Xx; /* First (dummy) language */
699 for (;p->name;p++)
701 if (!lstrcmpi32A( p->name, arg ))
703 WINE_LanguageId = p->langid;
704 return;
706 Options.language++;
708 MSG( "Invalid language specified '%s'. Supported languages are: ", arg );
709 for (p = Languages; p->name; p++) MSG( "%s ", p->name );
710 MSG( "\n" );
711 exit(1);
715 /***********************************************************************
716 * MAIN_ParseModeOption
718 * Parse -mode option.
720 static void MAIN_ParseModeOption( char *arg )
722 if (!lstrcmpi32A("enhanced", arg)) Options.mode = MODE_ENHANCED;
723 else if (!lstrcmpi32A("standard", arg)) Options.mode = MODE_STANDARD;
724 else
726 MSG( "Invalid mode '%s' specified.\n", arg);
727 MSG( "Valid modes are: 'standard', 'enhanced' (default).\n");
728 exit(1);
732 /***********************************************************************
733 * MAIN_ParseOptions
735 * Parse command line options and open display.
737 static void MAIN_ParseOptions( int *argc, char *argv[] )
739 char *display_name = NULL;
740 XrmValue value;
741 XrmDatabase db = TSXrmGetFileDatabase(WINE_APP_DEFAULTS);
742 int i;
743 char *xrm_string;
745 Options.programName = MAIN_GetProgramName( *argc, argv );
746 Options.argv0 = argv[0];
748 /* initialise Options.language to 0 to tell "no language choosen yet" */
749 Options.language = 0;
751 /* Get display name from command line */
752 for (i = 1; i < *argc; i++)
754 if (!strcmp( argv[i], "-display" )) display_name = argv[i+1];
755 if (!strcmp( argv[i], "-v" ) || !strcmp( argv[i], "-version" ))
757 MSG( "%s\n", WINE_RELEASE_INFO );
758 exit(0);
760 if (!strcmp( argv[i], "-h" ) || !strcmp( argv[i], "-help" ))
762 MAIN_Usage(argv[0]);
763 exit(0);
767 /* Open display */
769 if (display_name == NULL &&
770 MAIN_GetResource( db, ".display", &value )) display_name = value.addr;
772 if (!(display = TSXOpenDisplay( display_name )))
774 MSG( "%s: Can't open display: %s\n",
775 argv[0], display_name ? display_name : "(none specified)" );
776 exit(1);
779 /* tell the libX11 that we will do input method handling ourselves
780 * that keep libX11 from doing anything whith dead keys, allowing Wine
781 * to have total control over dead keys, that is this line allows
782 * them to work in Wine, even whith a libX11 including the dead key
783 * patches from Th.Quinot (http://Web.FdN.FR/~tquinot/dead-keys.en.html)
785 TSXOpenIM(display,NULL,NULL,NULL);
787 /* Merge file and screen databases */
788 if ((xrm_string = TSXResourceManagerString( display )) != NULL)
790 XrmDatabase display_db = TSXrmGetStringDatabase( xrm_string );
791 TSXrmMergeDatabases( display_db, &db );
794 /* Parse command line */
795 TSXrmParseCommand( &db, optionsTable, NB_OPTIONS,
796 Options.programName, argc, argv );
798 /* Get all options */
799 if (MAIN_GetResource( db, ".iconic", &value ))
800 Options.cmdShow = SW_SHOWMINIMIZED;
801 if (MAIN_GetResource( db, ".privatemap", &value ))
802 Options.usePrivateMap = TRUE;
803 if (MAIN_GetResource( db, ".fixedmap", &value ))
804 Options.useFixedMap = TRUE;
805 if (MAIN_GetResource( db, ".synchronous", &value ))
806 Options.synchronous = TRUE;
807 if (MAIN_GetResource( db, ".backingstore", &value ))
808 Options.backingstore = TRUE;
809 if (MAIN_GetResource( db, ".debug", &value ))
810 Options.debug = TRUE;
811 if (MAIN_GetResource( db, ".failreadonly", &value ))
812 Options.failReadOnly = TRUE;
813 if (MAIN_GetResource( db, ".perfect", &value ))
814 Options.perfectGraphics = TRUE;
815 if (MAIN_GetResource( db, ".depth", &value))
816 screenDepth = atoi( value.addr );
817 if (MAIN_GetResource( db, ".desktop", &value))
818 Options.desktopGeometry = value.addr;
819 if (MAIN_GetResource( db, ".language", &value))
820 MAIN_ParseLanguageOption( (char *)value.addr );
821 if (MAIN_GetResource( db, ".managed", &value))
822 Options.managed = TRUE;
823 if (MAIN_GetResource( db, ".mode", &value))
824 MAIN_ParseModeOption( (char *)value.addr );
825 if (MAIN_GetResource( db, ".debugoptions", &value))
826 MAIN_ParseDebugOptions((char*)value.addr);
827 if (MAIN_GetResource( db, ".debugmsg", &value))
829 #ifndef DEBUG_RUNTIME
830 MSG("%s: Option \"-debugmsg\" not implemented.\n" \
831 " Recompile with DEBUG_RUNTIME in include/debugtools.h defined.\n",
832 argv[0]);
833 exit(1);
834 #else
835 if (MAIN_ParseDebugOptions((char*)value.addr)==FALSE)
837 int i;
838 MSG("%s: Syntax: -debugmsg [class]+xxx,... or "
839 "-debugmsg [class]-xxx,...\n",argv[0]);
840 MSG("Example: -debugmsg +all,warn-heap\n"
841 " turn on all messages except warning heap messages\n");
842 MSG("Special case: -debugmsg +relay=DLL:DLL.###:FuncName\n"
843 " turn on -debugmsg +relay only as specified\n"
844 "Special case: -debugmsg -relay=DLL:DLL.###:FuncName\n"
845 " turn on -debugmsg +relay except as specified\n"
846 "Also permitted, +snoop=..., -snoop=... as with relay.\n\n");
848 MSG("Available message classes:\n");
849 for(i=0;i<DEBUG_CLASS_COUNT;i++)
850 MSG( "%-9s", debug_cl_name[i]);
851 MSG("\n\n");
853 MSG("Available message types:\n");
854 MSG("%-9s ","all");
855 for(i=0;i<DEBUG_CHANNEL_COUNT;i++)
856 if(debug_ch_name[i])
857 MSG("%-9s%c",debug_ch_name[i],
858 (((i+2)%8==0)?'\n':' '));
859 MSG("\n\n");
860 exit(1);
862 #endif
865 if (MAIN_GetResource( db, ".dll", &value))
867 /* Hack: store option value in Options to be retrieved */
868 /* later on inside the emulator code. */
869 if (!__winelib) Options.dllFlags = xstrdup((char *)value.addr);
870 else
872 MSG("-dll not supported in Winelib\n" );
873 exit(1);
877 if (MAIN_GetResource( db, ".winver", &value))
878 VERSION_ParseVersion( (char*)value.addr );
879 if (MAIN_GetResource( db, ".config", &value))
880 Options.configFileName = xstrdup((char *)value.addr);
881 if (MAIN_GetResource( db, ".nodga", &value))
882 Options.noDGA = TRUE;
883 if (MAIN_GetResource( db, ".console", &value))
884 Options.consoleDrivers = xstrdup((char *)value.addr);
885 else
886 Options.consoleDrivers = CONSOLE_DEFAULT_DRIVER;
888 CONSOLE_Init(Options.consoleDrivers);
892 /***********************************************************************
893 * MAIN_CreateDesktop
895 static void MAIN_CreateDesktop( int argc, char *argv[] )
897 int x, y, flags;
898 unsigned int width = 640, height = 480; /* Default size = 640x480 */
899 char *name = "Wine desktop";
900 XSizeHints *size_hints;
901 XWMHints *wm_hints;
902 XClassHint *class_hints;
903 XSetWindowAttributes win_attr;
904 XTextProperty window_name;
905 Atom XA_WM_DELETE_WINDOW;
907 flags = TSXParseGeometry( Options.desktopGeometry, &x, &y, &width, &height );
908 screenWidth = width;
909 screenHeight = height;
911 /* Create window */
913 win_attr.background_pixel = BlackPixel(display,0);
914 win_attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
915 PointerMotionMask | ButtonPressMask |
916 ButtonReleaseMask | EnterWindowMask;
917 win_attr.cursor = TSXCreateFontCursor( display, XC_top_left_arrow );
919 rootWindow = TSXCreateWindow( display, DefaultRootWindow(display),
920 x, y, width, height, 0,
921 CopyFromParent, InputOutput, CopyFromParent,
922 CWBackPixel | CWEventMask | CWCursor, &win_attr );
924 /* Set window manager properties */
926 size_hints = TSXAllocSizeHints();
927 wm_hints = TSXAllocWMHints();
928 class_hints = TSXAllocClassHint();
929 if (!size_hints || !wm_hints || !class_hints)
931 MSG("Not enough memory for window manager hints.\n" );
932 exit(1);
934 size_hints->min_width = size_hints->max_width = width;
935 size_hints->min_height = size_hints->max_height = height;
936 size_hints->flags = PMinSize | PMaxSize;
937 if (flags & (XValue | YValue)) size_hints->flags |= USPosition;
938 if (flags & (WidthValue | HeightValue)) size_hints->flags |= USSize;
939 else size_hints->flags |= PSize;
941 wm_hints->flags = InputHint | StateHint;
942 wm_hints->input = True;
943 wm_hints->initial_state = NormalState;
944 class_hints->res_name = argv[0];
945 class_hints->res_class = "Wine";
947 TSXStringListToTextProperty( &name, 1, &window_name );
948 TSXSetWMProperties( display, rootWindow, &window_name, &window_name,
949 argv, argc, size_hints, wm_hints, class_hints );
950 XA_WM_DELETE_WINDOW = TSXInternAtom( display, "WM_DELETE_WINDOW", False );
951 TSXSetWMProtocols( display, rootWindow, &XA_WM_DELETE_WINDOW, 1 );
952 TSXFree( size_hints );
953 TSXFree( wm_hints );
954 TSXFree( class_hints );
956 /* Map window */
958 TSXMapWindow( display, rootWindow );
962 XKeyboardState keyboard_state;
964 /***********************************************************************
965 * MAIN_SaveSetup
967 static void MAIN_SaveSetup(void)
969 TSXGetKeyboardControl(display, &keyboard_state);
972 /***********************************************************************
973 * MAIN_RestoreSetup
975 static void MAIN_RestoreSetup(void)
977 XKeyboardControl keyboard_value;
979 keyboard_value.key_click_percent = keyboard_state.key_click_percent;
980 keyboard_value.bell_percent = keyboard_state.bell_percent;
981 keyboard_value.bell_pitch = keyboard_state.bell_pitch;
982 keyboard_value.bell_duration = keyboard_state.bell_duration;
983 keyboard_value.auto_repeat_mode = keyboard_state.global_auto_repeat;
985 XChangeKeyboardControl(display, KBKeyClickPercent | KBBellPercent |
986 KBBellPitch | KBBellDuration | KBAutoRepeatMode, &keyboard_value);
990 /***********************************************************************
991 * called_at_exit
993 static void called_at_exit(void)
995 MAIN_RestoreSetup();
996 COLOR_Cleanup();
997 WINSOCK_Shutdown();
998 /* FIXME: should check for other processes or threads */
999 DeleteCriticalSection( HEAP_SystemLock );
1000 CONSOLE_Close();
1003 static int WINE_X11_ErrorHandler(Display *display,XErrorEvent *error_evt)
1005 kill( getpid(), SIGHUP ); /* force an entry in the debugger */
1006 return 0;
1009 /***********************************************************************
1010 * MAIN_WineInit
1012 * Wine initialisation and command-line parsing
1014 BOOL32 MAIN_WineInit( int *argc, char *argv[] )
1016 int depth_count, i;
1017 int *depth_list;
1018 struct timeval tv;
1020 #ifdef MALLOC_DEBUGGING
1021 char *trace;
1023 mcheck(NULL);
1024 if (!(trace = getenv("MALLOC_TRACE")))
1026 MSG( "MALLOC_TRACE not set. No trace generated\n" );
1028 else
1030 MSG( "malloc trace goes to %s\n", trace );
1031 mtrace();
1033 #endif
1035 setbuf(stdout,NULL);
1036 setbuf(stderr,NULL);
1038 setlocale(LC_CTYPE,"");
1039 gettimeofday( &tv, NULL);
1040 MSG_WineStartTicks = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
1042 /* We need this before calling any Xlib function */
1043 InitializeCriticalSection( &X11DRV_CritSection );
1045 TSXrmInitialize();
1047 putenv("XKB_DISABLE="); /* Disable XKB extension if present. */
1049 MAIN_ParseOptions( argc, argv );
1051 if (Options.synchronous) XSetErrorHandler( WINE_X11_ErrorHandler );
1053 if (Options.desktopGeometry && Options.managed)
1055 #if 0
1056 MSG( "%s: -managed and -desktop options cannot be used together\n",
1057 Options.programName );
1058 exit(1);
1059 #else
1060 Options.managed = FALSE;
1061 #endif
1064 screen = DefaultScreenOfDisplay( display );
1065 screenWidth = WidthOfScreen( screen );
1066 screenHeight = HeightOfScreen( screen );
1067 if (screenDepth) /* -depth option specified */
1069 depth_list = TSXListDepths(display,DefaultScreen(display),&depth_count);
1070 for (i = 0; i < depth_count; i++)
1071 if (depth_list[i] == screenDepth) break;
1072 TSXFree( depth_list );
1073 if (i >= depth_count)
1075 MSG( "%s: Depth %d not supported on this screen.\n",
1076 Options.programName, screenDepth );
1077 exit(1);
1080 else screenDepth = DefaultDepthOfScreen( screen );
1081 if (Options.synchronous) TSXSynchronize( display, True );
1082 if (Options.desktopGeometry) MAIN_CreateDesktop( *argc, argv );
1083 else rootWindow = DefaultRootWindow( display );
1085 MAIN_SaveSetup();
1086 atexit(called_at_exit);
1087 return TRUE;
1091 /***********************************************************************
1092 * MessageBeep16 (USER.104)
1094 void WINAPI MessageBeep16( UINT16 i )
1096 MessageBeep32( i );
1100 /***********************************************************************
1101 * MessageBeep32 (USER32.390)
1103 BOOL32 WINAPI MessageBeep32( UINT32 i )
1105 TSXBell( display, 0 );
1106 return TRUE;
1110 /***********************************************************************
1111 * Beep (KERNEL32.11)
1113 BOOL32 WINAPI Beep( DWORD dwFreq, DWORD dwDur )
1115 /* dwFreq and dwDur are ignored by Win95 */
1116 TSXBell(display, 0);
1117 return TRUE;
1121 /***********************************************************************
1122 * GetTimerResolution (USER.14)
1124 LONG WINAPI GetTimerResolution(void)
1126 return (1000);
1129 /***********************************************************************
1130 * SystemParametersInfo32A (USER32.540)
1132 BOOL32 WINAPI SystemParametersInfo32A( UINT32 uAction, UINT32 uParam,
1133 LPVOID lpvParam, UINT32 fuWinIni )
1135 int timeout, temp;
1136 XKeyboardState keyboard_state;
1138 switch (uAction) {
1139 case SPI_GETBEEP:
1140 TSXGetKeyboardControl(display, &keyboard_state);
1141 if (keyboard_state.bell_percent == 0)
1142 *(BOOL32 *) lpvParam = FALSE;
1143 else
1144 *(BOOL32 *) lpvParam = TRUE;
1145 break;
1147 case SPI_GETBORDER:
1148 *(INT32 *)lpvParam = GetSystemMetrics32( SM_CXFRAME );
1149 break;
1151 case SPI_GETDRAGFULLWINDOWS:
1152 *(BOOL32 *) lpvParam = FALSE;
1153 break;
1155 case SPI_SETDRAGFULLWINDOWS:
1156 break;
1158 case SPI_GETFASTTASKSWITCH:
1159 if ( GetProfileInt32A( "windows", "CoolSwitch", 1 ) == 1 )
1160 *(BOOL32 *) lpvParam = TRUE;
1161 else
1162 *(BOOL32 *) lpvParam = FALSE;
1163 break;
1165 case SPI_GETGRIDGRANULARITY:
1166 *(INT32*)lpvParam=GetProfileInt32A("desktop","GridGranularity",1);
1167 break;
1169 case SPI_GETICONTITLEWRAP:
1170 *(BOOL32*)lpvParam=GetProfileInt32A("desktop","IconTitleWrap",TRUE);
1171 break;
1173 case SPI_GETKEYBOARDDELAY:
1174 *(INT32*)lpvParam=GetProfileInt32A("keyboard","KeyboardDelay",1);
1175 break;
1177 case SPI_GETKEYBOARDSPEED:
1178 *(DWORD*)lpvParam=GetProfileInt32A("keyboard","KeyboardSpeed",30);
1179 break;
1181 case SPI_GETMENUDROPALIGNMENT:
1182 *(BOOL32*)lpvParam=GetSystemMetrics32(SM_MENUDROPALIGNMENT); /* XXX check this */
1183 break;
1185 case SPI_GETSCREENSAVEACTIVE:
1186 if ( GetProfileInt32A( "windows", "ScreenSaveActive", 1 ) == 1 )
1187 *(BOOL32*)lpvParam = TRUE;
1188 else
1189 *(BOOL32*)lpvParam = FALSE;
1190 break;
1192 case SPI_GETSCREENSAVETIMEOUT:
1193 /* FIXME GetProfileInt( "windows", "ScreenSaveTimeout", 300 ); */
1194 TSXGetScreenSaver(display, &timeout, &temp,&temp,&temp);
1195 *(INT32 *) lpvParam = timeout * 1000;
1196 break;
1198 case SPI_ICONHORIZONTALSPACING:
1199 /* FIXME Get/SetProfileInt */
1200 if (lpvParam == NULL)
1201 /*SetSystemMetrics( SM_CXICONSPACING, uParam )*/ ;
1202 else
1203 *(INT32*)lpvParam=GetSystemMetrics32(SM_CXICONSPACING);
1204 break;
1206 case SPI_ICONVERTICALSPACING:
1207 /* FIXME Get/SetProfileInt */
1208 if (lpvParam == NULL)
1209 /*SetSystemMetrics( SM_CYICONSPACING, uParam )*/ ;
1210 else
1211 *(INT32*)lpvParam=GetSystemMetrics32(SM_CYICONSPACING);
1212 break;
1214 case SPI_GETICONTITLELOGFONT: {
1215 LPLOGFONT32A lpLogFont = (LPLOGFONT32A)lpvParam;
1217 /* from now on we always have an alias for MS Sans Serif */
1219 GetProfileString32A("Desktop", "IconTitleFaceName", "MS Sans Serif",
1220 lpLogFont->lfFaceName, LF_FACESIZE );
1221 lpLogFont->lfHeight = -GetProfileInt32A("Desktop","IconTitleSize", 8);
1222 lpLogFont->lfWidth = 0;
1223 lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
1224 lpLogFont->lfWeight = FW_NORMAL;
1225 lpLogFont->lfItalic = FALSE;
1226 lpLogFont->lfStrikeOut = FALSE;
1227 lpLogFont->lfUnderline = FALSE;
1228 lpLogFont->lfCharSet = ANSI_CHARSET;
1229 lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
1230 lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
1231 lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
1232 break;
1234 case SPI_GETWORKAREA:
1235 SetRect32( (RECT32 *)lpvParam, 0, 0,
1236 GetSystemMetrics32( SM_CXSCREEN ),
1237 GetSystemMetrics32( SM_CYSCREEN )
1239 break;
1240 case SPI_GETNONCLIENTMETRICS:
1242 #define lpnm ((LPNONCLIENTMETRICS32A)lpvParam)
1244 if( lpnm->cbSize == sizeof(NONCLIENTMETRICS32A) )
1246 /* FIXME: initialize geometry entries */
1248 SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
1249 (LPVOID)&(lpnm->lfCaptionFont),0);
1250 lpnm->lfCaptionFont.lfWeight = FW_BOLD;
1251 SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
1252 (LPVOID)&(lpnm->lfSmCaptionFont),0);
1253 SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
1254 (LPVOID)&(lpnm->lfMenuFont),0);
1255 SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
1256 (LPVOID)&(lpnm->lfStatusFont),0);
1257 SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
1258 (LPVOID)&(lpnm->lfMessageFont),0);
1260 #undef lpnm
1261 break;
1263 case SPI_GETANIMATION: {
1264 LPANIMATIONINFO lpAnimInfo = (LPANIMATIONINFO)lpvParam;
1266 /* Tell it "disabled" */
1267 lpAnimInfo->cbSize = sizeof(ANIMATIONINFO);
1268 uParam = sizeof(ANIMATIONINFO);
1269 lpAnimInfo->iMinAnimate = 0; /* Minimise and restore animation is disabled (nonzero == enabled) */
1270 break;
1273 case SPI_SETANIMATION: {
1274 LPANIMATIONINFO lpAnimInfo = (LPANIMATIONINFO)lpvParam;
1276 /* Do nothing */
1277 WARN(system, "SPI_SETANIMATION ignored.\n");
1278 lpAnimInfo->cbSize = sizeof(ANIMATIONINFO);
1279 uParam = sizeof(ANIMATIONINFO);
1280 break;
1283 case SPI_GETHIGHCONTRAST:
1285 LPHIGHCONTRASTA lpHighContrastA = (LPHIGHCONTRASTA)lpvParam;
1287 FIXME(system,"SPI_GETHIGHCONTRAST not fully implemented\n");
1289 if ( lpHighContrastA->cbSize == sizeof( HIGHCONTRASTA ) )
1291 /* Indicate that there is no high contrast available */
1292 lpHighContrastA->dwFlags = 0;
1293 lpHighContrastA->lpszDefaultScheme = NULL;
1295 else
1297 return FALSE;
1300 break;
1303 default:
1304 return SystemParametersInfo16(uAction,uParam,lpvParam,fuWinIni);
1306 return TRUE;
1310 /***********************************************************************
1311 * SystemParametersInfo16 (USER.483)
1313 BOOL16 WINAPI SystemParametersInfo16( UINT16 uAction, UINT16 uParam,
1314 LPVOID lpvParam, UINT16 fuWinIni )
1316 int timeout, temp;
1317 char buffer[256];
1318 XKeyboardState keyboard_state;
1319 XKeyboardControl keyboard_value;
1322 switch (uAction)
1324 case SPI_GETBEEP:
1325 TSXGetKeyboardControl(display, &keyboard_state);
1326 if (keyboard_state.bell_percent == 0)
1327 *(BOOL16 *) lpvParam = FALSE;
1328 else
1329 *(BOOL16 *) lpvParam = TRUE;
1330 break;
1332 case SPI_GETBORDER:
1333 *(INT16 *)lpvParam = GetSystemMetrics16( SM_CXFRAME );
1334 break;
1336 case SPI_GETFASTTASKSWITCH:
1337 if ( GetProfileInt32A( "windows", "CoolSwitch", 1 ) == 1 )
1338 *(BOOL16 *) lpvParam = TRUE;
1339 else
1340 *(BOOL16 *) lpvParam = FALSE;
1341 break;
1343 case SPI_GETGRIDGRANULARITY:
1344 *(INT16 *) lpvParam = GetProfileInt32A( "desktop",
1345 "GridGranularity",
1346 1 );
1347 break;
1349 case SPI_GETICONTITLEWRAP:
1350 *(BOOL16 *) lpvParam = GetProfileInt32A( "desktop",
1351 "IconTitleWrap",
1352 TRUE );
1353 break;
1355 case SPI_GETKEYBOARDDELAY:
1356 *(INT16 *) lpvParam = GetProfileInt32A( "keyboard",
1357 "KeyboardDelay", 1 );
1358 break;
1360 case SPI_GETKEYBOARDSPEED:
1361 *(WORD *) lpvParam = GetProfileInt32A( "keyboard",
1362 "KeyboardSpeed",
1363 30 );
1364 break;
1366 case SPI_GETMENUDROPALIGNMENT:
1367 *(BOOL16 *) lpvParam = GetSystemMetrics16( SM_MENUDROPALIGNMENT ); /* XXX check this */
1368 break;
1370 case SPI_GETSCREENSAVEACTIVE:
1371 if ( GetProfileInt32A( "windows", "ScreenSaveActive", 1 ) == 1 )
1372 *(BOOL16 *) lpvParam = TRUE;
1373 else
1374 *(BOOL16 *) lpvParam = FALSE;
1375 break;
1377 case SPI_GETSCREENSAVETIMEOUT:
1378 /* FIXME GetProfileInt( "windows", "ScreenSaveTimeout", 300 ); */
1379 TSXGetScreenSaver(display, &timeout, &temp,&temp,&temp);
1380 *(INT16 *) lpvParam = timeout;
1381 break;
1383 case SPI_ICONHORIZONTALSPACING:
1384 /* FIXME Get/SetProfileInt */
1385 if (lpvParam == NULL)
1386 /*SetSystemMetrics( SM_CXICONSPACING, uParam )*/ ;
1387 else
1388 *(INT16 *)lpvParam = GetSystemMetrics16( SM_CXICONSPACING );
1389 break;
1391 case SPI_ICONVERTICALSPACING:
1392 /* FIXME Get/SetProfileInt */
1393 if (lpvParam == NULL)
1394 /*SetSystemMetrics( SM_CYICONSPACING, uParam )*/ ;
1395 else
1396 *(INT16 *)lpvParam = GetSystemMetrics16(SM_CYICONSPACING);
1397 break;
1399 case SPI_SETBEEP:
1400 if (uParam == TRUE)
1401 keyboard_value.bell_percent = -1;
1402 else
1403 keyboard_value.bell_percent = 0;
1404 TSXChangeKeyboardControl(display, KBBellPercent,
1405 &keyboard_value);
1406 break;
1408 case SPI_SETSCREENSAVEACTIVE:
1409 if (uParam == TRUE)
1410 TSXActivateScreenSaver(display);
1411 else
1412 TSXResetScreenSaver(display);
1413 break;
1415 case SPI_SETSCREENSAVETIMEOUT:
1416 TSXSetScreenSaver(display, uParam, 60, DefaultBlanking,
1417 DefaultExposures);
1418 break;
1420 case SPI_SETDESKWALLPAPER:
1421 return (SetDeskWallPaper32((LPSTR) lpvParam));
1422 break;
1424 case SPI_SETDESKPATTERN:
1425 if ((INT16)uParam == -1) {
1426 GetProfileString32A("Desktop", "Pattern",
1427 "170 85 170 85 170 85 170 85",
1428 buffer, sizeof(buffer) );
1429 return (DESKTOP_SetPattern((LPSTR) buffer));
1430 } else
1431 return (DESKTOP_SetPattern((LPSTR) lpvParam));
1432 break;
1434 case SPI_GETICONTITLELOGFONT:
1436 LPLOGFONT16 lpLogFont = (LPLOGFONT16)lpvParam;
1438 GetProfileString32A("Desktop", "IconTitleFaceName", "MS Sans Serif",
1439 lpLogFont->lfFaceName, LF_FACESIZE );
1440 lpLogFont->lfHeight = -GetProfileInt32A("Desktop","IconTitleSize", 8);
1441 lpLogFont->lfWidth = 0;
1442 lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
1443 lpLogFont->lfWeight = FW_NORMAL;
1444 lpLogFont->lfItalic = FALSE;
1445 lpLogFont->lfStrikeOut = FALSE;
1446 lpLogFont->lfUnderline = FALSE;
1447 lpLogFont->lfCharSet = ANSI_CHARSET;
1448 lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
1449 lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
1450 lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
1451 break;
1453 case SPI_GETNONCLIENTMETRICS:
1455 #define lpnm ((LPNONCLIENTMETRICS16)lpvParam)
1456 if( lpnm->cbSize == sizeof(NONCLIENTMETRICS16) )
1458 /* FIXME: initialize geometry entries */
1459 SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
1460 (LPVOID)&(lpnm->lfCaptionFont),0);
1461 lpnm->lfCaptionFont.lfWeight = FW_BOLD;
1462 SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
1463 (LPVOID)&(lpnm->lfSmCaptionFont),0);
1464 SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
1465 (LPVOID)&(lpnm->lfMenuFont),0);
1466 SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
1467 (LPVOID)&(lpnm->lfStatusFont),0);
1468 SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
1469 (LPVOID)&(lpnm->lfMessageFont),0);
1471 else /* winfile 95 sets sbSize to 340 */
1472 SystemParametersInfo32A( uAction, uParam, lpvParam, fuWinIni );
1473 #undef lpnm
1474 break;
1476 case SPI_LANGDRIVER:
1477 case SPI_SETBORDER:
1478 case SPI_SETDOUBLECLKHEIGHT:
1479 case SPI_SETDOUBLECLICKTIME:
1480 case SPI_SETDOUBLECLKWIDTH:
1481 case SPI_SETFASTTASKSWITCH:
1482 case SPI_SETKEYBOARDDELAY:
1483 case SPI_SETKEYBOARDSPEED:
1484 WARN(system, "Option %d ignored.\n", uAction);
1485 break;
1487 case SPI_GETWORKAREA:
1488 SetRect16( (RECT16 *)lpvParam, 0, 0,
1489 GetSystemMetrics16( SM_CXSCREEN ),
1490 GetSystemMetrics16( SM_CYSCREEN ) );
1491 break;
1493 default:
1494 WARN(system, "Unknown option %d.\n", uAction);
1495 break;
1497 return 1;
1500 /***********************************************************************
1501 * SystemParametersInfo32W (USER32.541)
1503 BOOL32 WINAPI SystemParametersInfo32W( UINT32 uAction, UINT32 uParam,
1504 LPVOID lpvParam, UINT32 fuWinIni )
1506 char buffer[256];
1508 switch (uAction)
1510 case SPI_SETDESKWALLPAPER:
1511 if (lpvParam)
1513 lstrcpynWtoA(buffer,(LPWSTR)lpvParam,sizeof(buffer));
1514 return SetDeskWallPaper32(buffer);
1516 return SetDeskWallPaper32(NULL);
1518 case SPI_SETDESKPATTERN:
1519 if ((INT32) uParam == -1)
1521 GetProfileString32A("Desktop", "Pattern",
1522 "170 85 170 85 170 85 170 85",
1523 buffer, sizeof(buffer) );
1524 return (DESKTOP_SetPattern((LPSTR) buffer));
1526 if (lpvParam)
1528 lstrcpynWtoA(buffer,(LPWSTR)lpvParam,sizeof(buffer));
1529 return DESKTOP_SetPattern(buffer);
1531 return DESKTOP_SetPattern(NULL);
1533 case SPI_GETICONTITLELOGFONT:
1535 LPLOGFONT32W lpLogFont = (LPLOGFONT32W)lpvParam;
1536 GetProfileString32A("Desktop", "IconTitleFaceName", "MS Sans Serif",
1537 buffer, sizeof(buffer) );
1538 lstrcpynAtoW(lpLogFont->lfFaceName, buffer ,LF_FACESIZE);
1539 lpLogFont->lfHeight = 10;
1540 lpLogFont->lfWidth = 0;
1541 lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
1542 lpLogFont->lfWeight = FW_NORMAL;
1543 lpLogFont->lfItalic = lpLogFont->lfStrikeOut = lpLogFont->lfUnderline = FALSE;
1544 lpLogFont->lfCharSet = ANSI_CHARSET;
1545 lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
1546 lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
1547 lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
1549 break;
1550 case SPI_GETNONCLIENTMETRICS: {
1551 /* FIXME: implement correctly */
1552 LPNONCLIENTMETRICS32W lpnm=(LPNONCLIENTMETRICS32W)lpvParam;
1554 SystemParametersInfo32W(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfCaptionFont),0);
1555 lpnm->lfCaptionFont.lfWeight = FW_BOLD;
1556 SystemParametersInfo32W(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfSmCaptionFont),0);
1557 SystemParametersInfo32W(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfMenuFont),0);
1558 SystemParametersInfo32W(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfStatusFont),0);
1559 SystemParametersInfo32W(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfMessageFont),0);
1560 break;
1563 case SPI_GETHIGHCONTRAST:
1565 LPHIGHCONTRASTW lpHighContrastW = (LPHIGHCONTRASTW)lpvParam;
1567 FIXME(system,"SPI_GETHIGHCONTRAST not fully implemented\n");
1569 if ( lpHighContrastW->cbSize == sizeof( HIGHCONTRASTW ) )
1571 /* Indicate that there is no high contrast available */
1572 lpHighContrastW->dwFlags = 0;
1573 lpHighContrastW->lpszDefaultScheme = NULL;
1575 else
1577 return FALSE;
1580 break;
1583 default:
1584 return SystemParametersInfo32A(uAction,uParam,lpvParam,fuWinIni);
1587 return TRUE;
1591 /***********************************************************************
1592 * FileCDR (KERNEL.130)
1594 FARPROC16 WINAPI FileCDR(FARPROC16 x)
1596 FIXME(file,"(0x%8x): stub\n", (int) x);
1597 return (FARPROC16)TRUE;