Added console support.
[wine.git] / misc / main.c
blob4752c45d399d63f814aebe5533cf525717ac701b
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 /* #include <locale.h> */
13 #ifdef MALLOC_DEBUGGING
14 #include <malloc.h>
15 #endif
16 #include "ts_xlib.h"
17 #include "ts_xresource.h"
18 #include "ts_xutil.h"
19 #include <X11/Xlocale.h>
20 #include <X11/cursorfont.h>
21 #include "winsock.h"
22 #include "heap.h"
23 #include "message.h"
24 #include "msdos.h"
25 #include "windows.h"
26 #include "color.h"
27 #include "options.h"
28 #include "desktop.h"
29 #include "process.h"
30 #include "shell.h"
31 #include "winbase.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 /* for compatibility whith non-iso names previously used */
63 {"Sw",0x041d}, /* LANG_Sv */
64 {"Cz",0x0405}, /* LANG_Cs */
65 {"Po",0x0416}, /* LANG_Pt */
66 {NULL,0}
69 WORD WINE_LanguageId = 0x409; /* english as default */
71 #define WINE_CLASS "Wine" /* Class name for resources */
73 #define WINE_APP_DEFAULTS "/usr/lib/X11/app-defaults/Wine"
75 Display *display;
76 Screen *screen;
77 Window rootWindow;
78 int screenWidth = 0, screenHeight = 0; /* Desktop window dimensions */
79 int screenDepth = 0; /* Screen depth to use */
81 struct options Options =
82 { /* default options */
83 NULL, /* desktopGeometry */
84 NULL, /* programName */
85 NULL, /* argv0 */
86 NULL, /* dllFlags */
87 FALSE, /* usePrivateMap */
88 FALSE, /* useFixedMap */
89 FALSE, /* synchronous */
90 FALSE, /* backing store */
91 SW_SHOWNORMAL, /* cmdShow */
92 FALSE,
93 FALSE, /* failReadOnly */
94 MODE_ENHANCED, /* Enhanced mode */
95 #ifdef DEFAULT_LANG
96 DEFAULT_LANG, /* Default language */
97 #else
98 LANG_En,
99 #endif
100 FALSE, /* Managed windows */
101 FALSE, /* Perfect graphics */
102 FALSE, /* No DGA */
103 NULL /* Alternate config file name */
107 static XrmOptionDescRec optionsTable[] =
109 { "-backingstore", ".backingstore", XrmoptionNoArg, (caddr_t)"on" },
110 { "-desktop", ".desktop", XrmoptionSepArg, (caddr_t)NULL },
111 { "-depth", ".depth", XrmoptionSepArg, (caddr_t)NULL },
112 { "-display", ".display", XrmoptionSepArg, (caddr_t)NULL },
113 { "-iconic", ".iconic", XrmoptionNoArg, (caddr_t)"on" },
114 { "-language", ".language", XrmoptionSepArg, (caddr_t)"En" },
115 { "-name", ".name", XrmoptionSepArg, (caddr_t)NULL },
116 { "-perfect", ".perfect", XrmoptionNoArg, (caddr_t)"on" },
117 { "-privatemap", ".privatemap", XrmoptionNoArg, (caddr_t)"on" },
118 { "-fixedmap", ".fixedmap", XrmoptionNoArg, (caddr_t)"on" },
119 { "-synchronous", ".synchronous", XrmoptionNoArg, (caddr_t)"on" },
120 { "-debug", ".debug", XrmoptionNoArg, (caddr_t)"on" },
121 { "-debugmsg", ".debugmsg", XrmoptionSepArg, (caddr_t)NULL },
122 { "-dll", ".dll", XrmoptionSepArg, (caddr_t)NULL },
123 { "-failreadonly", ".failreadonly", XrmoptionNoArg, (caddr_t)"on" },
124 { "-mode", ".mode", XrmoptionSepArg, (caddr_t)NULL },
125 { "-managed", ".managed", XrmoptionNoArg, (caddr_t)"off"},
126 { "-winver", ".winver", XrmoptionSepArg, (caddr_t)NULL },
127 { "-config", ".config", XrmoptionSepArg, (caddr_t)NULL },
128 { "-nodga", ".nodga", XrmoptionNoArg, (caddr_t)"off"}
131 #define NB_OPTIONS (sizeof(optionsTable) / sizeof(optionsTable[0]))
133 #define USAGE \
134 "%s\n" \
135 "Usage: %s [options] \"program_name [arguments]\"\n" \
136 "\n" \
137 "Options:\n" \
138 " -backingstore Turn on backing store\n" \
139 " -config name Specify config file to use\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 Version to imitate (one of win31,win95,nt351,nt40)\n"
163 /***********************************************************************
164 * MAIN_Usage
166 void MAIN_Usage( char *name )
168 MSG( USAGE, WINE_RELEASE_INFO, name );
169 exit(1);
173 /***********************************************************************
174 * MAIN_GetProgramName
176 * Get the program name. The name is specified by (in order of precedence):
177 * - the option '-name'.
178 * - the environment variable 'WINE_NAME'.
179 * - the last component of argv[0].
181 static char *MAIN_GetProgramName( int argc, char *argv[] )
183 int i;
184 char *p;
186 for (i = 1; i < argc-1; i++)
187 if (!strcmp( argv[i], "-name" )) return argv[i+1];
188 if ((p = getenv( "WINE_NAME" )) != NULL) return p;
189 if ((p = strrchr( argv[0], '/' )) != NULL) return p+1;
190 return argv[0];
194 /***********************************************************************
195 * MAIN_GetResource
197 * Fetch the value of resource 'name' using the correct instance name.
198 * 'name' must begin with '.' or '*'
200 static int MAIN_GetResource( XrmDatabase db, char *name, XrmValue *value )
202 char *buff_instance, *buff_class;
203 char *dummy;
204 int retval;
206 buff_instance = (char *)xmalloc(strlen(Options.programName)+strlen(name)+1);
207 buff_class = (char *)xmalloc( strlen(WINE_CLASS) + strlen(name) + 1 );
209 strcpy( buff_instance, Options.programName );
210 strcat( buff_instance, name );
211 strcpy( buff_class, WINE_CLASS );
212 strcat( buff_class, name );
213 retval = TSXrmGetResource( db, buff_instance, buff_class, &dummy, value );
214 free( buff_instance );
215 free( buff_class );
216 return retval;
220 /***********************************************************************
221 * MAIN_ParseDebugOptions
223 * Turns specific debug messages on or off, according to "options".
225 * RETURNS
226 * TRUE if parsing was successful
228 static BOOL32 MAIN_ParseDebugOptions(char *options)
230 /* defined in relay32/relay386.c */
231 extern char **debug_relay_includelist;
232 extern char **debug_relay_excludelist;
233 /* defined in relay32/snoop.c */
234 extern char **debug_snoop_includelist;
235 extern char **debug_snoop_excludelist;
237 int l, cls;
238 if (strlen(options)<3)
239 return FALSE;
242 if ((*options!='+')&&(*options!='-')){
243 int j;
245 for(j=0; j<DEBUG_CLASS_COUNT; j++)
246 if(!lstrncmpi32A(options, debug_cl_name[j], strlen(debug_cl_name[j])))
247 break;
248 if(j==DEBUG_CLASS_COUNT)
249 return FALSE;
250 options += strlen(debug_cl_name[j]);
251 if ((*options!='+')&&(*options!='-'))
252 return FALSE;
253 cls = j;
255 else
256 cls = -1; /* all classes */
258 if (strchr(options,','))
259 l=strchr(options,',')-options;
260 else
261 l=strlen(options);
263 if (!lstrncmpi32A(options+1,"all",l-1))
265 int i, j;
266 for (i=0; i<DEBUG_CHANNEL_COUNT; i++)
267 for(j=0; j<DEBUG_CLASS_COUNT; j++)
268 if(cls == -1 || cls == j)
269 debug_msg_enabled[i][j]=(*options=='+');
271 else if (!lstrncmpi32A(options+1, "relay=", 6) ||
272 !lstrncmpi32A(options+1, "snoop=", 6))
274 int i, j;
275 char *s, *s2, ***output, c;
277 for (i=0; i<DEBUG_CHANNEL_COUNT; i++)
278 if (debug_ch_name && (!lstrncmpi32A(debug_ch_name[i],options+1,5))){
279 for(j=0; j<DEBUG_CLASS_COUNT; j++)
280 if(cls == -1 || cls == j)
281 debug_msg_enabled[i][j]=TRUE;
282 break;
284 /* should never happen, maybe assert(i!=DEBUG_CHANNEL_COUNT)? */
285 if (i==DEBUG_CHANNEL_COUNT)
286 return FALSE;
287 output = (*options == '+') ?
288 ((*(options+1) == 'r') ?
289 &debug_relay_includelist :
290 &debug_snoop_includelist) :
291 ((*(options+1) == 'r') ?
292 &debug_relay_excludelist :
293 &debug_snoop_excludelist);
294 s = options + 7;
295 i = 1;
296 while((s = strchr(s, ':'))) i++, s++;
297 *output = malloc(sizeof(char **) * i + 1);
298 i = 0;
299 s = options + 7;
300 while((s2 = strchr(s, ':'))) {
301 c = *s2;
302 *s2 = '\0';
303 *((*output)+i) = strdup(s);
304 *s2 = c;
305 s = s2 + 1;
306 i++;
308 c = *(options + l);
309 *(options + l) = '\0';
310 *((*output)+i) = strdup(s);
311 *(options + l) = c;
312 *((*output)+i+1) = NULL;
314 else
316 int i, j;
317 for (i=0; i<DEBUG_CHANNEL_COUNT; i++)
318 if (debug_ch_name && (!lstrncmpi32A(options+1,debug_ch_name[i],l-1))){
319 for(j=0; j<DEBUG_CLASS_COUNT; j++)
320 if(cls == -1 || cls == j)
321 debug_msg_enabled[i][j]=(*options=='+');
322 break;
324 if (i==DEBUG_CHANNEL_COUNT)
325 return FALSE;
327 options+=l;
329 while((*options==',')&&(*(++options)));
330 if (*options)
331 return FALSE;
332 else
333 return TRUE;
336 /***********************************************************************
337 * MAIN_GetLanguageID
339 * INPUT:
340 * Lang: a string whose two first chars are the iso name of a language.
341 * Country: a string whose two first chars are the iso name of country
342 * Charset: a string defining the chossen charset encoding
343 * Dialect: a string defining a variation of the locale
345 * all those values are from the standardized format of locale
346 * name in unix which is: Lang[_Country][.Charset][@Dialect]
348 * RETURNS:
349 * the numeric code of the language used by Windows (or 0x00)
351 int MAIN_GetLanguageID(LPCSTR Lang,LPCSTR Country,LPCSTR Charset,LPCSTR Dialect)
353 char lang[3]="??", country[3]={0,0,0};
354 char *charset=NULL, *dialect=NULL;
355 int i,j,ret=0;
357 if (Lang==NULL) return 0x00;
358 if (Lang[0]) lang[0]=tolower(Lang[0]);
359 if (Lang[1]) lang[1]=tolower(Lang[1]);
361 if (Country!=NULL) {
362 if (Country[0]) country[0]=toupper(Country[0]);
363 if (Country[1]) country[1]=toupper(Country[1]);
366 if (Charset!=NULL) {
367 j=strlen(Charset);
368 charset=(char*)malloc(j+1);
369 for (i=0;i<j;i++)
370 charset[i]=toupper(Charset[i]);
371 charset[i]='\0';
374 if (Dialect!=NULL) {
375 j=strlen(Dialect);
376 dialect=(char*)malloc(j+1);
377 for (i=0;i<j;i++)
378 dialect[i]=tolower(Dialect[i]);
379 dialect[i]='\0';
382 #define LANG_ENTRY_BEGIN(x,y) if(!strcmp(lang, x )) { \
383 if (!country[0]) { \
384 ret=LANG_##y ; \
385 goto end_MAIN_GetLanguageID; \
387 #define LANG_SUB_ENTRY(x,y,z) if (!strcmp(country, x )) \
388 ret = MAKELANGID( LANG_##y , SUBLANG_##z ); \
389 goto end_MAIN_GetLanguageID;
390 #define LANG_DIALECT_ENTRY(x,y) { ret = MAKELANGID(LANG_##x , SUBLANG_##y ); \
391 goto end_MAIN_GetLanguageID; }
392 #define LANG_ENTRY_END(x) ret = MAKELANGID(LANG_##x , SUBLANG_DEFAULT); \
393 goto end_MAIN_GetLanguageID; \
396 /*x01*/ LANG_ENTRY_BEGIN( "ar", ARABIC )
397 LANG_SUB_ENTRY( "SA", ARABIC, ARABIC)
398 LANG_SUB_ENTRY( "IQ", ARABIC, ARABIC_IRAQ )
399 LANG_SUB_ENTRY( "EG", ARABIC, ARABIC_EGYPT )
400 LANG_SUB_ENTRY( "LY", ARABIC, ARABIC_LIBYA )
401 LANG_SUB_ENTRY( "DZ", ARABIC, ARABIC_ALGERIA )
402 LANG_SUB_ENTRY( "MA", ARABIC, ARABIC_MOROCCO )
403 LANG_SUB_ENTRY( "TN", ARABIC, ARABIC_TUNISIA )
404 LANG_SUB_ENTRY( "OM", ARABIC, ARABIC_OMAN )
405 LANG_SUB_ENTRY( "YE", ARABIC, ARABIC_YEMEN )
406 LANG_SUB_ENTRY( "SY", ARABIC, ARABIC_SYRIA )
407 LANG_SUB_ENTRY( "JO", ARABIC, ARABIC_JORDAN )
408 LANG_SUB_ENTRY( "LB", ARABIC, ARABIC_LEBANON )
409 LANG_SUB_ENTRY( "KW", ARABIC, ARABIC_KUWAIT )
410 LANG_SUB_ENTRY( "AE", ARABIC, ARABIC_UAE )
411 LANG_SUB_ENTRY( "BH", ARABIC, ARABIC_BAHRAIN )
412 LANG_SUB_ENTRY( "QA", ARABIC, ARABIC_QATAR )
413 LANG_ENTRY_END( ARABIC )
414 /*x02*/ LANG_ENTRY_BEGIN( "bu", BULGARIAN )
415 LANG_ENTRY_END( BULGARIAN )
416 /*x03*/ LANG_ENTRY_BEGIN( "ca", CATALAN )
417 LANG_ENTRY_END( CATALAN )
418 /*x04*/ LANG_ENTRY_BEGIN( "zh", CHINESE )
419 LANG_SUB_ENTRY( "TW", CHINESE, CHINESE_TRADITIONAL )
420 LANG_SUB_ENTRY( "CN", CHINESE, CHINESE_SIMPLIFIED )
421 LANG_SUB_ENTRY( "HK", CHINESE, CHINESE_HONGKONG )
422 LANG_SUB_ENTRY( "SG", CHINESE, CHINESE_SINGAPORE )
423 LANG_SUB_ENTRY( "MO", CHINESE, CHINESE_MACAU )
424 LANG_ENTRY_END( CHINESE )
425 /*x05*/ LANG_ENTRY_BEGIN( "cs", CZECH )
426 LANG_ENTRY_END( CZECH )
427 /*x06*/ LANG_ENTRY_BEGIN( "da", DANISH )
428 LANG_ENTRY_END( DANISH )
429 /*x07*/ LANG_ENTRY_BEGIN( "de", GERMAN )
430 LANG_SUB_ENTRY( "DE", GERMAN, GERMAN )
431 LANG_SUB_ENTRY( "CH", GERMAN, GERMAN_SWISS )
432 LANG_SUB_ENTRY( "AT", GERMAN, GERMAN_AUSTRIAN )
433 LANG_SUB_ENTRY( "LU", GERMAN, GERMAN_LUXEMBOURG )
434 LANG_SUB_ENTRY( "LI", GERMAN, GERMAN_LIECHTENSTEIN )
435 LANG_ENTRY_END( GERMAN )
436 /*x08*/ LANG_ENTRY_BEGIN( "el", GREEK )
437 LANG_ENTRY_END( GREEK )
438 /*x09*/ LANG_ENTRY_BEGIN( "en", ENGLISH )
439 LANG_SUB_ENTRY( "US", ENGLISH, ENGLISH_US )
440 LANG_SUB_ENTRY( "UK", ENGLISH, ENGLISH_UK )
441 LANG_SUB_ENTRY( "AU", ENGLISH, ENGLISH_AUS )
442 LANG_SUB_ENTRY( "CA", ENGLISH, ENGLISH_CAN )
443 LANG_SUB_ENTRY( "NZ", ENGLISH, ENGLISH_NZ )
444 LANG_SUB_ENTRY( "EI", ENGLISH, ENGLISH_EIRE )
445 LANG_SUB_ENTRY( "ZA", ENGLISH, ENGLISH_SAFRICA )
446 LANG_SUB_ENTRY( "JM", ENGLISH, ENGLISH_JAMAICA )
447 /* LANG_SUB_ENTRY( "AG", ENGLISH, ENGLISH_CARIBBEAN ) */
448 LANG_SUB_ENTRY( "BZ", ENGLISH, ENGLISH_BELIZE )
449 LANG_SUB_ENTRY( "TT", ENGLISH, ENGLISH_TRINIDAD )
450 LANG_SUB_ENTRY( "ZW", ENGLISH, ENGLISH_ZIMBABWE )
451 LANG_SUB_ENTRY( "PH", ENGLISH, ENGLISH_PHILIPPINES )
452 LANG_ENTRY_END( ENGLISH )
453 /*x0a*/ LANG_ENTRY_BEGIN( "es", SPANISH )
454 /* traditional sorting */
455 if (!strcmp(dialect,"tradicional"))
456 LANG_DIALECT_ENTRY( SPANISH, SPANISH )
457 LANG_SUB_ENTRY( "MX", SPANISH, SPANISH_MEXICAN )
458 LANG_SUB_ENTRY( "ES", SPANISH, SPANISH_MODERN )
459 LANG_SUB_ENTRY( "GT", SPANISH, SPANISH_GUATEMALA )
460 LANG_SUB_ENTRY( "CR", SPANISH, SPANISH_COSTARICA )
461 LANG_SUB_ENTRY( "PA", SPANISH, SPANISH_PANAMA )
462 LANG_SUB_ENTRY( "DO", SPANISH, SPANISH_DOMINICAN )
463 LANG_SUB_ENTRY( "VE", SPANISH, SPANISH_VENEZUELA )
464 LANG_SUB_ENTRY( "CO", SPANISH, SPANISH_COLOMBIA )
465 LANG_SUB_ENTRY( "PE", SPANISH, SPANISH_PERU )
466 LANG_SUB_ENTRY( "AR", SPANISH, SPANISH_ARGENTINA )
467 LANG_SUB_ENTRY( "EC", SPANISH, SPANISH_ECUADOR )
468 LANG_SUB_ENTRY( "CL", SPANISH, SPANISH_CHILE )
469 LANG_SUB_ENTRY( "UY", SPANISH, SPANISH_URUGUAY )
470 LANG_SUB_ENTRY( "PY", SPANISH, SPANISH_PARAGUAY )
471 LANG_SUB_ENTRY( "BO", SPANISH, SPANISH_BOLIVIA )
472 LANG_SUB_ENTRY( "HN", SPANISH, SPANISH_HONDURAS )
473 LANG_SUB_ENTRY( "NI", SPANISH, SPANISH_NICARAGUA )
474 LANG_SUB_ENTRY( "PR", SPANISH, SPANISH_PUERTO_RICO )
475 LANG_ENTRY_END( SPANISH )
476 /*x0b*/ LANG_ENTRY_BEGIN( "fi", FINNISH )
477 LANG_ENTRY_END( FINNISH )
478 /*x0c*/ LANG_ENTRY_BEGIN( "fr", FRENCH )
479 LANG_SUB_ENTRY( "FR", FRENCH, FRENCH )
480 LANG_SUB_ENTRY( "BE", FRENCH, FRENCH_BELGIAN )
481 LANG_SUB_ENTRY( "CA", FRENCH, FRENCH_CANADIAN )
482 LANG_SUB_ENTRY( "CH", FRENCH, FRENCH_SWISS )
483 LANG_SUB_ENTRY( "LU", FRENCH, FRENCH_LUXEMBOURG )
484 LANG_SUB_ENTRY( "MC", FRENCH, FRENCH_MONACO )
485 LANG_ENTRY_END( FRENCH )
486 /*x0d*/ LANG_ENTRY_BEGIN( "iw", HEBREW )
487 LANG_ENTRY_END( HEBREW )
488 /*x0e*/ LANG_ENTRY_BEGIN( "hu", HUNGARIAN )
489 LANG_ENTRY_END( HUNGARIAN )
490 /*x0f*/ LANG_ENTRY_BEGIN( "ic", ICELANDIC )
491 LANG_ENTRY_END( ICELANDIC )
492 /*x10*/ LANG_ENTRY_BEGIN( "it", ITALIAN )
493 LANG_SUB_ENTRY( "IT", ITALIAN, ITALIAN )
494 LANG_SUB_ENTRY( "CH", ITALIAN, ITALIAN_SWISS )
495 LANG_ENTRY_END( ITALIAN )
496 /*x11*/ LANG_ENTRY_BEGIN( "ja", JAPANESE )
497 LANG_ENTRY_END( JAPANESE )
498 /*x12*/ LANG_ENTRY_BEGIN( "ko", KOREAN )
499 /* JOHAB encoding */
500 if (!strcmp(charset,"JOHAB"))
501 LANG_DIALECT_ENTRY( KOREAN, KOREAN_JOHAB )
502 else
503 LANG_DIALECT_ENTRY( KOREAN, KOREAN )
504 LANG_ENTRY_END( KOREAN )
505 /*x13*/ LANG_ENTRY_BEGIN( "nl", DUTCH )
506 LANG_SUB_ENTRY( "NL", DUTCH, DUTCH )
507 LANG_SUB_ENTRY( "BE", DUTCH, DUTCH_BELGIAN )
508 LANG_SUB_ENTRY( "SR", DUTCH, DUTCH_SURINAM )
509 LANG_ENTRY_END( DUTCH )
510 /*x14*/ LANG_ENTRY_BEGIN( "no", NORWEGIAN )
511 /* nynorsk */
512 if (!strcmp(dialect,"nynorsk"))
513 LANG_DIALECT_ENTRY( NORWEGIAN, NORWEGIAN_NYNORSK )
514 else
515 LANG_DIALECT_ENTRY( NORWEGIAN, NORWEGIAN_BOKMAL )
516 LANG_ENTRY_END( NORWEGIAN )
517 /*x15*/ LANG_ENTRY_BEGIN( "pl", POLISH )
518 LANG_ENTRY_END( POLISH )
519 /*x16*/ LANG_ENTRY_BEGIN( "pt", PORTUGUESE )
520 LANG_SUB_ENTRY( "BR", PORTUGUESE, PORTUGUESE_BRAZILIAN )
521 LANG_SUB_ENTRY( "PT", PORTUGUESE, PORTUGUESE )
522 LANG_ENTRY_END( PORTUGUESE )
523 /*x17*/ LANG_ENTRY_BEGIN( "rm", RHAETO_ROMANCE )
524 LANG_ENTRY_END( RHAETO_ROMANCE )
525 /*x18*/ LANG_ENTRY_BEGIN( "ro", ROMANIAN )
526 LANG_SUB_ENTRY( "RO", ROMANIAN, ROMANIAN )
527 LANG_SUB_ENTRY( "MD", ROMANIAN, ROMANIAN_MOLDAVIA )
528 LANG_ENTRY_END( ROMANIAN )
529 /*x19*/ LANG_ENTRY_BEGIN( "ru", RUSSIAN )
530 LANG_SUB_ENTRY( "RU", RUSSIAN, RUSSIAN )
531 LANG_SUB_ENTRY( "MD", RUSSIAN, RUSSIAN_MOLDAVIA )
532 LANG_ENTRY_END( RUSSIAN )
533 /*x1a*/ if (!strcmp(lang,"sh") || !strcmp(lang,"hr") || !strcmp(lang,"sr")) {
534 if (!country[0])
535 LANG_DIALECT_ENTRY( SERBO_CROATIAN, NEUTRAL)
536 if (!strcmp(charset,"ISO-8859-5"))
537 LANG_DIALECT_ENTRY( SERBO_CROATIAN, SERBIAN )
538 LANG_SUB_ENTRY( "HR", SERBO_CROATIAN, CROATIAN )
539 if (!strcmp(country,"YU") && !strcmp(charset,"ISO-8859-2"))
540 LANG_DIALECT_ENTRY( SERBO_CROATIAN, SERBIAN_LATIN )
541 LANG_SUB_ENTRY( "YU", SERBO_CROATIAN, SERBIAN )
542 LANG_DIALECT_ENTRY( SERBO_CROATIAN, SERBIAN_LATIN )
544 /*x1b*/ LANG_ENTRY_BEGIN( "sk", SLOVAK )
545 LANG_ENTRY_END( SLOVAK )
546 /*x1c*/ LANG_ENTRY_BEGIN( "sq", ALBANIAN )
547 LANG_ENTRY_END( ALBANIAN )
548 /*x1d*/ LANG_ENTRY_BEGIN( "sv", SWEDISH )
549 LANG_SUB_ENTRY( "SE", SWEDISH, SWEDISH )
550 LANG_SUB_ENTRY( "FI", SWEDISH, SWEDISH_FINLAND )
551 LANG_ENTRY_END( SWEDISH )
552 /*x1e*/ LANG_ENTRY_BEGIN( "th", THAI )
553 LANG_ENTRY_END( THAI )
554 /*x1f*/ LANG_ENTRY_BEGIN( "tr", TURKISH )
555 LANG_ENTRY_END( TURKISH )
556 /*x20*/ LANG_ENTRY_BEGIN( "ur", URDU )
557 LANG_ENTRY_END( URDU )
558 /*x21*/ LANG_ENTRY_BEGIN( "in", INDONESIAN )
559 LANG_ENTRY_END( INDONESIAN )
560 /*x22*/ LANG_ENTRY_BEGIN( "uk", UKRAINIAN )
561 LANG_ENTRY_END( UKRAINIAN )
562 /*x23*/ LANG_ENTRY_BEGIN( "be", BYELORUSSIAN )
563 LANG_ENTRY_END( BYELORUSSIAN )
564 /*x24*/ LANG_ENTRY_BEGIN( "sl", SLOVENIAN )
565 LANG_ENTRY_END( SLOVENIAN )
566 /*x25*/ LANG_ENTRY_BEGIN( "et", ESTONIAN )
567 LANG_ENTRY_END( ESTONIAN )
568 /*x26*/ LANG_ENTRY_BEGIN( "lv", LATVIAN )
569 LANG_ENTRY_END( LATVIAN )
570 /*x27*/ LANG_ENTRY_BEGIN( "lt", LITHUANIAN )
571 /* traditional sorting ? */
572 if (!strcmp(dialect,"classic") || !strcmp(dialect,"traditional"))
573 LANG_DIALECT_ENTRY( LITHUANIAN, LITHUANIAN_CLASSIC )
574 else
575 LANG_DIALECT_ENTRY( LITHUANIAN, LITHUANIAN )
576 LANG_ENTRY_END( LITHUANIAN )
577 /*x28*/ LANG_ENTRY_BEGIN( "mi", MAORI )
578 LANG_ENTRY_END( MAORI )
579 /*x29*/ LANG_ENTRY_BEGIN( "fa", FARSI )
580 LANG_ENTRY_END( FARSI )
581 /*x2a*/ LANG_ENTRY_BEGIN( "vi", VIETNAMESE )
582 LANG_ENTRY_END( VIETNAMESE )
583 /*x2b*/ LANG_ENTRY_BEGIN( "hy", ARMENIAN )
584 LANG_ENTRY_END( ARMENIAN )
585 /*x2c*/ LANG_ENTRY_BEGIN( "az", AZERI )
586 /* Cyrillic */
587 if (strstr(charset,"KOI8") || !strcmp(charset,"ISO-8859-5"))
588 LANG_DIALECT_ENTRY( AZERI, AZERI_CYRILLIC )
589 else
590 LANG_DIALECT_ENTRY( AZERI, AZERI )
591 LANG_ENTRY_END( AZERI )
592 /*x2d*/ LANG_ENTRY_BEGIN( "eu", BASQUE )
593 LANG_ENTRY_END( BASQUE )
594 /*x2e*/ /*LANG_ENTRY_BEGIN( "??", SORBIAN )
595 LANG_ENTRY_END( SORBIAN ) */
596 /*x2f*/ LANG_ENTRY_BEGIN( "mk", MACEDONIAN )
597 LANG_ENTRY_END( MACEDONIAN )
598 /*x30*/ /*LANG_ENTRY_BEGIN( "??", SUTU )
599 LANG_ENTRY_END( SUTU ) */
600 /*x31*/ LANG_ENTRY_BEGIN( "ts", TSONGA )
601 LANG_ENTRY_END( TSONGA )
602 /*x32*/ /*LANG_ENTRY_BEGIN( "??", TSWANA )
603 LANG_ENTRY_END( TSWANA ) */
604 /*x33*/ /*LANG_ENTRY_BEGIN( "??", VENDA )
605 LANG_ENTRY_END( VENDA ) */
606 /*x34*/ LANG_ENTRY_BEGIN( "xh", XHOSA )
607 LANG_ENTRY_END( XHOSA )
608 /*x35*/ LANG_ENTRY_BEGIN( "zu", ZULU )
609 LANG_ENTRY_END( ZULU )
610 /*x36*/ LANG_ENTRY_BEGIN( "af", AFRIKAANS )
611 LANG_ENTRY_END( AFRIKAANS )
612 /*x37*/ LANG_ENTRY_BEGIN( "ka", GEORGIAN )
613 LANG_ENTRY_END( GEORGIAN )
614 /*x38*/ LANG_ENTRY_BEGIN( "fo", FAEROESE )
615 LANG_ENTRY_END( FAEROESE )
616 /*x39*/ LANG_ENTRY_BEGIN( "hi", HINDI )
617 LANG_ENTRY_END( HINDI )
618 /*x3a*/ LANG_ENTRY_BEGIN( "mt", MALTESE )
619 LANG_ENTRY_END( MALTESE )
620 /*x3b*/ /*LANG_ENTRY_BEGIN( "??", SAAMI )
621 LANG_ENTRY_END( SAAMI ) */
622 /*x3c*/ LANG_ENTRY_BEGIN( "ga", GAELIC )
623 LANG_DIALECT_ENTRY( GAELIC, GAELIC )
624 LANG_ENTRY_END( GAELIC )
625 /*x3c*/ LANG_ENTRY_BEGIN( "gd", GAELIC )
626 LANG_DIALECT_ENTRY( GAELIC, GAELIC_SCOTTISH )
627 LANG_ENTRY_END( GAELIC )
628 // 0x3d
629 /*x3e*/ LANG_ENTRY_BEGIN( "ms", MALAY )
630 LANG_SUB_ENTRY( "MY", MALAY, MALAY )
631 LANG_SUB_ENTRY( "BN", MALAY, MALAY_BRUNEI_DARUSSALAM )
632 LANG_ENTRY_END( MALAY )
633 /*x3f*/ LANG_ENTRY_BEGIN( "kk", KAZAKH )
634 LANG_ENTRY_END( KAZAKH )
635 // 0x40
636 /*x41*/ LANG_ENTRY_BEGIN( "sw", SWAHILI )
637 LANG_ENTRY_END( SWAHILI )
638 // 0x42
639 /*x43*/ LANG_ENTRY_BEGIN( "uz", UZBEK )
640 /* Cyrillic */
641 if (strstr(charset,"KOI8") || !strcmp(charset,"ISO-8859-5"))
642 LANG_DIALECT_ENTRY( UZBEK, UZBEK_CYRILLIC )
643 else
644 LANG_DIALECT_ENTRY( UZBEK, UZBEK )
645 LANG_ENTRY_END( UZBEK )
646 /*x44*/ LANG_ENTRY_BEGIN( "tt", TATAR )
647 LANG_ENTRY_END( TATAR )
648 /*x45*/ LANG_ENTRY_BEGIN( "bn", BENGALI )
649 LANG_ENTRY_END( BENGALI )
650 /*x46*/ LANG_ENTRY_BEGIN( "pa", PUNJABI )
651 LANG_ENTRY_END( PUNJABI )
652 /*x47*/ LANG_ENTRY_BEGIN( "gu", GUJARATI )
653 LANG_ENTRY_END( GUJARATI )
654 /*x48*/ LANG_ENTRY_BEGIN( "or", ORIYA )
655 LANG_ENTRY_END( ORIYA )
656 /*x49*/ LANG_ENTRY_BEGIN( "ta", TAMIL )
657 LANG_ENTRY_END( TAMIL )
658 /*x4a*/ LANG_ENTRY_BEGIN( "te", TELUGU )
659 LANG_ENTRY_END( TELUGU )
660 /*x4b*/ LANG_ENTRY_BEGIN( "kn", KANNADA )
661 LANG_ENTRY_END( KANNADA )
662 /*x4c*/ LANG_ENTRY_BEGIN( "ml", MALAYALAM )
663 LANG_ENTRY_END( MALAYALAM )
664 /*x4d*/ LANG_ENTRY_BEGIN( "as", ASSAMESE )
665 LANG_ENTRY_END( ASSAMESE )
666 /*x4e*/ LANG_ENTRY_BEGIN( "mr", MARATHI )
667 LANG_ENTRY_END( MARATHI )
668 /*x4f*/ LANG_ENTRY_BEGIN( "sa", SANSKRIT )
669 LANG_ENTRY_END( SANSKRIT )
670 // 0x50 -> 0x56
671 /*x57*/ /*LANG_ENTRY_BEGIN( "??", KONKANI )
672 LANG_ENTRY_END( KONKANI ) */
673 // 0x58 -> ...
674 LANG_ENTRY_BEGIN( "eo", ESPERANTO ) /* not official */
675 LANG_ENTRY_END( ESPERANTO )
677 ret = LANG_ENGLISH;
679 end_MAIN_GetLanguageID:
680 if (Charset) free(charset);
681 if (Dialect) free(dialect);
683 return ret;
686 /***********************************************************************
687 * MAIN_ParseLanguageOption
689 * Parse -language option.
691 static void MAIN_ParseLanguageOption( char *arg )
693 const WINE_LANGUAGE_DEF *p = Languages;
695 Options.language = LANG_En; /* First language */
696 for (;p->name;p++)
698 if (!lstrcmpi32A( p->name, arg ))
700 WINE_LanguageId = p->langid;
701 return;
703 Options.language++;
705 MSG( "Invalid language specified '%s'. Supported languages are: ", arg );
706 for (p = Languages; p->name; p++) MSG( "%s ", p->name );
707 MSG( "\n" );
708 exit(1);
712 /***********************************************************************
713 * MAIN_ParseModeOption
715 * Parse -mode option.
717 static void MAIN_ParseModeOption( char *arg )
719 if (!lstrcmpi32A("enhanced", arg)) Options.mode = MODE_ENHANCED;
720 else if (!lstrcmpi32A("standard", arg)) Options.mode = MODE_STANDARD;
721 else
723 MSG( "Invalid mode '%s' specified.\n", arg);
724 MSG( "Valid modes are: 'standard', 'enhanced' (default).\n");
725 exit(1);
729 /***********************************************************************
730 * MAIN_ParseOptions
732 * Parse command line options and open display.
734 static void MAIN_ParseOptions( int *argc, char *argv[] )
736 char *display_name = NULL;
737 XrmValue value;
738 XrmDatabase db = TSXrmGetFileDatabase(WINE_APP_DEFAULTS);
739 int i;
740 char *xrm_string;
742 Options.programName = MAIN_GetProgramName( *argc, argv );
743 Options.argv0 = argv[0];
745 /* initialise Options.language to 0 to tell "no language choosen yet" */
746 Options.language = 0;
748 /* Get display name from command line */
749 for (i = 1; i < *argc; i++)
751 if (!strcmp( argv[i], "-display" )) display_name = argv[i+1];
752 if (!strcmp( argv[i], "-v" ) || !strcmp( argv[i], "-version" ))
754 MSG( "%s\n", WINE_RELEASE_INFO );
755 exit(0);
757 if (!strcmp( argv[i], "-h" ) || !strcmp( argv[i], "-help" ))
759 MAIN_Usage(argv[0]);
760 exit(0);
764 /* Open display */
766 if (display_name == NULL &&
767 MAIN_GetResource( db, ".display", &value )) display_name = value.addr;
769 if (!(display = TSXOpenDisplay( display_name )))
771 MSG( "%s: Can't open display: %s\n",
772 argv[0], display_name ? display_name : "(none specified)" );
773 exit(1);
776 /* tell the libX11 that we will do input method handling ourselves
777 * that keep libX11 from doing anything whith dead keys, allowing Wine
778 * to have total control over dead keys, that is this line allows
779 * them to work in Wine, even whith a libX11 including the dead key
780 * patches from Th.Quinot (http://Web.FdN.FR/~tquinot/dead-keys.en.html)
782 TSXOpenIM(display,NULL,NULL,NULL);
784 /* Merge file and screen databases */
785 if ((xrm_string = TSXResourceManagerString( display )) != NULL)
787 XrmDatabase display_db = TSXrmGetStringDatabase( xrm_string );
788 TSXrmMergeDatabases( display_db, &db );
791 /* Parse command line */
792 TSXrmParseCommand( &db, optionsTable, NB_OPTIONS,
793 Options.programName, argc, argv );
795 /* Get all options */
796 if (MAIN_GetResource( db, ".iconic", &value ))
797 Options.cmdShow = SW_SHOWMINIMIZED;
798 if (MAIN_GetResource( db, ".privatemap", &value ))
799 Options.usePrivateMap = TRUE;
800 if (MAIN_GetResource( db, ".fixedmap", &value ))
801 Options.useFixedMap = TRUE;
802 if (MAIN_GetResource( db, ".synchronous", &value ))
803 Options.synchronous = TRUE;
804 if (MAIN_GetResource( db, ".backingstore", &value ))
805 Options.backingstore = TRUE;
806 if (MAIN_GetResource( db, ".debug", &value ))
807 Options.debug = TRUE;
808 if (MAIN_GetResource( db, ".failreadonly", &value ))
809 Options.failReadOnly = TRUE;
810 if (MAIN_GetResource( db, ".perfect", &value ))
811 Options.perfectGraphics = TRUE;
812 if (MAIN_GetResource( db, ".depth", &value))
813 screenDepth = atoi( value.addr );
814 if (MAIN_GetResource( db, ".desktop", &value))
815 Options.desktopGeometry = value.addr;
816 if (MAIN_GetResource( db, ".language", &value))
817 MAIN_ParseLanguageOption( (char *)value.addr );
818 if (MAIN_GetResource( db, ".managed", &value))
819 Options.managed = TRUE;
820 if (MAIN_GetResource( db, ".mode", &value))
821 MAIN_ParseModeOption( (char *)value.addr );
822 if (MAIN_GetResource( db, ".debugoptions", &value))
823 MAIN_ParseDebugOptions((char*)value.addr);
824 if (MAIN_GetResource( db, ".debugmsg", &value))
826 #ifndef DEBUG_RUNTIME
827 MSG("%s: Option \"-debugmsg\" not implemented.\n" \
828 " Recompile with DEBUG_RUNTIME in include/debugtools.h defined.\n",
829 argv[0]);
830 exit(1);
831 #else
832 if (MAIN_ParseDebugOptions((char*)value.addr)==FALSE)
834 int i;
835 MSG("%s: Syntax: -debugmsg [class]+xxx,... or "
836 "-debugmsg [class]-xxx,...\n",argv[0]);
837 MSG("Example: -debugmsg +all,warn-heap\n"
838 " turn on all messages except warning heap messages\n");
839 MSG("Special case: -debugmsg +relay=DLL:DLL.###:FuncName\n"
840 " turn on -debugmsg +relay only as specified\n"
841 "Special case: -debugmsg -relay=DLL:DLL.###:FuncName\n"
842 " turn on -debugmsg +relay except as specified\n"
843 "Also permitted, +snoop=..., -snoop=... as with relay.\n\n");
845 MSG("Available message classes:\n");
846 for(i=0;i<DEBUG_CLASS_COUNT;i++)
847 MSG( "%-9s", debug_cl_name[i]);
848 MSG("\n\n");
850 MSG("Available message types:\n");
851 MSG("%-9s ","all");
852 for(i=0;i<DEBUG_CHANNEL_COUNT;i++)
853 if(debug_ch_name[i])
854 MSG("%-9s%c",debug_ch_name[i],
855 (((i+2)%8==0)?'\n':' '));
856 MSG("\n\n");
857 exit(1);
859 #endif
862 if (MAIN_GetResource( db, ".dll", &value))
864 /* Hack: store option value in Options to be retrieved */
865 /* later on inside the emulator code. */
866 if (!__winelib) Options.dllFlags = xstrdup((char *)value.addr);
867 else
869 MSG("-dll not supported in Winelib\n" );
870 exit(1);
874 if (MAIN_GetResource( db, ".winver", &value))
875 VERSION_ParseVersion( (char*)value.addr );
876 if (MAIN_GetResource( db, ".config", &value))
877 Options.configFileName = xstrdup((char *)value.addr);
878 if (MAIN_GetResource( db, ".nodga", &value))
879 Options.noDGA = TRUE;
883 /***********************************************************************
884 * MAIN_CreateDesktop
886 static void MAIN_CreateDesktop( int argc, char *argv[] )
888 int x, y, flags;
889 unsigned int width = 640, height = 480; /* Default size = 640x480 */
890 char *name = "Wine desktop";
891 XSizeHints *size_hints;
892 XWMHints *wm_hints;
893 XClassHint *class_hints;
894 XSetWindowAttributes win_attr;
895 XTextProperty window_name;
896 Atom XA_WM_DELETE_WINDOW;
898 flags = TSXParseGeometry( Options.desktopGeometry, &x, &y, &width, &height );
899 screenWidth = width;
900 screenHeight = height;
902 /* Create window */
904 win_attr.background_pixel = BlackPixel(display,0);
905 win_attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
906 PointerMotionMask | ButtonPressMask |
907 ButtonReleaseMask | EnterWindowMask;
908 win_attr.cursor = TSXCreateFontCursor( display, XC_top_left_arrow );
910 rootWindow = TSXCreateWindow( display, DefaultRootWindow(display),
911 x, y, width, height, 0,
912 CopyFromParent, InputOutput, CopyFromParent,
913 CWBackPixel | CWEventMask | CWCursor, &win_attr );
915 /* Set window manager properties */
917 size_hints = TSXAllocSizeHints();
918 wm_hints = TSXAllocWMHints();
919 class_hints = TSXAllocClassHint();
920 if (!size_hints || !wm_hints || !class_hints)
922 MSG("Not enough memory for window manager hints.\n" );
923 exit(1);
925 size_hints->min_width = size_hints->max_width = width;
926 size_hints->min_height = size_hints->max_height = height;
927 size_hints->flags = PMinSize | PMaxSize;
928 if (flags & (XValue | YValue)) size_hints->flags |= USPosition;
929 if (flags & (WidthValue | HeightValue)) size_hints->flags |= USSize;
930 else size_hints->flags |= PSize;
932 wm_hints->flags = InputHint | StateHint;
933 wm_hints->input = True;
934 wm_hints->initial_state = NormalState;
935 class_hints->res_name = argv[0];
936 class_hints->res_class = "Wine";
938 TSXStringListToTextProperty( &name, 1, &window_name );
939 TSXSetWMProperties( display, rootWindow, &window_name, &window_name,
940 argv, argc, size_hints, wm_hints, class_hints );
941 XA_WM_DELETE_WINDOW = TSXInternAtom( display, "WM_DELETE_WINDOW", False );
942 TSXSetWMProtocols( display, rootWindow, &XA_WM_DELETE_WINDOW, 1 );
943 TSXFree( size_hints );
944 TSXFree( wm_hints );
945 TSXFree( class_hints );
947 /* Map window */
949 TSXMapWindow( display, rootWindow );
953 XKeyboardState keyboard_state;
955 /***********************************************************************
956 * MAIN_SaveSetup
958 static void MAIN_SaveSetup(void)
960 TSXGetKeyboardControl(display, &keyboard_state);
963 /***********************************************************************
964 * MAIN_RestoreSetup
966 static void MAIN_RestoreSetup(void)
968 XKeyboardControl keyboard_value;
970 keyboard_value.key_click_percent = keyboard_state.key_click_percent;
971 keyboard_value.bell_percent = keyboard_state.bell_percent;
972 keyboard_value.bell_pitch = keyboard_state.bell_pitch;
973 keyboard_value.bell_duration = keyboard_state.bell_duration;
974 keyboard_value.auto_repeat_mode = keyboard_state.global_auto_repeat;
976 XChangeKeyboardControl(display, KBKeyClickPercent | KBBellPercent |
977 KBBellPitch | KBBellDuration | KBAutoRepeatMode, &keyboard_value);
981 /***********************************************************************
982 * called_at_exit
984 static void called_at_exit(void)
986 MAIN_RestoreSetup();
987 COLOR_Cleanup();
988 WINSOCK_Shutdown();
989 /* FIXME: should check for other processes or threads */
990 DeleteCriticalSection( HEAP_SystemLock );
991 CONSOLE_Close();
994 static int WINE_X11_ErrorHandler(Display *display,XErrorEvent *error_evt)
996 kill( getpid(), SIGHUP ); /* force an entry in the debugger */
997 return 0;
1000 /***********************************************************************
1001 * MAIN_WineInit
1003 * Wine initialisation and command-line parsing
1005 BOOL32 MAIN_WineInit( int *argc, char *argv[] )
1007 int depth_count, i;
1008 int *depth_list;
1009 struct timeval tv;
1011 #ifdef MALLOC_DEBUGGING
1012 char *trace;
1014 mcheck(NULL);
1015 if (!(trace = getenv("MALLOC_TRACE")))
1017 MSG( "MALLOC_TRACE not set. No trace generated\n" );
1019 else
1021 MSG( "malloc trace goes to %s\n", trace );
1022 mtrace();
1024 #endif
1026 setbuf(stdout,NULL);
1027 setbuf(stderr,NULL);
1029 setlocale(LC_CTYPE,"");
1030 gettimeofday( &tv, NULL);
1031 MSG_WineStartTicks = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
1033 /* We need this before calling any Xlib function */
1034 InitializeCriticalSection( &X11DRV_CritSection );
1036 TSXrmInitialize();
1038 putenv("XKB_DISABLE="); /* Disable XKB extension if present. */
1040 MAIN_ParseOptions( argc, argv );
1042 if (Options.synchronous) XSetErrorHandler( WINE_X11_ErrorHandler );
1044 if (Options.desktopGeometry && Options.managed)
1046 #if 0
1047 MSG( "%s: -managed and -desktop options cannot be used together\n",
1048 Options.programName );
1049 exit(1);
1050 #else
1051 Options.managed = FALSE;
1052 #endif
1055 screen = DefaultScreenOfDisplay( display );
1056 screenWidth = WidthOfScreen( screen );
1057 screenHeight = HeightOfScreen( screen );
1058 if (screenDepth) /* -depth option specified */
1060 depth_list = TSXListDepths(display,DefaultScreen(display),&depth_count);
1061 for (i = 0; i < depth_count; i++)
1062 if (depth_list[i] == screenDepth) break;
1063 TSXFree( depth_list );
1064 if (i >= depth_count)
1066 MSG( "%s: Depth %d not supported on this screen.\n",
1067 Options.programName, screenDepth );
1068 exit(1);
1071 else screenDepth = DefaultDepthOfScreen( screen );
1072 if (Options.synchronous) TSXSynchronize( display, True );
1073 if (Options.desktopGeometry) MAIN_CreateDesktop( *argc, argv );
1074 else rootWindow = DefaultRootWindow( display );
1076 MAIN_SaveSetup();
1077 atexit(called_at_exit);
1078 return TRUE;
1082 /***********************************************************************
1083 * MessageBeep16 (USER.104)
1085 void WINAPI MessageBeep16( UINT16 i )
1087 MessageBeep32( i );
1091 /***********************************************************************
1092 * MessageBeep32 (USER32.390)
1094 BOOL32 WINAPI MessageBeep32( UINT32 i )
1096 TSXBell( display, 0 );
1097 return TRUE;
1101 /***********************************************************************
1102 * Beep (KERNEL32.11)
1104 BOOL32 WINAPI Beep( DWORD dwFreq, DWORD dwDur )
1106 /* dwFreq and dwDur are ignored by Win95 */
1107 TSXBell(display, 0);
1108 return TRUE;
1112 /***********************************************************************
1113 * GetTimerResolution (USER.14)
1115 LONG WINAPI GetTimerResolution(void)
1117 return (1000);
1120 /***********************************************************************
1121 * SystemParametersInfo32A (USER32.540)
1123 BOOL32 WINAPI SystemParametersInfo32A( UINT32 uAction, UINT32 uParam,
1124 LPVOID lpvParam, UINT32 fuWinIni )
1126 int timeout, temp;
1127 XKeyboardState keyboard_state;
1129 switch (uAction) {
1130 case SPI_GETBEEP:
1131 TSXGetKeyboardControl(display, &keyboard_state);
1132 if (keyboard_state.bell_percent == 0)
1133 *(BOOL32 *) lpvParam = FALSE;
1134 else
1135 *(BOOL32 *) lpvParam = TRUE;
1136 break;
1138 case SPI_GETBORDER:
1139 *(INT32 *)lpvParam = GetSystemMetrics32( SM_CXFRAME );
1140 break;
1142 case SPI_GETDRAGFULLWINDOWS:
1143 *(BOOL32 *) lpvParam = FALSE;
1144 break;
1146 case SPI_SETDRAGFULLWINDOWS:
1147 break;
1149 case SPI_GETFASTTASKSWITCH:
1150 if ( GetProfileInt32A( "windows", "CoolSwitch", 1 ) == 1 )
1151 *(BOOL32 *) lpvParam = TRUE;
1152 else
1153 *(BOOL32 *) lpvParam = FALSE;
1154 break;
1156 case SPI_GETGRIDGRANULARITY:
1157 *(INT32*)lpvParam=GetProfileInt32A("desktop","GridGranularity",1);
1158 break;
1160 case SPI_GETICONTITLEWRAP:
1161 *(BOOL32*)lpvParam=GetProfileInt32A("desktop","IconTitleWrap",TRUE);
1162 break;
1164 case SPI_GETKEYBOARDDELAY:
1165 *(INT32*)lpvParam=GetProfileInt32A("keyboard","KeyboardDelay",1);
1166 break;
1168 case SPI_GETKEYBOARDSPEED:
1169 *(DWORD*)lpvParam=GetProfileInt32A("keyboard","KeyboardSpeed",30);
1170 break;
1172 case SPI_GETMENUDROPALIGNMENT:
1173 *(BOOL32*)lpvParam=GetSystemMetrics32(SM_MENUDROPALIGNMENT); /* XXX check this */
1174 break;
1176 case SPI_GETSCREENSAVEACTIVE:
1177 if ( GetProfileInt32A( "windows", "ScreenSaveActive", 1 ) == 1 )
1178 *(BOOL32*)lpvParam = TRUE;
1179 else
1180 *(BOOL32*)lpvParam = FALSE;
1181 break;
1183 case SPI_GETSCREENSAVETIMEOUT:
1184 /* FIXME GetProfileInt( "windows", "ScreenSaveTimeout", 300 ); */
1185 TSXGetScreenSaver(display, &timeout, &temp,&temp,&temp);
1186 *(INT32 *) lpvParam = timeout * 1000;
1187 break;
1189 case SPI_ICONHORIZONTALSPACING:
1190 /* FIXME Get/SetProfileInt */
1191 if (lpvParam == NULL)
1192 /*SetSystemMetrics( SM_CXICONSPACING, uParam )*/ ;
1193 else
1194 *(INT32*)lpvParam=GetSystemMetrics32(SM_CXICONSPACING);
1195 break;
1197 case SPI_ICONVERTICALSPACING:
1198 /* FIXME Get/SetProfileInt */
1199 if (lpvParam == NULL)
1200 /*SetSystemMetrics( SM_CYICONSPACING, uParam )*/ ;
1201 else
1202 *(INT32*)lpvParam=GetSystemMetrics32(SM_CYICONSPACING);
1203 break;
1205 case SPI_GETICONTITLELOGFONT: {
1206 LPLOGFONT32A lpLogFont = (LPLOGFONT32A)lpvParam;
1208 /* from now on we always have an alias for MS Sans Serif */
1210 GetProfileString32A("Desktop", "IconTitleFaceName", "MS Sans Serif",
1211 lpLogFont->lfFaceName, LF_FACESIZE );
1212 lpLogFont->lfHeight = -GetProfileInt32A("Desktop","IconTitleSize", 8);
1213 lpLogFont->lfWidth = 0;
1214 lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
1215 lpLogFont->lfWeight = FW_NORMAL;
1216 lpLogFont->lfItalic = FALSE;
1217 lpLogFont->lfStrikeOut = FALSE;
1218 lpLogFont->lfUnderline = FALSE;
1219 lpLogFont->lfCharSet = ANSI_CHARSET;
1220 lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
1221 lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
1222 lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
1223 break;
1225 case SPI_GETWORKAREA:
1226 SetRect32( (RECT32 *)lpvParam, 0, 0,
1227 GetSystemMetrics32( SM_CXSCREEN ),
1228 GetSystemMetrics32( SM_CYSCREEN )
1230 break;
1231 case SPI_GETNONCLIENTMETRICS:
1233 #define lpnm ((LPNONCLIENTMETRICS32A)lpvParam)
1235 if( lpnm->cbSize == sizeof(NONCLIENTMETRICS32A) )
1237 /* FIXME: initialize geometry entries */
1239 SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
1240 (LPVOID)&(lpnm->lfCaptionFont),0);
1241 lpnm->lfCaptionFont.lfWeight = FW_BOLD;
1242 SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
1243 (LPVOID)&(lpnm->lfSmCaptionFont),0);
1244 SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
1245 (LPVOID)&(lpnm->lfMenuFont),0);
1246 SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
1247 (LPVOID)&(lpnm->lfStatusFont),0);
1248 SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
1249 (LPVOID)&(lpnm->lfMessageFont),0);
1251 #undef lpnm
1252 break;
1254 case SPI_GETANIMATION: {
1255 LPANIMATIONINFO lpAnimInfo = (LPANIMATIONINFO)lpvParam;
1257 /* Tell it "disabled" */
1258 lpAnimInfo->cbSize = sizeof(ANIMATIONINFO);
1259 uParam = sizeof(ANIMATIONINFO);
1260 lpAnimInfo->iMinAnimate = 0; /* Minimise and restore animation is disabled (nonzero == enabled) */
1261 break;
1264 case SPI_SETANIMATION: {
1265 LPANIMATIONINFO lpAnimInfo = (LPANIMATIONINFO)lpvParam;
1267 /* Do nothing */
1268 WARN(system, "SPI_SETANIMATION ignored.\n");
1269 lpAnimInfo->cbSize = sizeof(ANIMATIONINFO);
1270 uParam = sizeof(ANIMATIONINFO);
1271 break;
1274 case SPI_GETHIGHCONTRAST:
1276 LPHIGHCONTRASTA lpHighContrastA = (LPHIGHCONTRASTA)lpvParam;
1278 FIXME(system,"SPI_GETHIGHCONTRAST not fully implemented\n");
1280 if ( lpHighContrastA->cbSize == sizeof( HIGHCONTRASTA ) )
1282 /* Indicate that there is no high contrast available */
1283 lpHighContrastA->dwFlags = 0;
1284 lpHighContrastA->lpszDefaultScheme = NULL;
1286 else
1288 return FALSE;
1291 break;
1294 default:
1295 return SystemParametersInfo16(uAction,uParam,lpvParam,fuWinIni);
1297 return TRUE;
1301 /***********************************************************************
1302 * SystemParametersInfo16 (USER.483)
1304 BOOL16 WINAPI SystemParametersInfo16( UINT16 uAction, UINT16 uParam,
1305 LPVOID lpvParam, UINT16 fuWinIni )
1307 int timeout, temp;
1308 char buffer[256];
1309 XKeyboardState keyboard_state;
1310 XKeyboardControl keyboard_value;
1313 switch (uAction)
1315 case SPI_GETBEEP:
1316 TSXGetKeyboardControl(display, &keyboard_state);
1317 if (keyboard_state.bell_percent == 0)
1318 *(BOOL16 *) lpvParam = FALSE;
1319 else
1320 *(BOOL16 *) lpvParam = TRUE;
1321 break;
1323 case SPI_GETBORDER:
1324 *(INT16 *)lpvParam = GetSystemMetrics16( SM_CXFRAME );
1325 break;
1327 case SPI_GETFASTTASKSWITCH:
1328 if ( GetProfileInt32A( "windows", "CoolSwitch", 1 ) == 1 )
1329 *(BOOL16 *) lpvParam = TRUE;
1330 else
1331 *(BOOL16 *) lpvParam = FALSE;
1332 break;
1334 case SPI_GETGRIDGRANULARITY:
1335 *(INT16 *) lpvParam = GetProfileInt32A( "desktop",
1336 "GridGranularity",
1337 1 );
1338 break;
1340 case SPI_GETICONTITLEWRAP:
1341 *(BOOL16 *) lpvParam = GetProfileInt32A( "desktop",
1342 "IconTitleWrap",
1343 TRUE );
1344 break;
1346 case SPI_GETKEYBOARDDELAY:
1347 *(INT16 *) lpvParam = GetProfileInt32A( "keyboard",
1348 "KeyboardDelay", 1 );
1349 break;
1351 case SPI_GETKEYBOARDSPEED:
1352 *(WORD *) lpvParam = GetProfileInt32A( "keyboard",
1353 "KeyboardSpeed",
1354 30 );
1355 break;
1357 case SPI_GETMENUDROPALIGNMENT:
1358 *(BOOL16 *) lpvParam = GetSystemMetrics16( SM_MENUDROPALIGNMENT ); /* XXX check this */
1359 break;
1361 case SPI_GETSCREENSAVEACTIVE:
1362 if ( GetProfileInt32A( "windows", "ScreenSaveActive", 1 ) == 1 )
1363 *(BOOL16 *) lpvParam = TRUE;
1364 else
1365 *(BOOL16 *) lpvParam = FALSE;
1366 break;
1368 case SPI_GETSCREENSAVETIMEOUT:
1369 /* FIXME GetProfileInt( "windows", "ScreenSaveTimeout", 300 ); */
1370 TSXGetScreenSaver(display, &timeout, &temp,&temp,&temp);
1371 *(INT16 *) lpvParam = timeout;
1372 break;
1374 case SPI_ICONHORIZONTALSPACING:
1375 /* FIXME Get/SetProfileInt */
1376 if (lpvParam == NULL)
1377 /*SetSystemMetrics( SM_CXICONSPACING, uParam )*/ ;
1378 else
1379 *(INT16 *)lpvParam = GetSystemMetrics16( SM_CXICONSPACING );
1380 break;
1382 case SPI_ICONVERTICALSPACING:
1383 /* FIXME Get/SetProfileInt */
1384 if (lpvParam == NULL)
1385 /*SetSystemMetrics( SM_CYICONSPACING, uParam )*/ ;
1386 else
1387 *(INT16 *)lpvParam = GetSystemMetrics16(SM_CYICONSPACING);
1388 break;
1390 case SPI_SETBEEP:
1391 if (uParam == TRUE)
1392 keyboard_value.bell_percent = -1;
1393 else
1394 keyboard_value.bell_percent = 0;
1395 TSXChangeKeyboardControl(display, KBBellPercent,
1396 &keyboard_value);
1397 break;
1399 case SPI_SETSCREENSAVEACTIVE:
1400 if (uParam == TRUE)
1401 TSXActivateScreenSaver(display);
1402 else
1403 TSXResetScreenSaver(display);
1404 break;
1406 case SPI_SETSCREENSAVETIMEOUT:
1407 TSXSetScreenSaver(display, uParam, 60, DefaultBlanking,
1408 DefaultExposures);
1409 break;
1411 case SPI_SETDESKWALLPAPER:
1412 return (SetDeskWallPaper32((LPSTR) lpvParam));
1413 break;
1415 case SPI_SETDESKPATTERN:
1416 if ((INT16)uParam == -1) {
1417 GetProfileString32A("Desktop", "Pattern",
1418 "170 85 170 85 170 85 170 85",
1419 buffer, sizeof(buffer) );
1420 return (DESKTOP_SetPattern((LPSTR) buffer));
1421 } else
1422 return (DESKTOP_SetPattern((LPSTR) lpvParam));
1423 break;
1425 case SPI_GETICONTITLELOGFONT:
1427 LPLOGFONT16 lpLogFont = (LPLOGFONT16)lpvParam;
1429 GetProfileString32A("Desktop", "IconTitleFaceName", "MS Sans Serif",
1430 lpLogFont->lfFaceName, LF_FACESIZE );
1431 lpLogFont->lfHeight = -GetProfileInt32A("Desktop","IconTitleSize", 8);
1432 lpLogFont->lfWidth = 0;
1433 lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
1434 lpLogFont->lfWeight = FW_NORMAL;
1435 lpLogFont->lfItalic = FALSE;
1436 lpLogFont->lfStrikeOut = FALSE;
1437 lpLogFont->lfUnderline = FALSE;
1438 lpLogFont->lfCharSet = ANSI_CHARSET;
1439 lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
1440 lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
1441 lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
1442 break;
1444 case SPI_GETNONCLIENTMETRICS:
1446 #define lpnm ((LPNONCLIENTMETRICS16)lpvParam)
1447 if( lpnm->cbSize == sizeof(NONCLIENTMETRICS16) )
1449 /* FIXME: initialize geometry entries */
1450 SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
1451 (LPVOID)&(lpnm->lfCaptionFont),0);
1452 lpnm->lfCaptionFont.lfWeight = FW_BOLD;
1453 SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
1454 (LPVOID)&(lpnm->lfSmCaptionFont),0);
1455 SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
1456 (LPVOID)&(lpnm->lfMenuFont),0);
1457 SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
1458 (LPVOID)&(lpnm->lfStatusFont),0);
1459 SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
1460 (LPVOID)&(lpnm->lfMessageFont),0);
1462 else /* winfile 95 sets sbSize to 340 */
1463 SystemParametersInfo32A( uAction, uParam, lpvParam, fuWinIni );
1464 #undef lpnm
1465 break;
1467 case SPI_LANGDRIVER:
1468 case SPI_SETBORDER:
1469 case SPI_SETDOUBLECLKHEIGHT:
1470 case SPI_SETDOUBLECLICKTIME:
1471 case SPI_SETDOUBLECLKWIDTH:
1472 case SPI_SETFASTTASKSWITCH:
1473 case SPI_SETKEYBOARDDELAY:
1474 case SPI_SETKEYBOARDSPEED:
1475 WARN(system, "Option %d ignored.\n", uAction);
1476 break;
1478 case SPI_GETWORKAREA:
1479 SetRect16( (RECT16 *)lpvParam, 0, 0,
1480 GetSystemMetrics16( SM_CXSCREEN ),
1481 GetSystemMetrics16( SM_CYSCREEN ) );
1482 break;
1484 default:
1485 WARN(system, "Unknown option %d.\n", uAction);
1486 break;
1488 return 1;
1491 /***********************************************************************
1492 * SystemParametersInfo32W (USER32.541)
1494 BOOL32 WINAPI SystemParametersInfo32W( UINT32 uAction, UINT32 uParam,
1495 LPVOID lpvParam, UINT32 fuWinIni )
1497 char buffer[256];
1499 switch (uAction)
1501 case SPI_SETDESKWALLPAPER:
1502 if (lpvParam)
1504 lstrcpynWtoA(buffer,(LPWSTR)lpvParam,sizeof(buffer));
1505 return SetDeskWallPaper32(buffer);
1507 return SetDeskWallPaper32(NULL);
1509 case SPI_SETDESKPATTERN:
1510 if ((INT32) uParam == -1)
1512 GetProfileString32A("Desktop", "Pattern",
1513 "170 85 170 85 170 85 170 85",
1514 buffer, sizeof(buffer) );
1515 return (DESKTOP_SetPattern((LPSTR) buffer));
1517 if (lpvParam)
1519 lstrcpynWtoA(buffer,(LPWSTR)lpvParam,sizeof(buffer));
1520 return DESKTOP_SetPattern(buffer);
1522 return DESKTOP_SetPattern(NULL);
1524 case SPI_GETICONTITLELOGFONT:
1526 LPLOGFONT32W lpLogFont = (LPLOGFONT32W)lpvParam;
1527 GetProfileString32A("Desktop", "IconTitleFaceName", "MS Sans Serif",
1528 buffer, sizeof(buffer) );
1529 lstrcpynAtoW(lpLogFont->lfFaceName, buffer ,LF_FACESIZE);
1530 lpLogFont->lfHeight = 10;
1531 lpLogFont->lfWidth = 0;
1532 lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
1533 lpLogFont->lfWeight = FW_NORMAL;
1534 lpLogFont->lfItalic = lpLogFont->lfStrikeOut = lpLogFont->lfUnderline = FALSE;
1535 lpLogFont->lfCharSet = ANSI_CHARSET;
1536 lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
1537 lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
1538 lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
1540 break;
1541 case SPI_GETNONCLIENTMETRICS: {
1542 /* FIXME: implement correctly */
1543 LPNONCLIENTMETRICS32W lpnm=(LPNONCLIENTMETRICS32W)lpvParam;
1545 SystemParametersInfo32W(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfCaptionFont),0);
1546 lpnm->lfCaptionFont.lfWeight = FW_BOLD;
1547 SystemParametersInfo32W(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfSmCaptionFont),0);
1548 SystemParametersInfo32W(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfMenuFont),0);
1549 SystemParametersInfo32W(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfStatusFont),0);
1550 SystemParametersInfo32W(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfMessageFont),0);
1551 break;
1554 case SPI_GETHIGHCONTRAST:
1556 LPHIGHCONTRASTW lpHighContrastW = (LPHIGHCONTRASTW)lpvParam;
1558 FIXME(system,"SPI_GETHIGHCONTRAST not fully implemented\n");
1560 if ( lpHighContrastW->cbSize == sizeof( HIGHCONTRASTW ) )
1562 /* Indicate that there is no high contrast available */
1563 lpHighContrastW->dwFlags = 0;
1564 lpHighContrastW->lpszDefaultScheme = NULL;
1566 else
1568 return FALSE;
1571 break;
1574 default:
1575 return SystemParametersInfo32A(uAction,uParam,lpvParam,fuWinIni);
1578 return TRUE;
1582 /***********************************************************************
1583 * FileCDR (KERNEL.130)
1585 FARPROC16 WINAPI FileCDR(FARPROC16 x)
1587 FIXME(file,"(0x%8x): stub\n", (int) x);
1588 return (FARPROC16)TRUE;