Release 970329
[wine/multimedia.git] / misc / main.c
blob57832ad3ac4a7852b53e071fcc546924c3de148b
1 /*
2 * Main function.
4 * Copyright 1994 Alexandre Julliard
5 */
7 #include <stdio.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 <X11/Xlib.h>
17 #include <X11/Xresource.h>
18 #include <X11/Xutil.h>
19 #include <X11/Xlocale.h>
20 #include <X11/cursorfont.h>
21 #include "heap.h"
22 #include "message.h"
23 #include "module.h"
24 #include "msdos.h"
25 #include "windows.h"
26 #include "color.h"
27 #include "winsock.h"
28 #include "options.h"
29 #include "desktop.h"
30 #include "shell.h"
31 #include "winbase.h"
32 #define DEBUG_DEFINE_VARIABLES
33 #include "stddebug.h"
34 #include "debug.h"
35 #include "xmalloc.h"
37 const char people[] = "Wine is available thanks to the work of "
38 "Bob Amstadt, Dag Asheim, Martin Ayotte, Peter Bajusz, Ross Biro, "
39 "Uwe Bonnes, Erik Bos, Fons Botman, John Brezak, Andrew Bulhak, "
40 "John Burton, Niels de Carpentier, Jimen Ching, Huw D. M. Davies, "
41 "Roman Dolejsi, Frans van Dorsselaer, Paul Falstad, David Faure, "
42 "Olaf Flebbe, Peter Galbavy, Ramon Garcia, Matthew Ghio, "
43 "Hans de Graaff, Charles M. Hannum, John Harvey, Cameron Heide, "
44 "Jochen Hoenicke, Onno Hovers, Jeffrey Hsu, Miguel de Icaza, "
45 "Jukka Iivonen, Lee Jaekil, Alexandre Julliard, Bang Jun-Young, "
46 "Pavel Kankovsky, Jochen Karrer, Andreas Kirschbaum, Albrecht Kleine, "
47 "Jon Konrath, Alex Korobka, Greg Kreider, Anand Kumria, Scott A. Laird, "
48 "Andrew Lewycky, Martin von Loewis, Kenneth MacDonald, Peter MacDonald, "
49 "William Magro, Juergen Marquardt, Ricardo Massaro, Marcus Meissner, "
50 "Graham Menhennitt, David Metcalfe, Bruce Milner, Steffen Moeller, "
51 "Andreas Mohr, Philippe De Muyter, Itai Nahshon, Michael Patra, "
52 "Jim Peterson, Robert Pouliot, Keith Reynolds, Slaven Rezic, "
53 "John Richardson, Johannes Ruscheinski, Thomas Sandford, "
54 "Constantine Sapuntzakis, Pablo Saratxaga, Daniel Schepler, "
55 "Ulrich Schmid, Bernd Schmidt, Yngvi Sigurjonsson, Stephen Simmons, "
56 "Rick Sladkey, William Smith, Dominik Strasser, Vadim Strizhevsky, "
57 "Erik Svendsen, Tristan Tarrant, Andrew Taylor, Duncan C Thomson, "
58 "Goran Thyni, Jimmy Tirtawangsa, Jon Tombs, Linus Torvalds, "
59 "Gregory Trubetskoy, Petri Tuomola, Michael Veksler, Sven Verdoolaege, "
60 "Ronan Waide, Eric Warnke, Manfred Weichel, Morten Welinder, "
61 "Jan Willamowius, Carl Williams, Karl Guenter Wuensch, Eric Youngdale, "
62 "James Youngman, Mikolaj Zalewski, and John Zero.";
64 const WINE_LANGUAGE_DEF Languages[] =
66 {"En",0x0409}, /* LANG_En */
67 {"Es",0x040A}, /* LANG_Es */
68 {"De",0x0407}, /* LANG_De */
69 {"No",0x0414}, /* LANG_No */
70 {"Fr",0x0400}, /* LANG_Fr */
71 {"Fi",0x040B}, /* LANG_Fi */
72 {"Da",0x0406}, /* LANG_Da */
73 {"Cz",0x0405}, /* LANG_Cz */
74 {"Eo", 0}, /* LANG_Eo */ /* FIXME languageid */
75 {"It",0x0410}, /* LANG_It */
76 {"Ko",0x0412}, /* LANG_Ko */
77 {"Hu",0x0436}, /* LANG_Hu */
78 {"Pl",0x0415}, /* LANG_Pl */
79 {"Po",0x0416}, /* LANG_Po */
80 {NULL,0}
83 WORD WINE_LanguageId = 0;
85 #define WINE_CLASS "Wine" /* Class name for resources */
87 #define WINE_APP_DEFAULTS "/usr/lib/X11/app-defaults/Wine"
89 typedef struct tagENVENTRY {
90 LPSTR Name;
91 LPSTR Value;
92 WORD wSize;
93 struct tagENVENTRY *Prev;
94 struct tagENVENTRY *Next;
95 } ENVENTRY, *LPENVENTRY;
97 LPENVENTRY lpEnvList = NULL;
99 Display *display;
100 Screen *screen;
101 Window rootWindow;
102 int screenWidth = 0, screenHeight = 0; /* Desktop window dimensions */
103 int screenDepth = 0; /* Screen depth to use */
104 int desktopX = 0, desktopY = 0; /* Desktop window position (if any) */
105 int getVersion16 = 0;
106 int getVersion32 = 0;
107 OSVERSIONINFO32A getVersionEx;
109 struct options Options =
110 { /* default options */
111 NULL, /* desktopGeometry */
112 NULL, /* programName */
113 FALSE, /* usePrivateMap */
114 FALSE, /* useFixedMap */
115 FALSE, /* synchronous */
116 FALSE, /* backing store */
117 SW_SHOWNORMAL, /* cmdShow */
118 FALSE,
119 FALSE, /* failReadOnly */
120 MODE_ENHANCED, /* Enhanced mode */
121 FALSE, /* IPC enabled */
122 #ifdef DEFAULT_LANG
123 DEFAULT_LANG, /* Default language */
124 #else
125 LANG_En,
126 #endif
127 FALSE, /* Managed windows */
128 FALSE /* Perfect graphics */
132 static XrmOptionDescRec optionsTable[] =
134 { "-backingstore", ".backingstore", XrmoptionNoArg, (caddr_t)"on" },
135 { "-desktop", ".desktop", XrmoptionSepArg, (caddr_t)NULL },
136 { "-depth", ".depth", XrmoptionSepArg, (caddr_t)NULL },
137 { "-display", ".display", XrmoptionSepArg, (caddr_t)NULL },
138 { "-iconic", ".iconic", XrmoptionNoArg, (caddr_t)"on" },
139 { "-ipc", ".ipc", XrmoptionNoArg, (caddr_t)"off"},
140 { "-language", ".language", XrmoptionSepArg, (caddr_t)"En" },
141 { "-name", ".name", XrmoptionSepArg, (caddr_t)NULL },
142 { "-perfect", ".perfect", XrmoptionNoArg, (caddr_t)"on" },
143 { "-privatemap", ".privatemap", XrmoptionNoArg, (caddr_t)"on" },
144 { "-fixedmap", ".fixedmap", XrmoptionNoArg, (caddr_t)"on" },
145 { "-synchronous", ".synchronous", XrmoptionNoArg, (caddr_t)"on" },
146 { "-debug", ".debug", XrmoptionNoArg, (caddr_t)"on" },
147 { "-debugmsg", ".debugmsg", XrmoptionSepArg, (caddr_t)NULL },
148 { "-dll", ".dll", XrmoptionSepArg, (caddr_t)NULL },
149 { "-failreadonly", ".failreadonly", XrmoptionNoArg, (caddr_t)"on" },
150 { "-mode", ".mode", XrmoptionSepArg, (caddr_t)NULL },
151 { "-managed", ".managed", XrmoptionNoArg, (caddr_t)"off"},
152 { "-winver", ".winver", XrmoptionSepArg, (caddr_t)NULL }
155 #define NB_OPTIONS (sizeof(optionsTable) / sizeof(optionsTable[0]))
157 #define USAGE \
158 "Usage: %s [options] program_name [arguments]\n" \
159 "\n" \
160 "Options:\n" \
161 " -backingstore Turn on backing store\n" \
162 " -debug Enter debugger before starting application\n" \
163 " -debugmsg name Turn debugging-messages on or off\n" \
164 " -depth n Change the depth to use for multiple-depth screens\n" \
165 " -desktop geom Use a desktop window of the given geometry\n" \
166 " -display name Use the specified display\n" \
167 " -dll name Enable or disable built-in DLLs\n" \
168 " -failreadonly Read only files may not be opened in write mode\n" \
169 " -fixedmap Use a \"standard\" color map\n" \
170 " -iconic Start as an icon\n" \
171 " -ipc Enable IPC facilities\n" \
172 " -language xx Set the language (one of En,Es,De,No,Fr,Fi,Da,Cz,Eo,It,Ko,\n Hu,Pl,Po)\n" \
173 " -managed Allow the window manager to manage created windows\n" \
174 " -mode mode Start Wine in a particular mode (standard or enhanced)\n" \
175 " -name name Set the application name\n" \
176 " -perfect Favor correctness over speed for graphical operations\n" \
177 " -privatemap Use a private color map\n" \
178 " -synchronous Turn on synchronous display mode\n" \
179 " -winver Version to imitate (one of win31,win95,nt351)\n"
183 /***********************************************************************
184 * MAIN_Usage
186 #ifndef WINELIB32
187 void MAIN_Usage( char *name )
189 fprintf( stderr, USAGE, name );
190 exit(1);
192 #endif
195 /***********************************************************************
196 * MAIN_GetProgramName
198 * Get the program name. The name is specified by (in order of precedence):
199 * - the option '-name'.
200 * - the environment variable 'WINE_NAME'.
201 * - the last component of argv[0].
203 static char *MAIN_GetProgramName( int argc, char *argv[] )
205 int i;
206 char *p;
208 for (i = 1; i < argc-1; i++)
209 if (!strcmp( argv[i], "-name" )) return argv[i+1];
210 if ((p = getenv( "WINE_NAME" )) != NULL) return p;
211 if ((p = strrchr( argv[0], '/' )) != NULL) return p+1;
212 return argv[0];
216 /***********************************************************************
217 * MAIN_GetResource
219 * Fetch the value of resource 'name' using the correct instance name.
220 * 'name' must begin with '.' or '*'
222 static int MAIN_GetResource( XrmDatabase db, char *name, XrmValue *value )
224 char *buff_instance, *buff_class;
225 char *dummy;
226 int retval;
228 buff_instance = (char *)xmalloc(strlen(Options.programName)+strlen(name)+1);
229 buff_class = (char *)xmalloc( strlen(WINE_CLASS) + strlen(name) + 1 );
231 strcpy( buff_instance, Options.programName );
232 strcat( buff_instance, name );
233 strcpy( buff_class, WINE_CLASS );
234 strcat( buff_class, name );
235 retval = XrmGetResource( db, buff_instance, buff_class, &dummy, value );
236 free( buff_instance );
237 free( buff_class );
238 return retval;
242 /***********************************************************************
243 * ParseDebugOptions
245 * Turns specific debug messages on or off, according to "options".
246 * Returns TRUE if parsing was successful
248 #ifdef DEBUG_RUNTIME
250 BOOL32 ParseDebugOptions(char *options)
252 int l;
253 if (strlen(options)<3)
254 return FALSE;
257 if ((*options!='+')&&(*options!='-'))
258 return FALSE;
259 if (strchr(options,','))
260 l=strchr(options,',')-options;
261 else
262 l=strlen(options);
263 if (!lstrncmpi32A(options+1,"all",l-1))
265 int i;
266 for (i=0;i<sizeof(debug_msg_enabled)/sizeof(short);i++)
267 debug_msg_enabled[i]=(*options=='+');
269 else
271 int i;
272 for (i=0;i<sizeof(debug_msg_enabled)/sizeof(short);i++)
273 if (debug_msg_name && (!lstrncmpi32A(options+1,debug_msg_name[i],l-1)))
275 debug_msg_enabled[i]=(*options=='+');
276 break;
278 if (i==sizeof(debug_msg_enabled)/sizeof(short))
279 return FALSE;
281 options+=l;
283 while((*options==',')&&(*(++options)));
284 if (*options)
285 return FALSE;
286 else
287 return TRUE;
290 #endif
293 /***********************************************************************
294 * MAIN_ParseLanguageOption
296 * Parse -language option.
298 static void MAIN_ParseLanguageOption( char *arg )
300 const WINE_LANGUAGE_DEF *p = Languages;
302 Options.language = LANG_En; /* First language */
303 for (;p->name;p++)
305 if (!lstrcmpi32A( p->name, arg ))
307 WINE_LanguageId = p->langid;
308 return;
310 Options.language++;
312 fprintf( stderr, "Invalid language specified '%s'. Supported languages are: ", arg );
313 for (p = Languages; p->name; p++) fprintf( stderr, "%s ", p->name );
314 fprintf( stderr, "\n" );
315 exit(1);
319 /***********************************************************************
320 * MAIN_ParseModeOption
322 * Parse -mode option.
324 static void MAIN_ParseModeOption( char *arg )
326 if (!lstrcmpi32A("enhanced", arg)) Options.mode = MODE_ENHANCED;
327 else if (!lstrcmpi32A("standard", arg)) Options.mode = MODE_STANDARD;
328 else
330 fprintf(stderr, "Invalid mode '%s' specified.\n", arg);
331 fprintf(stderr, "Valid modes are: 'standard', 'enhanced' (default).\n");
332 exit(1);
336 /**********************************************************************
337 * MAIN_ParseVersion
339 static void MAIN_ParseVersion( char *arg )
341 /* If you add any other options,
342 verify the values you return on the real thing */
343 if(strcmp(arg,"win31")==0)
345 getVersion16 = 0x06160A03;
346 /* FIXME: My Win32s installation failed to execute the
347 MSVC 4 test program. So check these values */
348 getVersion32 = 0x80000A03;
349 getVersionEx.dwMajorVersion=3;
350 getVersionEx.dwMinorVersion=10;
351 getVersionEx.dwBuildNumber=0;
352 getVersionEx.dwPlatformId=VER_PLATFORM_WIN32s;
353 strcpy(getVersionEx.szCSDVersion,"Win32s 1.3");
355 else if(strcmp(arg, "win95")==0)
357 getVersion16 = 0x07005F03;
358 getVersion32 = 0xC0000004;
359 getVersionEx.dwMajorVersion=4;
360 getVersionEx.dwMinorVersion=0;
361 getVersionEx.dwBuildNumber=0x40003B6;
362 getVersionEx.dwPlatformId=VER_PLATFORM_WIN32_WINDOWS;
363 strcpy(getVersionEx.szCSDVersion,"");
365 else if(strcmp(arg, "nt351")==0)
367 getVersion16 = 0x05000A03;
368 getVersion32 = 0x04213303;
369 getVersionEx.dwMajorVersion=3;
370 getVersionEx.dwMinorVersion=51;
371 getVersionEx.dwBuildNumber=0x421;
372 getVersionEx.dwPlatformId=VER_PLATFORM_WIN32_NT;
373 strcpy(getVersionEx.szCSDVersion,"Service Pack 2");
375 else fprintf(stderr, "Unknown winver system code - ignored\n");
378 /***********************************************************************
379 * MAIN_ParseOptions
381 * Parse command line options and open display.
383 static void MAIN_ParseOptions( int *argc, char *argv[] )
385 char *display_name = NULL;
386 XrmValue value;
387 XrmDatabase db = XrmGetFileDatabase(WINE_APP_DEFAULTS);
388 int i;
389 char *xrm_string;
391 Options.programName = MAIN_GetProgramName( *argc, argv );
393 /* Get display name from command line */
394 for (i = 1; i < *argc - 1; i++)
395 if (!strcmp( argv[i], "-display" ))
397 display_name = argv[i+1];
398 break;
401 #ifdef WINELIB
402 /* Need to assemble command line and pass it to WinMain */
403 #else
404 if (*argc < 2 || lstrcmpi32A(argv[1], "-h") == 0)
405 MAIN_Usage( argv[0] );
406 #endif
408 /* Open display */
410 if (display_name == NULL &&
411 MAIN_GetResource( db, ".display", &value )) display_name = value.addr;
413 if (!(display = XOpenDisplay( display_name )))
415 fprintf( stderr, "%s: Can't open display: %s\n",
416 argv[0], display_name ? display_name : "(none specified)" );
417 exit(1);
420 /* Merge file and screen databases */
421 if ((xrm_string = XResourceManagerString( display )) != NULL)
423 XrmDatabase display_db = XrmGetStringDatabase( xrm_string );
424 XrmMergeDatabases( display_db, &db );
427 /* Parse command line */
428 XrmParseCommand( &db, optionsTable, NB_OPTIONS,
429 Options.programName, argc, argv );
431 /* Get all options */
432 if (MAIN_GetResource( db, ".iconic", &value ))
433 Options.cmdShow = SW_SHOWMINIMIZED;
434 if (MAIN_GetResource( db, ".privatemap", &value ))
435 Options.usePrivateMap = TRUE;
436 if (MAIN_GetResource( db, ".fixedmap", &value ))
437 Options.useFixedMap = TRUE;
438 if (MAIN_GetResource( db, ".synchronous", &value ))
439 Options.synchronous = TRUE;
440 if (MAIN_GetResource( db, ".backingstore", &value ))
441 Options.backingstore = TRUE;
442 if (MAIN_GetResource( db, ".debug", &value ))
443 Options.debug = TRUE;
444 if (MAIN_GetResource( db, ".failreadonly", &value ))
445 Options.failReadOnly = TRUE;
446 if (MAIN_GetResource( db, ".ipc", &value ))
447 Options.ipc = TRUE;
448 if (MAIN_GetResource( db, ".perfect", &value ))
449 Options.perfectGraphics = TRUE;
450 if (MAIN_GetResource( db, ".depth", &value))
451 screenDepth = atoi( value.addr );
452 if (MAIN_GetResource( db, ".desktop", &value))
453 Options.desktopGeometry = value.addr;
454 if (MAIN_GetResource( db, ".language", &value))
455 MAIN_ParseLanguageOption( (char *)value.addr );
456 if (MAIN_GetResource( db, ".managed", &value))
457 Options.managed = TRUE;
458 if (MAIN_GetResource( db, ".mode", &value))
459 MAIN_ParseModeOption( (char *)value.addr );
461 #ifdef DEBUG_RUNTIME
462 if (MAIN_GetResource( db, ".debugoptions", &value))
463 ParseDebugOptions((char*)value.addr);
464 #endif
465 if (MAIN_GetResource( db, ".debugmsg", &value))
467 #ifndef DEBUG_RUNTIME
468 fprintf(stderr,"%s: Option \"-debugmsg\" not implemented.\n" \
469 " Recompile with DEBUG_RUNTIME in include/stddebug.h defined.\n",
470 argv[0]);
471 exit(1);
472 #else
473 if (ParseDebugOptions((char*)value.addr)==FALSE)
475 int i;
476 fprintf(stderr,"%s: Syntax: -debugmsg +xxx,... or -debugmsg -xxx,...\n",argv[0]);
477 fprintf(stderr,"Example: -debugmsg +all,-heap turn on all messages except heap messages\n");
478 fprintf(stderr,"Available message types:\n");
479 fprintf(stderr,"%-9s ","all");
480 for(i=0;i<sizeof(debug_msg_enabled)/sizeof(short);i++)
481 if(debug_msg_name[i])
482 fprintf(stderr,"%-9s%c",debug_msg_name[i],
483 (((i+2)%8==0)?'\n':' '));
484 fprintf(stderr,"\n\n");
485 exit(1);
487 #endif
490 if(MAIN_GetResource( db, ".dll", &value))
492 #ifndef WINELIB
493 if (!BUILTIN_ParseDLLOptions( (char*)value.addr ))
495 fprintf(stderr,"%s: Syntax: -dll +xxx,... or -dll -xxx,...\n",argv[0]);
496 fprintf(stderr,"Example: -dll -ole2 Do not use emulated OLE2.DLL\n");
497 fprintf(stderr,"Available DLLs:\n");
498 BUILTIN_PrintDLLs();
499 exit(1);
501 #else
502 fprintf(stderr,"-dll not supported in libwine\n");
503 #endif
506 if(MAIN_GetResource( db, ".winver", &value))
507 MAIN_ParseVersion( (char*)value.addr );
511 /***********************************************************************
512 * MAIN_CreateDesktop
514 static void MAIN_CreateDesktop( int argc, char *argv[] )
516 int flags;
517 unsigned int width = 640, height = 480; /* Default size = 640x480 */
518 char *name = "Wine desktop";
519 XSizeHints *size_hints;
520 XWMHints *wm_hints;
521 XClassHint *class_hints;
522 XSetWindowAttributes win_attr;
523 XTextProperty window_name;
524 Atom XA_WM_DELETE_WINDOW;
526 flags = XParseGeometry( Options.desktopGeometry,
527 &desktopX, &desktopY, &width, &height );
528 screenWidth = width;
529 screenHeight = height;
531 /* Create window */
533 win_attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
534 PointerMotionMask | ButtonPressMask |
535 ButtonReleaseMask | EnterWindowMask |
536 StructureNotifyMask;
537 win_attr.cursor = XCreateFontCursor( display, XC_top_left_arrow );
539 rootWindow = XCreateWindow( display, DefaultRootWindow(display),
540 desktopX, desktopY, width, height, 0,
541 CopyFromParent, InputOutput, CopyFromParent,
542 CWEventMask | CWCursor, &win_attr );
544 /* Set window manager properties */
546 size_hints = XAllocSizeHints();
547 wm_hints = XAllocWMHints();
548 class_hints = XAllocClassHint();
549 if (!size_hints || !wm_hints || !class_hints)
551 fprintf( stderr, "Not enough memory for window manager hints.\n" );
552 exit(1);
554 size_hints->min_width = size_hints->max_width = width;
555 size_hints->min_height = size_hints->max_height = height;
556 size_hints->flags = PMinSize | PMaxSize;
557 if (flags & (XValue | YValue)) size_hints->flags |= USPosition;
558 if (flags & (WidthValue | HeightValue)) size_hints->flags |= USSize;
559 else size_hints->flags |= PSize;
561 wm_hints->flags = InputHint | StateHint;
562 wm_hints->input = True;
563 wm_hints->initial_state = NormalState;
564 class_hints->res_name = argv[0];
565 class_hints->res_class = "Wine";
567 XStringListToTextProperty( &name, 1, &window_name );
568 XSetWMProperties( display, rootWindow, &window_name, &window_name,
569 argv, argc, size_hints, wm_hints, class_hints );
570 XA_WM_DELETE_WINDOW = XInternAtom( display, "WM_DELETE_WINDOW", False );
571 XSetWMProtocols( display, rootWindow, &XA_WM_DELETE_WINDOW, 1 );
572 XFree( size_hints );
573 XFree( wm_hints );
574 XFree( class_hints );
576 /* Map window */
578 XMapWindow( display, rootWindow );
582 XKeyboardState keyboard_state;
584 /***********************************************************************
585 * MAIN_SaveSetup
587 static void MAIN_SaveSetup(void)
589 XGetKeyboardControl(display, &keyboard_state);
592 /***********************************************************************
593 * MAIN_RestoreSetup
595 static void MAIN_RestoreSetup(void)
597 XKeyboardControl keyboard_value;
599 keyboard_value.key_click_percent = keyboard_state.key_click_percent;
600 keyboard_value.bell_percent = keyboard_state.bell_percent;
601 keyboard_value.bell_pitch = keyboard_state.bell_pitch;
602 keyboard_value.bell_duration = keyboard_state.bell_duration;
603 keyboard_value.auto_repeat_mode = keyboard_state.global_auto_repeat;
605 XChangeKeyboardControl(display, KBKeyClickPercent | KBBellPercent |
606 KBBellPitch | KBBellDuration | KBAutoRepeatMode, &keyboard_value);
610 static void called_at_exit(void)
612 MAIN_RestoreSetup();
613 COLOR_Cleanup();
614 WINSOCK_Shutdown();
617 /***********************************************************************
618 * MAIN_WineInit
620 * Wine initialisation and command-line parsing
622 BOOL32 MAIN_WineInit( int *argc, char *argv[] )
624 int depth_count, i;
625 int *depth_list;
626 struct timeval tv;
628 extern int _WinMain(int argc, char **argv);
630 #ifdef MALLOC_DEBUGGING
631 char *trace;
633 mcheck(NULL);
634 if (!(trace = getenv("MALLOC_TRACE")))
636 fprintf( stderr, "MALLOC_TRACE not set. No trace generated\n" );
638 else
640 fprintf( stderr, "malloc trace goes to %s\n", trace );
641 mtrace();
643 #endif
645 setbuf(stdout,NULL);
646 setbuf(stderr,NULL);
648 setlocale(LC_CTYPE,"");
649 gettimeofday( &tv, NULL);
650 MSG_WineStartTicks = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
652 XrmInitialize();
654 putenv("XKB_DISABLE="); /* Disable XKB extension if present. */
656 MAIN_ParseOptions( argc, argv );
658 if (Options.desktopGeometry && Options.managed)
660 fprintf( stderr, "%s: -managed and -desktop options cannot be used together\n",
661 Options.programName );
662 exit(1);
665 screen = DefaultScreenOfDisplay( display );
666 screenWidth = WidthOfScreen( screen );
667 screenHeight = HeightOfScreen( screen );
668 if (screenDepth) /* -depth option specified */
670 depth_list = XListDepths(display,DefaultScreen(display),&depth_count);
671 for (i = 0; i < depth_count; i++)
672 if (depth_list[i] == screenDepth) break;
673 XFree( depth_list );
674 if (i >= depth_count)
676 fprintf( stderr, "%s: Depth %d not supported on this screen.\n",
677 Options.programName, screenDepth );
678 exit(1);
681 else screenDepth = DefaultDepthOfScreen( screen );
682 if (Options.synchronous) XSynchronize( display, True );
683 if (Options.desktopGeometry) MAIN_CreateDesktop( *argc, argv );
684 else rootWindow = DefaultRootWindow( display );
686 MAIN_SaveSetup();
687 atexit(called_at_exit);
688 return TRUE;
692 /***********************************************************************
693 * MessageBeep16 (USER.104)
695 void MessageBeep16( UINT16 i )
697 MessageBeep32( i );
701 /***********************************************************************
702 * MessageBeep32 (USER32.389)
704 BOOL32 MessageBeep32( UINT32 i )
706 XBell( display, 100 );
707 return TRUE;
711 /***********************************************************************
712 * Beep (KERNEL32.11)
714 BOOL32 Beep( DWORD dwFreq, DWORD dwDur )
716 /* dwFreq and dwDur are ignored by Win95 */
717 XBell(display, 100);
718 return TRUE;
722 /***********************************************************************
723 * GetVersion16 (KERNEL.3)
725 LONG GetVersion16(void)
727 if (getVersion16) return getVersion16;
728 return MAKELONG( WINVERSION, WINDOSVER );
732 /***********************************************************************
733 * GetVersion32
735 LONG GetVersion32(void)
737 if (getVersion32) return getVersion32;
738 return MAKELONG( 4, DOSVERSION);
742 /***********************************************************************
743 * GetVersionExA
745 BOOL32 GetVersionEx32A(OSVERSIONINFO32A *v)
747 if(v->dwOSVersionInfoSize!=sizeof(OSVERSIONINFO32A))
749 fprintf(stddeb,"wrong OSVERSIONINFO size from app");
750 return FALSE;
752 if(!getVersion32)
754 /* Return something like NT 3.5 */
755 v->dwMajorVersion = 3;
756 v->dwMinorVersion = 5;
757 v->dwBuildNumber = 42;
758 v->dwPlatformId = VER_PLATFORM_WIN32_NT;
759 strcpy(v->szCSDVersion, "Wine is not an emulator");
760 return TRUE;
762 v->dwMajorVersion = getVersionEx.dwMajorVersion;
763 v->dwMinorVersion = getVersionEx.dwMinorVersion;
764 v->dwBuildNumber = getVersionEx.dwBuildNumber;
765 v->dwPlatformId = getVersionEx.dwPlatformId;
766 strcpy(v->szCSDVersion, getVersionEx.szCSDVersion);
767 return TRUE;
771 /***********************************************************************
772 * GetVersionExW
774 BOOL32 GetVersionEx32W(OSVERSIONINFO32W *v)
776 OSVERSIONINFO32A v1;
777 if(v->dwOSVersionInfoSize!=sizeof(OSVERSIONINFO32W))
779 fprintf(stddeb,"wrong OSVERSIONINFO size from app");
780 return FALSE;
782 v1.dwOSVersionInfoSize=sizeof(v1);
783 GetVersionEx32A(&v1);
784 v->dwMajorVersion = v1.dwMajorVersion;
785 v->dwMinorVersion = v1.dwMinorVersion;
786 v->dwBuildNumber = v1.dwBuildNumber;
787 v->dwPlatformId = v1.dwPlatformId;
788 lstrcpyAtoW( v->szCSDVersion, v1.szCSDVersion );
789 return TRUE;
792 /***********************************************************************
793 * GetWinFlags (KERNEL.132)
795 DWORD GetWinFlags(void)
797 static const long cpuflags[5] =
798 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
799 SYSTEM_INFO si;
800 long result = 0,cpuflag;
802 GetSystemInfo(&si);
804 /* There doesn't seem to be any Pentium flag. */
805 cpuflag = cpuflags[MIN (si.wProcessorLevel, 4)];
807 switch(Options.mode) {
808 case MODE_STANDARD:
809 result = (WF_STANDARD | cpuflag | WF_PMODE | WF_80x87);
810 break;
812 case MODE_ENHANCED:
813 result = (WF_ENHANCED | cpuflag | WF_PMODE | WF_80x87 | WF_PAGING);
814 break;
816 default:
817 fprintf(stderr, "Unknown mode set? This shouldn't happen. Check GetWinFlags()!\n");
818 break;
820 if( getVersionEx.dwPlatformId == VER_PLATFORM_WIN32_NT )
821 result |= WF_WIN32WOW; /* undocumented WF_WINNT */
822 return result;
825 /***********************************************************************
826 * SetEnvironment (GDI.132)
828 INT16 SetEnvironment( LPCSTR lpPortName, LPCSTR lpEnviron, UINT16 nCount )
830 LPENVENTRY lpNewEnv;
831 LPENVENTRY lpEnv = lpEnvList;
832 dprintf_env(stddeb, "SetEnvironment('%s', '%s', %d) !\n",
833 lpPortName, lpEnviron, nCount);
834 if (lpPortName == NULL) return -1;
835 while (lpEnv != NULL) {
836 if (lpEnv->Name != NULL && strcmp(lpEnv->Name, lpPortName) == 0) {
837 if (nCount == 0 || lpEnviron == NULL) {
838 if (lpEnv->Prev != NULL) lpEnv->Prev->Next = lpEnv->Next;
839 if (lpEnv->Next != NULL) lpEnv->Next->Prev = lpEnv->Prev;
840 free(lpEnv->Value);
841 free(lpEnv->Name);
842 free(lpEnv);
843 dprintf_env(stddeb, "SetEnvironment() // entry deleted !\n");
844 return -1;
846 free(lpEnv->Value);
847 lpEnv->Value = malloc(nCount);
848 if (lpEnv->Value == NULL) {
849 dprintf_env(stddeb, "SetEnvironment() // Error allocating entry value !\n");
850 return 0;
852 memcpy(lpEnv->Value, lpEnviron, nCount);
853 lpEnv->wSize = nCount;
854 dprintf_env(stddeb, "SetEnvironment() // entry modified !\n");
855 return nCount;
857 if (lpEnv->Next == NULL) break;
858 lpEnv = lpEnv->Next;
860 if (nCount == 0 || lpEnviron == NULL) return -1;
861 dprintf_env(stddeb, "SetEnvironment() // new entry !\n");
862 lpNewEnv = malloc(sizeof(ENVENTRY));
863 if (lpNewEnv == NULL) {
864 dprintf_env(stddeb, "SetEnvironment() // Error allocating new entry !\n");
865 return 0;
867 if (lpEnvList == NULL) {
868 lpEnvList = lpNewEnv;
869 lpNewEnv->Prev = NULL;
871 else
873 lpEnv->Next = lpNewEnv;
874 lpNewEnv->Prev = lpEnv;
876 lpNewEnv->Next = NULL;
877 lpNewEnv->Name = malloc(strlen(lpPortName) + 1);
878 if (lpNewEnv->Name == NULL) {
879 dprintf_env(stddeb, "SetEnvironment() // Error allocating entry name !\n");
880 return 0;
882 strcpy(lpNewEnv->Name, lpPortName);
883 lpNewEnv->Value = malloc(nCount);
884 if (lpNewEnv->Value == NULL) {
885 dprintf_env(stddeb, "SetEnvironment() // Error allocating entry value !\n");
886 return 0;
888 memcpy(lpNewEnv->Value, lpEnviron, nCount);
889 lpNewEnv->wSize = nCount;
890 return nCount;
894 /***********************************************************************
895 * GetEnvironment (GDI.134)
897 INT16 GetEnvironment( LPCSTR lpPortName, LPSTR lpEnviron, UINT16 nMaxSiz )
899 WORD nCount;
900 LPENVENTRY lpEnv = lpEnvList;
902 dprintf_env(stddeb, "GetEnvironment('%s', '%s', %d) !\n",
903 lpPortName, lpEnviron, nMaxSiz);
904 while (lpEnv != NULL) {
905 if (lpEnv->Name != NULL && strcmp(lpEnv->Name, lpPortName) == 0) {
906 if( lpEnviron == NULL ) return lpEnv->wSize;
907 nCount = MIN(nMaxSiz, lpEnv->wSize);
908 memcpy(lpEnviron, lpEnv->Value, nCount);
909 dprintf_env(stddeb, "GetEnvironment() // found '%s' !\n", lpEnv->Value);
910 return nCount;
912 lpEnv = lpEnv->Next;
914 dprintf_env(stddeb, "GetEnvironment() // not found !\n");
915 return 0;
919 /***********************************************************************
920 * GetTimerResolution (USER.14)
922 LONG GetTimerResolution(void)
924 return (1000);
927 /***********************************************************************
928 * SystemParametersInfo32A (USER32.539)
930 BOOL32 SystemParametersInfo32A( UINT32 uAction, UINT32 uParam,
931 LPVOID lpvParam, UINT32 fuWinIni )
933 return SystemParametersInfo16(uAction,uParam,lpvParam,fuWinIni);
937 /***********************************************************************
938 * SystemParametersInfo16 (USER.483)
940 BOOL16 SystemParametersInfo16( UINT16 uAction, UINT16 uParam,
941 LPVOID lpvParam, UINT16 fuWinIni )
943 int timeout, temp;
944 char buffer[256];
945 XKeyboardState keyboard_state;
946 XKeyboardControl keyboard_value;
949 switch (uAction)
951 case SPI_GETBEEP:
952 XGetKeyboardControl(display, &keyboard_state);
953 if (keyboard_state.bell_percent == 0)
954 *(BOOL16 *) lpvParam = FALSE;
955 else
956 *(BOOL16 *) lpvParam = TRUE;
957 break;
959 case SPI_GETBORDER:
960 *(INT16 *)lpvParam = GetSystemMetrics16( SM_CXFRAME );
961 break;
963 case SPI_GETFASTTASKSWITCH:
964 if ( GetProfileInt32A( "windows", "CoolSwitch", 1 ) == 1 )
965 *(BOOL16 *) lpvParam = TRUE;
966 else
967 *(BOOL16 *) lpvParam = FALSE;
968 break;
970 case SPI_GETGRIDGRANULARITY:
971 *(INT16 *) lpvParam = GetProfileInt32A( "desktop",
972 "GridGranularity",
973 1 );
974 break;
976 case SPI_GETICONTITLEWRAP:
977 *(BOOL16 *) lpvParam = GetProfileInt32A( "desktop",
978 "IconTitleWrap",
979 TRUE );
980 break;
982 case SPI_GETKEYBOARDDELAY:
983 *(INT16 *) lpvParam = GetProfileInt32A( "keyboard",
984 "KeyboardDelay", 1 );
985 break;
987 case SPI_GETKEYBOARDSPEED:
988 *(WORD *) lpvParam = GetProfileInt32A( "keyboard",
989 "KeyboardSpeed",
990 30 );
991 break;
993 case SPI_GETMENUDROPALIGNMENT:
994 *(BOOL16 *) lpvParam = GetSystemMetrics16( SM_MENUDROPALIGNMENT ); /* XXX check this */
995 break;
997 case SPI_GETSCREENSAVEACTIVE:
998 if ( GetProfileInt32A( "windows", "ScreenSaveActive", 1 ) == 1 )
999 *(BOOL16 *) lpvParam = TRUE;
1000 else
1001 *(BOOL16 *) lpvParam = FALSE;
1002 break;
1004 case SPI_GETSCREENSAVETIMEOUT:
1005 /* FIXME GetProfileInt( "windows", "ScreenSaveTimeout", 300 ); */
1006 XGetScreenSaver(display, &timeout, &temp,&temp,&temp);
1007 *(INT16 *) lpvParam = timeout * 1000;
1008 break;
1010 case SPI_ICONHORIZONTALSPACING:
1011 /* FIXME Get/SetProfileInt */
1012 if (lpvParam == NULL)
1013 /*SetSystemMetrics( SM_CXICONSPACING, uParam )*/ ;
1014 else
1015 *(INT16 *)lpvParam = GetSystemMetrics16( SM_CXICONSPACING );
1016 break;
1018 case SPI_ICONVERTICALSPACING:
1019 /* FIXME Get/SetProfileInt */
1020 if (lpvParam == NULL)
1021 /*SetSystemMetrics( SM_CYICONSPACING, uParam )*/ ;
1022 else
1023 *(INT16 *)lpvParam = GetSystemMetrics16(SM_CYICONSPACING);
1024 break;
1026 case SPI_SETBEEP:
1027 if (uParam == TRUE)
1028 keyboard_value.bell_percent = -1;
1029 else
1030 keyboard_value.bell_percent = 0;
1031 XChangeKeyboardControl(display, KBBellPercent,
1032 &keyboard_value);
1033 break;
1035 case SPI_SETSCREENSAVEACTIVE:
1036 if (uParam == TRUE)
1037 XActivateScreenSaver(display);
1038 else
1039 XResetScreenSaver(display);
1040 break;
1042 case SPI_SETSCREENSAVETIMEOUT:
1043 XSetScreenSaver(display, uParam, 60, DefaultBlanking,
1044 DefaultExposures);
1045 break;
1047 case SPI_SETDESKWALLPAPER:
1048 return (SetDeskWallPaper32((LPSTR) lpvParam));
1049 break;
1051 case SPI_SETDESKPATTERN:
1052 if ((INT16)uParam == -1) {
1053 GetProfileString32A("Desktop", "Pattern",
1054 "170 85 170 85 170 85 170 85",
1055 buffer, sizeof(buffer) );
1056 return (DESKTOP_SetPattern((LPSTR) buffer));
1057 } else
1058 return (DESKTOP_SetPattern((LPSTR) lpvParam));
1059 break;
1061 case SPI_GETICONTITLELOGFONT:
1063 /* FIXME GetProfileString32A( "?", "?", "?" ) */
1064 LPLOGFONT16 lpLogFont = (LPLOGFONT16)lpvParam;
1065 lpLogFont->lfHeight = 10;
1066 lpLogFont->lfWidth = 0;
1067 lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
1068 lpLogFont->lfWeight = FW_NORMAL;
1069 lpLogFont->lfItalic = FALSE;
1070 lpLogFont->lfStrikeOut = FALSE;
1071 lpLogFont->lfUnderline = FALSE;
1072 lpLogFont->lfCharSet = ANSI_CHARSET;
1073 lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
1074 lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
1075 lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
1076 break;
1079 case SPI_LANGDRIVER:
1080 case SPI_SETBORDER:
1081 case SPI_SETDOUBLECLKHEIGHT:
1082 case SPI_SETDOUBLECLICKTIME:
1083 case SPI_SETDOUBLECLKWIDTH:
1084 case SPI_SETFASTTASKSWITCH:
1085 case SPI_SETKEYBOARDDELAY:
1086 case SPI_SETKEYBOARDSPEED:
1087 fprintf(stderr, "SystemParametersInfo: option %d ignored.\n", uAction);
1088 break;
1090 case SPI_GETWORKAREA:
1091 SetRect16( (RECT16 *)lpvParam, 0, 0,
1092 GetSystemMetrics16( SM_CXSCREEN ),
1093 GetSystemMetrics16( SM_CYSCREEN ) );
1094 break;
1096 default:
1097 fprintf(stderr, "SystemParametersInfo: unknown option %d.\n", uAction);
1098 break;
1100 return 1;
1103 /***********************************************************************
1104 * SystemParametersInfo32W (USER32.540)
1106 BOOL32 SystemParametersInfo32W( UINT32 uAction, UINT32 uParam,
1107 LPVOID lpvParam, UINT32 fuWinIni )
1109 char buffer[256];
1111 switch (uAction)
1113 case SPI_SETDESKWALLPAPER:
1114 if (lpvParam)
1116 lstrcpynWtoA(buffer,(LPWSTR)lpvParam,sizeof(buffer));
1117 return SetDeskWallPaper32(buffer);
1119 return SetDeskWallPaper32(NULL);
1121 case SPI_SETDESKPATTERN:
1122 if ((INT32) uParam == -1)
1124 GetProfileString32A("Desktop", "Pattern",
1125 "170 85 170 85 170 85 170 85",
1126 buffer, sizeof(buffer) );
1127 return (DESKTOP_SetPattern((LPSTR) buffer));
1129 if (lpvParam)
1131 lstrcpynWtoA(buffer,(LPWSTR)lpvParam,sizeof(buffer));
1132 return DESKTOP_SetPattern(buffer);
1134 return DESKTOP_SetPattern(NULL);
1136 case SPI_GETICONTITLELOGFONT:
1138 /* FIXME GetProfileString32A( "?", "?", "?" ) */
1139 LPLOGFONT32W lpLogFont = (LPLOGFONT32W)lpvParam;
1140 lpLogFont->lfHeight = 10;
1141 lpLogFont->lfWidth = 0;
1142 lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
1143 lpLogFont->lfWeight = FW_NORMAL;
1144 lpLogFont->lfItalic = lpLogFont->lfStrikeOut = lpLogFont->lfUnderline = FALSE;
1145 lpLogFont->lfCharSet = ANSI_CHARSET;
1146 lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
1147 lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
1148 lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
1150 break;
1152 default:
1153 return SystemParametersInfo32A(uAction,uParam,lpvParam,fuWinIni);
1156 return TRUE;
1160 /***********************************************************************
1161 * FileCDR (KERNEL.130)
1163 void FileCDR(FARPROC16 x)
1165 printf("FileCDR(%8x)\n", (int) x);
1168 /***********************************************************************
1169 * GetWinDebugInfo (KERNEL.355)
1171 BOOL16 GetWinDebugInfo(WINDEBUGINFO *lpwdi, UINT16 flags)
1173 printf("GetWinDebugInfo(%8lx,%d) stub returning 0\n", (unsigned long)lpwdi, flags);
1174 /* 0 means not in debugging mode/version */
1175 /* Can this type of debugging be used in wine ? */
1176 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
1177 return 0;
1180 /***********************************************************************
1181 * GetWinDebugInfo (KERNEL.355)
1183 BOOL16 SetWinDebugInfo(WINDEBUGINFO *lpwdi)
1185 printf("SetWinDebugInfo(%8lx) stub returning 0\n", (unsigned long)lpwdi);
1186 /* 0 means not in debugging mode/version */
1187 /* Can this type of debugging be used in wine ? */
1188 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
1189 return 0;