Release 960818
[wine/multimedia.git] / misc / main.c
blobe2bc1f5f10fc845fdb5fdcb32e248b4e72362446
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/cursorfont.h>
20 #include "message.h"
21 #include "module.h"
22 #include "msdos.h"
23 #include "windows.h"
24 #include "winsock.h"
25 #include "options.h"
26 #include "desktop.h"
27 #include "registers.h"
28 #include "shell.h"
29 #include "winbase.h"
30 #include "string32.h"
31 #define DEBUG_DEFINE_VARIABLES
32 #include "stddebug.h"
33 #include "debug.h"
34 #include "xmalloc.h"
36 const char people[] = "Wine is available thanks to the work of "
37 "Bob Amstadt, Dag Asheim, Martin Ayotte, Ross Biro, Uwe Bonnes, Erik Bos, "
38 "Fons Botman, John Brezak, Andrew Bulhak, John Burton, "
39 "Niels de Carpentier, Roman Dolejsi, Frans van Dorsselaer, Paul Falstad, "
40 "Olaf Flebbe, Peter Galbavy, Ramon Garcia, Hans de Graaff, "
41 "Charles M. Hannum, John Harvey, Cameron Heide, Jochen Hoenicke, "
42 "Onno Hovers, Jeffrey Hsu, Miguel de Icaza, Jukka Iivonen, "
43 "Alexandre Julliard, Jochen Karrer, Andreas Kirschbaum, Albrecht Kleine, "
44 "Jon Konrath, Alex Korobka, Greg Kreider, Anand Kumria, Scott A. Laird, "
45 "Martin von Loewis, Kenneth MacDonald, Peter MacDonald, William Magro, "
46 "Juergen Marquardt, Marcus Meissner, Graham Menhennitt, David Metcalfe, "
47 "Steffen Moeller, Philippe De Muyter, Itai Nahshon, Michael Patra, "
48 "Jim Peterson, Robert Pouliot, Keith Reynolds, John Richardson, "
49 "Johannes Ruscheinski, Thomas Sandford, Constantine Sapuntzakis, "
50 "Daniel Schepler, Ulrich Schmid, Bernd Schmidt, Yngvi Sigurjonsson, "
51 "Rick Sladkey, William Smith, Erik Svendsen, Tristan Tarrant, "
52 "Andrew Taylor, Duncan C Thomson, Goran Thyni, Jimmy Tirtawangsa, "
53 "Jon Tombs, Linus Torvalds, Gregory Trubetskoy, Michael Veksler, "
54 "Sven Verdoolaege, Eric Warnke, Manfred Weichel, Morten Welinder, "
55 "Jan Willamowius, Carl Williams, Karl Guenter Wuensch, Eric Youngdale, "
56 "and James Youngman. ";
58 const WINE_LANGUAGE_DEF Languages[] =
60 {"En",0x0409}, /* LANG_En */
61 {"Es",0x040A}, /* LANG_Es */
62 {"De",0x0407}, /* LANG_De */
63 {"No",0x0414}, /* LANG_No */
64 {"Fr",0x0400}, /* LANG_Fr */
65 {"Fi",0x040B}, /* LANG_Fi */
66 {"Da",0x0406}, /* LANG_Da */
67 {"Cz",0x0405}, /* LANG_Cz */
68 {"Eo", 0}, /* LANG_Eo */ /* FIXME languageid */
69 {"It",0x0410}, /* LANG_It */
70 {"Ko",0x0412}, /* LANG_Ko */
71 {NULL,0}
74 WORD WINE_LanguageId = 0;
76 #define WINE_CLASS "Wine" /* Class name for resources */
78 typedef struct tagENVENTRY {
79 LPSTR Name;
80 LPSTR Value;
81 WORD wSize;
82 struct tagENVENTRY *Prev;
83 struct tagENVENTRY *Next;
84 } ENVENTRY, *LPENVENTRY;
86 LPENVENTRY lpEnvList = NULL;
88 Display *display;
89 Screen *screen;
90 Window rootWindow;
91 int screenWidth = 0, screenHeight = 0; /* Desktop window dimensions */
92 int screenDepth = 0; /* Screen depth to use */
93 int desktopX = 0, desktopY = 0; /* Desktop window position (if any) */
94 int getVersion16 = 0;
95 int getVersion32 = 0;
96 OSVERSIONINFO32A getVersionEx;
98 struct options Options =
99 { /* default options */
100 NULL, /* desktopGeometry */
101 NULL, /* programName */
102 FALSE, /* usePrivateMap */
103 FALSE, /* useFixedMap */
104 FALSE, /* synchronous */
105 FALSE, /* backing store */
106 SW_SHOWNORMAL, /* cmdShow */
107 FALSE,
108 FALSE, /* AllowReadOnly */
109 MODE_ENHANCED, /* Enhanced mode */
110 FALSE, /* IPC enabled */
111 #ifdef DEFAULT_LANG
112 DEFAULT_LANG, /* Default language */
113 #else
114 LANG_En,
115 #endif
116 FALSE, /* Managed windows */
117 FALSE /* Perfect graphics */
121 static XrmOptionDescRec optionsTable[] =
123 { "-backingstore", ".backingstore", XrmoptionNoArg, (caddr_t)"on" },
124 { "-desktop", ".desktop", XrmoptionSepArg, (caddr_t)NULL },
125 { "-depth", ".depth", XrmoptionSepArg, (caddr_t)NULL },
126 { "-display", ".display", XrmoptionSepArg, (caddr_t)NULL },
127 { "-iconic", ".iconic", XrmoptionNoArg, (caddr_t)"on" },
128 { "-ipc", ".ipc", XrmoptionNoArg, (caddr_t)"off"},
129 { "-language", ".language", XrmoptionSepArg, (caddr_t)"En" },
130 { "-name", ".name", XrmoptionSepArg, (caddr_t)NULL },
131 { "-perfect", ".perfect", XrmoptionNoArg, (caddr_t)"on" },
132 { "-privatemap", ".privatemap", XrmoptionNoArg, (caddr_t)"on" },
133 { "-fixedmap", ".fixedmap", XrmoptionNoArg, (caddr_t)"on" },
134 { "-synchronous", ".synchronous", XrmoptionNoArg, (caddr_t)"on" },
135 { "-debug", ".debug", XrmoptionNoArg, (caddr_t)"on" },
136 { "-debugmsg", ".debugmsg", XrmoptionSepArg, (caddr_t)NULL },
137 { "-dll", ".dll", XrmoptionSepArg, (caddr_t)NULL },
138 { "-allowreadonly", ".allowreadonly", XrmoptionNoArg, (caddr_t)"on" },
139 { "-mode", ".mode", XrmoptionSepArg, (caddr_t)NULL },
140 { "-managed", ".managed", XrmoptionNoArg, (caddr_t)"off"},
141 { "-winver", ".winver", XrmoptionSepArg, (caddr_t)NULL }
144 #define NB_OPTIONS (sizeof(optionsTable) / sizeof(optionsTable[0]))
146 #define USAGE \
147 "Usage: %s [options] program_name [arguments]\n" \
148 "\n" \
149 "Options:\n" \
150 " -allowreadonly Read only files may be opened in write mode\n" \
151 " -backingstore Turn on backing store\n" \
152 " -debug Enter debugger before starting application\n" \
153 " -debugmsg name Turn debugging-messages on or off\n" \
154 " -depth n Change the depth to use for multiple-depth screens\n" \
155 " -desktop geom Use a desktop window of the given geometry\n" \
156 " -display name Use the specified display\n" \
157 " -dll name Enable or disable built-in DLLs\n" \
158 " -fixedmap Use a \"standard\" color map\n" \
159 " -iconic Start as an icon\n" \
160 " -ipc Enable IPC facilities\n" \
161 " -language xx Set the language (one of En,Es,De,No,Fr,Fi,Da,Cz,Eo,It,Ko)\n" \
162 " -managed Allow the window manager to manage created windows\n" \
163 " -mode mode Start Wine in a particular mode (standard or enhanced)\n" \
164 " -name name Set the application name\n" \
165 " -perfect Favor correctness over speed for graphical operations\n" \
166 " -privatemap Use a private color map\n" \
167 " -synchronous Turn on synchronous display mode\n" \
168 " -winver Version to imitate (one of win31,win95,nt351)\n"
172 /***********************************************************************
173 * MAIN_Usage
175 #ifndef WINELIB32
176 static void MAIN_Usage( char *name )
178 fprintf( stderr, USAGE, name );
179 exit(1);
181 #endif
184 /***********************************************************************
185 * MAIN_GetProgramName
187 * Get the program name. The name is specified by (in order of precedence):
188 * - the option '-name'.
189 * - the environment variable 'WINE_NAME'.
190 * - the last component of argv[0].
192 static char *MAIN_GetProgramName( int argc, char *argv[] )
194 int i;
195 char *p;
197 for (i = 1; i < argc-1; i++)
198 if (!strcmp( argv[i], "-name" )) return argv[i+1];
199 if ((p = getenv( "WINE_NAME" )) != NULL) return p;
200 if ((p = strrchr( argv[0], '/' )) != NULL) return p+1;
201 return argv[0];
205 /***********************************************************************
206 * MAIN_GetResource
208 * Fetch the value of resource 'name' using the correct instance name.
209 * 'name' must begin with '.' or '*'
211 static int MAIN_GetResource( XrmDatabase db, char *name, XrmValue *value )
213 char *buff_instance, *buff_class;
214 char *dummy;
215 int retval;
217 buff_instance = (char *)xmalloc(strlen(Options.programName)+strlen(name)+1);
218 buff_class = (char *)xmalloc( strlen(WINE_CLASS) + strlen(name) + 1 );
220 strcpy( buff_instance, Options.programName );
221 strcat( buff_instance, name );
222 strcpy( buff_class, WINE_CLASS );
223 strcat( buff_class, name );
224 retval = XrmGetResource( db, buff_instance, buff_class, &dummy, value );
225 free( buff_instance );
226 free( buff_class );
227 return retval;
231 /***********************************************************************
232 * ParseDebugOptions
234 * Turns specific debug messages on or off, according to "options".
235 * Returns TRUE if parsing was successful
237 #ifdef DEBUG_RUNTIME
239 BOOL ParseDebugOptions(char *options)
241 int l;
242 if (strlen(options)<3)
243 return FALSE;
246 if ((*options!='+')&&(*options!='-'))
247 return FALSE;
248 if (strchr(options,','))
249 l=strchr(options,',')-options;
250 else
251 l=strlen(options);
252 if (!lstrncmpi32A(options+1,"all",l-1))
254 int i;
255 for (i=0;i<sizeof(debug_msg_enabled)/sizeof(short);i++)
256 debug_msg_enabled[i]=(*options=='+');
258 else
260 int i;
261 for (i=0;i<sizeof(debug_msg_enabled)/sizeof(short);i++)
262 if (debug_msg_name && (!lstrncmpi32A(options+1,debug_msg_name[i],l-1)))
264 debug_msg_enabled[i]=(*options=='+');
265 break;
267 if (i==sizeof(debug_msg_enabled)/sizeof(short))
268 return FALSE;
270 options+=l;
272 while((*options==',')&&(*(++options)));
273 if (*options)
274 return FALSE;
275 else
276 return TRUE;
279 #endif
282 /***********************************************************************
283 * MAIN_ParseLanguageOption
285 * Parse -language option.
287 static void MAIN_ParseLanguageOption( char *arg )
289 const WINE_LANGUAGE_DEF *p = Languages;
291 Options.language = LANG_En; /* First language */
292 for (;p->name;p++)
294 if (!lstrcmpi32A( p->name, arg ))
296 WINE_LanguageId = p->langid;
297 return;
299 Options.language++;
301 fprintf( stderr, "Invalid language specified '%s'. Supported languages are: ", arg );
302 for (p = Languages; p->name; p++) fprintf( stderr, "%s ", p->name );
303 fprintf( stderr, "\n" );
304 exit(1);
308 /***********************************************************************
309 * MAIN_ParseModeOption
311 * Parse -mode option.
313 static void MAIN_ParseModeOption( char *arg )
315 if (!lstrcmpi32A("enhanced", arg)) Options.mode = MODE_ENHANCED;
316 else if (!lstrcmpi32A("standard", arg)) Options.mode = MODE_STANDARD;
317 else
319 fprintf(stderr, "Invalid mode '%s' specified.\n", arg);
320 fprintf(stderr, "Valid modes are: 'standard', 'enhanced' (default).\n");
321 exit(1);
325 /**********************************************************************
326 * MAIN_ParseVersion
328 static void MAIN_ParseVersion( char *arg )
330 /* If you add any other options,
331 verify the values you return on the real thing */
332 if(strcmp(arg,"win31")==0)
334 getVersion16 = 0x06160A03;
335 /* FIXME: My Win32s installation failed to execute the
336 MSVC 4 test program. So check these values */
337 getVersion32 = 0x80000A03;
338 getVersionEx.dwMajorVersion=3;
339 getVersionEx.dwMinorVersion=10;
340 getVersionEx.dwBuildNumber=0;
341 getVersionEx.dwPlatformId=VER_PLATFORM_WIN32s;
342 strcpy(getVersionEx.szCSDVersion,"Win32s 1.3");
344 else if(strcmp(arg, "win95")==0)
346 getVersion16 = 0x07005F03;
347 getVersion32 = 0xC0000004;
348 getVersionEx.dwMajorVersion=4;
349 getVersionEx.dwMinorVersion=0;
350 getVersionEx.dwBuildNumber=0x40003B6;
351 getVersionEx.dwPlatformId=VER_PLATFORM_WIN32_WINDOWS;
352 strcpy(getVersionEx.szCSDVersion,"");
354 else if(strcmp(arg, "nt351")==0)
356 getVersion16 = 0x05000A03;
357 getVersion32 = 0x04213303;
358 getVersionEx.dwMajorVersion=3;
359 getVersionEx.dwMinorVersion=51;
360 getVersionEx.dwBuildNumber=0x421;
361 getVersionEx.dwPlatformId=VER_PLATFORM_WIN32_NT;
362 strcpy(getVersionEx.szCSDVersion,"Service Pack 2");
364 else fprintf(stderr, "Unknown winver system code - ignored\n");
367 /***********************************************************************
368 * MAIN_ParseOptions
370 * Parse command line options and open display.
372 static void MAIN_ParseOptions( int *argc, char *argv[] )
374 char *display_name;
375 XrmValue value;
376 XrmDatabase db = XrmGetFileDatabase("/usr/lib/X11/app-defaults/Wine");
378 /* Parse command line */
379 Options.programName = MAIN_GetProgramName( *argc, argv );
380 XrmParseCommand( &db, optionsTable, NB_OPTIONS,
381 Options.programName, argc, argv );
383 #ifdef WINELIB
384 /* Need to assemble command line and pass it to WinMain */
385 #else
386 if (*argc < 2 || lstrcmpi32A(argv[1], "-h") == 0)
387 MAIN_Usage( argv[0] );
388 #endif
390 /* Open display */
392 if (MAIN_GetResource( db, ".display", &value )) display_name = value.addr;
393 else display_name = NULL;
395 if (!(display = XOpenDisplay( display_name )))
397 fprintf( stderr, "%s: Can't open display: %s\n",
398 argv[0], display_name ? display_name : "(none specified)" );
399 exit(1);
402 /* Get all options */
403 if (MAIN_GetResource( db, ".iconic", &value ))
404 Options.cmdShow = SW_SHOWMINIMIZED;
405 if (MAIN_GetResource( db, ".privatemap", &value ))
406 Options.usePrivateMap = TRUE;
407 if (MAIN_GetResource( db, ".fixedmap", &value ))
408 Options.useFixedMap = TRUE;
409 if (MAIN_GetResource( db, ".synchronous", &value ))
410 Options.synchronous = TRUE;
411 if (MAIN_GetResource( db, ".backingstore", &value ))
412 Options.backingstore = TRUE;
413 if (MAIN_GetResource( db, ".debug", &value ))
414 Options.debug = TRUE;
415 if (MAIN_GetResource( db, ".allowreadonly", &value ))
416 Options.allowReadOnly = TRUE;
417 if (MAIN_GetResource( db, ".ipc", &value ))
418 Options.ipc = TRUE;
419 if (MAIN_GetResource( db, ".perfect", &value ))
420 Options.perfectGraphics = TRUE;
421 if (MAIN_GetResource( db, ".depth", &value))
422 screenDepth = atoi( value.addr );
423 if (MAIN_GetResource( db, ".desktop", &value))
424 Options.desktopGeometry = value.addr;
425 if (MAIN_GetResource( db, ".language", &value))
426 MAIN_ParseLanguageOption( (char *)value.addr );
427 if (MAIN_GetResource( db, ".managed", &value))
428 Options.managed = TRUE;
429 if (MAIN_GetResource( db, ".mode", &value))
430 MAIN_ParseModeOption( (char *)value.addr );
432 #ifdef DEBUG_RUNTIME
433 if (MAIN_GetResource( db, ".debugoptions", &value))
434 ParseDebugOptions((char*)value.addr);
435 #endif
436 if (MAIN_GetResource( db, ".debugmsg", &value))
438 #ifndef DEBUG_RUNTIME
439 fprintf(stderr,"%s: Option \"-debugmsg\" not implemented.\n" \
440 " Recompile with DEBUG_RUNTIME in include/stddebug.h defined.\n",
441 argv[0]);
442 exit(1);
443 #else
444 if (ParseDebugOptions((char*)value.addr)==FALSE)
446 int i;
447 fprintf(stderr,"%s: Syntax: -debugmsg +xxx,... or -debugmsg -xxx,...\n",argv[0]);
448 fprintf(stderr,"Example: -debugmsg +all,-heap turn on all messages except heap messages\n");
449 fprintf(stderr,"Available message types:\n");
450 fprintf(stderr,"%-9s ","all");
451 for(i=0;i<sizeof(debug_msg_enabled)/sizeof(short);i++)
452 if(debug_msg_name[i])
453 fprintf(stderr,"%-9s%c",debug_msg_name[i],
454 (((i+2)%8==0)?'\n':' '));
455 fprintf(stderr,"\n\n");
456 exit(1);
458 #endif
461 if(MAIN_GetResource( db, ".dll", &value))
463 #ifndef WINELIB
464 if (!BUILTIN_ParseDLLOptions( (char*)value.addr ))
466 fprintf(stderr,"%s: Syntax: -dll +xxx,... or -dll -xxx,...\n",argv[0]);
467 fprintf(stderr,"Example: -dll -ole2 Do not use emulated OLE2.DLL\n");
468 fprintf(stderr,"Available DLLs:\n");
469 BUILTIN_PrintDLLs();
470 exit(1);
472 #else
473 fprintf(stderr,"-dll not supported in libwine\n");
474 #endif
477 if(MAIN_GetResource( db, ".winver", &value))
478 MAIN_ParseVersion( (char*)value.addr );
482 /***********************************************************************
483 * MAIN_CreateDesktop
485 static void MAIN_CreateDesktop( int argc, char *argv[] )
487 int flags;
488 unsigned int width = 640, height = 480; /* Default size = 640x480 */
489 char *name = "Wine desktop";
490 XSizeHints *size_hints;
491 XWMHints *wm_hints;
492 XClassHint *class_hints;
493 XSetWindowAttributes win_attr;
494 XTextProperty window_name;
495 Atom XA_WM_DELETE_WINDOW;
497 flags = XParseGeometry( Options.desktopGeometry,
498 &desktopX, &desktopY, &width, &height );
499 screenWidth = width;
500 screenHeight = height;
502 /* Create window */
504 win_attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
505 PointerMotionMask | ButtonPressMask |
506 ButtonReleaseMask | EnterWindowMask |
507 StructureNotifyMask;
508 win_attr.cursor = XCreateFontCursor( display, XC_top_left_arrow );
510 rootWindow = XCreateWindow( display, DefaultRootWindow(display),
511 desktopX, desktopY, width, height, 0,
512 CopyFromParent, InputOutput, CopyFromParent,
513 CWEventMask | CWCursor, &win_attr );
515 /* Set window manager properties */
517 size_hints = XAllocSizeHints();
518 wm_hints = XAllocWMHints();
519 class_hints = XAllocClassHint();
520 if (!size_hints || !wm_hints || !class_hints)
522 fprintf( stderr, "Not enough memory for window manager hints.\n" );
523 exit(1);
525 size_hints->min_width = size_hints->max_width = width;
526 size_hints->min_height = size_hints->max_height = height;
527 size_hints->flags = PMinSize | PMaxSize;
528 if (flags & (XValue | YValue)) size_hints->flags |= USPosition;
529 if (flags & (WidthValue | HeightValue)) size_hints->flags |= USSize;
530 else size_hints->flags |= PSize;
532 wm_hints->flags = InputHint | StateHint;
533 wm_hints->input = True;
534 wm_hints->initial_state = NormalState;
535 class_hints->res_name = argv[0];
536 class_hints->res_class = "Wine";
538 XStringListToTextProperty( &name, 1, &window_name );
539 XSetWMProperties( display, rootWindow, &window_name, &window_name,
540 argv, argc, size_hints, wm_hints, class_hints );
541 XA_WM_DELETE_WINDOW = XInternAtom( display, "WM_DELETE_WINDOW", False );
542 XSetWMProtocols( display, rootWindow, &XA_WM_DELETE_WINDOW, 1 );
543 XFree( size_hints );
544 XFree( wm_hints );
545 XFree( class_hints );
547 /* Map window */
549 XMapWindow( display, rootWindow );
553 XKeyboardState keyboard_state;
555 /***********************************************************************
556 * MAIN_SaveSetup
558 static void MAIN_SaveSetup(void)
560 XGetKeyboardControl(display, &keyboard_state);
563 /***********************************************************************
564 * MAIN_RestoreSetup
566 static void MAIN_RestoreSetup(void)
568 XKeyboardControl keyboard_value;
570 keyboard_value.key_click_percent = keyboard_state.key_click_percent;
571 keyboard_value.bell_percent = keyboard_state.bell_percent;
572 keyboard_value.bell_pitch = keyboard_state.bell_pitch;
573 keyboard_value.bell_duration = keyboard_state.bell_duration;
574 keyboard_value.auto_repeat_mode = keyboard_state.global_auto_repeat;
576 XChangeKeyboardControl(display, KBKeyClickPercent | KBBellPercent |
577 KBBellPitch | KBBellDuration | KBAutoRepeatMode, &keyboard_value);
581 static void called_at_exit(void)
583 MAIN_RestoreSetup();
584 WSACleanup();
587 /***********************************************************************
588 * main
590 #if defined(WINELIB) && defined(WINELIBDLL)
591 int _wine_main (int argc, char *argv[])
592 #else
593 int main( int argc, char *argv[] )
594 #endif
596 int ret_val;
597 int depth_count, i;
598 int *depth_list;
599 struct timeval tv;
601 extern int _WinMain(int argc, char **argv);
603 #ifdef MALLOC_DEBUGGING
604 char *trace;
606 mcheck(NULL);
607 if (!(trace = getenv("MALLOC_TRACE")))
609 fprintf( stderr, "MALLOC_TRACE not set. No trace generated\n" );
611 else
613 fprintf( stderr, "malloc trace goes to %s\n", trace );
614 mtrace();
616 #endif
618 setbuf(stdout,NULL);
619 setbuf(stderr,NULL);
621 setlocale(LC_CTYPE,"");
622 gettimeofday( &tv, NULL);
623 MSG_WineStartTicks = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
625 XrmInitialize();
627 MAIN_ParseOptions( &argc, argv );
629 if (Options.desktopGeometry && Options.managed)
631 fprintf( stderr, "%s: -managed and -desktop options cannot be used together\n",
632 Options.programName );
633 exit(1);
636 screen = DefaultScreenOfDisplay( display );
637 screenWidth = WidthOfScreen( screen );
638 screenHeight = HeightOfScreen( screen );
639 if (screenDepth) /* -depth option specified */
641 depth_list = XListDepths(display,DefaultScreen(display),&depth_count);
642 for (i = 0; i < depth_count; i++)
643 if (depth_list[i] == screenDepth) break;
644 XFree( depth_list );
645 if (i >= depth_count)
647 fprintf( stderr, "%s: Depth %d not supported on this screen.\n",
648 Options.programName, screenDepth );
649 exit(1);
652 else screenDepth = DefaultDepthOfScreen( screen );
653 if (Options.synchronous) XSynchronize( display, True );
654 if (Options.desktopGeometry) MAIN_CreateDesktop( argc, argv );
655 else rootWindow = DefaultRootWindow( display );
657 MAIN_SaveSetup();
658 atexit(called_at_exit);
660 ret_val = _WinMain( argc, argv );
662 return ret_val;
666 /***********************************************************************
667 * MessageBeep (USER.104)
669 void MessageBeep(WORD i)
671 XBell(display, 100);
675 /***********************************************************************
676 * Beep (KERNEL32.11)
678 BOOL32 Beep( DWORD dwFreq, DWORD dwDur )
680 /* dwFreq and dwDur are ignored by Win95 */
681 XBell(display, 100);
682 return TRUE;
686 /***********************************************************************
687 * GetVersion16 (KERNEL.3)
689 LONG GetVersion16(void)
691 if (getVersion16) return getVersion16;
692 return MAKELONG( WINVERSION, WINDOSVER );
696 /***********************************************************************
697 * GetVersion32
699 LONG GetVersion32(void)
701 if (getVersion32) return getVersion32;
702 return MAKELONG( 4, DOSVERSION);
706 /***********************************************************************
707 * GetVersionExA
709 BOOL32 GetVersionEx32A(OSVERSIONINFO32A *v)
711 if(v->dwOSVersionInfoSize!=sizeof(OSVERSIONINFO32A))
713 fprintf(stddeb,"wrong OSVERSIONINFO size from app");
714 return FALSE;
716 if(!getVersion32)
718 /* Return something like NT 3.5 */
719 v->dwMajorVersion = 3;
720 v->dwMinorVersion = 5;
721 v->dwBuildNumber = 42;
722 v->dwPlatformId = VER_PLATFORM_WIN32_NT;
723 strcpy(v->szCSDVersion, "Wine is not an emulator");
724 return TRUE;
726 v->dwMajorVersion = getVersionEx.dwMajorVersion;
727 v->dwMinorVersion = getVersionEx.dwMinorVersion;
728 v->dwBuildNumber = getVersionEx.dwBuildNumber;
729 v->dwPlatformId = getVersionEx.dwPlatformId;
730 strcpy(v->szCSDVersion, getVersionEx.szCSDVersion);
731 return TRUE;
735 /***********************************************************************
736 * GetVersionExW
738 BOOL32 GetVersionEx32W(OSVERSIONINFO32W *v)
740 OSVERSIONINFO32A v1;
741 if(v->dwOSVersionInfoSize!=sizeof(OSVERSIONINFO32W))
743 fprintf(stddeb,"wrong OSVERSIONINFO size from app");
744 return FALSE;
746 v1.dwOSVersionInfoSize=sizeof(v1);
747 GetVersionEx32A(&v1);
748 v->dwMajorVersion = v1.dwMajorVersion;
749 v->dwMinorVersion = v1.dwMinorVersion;
750 v->dwBuildNumber = v1.dwBuildNumber;
751 v->dwPlatformId = v1.dwPlatformId;
752 STRING32_AnsiToUni(v->szCSDVersion, v1.szCSDVersion);
753 return TRUE;
756 /***********************************************************************
757 * GetWinFlags (KERNEL.132)
759 LONG GetWinFlags(void)
761 static const long cpuflags[5] =
762 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
764 long result = 0;
766 /* There doesn't seem to be any Pentium flag. */
767 #ifndef WINELIB
768 long cpuflag = cpuflags[MIN (runtime_cpu (), 4)];
769 #else
770 long cpuflag = cpuflags[4];
771 #endif
773 switch(Options.mode) {
774 case MODE_STANDARD:
775 result = (WF_STANDARD | cpuflag | WF_PMODE | WF_80x87);
776 break;
778 case MODE_ENHANCED:
779 result = (WF_ENHANCED | cpuflag | WF_PMODE | WF_80x87 | WF_PAGING);
780 break;
782 default:
783 fprintf(stderr, "Unknown mode set? This shouldn't happen. Check GetWinFlags()!\n");
784 break;
787 return result;
790 /***********************************************************************
791 * SetEnvironment (GDI.132)
793 int SetEnvironment(LPCSTR lpPortName, LPCSTR lpEnviron, WORD nCount)
795 LPENVENTRY lpNewEnv;
796 LPENVENTRY lpEnv = lpEnvList;
797 dprintf_env(stddeb, "SetEnvironment('%s', '%s', %d) !\n",
798 lpPortName, lpEnviron, nCount);
799 if (lpPortName == NULL) return -1;
800 while (lpEnv != NULL) {
801 if (lpEnv->Name != NULL && strcmp(lpEnv->Name, lpPortName) == 0) {
802 if (nCount == 0 || lpEnviron == NULL) {
803 if (lpEnv->Prev != NULL) lpEnv->Prev->Next = lpEnv->Next;
804 if (lpEnv->Next != NULL) lpEnv->Next->Prev = lpEnv->Prev;
805 free(lpEnv->Value);
806 free(lpEnv->Name);
807 free(lpEnv);
808 dprintf_env(stddeb, "SetEnvironment() // entry deleted !\n");
809 return -1;
811 free(lpEnv->Value);
812 lpEnv->Value = malloc(nCount);
813 if (lpEnv->Value == NULL) {
814 dprintf_env(stddeb, "SetEnvironment() // Error allocating entry value !\n");
815 return 0;
817 memcpy(lpEnv->Value, lpEnviron, nCount);
818 lpEnv->wSize = nCount;
819 dprintf_env(stddeb, "SetEnvironment() // entry modified !\n");
820 return nCount;
822 if (lpEnv->Next == NULL) break;
823 lpEnv = lpEnv->Next;
825 if (nCount == 0 || lpEnviron == NULL) return -1;
826 dprintf_env(stddeb, "SetEnvironment() // new entry !\n");
827 lpNewEnv = malloc(sizeof(ENVENTRY));
828 if (lpNewEnv == NULL) {
829 dprintf_env(stddeb, "SetEnvironment() // Error allocating new entry !\n");
830 return 0;
832 if (lpEnvList == NULL) {
833 lpEnvList = lpNewEnv;
834 lpNewEnv->Prev = NULL;
836 else
838 lpEnv->Next = lpNewEnv;
839 lpNewEnv->Prev = lpEnv;
841 lpNewEnv->Next = NULL;
842 lpNewEnv->Name = malloc(strlen(lpPortName) + 1);
843 if (lpNewEnv->Name == NULL) {
844 dprintf_env(stddeb, "SetEnvironment() // Error allocating entry name !\n");
845 return 0;
847 strcpy(lpNewEnv->Name, lpPortName);
848 lpNewEnv->Value = malloc(nCount);
849 if (lpNewEnv->Value == NULL) {
850 dprintf_env(stddeb, "SetEnvironment() // Error allocating entry value !\n");
851 return 0;
853 memcpy(lpNewEnv->Value, lpEnviron, nCount);
854 lpNewEnv->wSize = nCount;
855 return nCount;
859 /***********************************************************************
860 * SetEnvironmentVariable32A (KERNEL32.484)
862 BOOL32 SetEnvironmentVariable32A( LPCSTR lpName, LPCSTR lpValue )
864 int rc;
866 rc = SetEnvironment(lpName, lpValue, strlen(lpValue) + 1);
867 return (rc > 0) ? 1 : 0;
871 /***********************************************************************
872 * SetEnvironmentVariable32W (KERNEL32.485)
874 BOOL32 SetEnvironmentVariable32W( LPCWSTR lpName, LPCWSTR lpValue )
876 LPSTR lpAName, lpAValue;
877 BOOL ret;
879 lpAName = STRING32_DupUniToAnsi( lpName );
880 lpAValue = STRING32_DupUniToAnsi ( lpValue );
881 ret = SetEnvironment(lpAName, lpAValue, strlen(lpAValue) + 1);
882 free (lpAName);
883 free (lpAValue);
884 return (ret > 0) ? 1 : 0;
888 /***********************************************************************
889 * GetEnvironment (GDI.134)
891 int GetEnvironment(LPSTR lpPortName, LPSTR lpEnviron, WORD nMaxSiz)
893 WORD nCount;
894 LPENVENTRY lpEnv = lpEnvList;
895 dprintf_env(stddeb, "GetEnvironment('%s', '%s', %d) !\n",
896 lpPortName, lpEnviron, nMaxSiz);
897 while (lpEnv != NULL) {
898 if (lpEnv->Name != NULL && strcmp(lpEnv->Name, lpPortName) == 0) {
899 nCount = MIN(nMaxSiz, lpEnv->wSize);
900 memcpy(lpEnviron, lpEnv->Value, nCount);
901 dprintf_env(stddeb, "GetEnvironment() // found '%s' !\n", lpEnviron);
902 return nCount;
904 lpEnv = lpEnv->Next;
906 dprintf_env(stddeb, "GetEnvironment() // not found !\n");
907 return 0;
910 /***********************************************************************
911 * GetEnvironmentVariableA (KERNEL32.213)
913 DWORD GetEnvironmentVariableA(LPSTR lpName, LPSTR lpValue, DWORD size)
915 return GetEnvironment(lpName, lpValue, size);
918 /***********************************************************************
919 * GetEnvironmentStrings (KERNEL32.210)
921 LPVOID GetEnvironmentStrings(void)
923 int count;
924 LPENVENTRY lpEnv;
925 char *envtable, *envptr;
927 /* Count the total number of bytes we'll need for the string
928 * table. Include the trailing nuls and the final double nul.
930 count = 1;
931 lpEnv = lpEnvList;
932 while(lpEnv != NULL)
934 if(lpEnv->Name != NULL)
936 count += strlen(lpEnv->Name) + 1;
937 count += strlen(lpEnv->Value) + 1;
939 lpEnv = lpEnv->Next;
942 envtable = malloc(count);
943 if(envtable)
945 lpEnv = lpEnvList;
946 envptr = envtable;
948 while(lpEnv != NULL)
950 if(lpEnv->Name != NULL)
952 count = sprintf(envptr, "%s=%s", lpEnv->Name, lpEnv->Value);
953 envptr += count + 1;
955 lpEnv = lpEnv->Next;
957 *envptr = '\0';
960 return envtable;
964 LPVOID GetEnvironmentStringsW(void)
966 int count,len;
967 LPENVENTRY lpEnv;
968 char *envtable, *envptr;
969 WCHAR *wenvtable;
971 /* Count the total number of bytes we'll need for the string
972 * table. Include the trailing nuls and the final double nul.
974 count = 1;
975 lpEnv = lpEnvList;
976 while(lpEnv != NULL)
978 if(lpEnv->Name != NULL)
980 count += strlen(lpEnv->Name) + 1;
981 count += strlen(lpEnv->Value) + 1;
983 lpEnv = lpEnv->Next;
986 len=count;
987 envtable = malloc(count);
988 if(envtable)
990 lpEnv = lpEnvList;
991 envptr = envtable;
993 while(lpEnv != NULL)
995 if(lpEnv->Name != NULL)
997 count = sprintf(envptr, "%s=%s", lpEnv->Name, lpEnv->Value);
998 envptr += count + 1;
1000 lpEnv = lpEnv->Next;
1002 *envptr = '\0';
1005 wenvtable = malloc(2*len);
1006 for(count=0;count<len;count++)
1007 wenvtable[count]=(WCHAR)envtable[count];
1008 free(envtable);
1010 return envtable;
1013 void FreeEnvironmentStringsA(void *e)
1015 free(e);
1018 void FreeEnvironmentStringsW(void* e)
1020 free(e);
1023 /***********************************************************************
1024 * GetTimerResolution (USER.14)
1026 LONG GetTimerResolution(void)
1028 return (1000);
1031 /***********************************************************************
1032 * SystemParametersInfo (USER.483)
1034 BOOL SystemParametersInfo (UINT uAction, UINT uParam, LPVOID lpvParam, UINT fuWinIni)
1036 int timeout, temp;
1037 char buffer[256];
1038 XKeyboardState keyboard_state;
1039 XKeyboardControl keyboard_value;
1042 switch (uAction) {
1043 case SPI_GETBEEP:
1044 XGetKeyboardControl(display, &keyboard_state);
1045 if (keyboard_state.bell_percent == 0)
1046 *(BOOL *) lpvParam = FALSE;
1047 else
1048 *(BOOL *) lpvParam = TRUE;
1049 break;
1051 case SPI_GETBORDER:
1052 *(INT *)lpvParam = GetSystemMetrics( SM_CXFRAME );
1053 break;
1055 case SPI_GETFASTTASKSWITCH:
1056 *(BOOL *) lpvParam = FALSE;
1057 /* FIXME GetProfileInt( "windows", "CoolSwitch", 1 ) */
1058 break;
1060 case SPI_GETGRIDGRANULARITY:
1061 *(INT *) lpvParam = 1;
1062 /* FIXME GetProfileInt( "desktop", "GridGranularity", 1 ) */
1063 break;
1065 case SPI_GETICONTITLEWRAP:
1066 *(BOOL *) lpvParam = FALSE;
1067 /* FIXME GetProfileInt( "desktop", "?", True ) */
1068 break;
1070 case SPI_GETKEYBOARDDELAY:
1071 *(INT *) lpvParam = 1;
1072 /* FIXME */
1073 break;
1075 case SPI_GETKEYBOARDSPEED:
1076 *(WORD *) lpvParam = 30;
1077 /* FIXME */
1078 break;
1080 case SPI_GETMENUDROPALIGNMENT:
1081 *(BOOL *) lpvParam = GetSystemMetrics( SM_MENUDROPALIGNMENT ); /* XXX check this */
1082 break;
1084 case SPI_GETSCREENSAVEACTIVE:
1085 /* FIXME GetProfileInt( "windows", "ScreenSaveActive", 1 ); */
1086 *(BOOL *) lpvParam = FALSE;
1087 break;
1089 case SPI_GETSCREENSAVETIMEOUT:
1090 /* FIXME GetProfileInt( "windows", "ScreenSaveTimeout", 300 ); */
1091 XGetScreenSaver(display, &timeout, &temp,&temp,&temp);
1092 *(INT *) lpvParam = timeout * 1000;
1093 break;
1095 case SPI_ICONHORIZONTALSPACING:
1096 if (lpvParam == NULL)
1097 fprintf(stderr, "SystemParametersInfo: Horizontal icon spacing set to %d\n.", uParam);
1098 else
1099 *(INT *) lpvParam = GetSystemMetrics( SM_CXICONSPACING );
1100 break;
1102 case SPI_ICONVERTICALSPACING:
1103 if (lpvParam == NULL)
1104 fprintf(stderr, "SystemParametersInfo: Vertical icon spacing set to %d\n.", uParam);
1105 else
1106 *(INT *) lpvParam = GetSystemMetrics( SM_CYICONSPACING );
1107 break;
1109 case SPI_SETBEEP:
1110 if (uParam == TRUE)
1111 keyboard_value.bell_percent = -1;
1112 else
1113 keyboard_value.bell_percent = 0;
1114 XChangeKeyboardControl(display, KBBellPercent,
1115 &keyboard_value);
1116 break;
1118 case SPI_SETSCREENSAVEACTIVE:
1119 if (uParam == TRUE)
1120 XActivateScreenSaver(display);
1121 else
1122 XResetScreenSaver(display);
1123 break;
1125 case SPI_SETSCREENSAVETIMEOUT:
1126 XSetScreenSaver(display, uParam, 60, DefaultBlanking,
1127 DefaultExposures);
1128 break;
1130 case SPI_SETDESKWALLPAPER:
1131 return (SetDeskWallPaper((LPSTR) lpvParam));
1132 break;
1134 case SPI_SETDESKPATTERN:
1135 if ((INT) uParam == -1) {
1136 GetProfileString("Desktop", "Pattern",
1137 "170 85 170 85 170 85 170 85",
1138 buffer, sizeof(buffer) );
1139 return (DESKTOP_SetPattern((LPSTR) buffer));
1140 } else
1141 return (DESKTOP_SetPattern((LPSTR) lpvParam));
1142 break;
1144 case SPI_GETICONTITLELOGFONT:
1146 /* FIXME GetProfileString( "?", "?", "?" ) */
1147 LPLOGFONT16 lpLogFont = (LPLOGFONT16)lpvParam;
1148 lpLogFont->lfHeight = 10;
1149 lpLogFont->lfWidth = 0;
1150 lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
1151 lpLogFont->lfWeight = FW_NORMAL;
1152 lpLogFont->lfItalic = lpLogFont->lfStrikeOut = lpLogFont->lfUnderline = FALSE;
1153 lpLogFont->lfCharSet = ANSI_CHARSET;
1154 lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
1155 lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
1156 lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
1157 break;
1159 case SPI_LANGDRIVER:
1160 case SPI_SETBORDER:
1161 case SPI_SETDOUBLECLKHEIGHT:
1162 case SPI_SETDOUBLECLICKTIME:
1163 case SPI_SETDOUBLECLKWIDTH:
1164 case SPI_SETFASTTASKSWITCH:
1165 case SPI_SETKEYBOARDDELAY:
1166 case SPI_SETKEYBOARDSPEED:
1167 fprintf(stderr, "SystemParametersInfo: option %d ignored.\n", uParam);
1168 break;
1170 default:
1171 fprintf(stderr, "SystemParametersInfo: unknown option %d.\n", uParam);
1172 break;
1174 return 1;
1177 /***********************************************************************
1178 * COPY (GDI.250)
1180 void Copy(LPVOID lpSource, LPVOID lpDest, WORD nBytes)
1182 memcpy(lpDest, lpSource, nBytes);
1185 /***********************************************************************
1186 * SWAPMOUSEBUTTON (USER.186)
1188 BOOL SwapMouseButton(BOOL fSwap)
1190 return 0; /* don't swap */
1193 /***********************************************************************
1194 * FileCDR (KERNEL.130)
1196 void FileCDR(FARPROC16 x)
1198 printf("FileCDR(%8x)\n", (int) x);
1201 /***********************************************************************
1202 * GetWinDebugInfo (KERNEL.355)
1204 BOOL GetWinDebugInfo(WINDEBUGINFO *lpwdi, UINT flags)
1206 printf("GetWinDebugInfo(%8lx,%d) stub returning 0\n", (unsigned long)lpwdi, flags);
1207 /* 0 means not in debugging mode/version */
1208 /* Can this type of debugging be used in wine ? */
1209 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
1210 return 0;
1213 /***********************************************************************
1214 * GetWinDebugInfo (KERNEL.355)
1216 BOOL SetWinDebugInfo(WINDEBUGINFO *lpwdi)
1218 printf("SetWinDebugInfo(%8lx) stub returning 0\n", (unsigned long)lpwdi);
1219 /* 0 means not in debugging mode/version */
1220 /* Can this type of debugging be used in wine ? */
1221 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
1222 return 0;