Release 960712
[wine/testsucceed.git] / misc / main.c
blob34dbccc831829f3e9f52f435efb47822e7177e6e
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 char * langNames[] =
60 "En", /* LANG_En */
61 "Es", /* LANG_Es */
62 "De", /* LANG_De */
63 "No", /* LANG_No */
64 "Fr", /* LANG_Fr */
65 "Fi", /* LANG_Fi */
66 "Da", /* LANG_Da */
67 "Cz", /* LANG_Cz */
68 "Eo", /* LANG_Eo */
69 "It", /* LANG_It */
70 "Ko", /* LANG_Ko */
71 NULL
74 #define WINE_CLASS "Wine" /* Class name for resources */
76 typedef struct tagENVENTRY {
77 LPSTR Name;
78 LPSTR Value;
79 WORD wSize;
80 struct tagENVENTRY *Prev;
81 struct tagENVENTRY *Next;
82 } ENVENTRY, *LPENVENTRY;
84 LPENVENTRY lpEnvList = NULL;
86 Display *display;
87 Screen *screen;
88 Window rootWindow;
89 int screenWidth = 0, screenHeight = 0; /* Desktop window dimensions */
90 int screenDepth = 0; /* Screen depth to use */
91 int desktopX = 0, desktopY = 0; /* Desktop window position (if any) */
92 int getVersion16 = 0;
93 int getVersion32 = 0;
94 OSVERSIONINFO32A getVersionEx;
96 struct options Options =
97 { /* default options */
98 NULL, /* desktopGeometry */
99 NULL, /* programName */
100 FALSE, /* usePrivateMap */
101 FALSE, /* useFixedMap */
102 FALSE, /* synchronous */
103 FALSE, /* backing store */
104 SW_SHOWNORMAL, /* cmdShow */
105 FALSE,
106 FALSE, /* AllowReadOnly */
107 MODE_ENHANCED, /* Enhanced mode */
108 FALSE, /* IPC enabled */
109 #ifdef DEFAULT_LANG
110 DEFAULT_LANG, /* Default language */
111 #else
112 LANG_En,
113 #endif
114 FALSE /* Managed windows */
118 static XrmOptionDescRec optionsTable[] =
120 { "-backingstore", ".backingstore", XrmoptionNoArg, (caddr_t)"on" },
121 { "-desktop", ".desktop", XrmoptionSepArg, (caddr_t)NULL },
122 { "-depth", ".depth", XrmoptionSepArg, (caddr_t)NULL },
123 { "-display", ".display", XrmoptionSepArg, (caddr_t)NULL },
124 { "-iconic", ".iconic", XrmoptionNoArg, (caddr_t)"on" },
125 { "-ipc", ".ipc", XrmoptionNoArg, (caddr_t)"off"},
126 { "-language", ".language", XrmoptionSepArg, (caddr_t)"En" },
127 { "-name", ".name", XrmoptionSepArg, (caddr_t)NULL },
128 { "-privatemap", ".privatemap", XrmoptionNoArg, (caddr_t)"on" },
129 { "-fixedmap", ".fixedmap", XrmoptionNoArg, (caddr_t)"on" },
130 { "-synchronous", ".synchronous", XrmoptionNoArg, (caddr_t)"on" },
131 { "-debug", ".debug", XrmoptionNoArg, (caddr_t)"on" },
132 { "-debugmsg", ".debugmsg", XrmoptionSepArg, (caddr_t)NULL },
133 { "-dll", ".dll", XrmoptionSepArg, (caddr_t)NULL },
134 { "-allowreadonly", ".allowreadonly", XrmoptionNoArg, (caddr_t)"on" },
135 { "-mode", ".mode", XrmoptionSepArg, (caddr_t)NULL },
136 { "-managed", ".managed", XrmoptionNoArg, (caddr_t)"off"},
137 { "-winver", ".winver", XrmoptionSepArg, (caddr_t)NULL }
140 #define NB_OPTIONS (sizeof(optionsTable) / sizeof(optionsTable[0]))
142 #define USAGE \
143 "Usage: %s [options] program_name [arguments]\n" \
144 "\n" \
145 "Options:\n" \
146 " -allowreadonly Read only files may be opened in write mode\n" \
147 " -backingstore Turn on backing store\n" \
148 " -debug Enter debugger before starting application\n" \
149 " -debugmsg name Turn debugging-messages on or off\n" \
150 " -depth n Change the depth to use for multiple-depth screens\n" \
151 " -desktop geom Use a desktop window of the given geometry\n" \
152 " -display name Use the specified display\n" \
153 " -dll name Enable or disable built-in DLLs\n" \
154 " -fixedmap Use a \"standard\" color map\n" \
155 " -iconic Start as an icon\n" \
156 " -ipc Enable IPC facilities\n" \
157 " -language xx Set the language (one of En,Es,De,No,Fr,Fi,Da,Cz,Eo,It,Ko)\n" \
158 " -managed Allow the window manager to manage created windows\n" \
159 " -mode mode Start Wine in a particular mode (standard or enhanced)\n" \
160 " -name name Set the application name\n" \
161 " -privatemap Use a private color map\n" \
162 " -synchronous Turn on synchronous display mode\n" \
163 " -winver Version to imitate (one of win31,win95,nt351)\n"
167 /***********************************************************************
168 * MAIN_Usage
170 #ifndef WINELIB32
171 static void MAIN_Usage( char *name )
173 fprintf( stderr, USAGE, name );
174 exit(1);
176 #endif
179 /***********************************************************************
180 * MAIN_GetProgramName
182 * Get the program name. The name is specified by (in order of precedence):
183 * - the option '-name'.
184 * - the environment variable 'WINE_NAME'.
185 * - the last component of argv[0].
187 static char *MAIN_GetProgramName( int argc, char *argv[] )
189 int i;
190 char *p;
192 for (i = 1; i < argc-1; i++)
193 if (!strcmp( argv[i], "-name" )) return argv[i+1];
194 if ((p = getenv( "WINE_NAME" )) != NULL) return p;
195 if ((p = strrchr( argv[0], '/' )) != NULL) return p+1;
196 return argv[0];
200 /***********************************************************************
201 * MAIN_GetResource
203 * Fetch the value of resource 'name' using the correct instance name.
204 * 'name' must begin with '.' or '*'
206 static int MAIN_GetResource( XrmDatabase db, char *name, XrmValue *value )
208 char *buff_instance, *buff_class;
209 char *dummy;
210 int retval;
212 buff_instance = (char *)xmalloc(strlen(Options.programName)+strlen(name)+1);
213 buff_class = (char *)xmalloc( strlen(WINE_CLASS) + strlen(name) + 1 );
215 strcpy( buff_instance, Options.programName );
216 strcat( buff_instance, name );
217 strcpy( buff_class, WINE_CLASS );
218 strcat( buff_class, name );
219 retval = XrmGetResource( db, buff_instance, buff_class, &dummy, value );
220 free( buff_instance );
221 free( buff_class );
222 return retval;
226 /***********************************************************************
227 * ParseDebugOptions
229 * Turns specific debug messages on or off, according to "options".
230 * Returns TRUE if parsing was successful
232 #ifdef DEBUG_RUNTIME
234 BOOL ParseDebugOptions(char *options)
236 int l;
237 if (strlen(options)<3)
238 return FALSE;
241 if ((*options!='+')&&(*options!='-'))
242 return FALSE;
243 if (strchr(options,','))
244 l=strchr(options,',')-options;
245 else
246 l=strlen(options);
247 if (!lstrncmpi32A(options+1,"all",l-1))
249 int i;
250 for (i=0;i<sizeof(debug_msg_enabled)/sizeof(short);i++)
251 debug_msg_enabled[i]=(*options=='+');
253 else
255 int i;
256 for (i=0;i<sizeof(debug_msg_enabled)/sizeof(short);i++)
257 if (debug_msg_name && (!lstrncmpi32A(options+1,debug_msg_name[i],l-1)))
259 debug_msg_enabled[i]=(*options=='+');
260 break;
262 if (i==sizeof(debug_msg_enabled)/sizeof(short))
263 return FALSE;
265 options+=l;
267 while((*options==',')&&(*(++options)));
268 if (*options)
269 return FALSE;
270 else
271 return TRUE;
274 #endif
277 /***********************************************************************
278 * MAIN_ParseLanguageOption
280 * Parse -language option.
282 static void MAIN_ParseLanguageOption( char *arg )
284 const char **p = langNames;
286 Options.language = LANG_En; /* First language */
287 for (p = langNames; *p; p++)
289 if (!lstrcmpi32A( *p, arg )) return;
290 Options.language++;
292 fprintf( stderr, "Invalid language specified '%s'. Supported languages are: ", arg );
293 for (p = langNames; *p; p++) fprintf( stderr, "%s ", *p );
294 fprintf( stderr, "\n" );
295 exit(1);
299 /***********************************************************************
300 * MAIN_ParseModeOption
302 * Parse -mode option.
304 static void MAIN_ParseModeOption( char *arg )
306 if (!lstrcmpi32A("enhanced", arg)) Options.mode = MODE_ENHANCED;
307 else if (!lstrcmpi32A("standard", arg)) Options.mode = MODE_STANDARD;
308 else
310 fprintf(stderr, "Invalid mode '%s' specified.\n", arg);
311 fprintf(stderr, "Valid modes are: 'standard', 'enhanced' (default).\n");
312 exit(1);
316 /**********************************************************************
317 * MAIN_ParseVersion
319 static void MAIN_ParseVersion( char *arg )
321 /* If you add any other options,
322 verify the values you return on the real thing */
323 if(strcmp(arg,"win31")==0)
325 getVersion16 = 0x06160A03;
326 /* FIXME: My Win32s installation failed to execute the
327 MSVC 4 test program. So check these values */
328 getVersion32 = 0x80000A03;
329 getVersionEx.dwMajorVersion=3;
330 getVersionEx.dwMinorVersion=10;
331 getVersionEx.dwBuildNumber=0;
332 getVersionEx.dwPlatformId=VER_PLATFORM_WIN32s;
333 strcpy(getVersionEx.szCSDVersion,"Win32s 1.3");
335 else if(strcmp(arg, "win95")==0)
337 getVersion16 = 0x07005F03;
338 getVersion32 = 0xC0000004;
339 getVersionEx.dwMajorVersion=4;
340 getVersionEx.dwMinorVersion=0;
341 getVersionEx.dwBuildNumber=0x40003B6;
342 getVersionEx.dwPlatformId=VER_PLATFORM_WIN32_WINDOWS;
343 strcpy(getVersionEx.szCSDVersion,"");
345 else if(strcmp(arg, "nt351")==0)
347 getVersion16 = 0x05000A03;
348 getVersion32 = 0x04213303;
349 getVersionEx.dwMajorVersion=3;
350 getVersionEx.dwMinorVersion=51;
351 getVersionEx.dwBuildNumber=0x421;
352 getVersionEx.dwPlatformId=VER_PLATFORM_WIN32_NT;
353 strcpy(getVersionEx.szCSDVersion,"Service Pack 2");
355 else fprintf(stderr, "Unknown winver system code - ignored\n");
358 /***********************************************************************
359 * MAIN_ParseOptions
361 * Parse command line options and open display.
363 static void MAIN_ParseOptions( int *argc, char *argv[] )
365 char *display_name;
366 XrmValue value;
367 XrmDatabase db = XrmGetFileDatabase("/usr/lib/X11/app-defaults/Wine");
369 /* Parse command line */
370 Options.programName = MAIN_GetProgramName( *argc, argv );
371 XrmParseCommand( &db, optionsTable, NB_OPTIONS,
372 Options.programName, argc, argv );
374 #ifdef WINELIB
375 /* Need to assemble command line and pass it to WinMain */
376 #else
377 if (*argc < 2 || lstrcmpi32A(argv[1], "-h") == 0)
378 MAIN_Usage( argv[0] );
379 #endif
381 /* Open display */
383 if (MAIN_GetResource( db, ".display", &value )) display_name = value.addr;
384 else display_name = NULL;
386 if (!(display = XOpenDisplay( display_name )))
388 fprintf( stderr, "%s: Can't open display: %s\n",
389 argv[0], display_name ? display_name : "(none specified)" );
390 exit(1);
393 /* Get all options */
394 if (MAIN_GetResource( db, ".iconic", &value ))
395 Options.cmdShow = SW_SHOWMINIMIZED;
396 if (MAIN_GetResource( db, ".privatemap", &value ))
397 Options.usePrivateMap = TRUE;
398 if (MAIN_GetResource( db, ".fixedmap", &value ))
399 Options.useFixedMap = TRUE;
400 if (MAIN_GetResource( db, ".synchronous", &value ))
401 Options.synchronous = TRUE;
402 if (MAIN_GetResource( db, ".backingstore", &value ))
403 Options.backingstore = TRUE;
404 if (MAIN_GetResource( db, ".debug", &value ))
405 Options.debug = TRUE;
406 if (MAIN_GetResource( db, ".allowreadonly", &value ))
407 Options.allowReadOnly = TRUE;
408 if (MAIN_GetResource( db, ".ipc", &value ))
409 Options.ipc = TRUE;
410 if (MAIN_GetResource( db, ".depth", &value))
411 screenDepth = atoi( value.addr );
412 if (MAIN_GetResource( db, ".desktop", &value))
413 Options.desktopGeometry = value.addr;
414 if (MAIN_GetResource( db, ".language", &value))
415 MAIN_ParseLanguageOption( (char *)value.addr );
416 if (MAIN_GetResource( db, ".managed", &value))
417 Options.managed = TRUE;
418 if (MAIN_GetResource( db, ".mode", &value))
419 MAIN_ParseModeOption( (char *)value.addr );
421 #ifdef DEBUG_RUNTIME
422 if (MAIN_GetResource( db, ".debugoptions", &value))
423 ParseDebugOptions((char*)value.addr);
424 #endif
425 if (MAIN_GetResource( db, ".debugmsg", &value))
427 #ifndef DEBUG_RUNTIME
428 fprintf(stderr,"%s: Option \"-debugmsg\" not implemented.\n" \
429 " Recompile with DEBUG_RUNTIME in include/stddebug.h defined.\n",
430 argv[0]);
431 exit(1);
432 #else
433 if (ParseDebugOptions((char*)value.addr)==FALSE)
435 int i;
436 fprintf(stderr,"%s: Syntax: -debugmsg +xxx,... or -debugmsg -xxx,...\n",argv[0]);
437 fprintf(stderr,"Example: -debugmsg +all,-heap turn on all messages except heap messages\n");
438 fprintf(stderr,"Available message types:\n");
439 fprintf(stderr,"%-9s ","all");
440 for(i=0;i<sizeof(debug_msg_enabled)/sizeof(short);i++)
441 if(debug_msg_name[i])
442 fprintf(stderr,"%-9s%c",debug_msg_name[i],
443 (((i+2)%8==0)?'\n':' '));
444 fprintf(stderr,"\n\n");
445 exit(1);
447 #endif
450 if(MAIN_GetResource( db, ".dll", &value))
452 #ifndef WINELIB
453 if (!BUILTIN_ParseDLLOptions( (char*)value.addr ))
455 fprintf(stderr,"%s: Syntax: -dll +xxx,... or -dll -xxx,...\n",argv[0]);
456 fprintf(stderr,"Example: -dll -ole2 Do not use emulated OLE2.DLL\n");
457 fprintf(stderr,"Available DLLs:\n");
458 BUILTIN_PrintDLLs();
459 exit(1);
461 #else
462 fprintf(stderr,"-dll not supported in libwine\n");
463 #endif
466 if(MAIN_GetResource( db, ".winver", &value))
467 MAIN_ParseVersion( (char*)value.addr );
471 /***********************************************************************
472 * MAIN_CreateDesktop
474 static void MAIN_CreateDesktop( int argc, char *argv[] )
476 int flags;
477 unsigned int width = 640, height = 480; /* Default size = 640x480 */
478 char *name = "Wine desktop";
479 XSizeHints *size_hints;
480 XWMHints *wm_hints;
481 XClassHint *class_hints;
482 XSetWindowAttributes win_attr;
483 XTextProperty window_name;
484 Atom XA_WM_DELETE_WINDOW;
486 flags = XParseGeometry( Options.desktopGeometry,
487 &desktopX, &desktopY, &width, &height );
488 screenWidth = width;
489 screenHeight = height;
491 /* Create window */
493 win_attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
494 PointerMotionMask | ButtonPressMask |
495 ButtonReleaseMask | EnterWindowMask |
496 StructureNotifyMask;
497 win_attr.cursor = XCreateFontCursor( display, XC_top_left_arrow );
499 rootWindow = XCreateWindow( display, DefaultRootWindow(display),
500 desktopX, desktopY, width, height, 0,
501 CopyFromParent, InputOutput, CopyFromParent,
502 CWEventMask | CWCursor, &win_attr );
504 /* Set window manager properties */
506 size_hints = XAllocSizeHints();
507 wm_hints = XAllocWMHints();
508 class_hints = XAllocClassHint();
509 if (!size_hints || !wm_hints || !class_hints)
511 fprintf( stderr, "Not enough memory for window manager hints.\n" );
512 exit(1);
514 size_hints->min_width = size_hints->max_width = width;
515 size_hints->min_height = size_hints->max_height = height;
516 size_hints->flags = PMinSize | PMaxSize;
517 if (flags & (XValue | YValue)) size_hints->flags |= USPosition;
518 if (flags & (WidthValue | HeightValue)) size_hints->flags |= USSize;
519 else size_hints->flags |= PSize;
521 wm_hints->flags = InputHint | StateHint;
522 wm_hints->input = True;
523 wm_hints->initial_state = NormalState;
524 class_hints->res_name = argv[0];
525 class_hints->res_class = "Wine";
527 XStringListToTextProperty( &name, 1, &window_name );
528 XSetWMProperties( display, rootWindow, &window_name, &window_name,
529 argv, argc, size_hints, wm_hints, class_hints );
530 XA_WM_DELETE_WINDOW = XInternAtom( display, "WM_DELETE_WINDOW", False );
531 XSetWMProtocols( display, rootWindow, &XA_WM_DELETE_WINDOW, 1 );
532 XFree( size_hints );
533 XFree( wm_hints );
534 XFree( class_hints );
536 /* Map window */
538 XMapWindow( display, rootWindow );
542 XKeyboardState keyboard_state;
544 /***********************************************************************
545 * MAIN_SaveSetup
547 static void MAIN_SaveSetup(void)
549 XGetKeyboardControl(display, &keyboard_state);
552 /***********************************************************************
553 * MAIN_RestoreSetup
555 static void MAIN_RestoreSetup(void)
557 XKeyboardControl keyboard_value;
559 keyboard_value.key_click_percent = keyboard_state.key_click_percent;
560 keyboard_value.bell_percent = keyboard_state.bell_percent;
561 keyboard_value.bell_pitch = keyboard_state.bell_pitch;
562 keyboard_value.bell_duration = keyboard_state.bell_duration;
563 keyboard_value.auto_repeat_mode = keyboard_state.global_auto_repeat;
565 XChangeKeyboardControl(display, KBKeyClickPercent | KBBellPercent |
566 KBBellPitch | KBBellDuration | KBAutoRepeatMode, &keyboard_value);
570 static void called_at_exit(void)
572 MAIN_RestoreSetup();
573 WSACleanup();
576 /***********************************************************************
577 * main
579 #if defined(WINELIB) && defined(WINELIBDLL)
580 int _wine_main (int argc, char *argv[])
581 #else
582 int main( int argc, char *argv[] )
583 #endif
585 int ret_val;
586 int depth_count, i;
587 int *depth_list;
588 struct timeval tv;
590 extern int _WinMain(int argc, char **argv);
592 #ifdef MALLOC_DEBUGGING
593 char *trace;
595 mcheck(NULL);
596 if (!(trace = getenv("MALLOC_TRACE")))
598 fprintf( stderr, "MALLOC_TRACE not set. No trace generated\n" );
600 else
602 fprintf( stderr, "malloc trace goes to %s\n", trace );
603 mtrace();
605 #endif
607 setbuf(stdout,NULL);
608 setbuf(stderr,NULL);
610 setlocale(LC_CTYPE,"");
611 gettimeofday( &tv, NULL);
612 MSG_WineStartTicks = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
614 XrmInitialize();
616 MAIN_ParseOptions( &argc, argv );
618 screen = DefaultScreenOfDisplay( display );
619 screenWidth = WidthOfScreen( screen );
620 screenHeight = HeightOfScreen( screen );
621 if (screenDepth) /* -depth option specified */
623 depth_list = XListDepths(display,DefaultScreen(display),&depth_count);
624 for (i = 0; i < depth_count; i++)
625 if (depth_list[i] == screenDepth) break;
626 XFree( depth_list );
627 if (i >= depth_count)
629 fprintf( stderr, "%s: Depth %d not supported on this screen.\n",
630 Options.programName, screenDepth );
631 exit(1);
634 else screenDepth = DefaultDepthOfScreen( screen );
635 if (Options.synchronous) XSynchronize( display, True );
636 if (Options.desktopGeometry) MAIN_CreateDesktop( argc, argv );
637 else rootWindow = DefaultRootWindow( display );
639 MAIN_SaveSetup();
640 atexit(called_at_exit);
642 ret_val = _WinMain( argc, argv );
644 return ret_val;
648 /***********************************************************************
649 * MessageBeep (USER.104)
651 void MessageBeep(WORD i)
653 XBell(display, 100);
657 /***********************************************************************
658 * Beep (KERNEL32.11)
660 BOOL32 Beep( DWORD dwFreq, DWORD dwDur )
662 /* dwFreq and dwDur are ignored by Win95 */
663 XBell(display, 100);
664 return TRUE;
668 /***********************************************************************
669 * GetVersion (KERNEL.3)
671 LONG GetVersion(void)
673 if (getVersion16) return getVersion16;
674 return MAKELONG( WINVERSION, WINDOSVER );
678 /***********************************************************************
679 * GetVersion32
681 LONG GetVersion32(void)
683 if (getVersion32) return getVersion32;
684 return MAKELONG( 4, DOSVERSION);
688 /***********************************************************************
689 * GetVersionExA
691 BOOL32 GetVersionEx32A(OSVERSIONINFO32A *v)
693 if(v->dwOSVersionInfoSize!=sizeof(OSVERSIONINFO32A))
695 fprintf(stddeb,"wrong OSVERSIONINFO size from app");
696 return FALSE;
698 if(!getVersion32)
700 /* Return something like NT 3.5 */
701 v->dwMajorVersion = 3;
702 v->dwMinorVersion = 5;
703 v->dwBuildNumber = 42;
704 v->dwPlatformId = VER_PLATFORM_WIN32_NT;
705 strcpy(v->szCSDVersion, "Wine is not an emulator");
706 return TRUE;
708 v->dwMajorVersion = getVersionEx.dwMajorVersion;
709 v->dwMinorVersion = getVersionEx.dwMinorVersion;
710 v->dwBuildNumber = getVersionEx.dwBuildNumber;
711 v->dwPlatformId = getVersionEx.dwPlatformId;
712 strcpy(v->szCSDVersion, getVersionEx.szCSDVersion);
713 return TRUE;
717 /***********************************************************************
718 * GetVersionExW
720 BOOL32 GetVersionEx32W(OSVERSIONINFO32W *v)
722 OSVERSIONINFO32A v1;
723 if(v->dwOSVersionInfoSize!=sizeof(OSVERSIONINFO32W))
725 fprintf(stddeb,"wrong OSVERSIONINFO size from app");
726 return FALSE;
728 v1.dwOSVersionInfoSize=sizeof(v1);
729 GetVersionEx32A(&v1);
730 v->dwMajorVersion = v1.dwMajorVersion;
731 v->dwMinorVersion = v1.dwMinorVersion;
732 v->dwBuildNumber = v1.dwBuildNumber;
733 v->dwPlatformId = v1.dwPlatformId;
734 STRING32_AnsiToUni(v->szCSDVersion, v1.szCSDVersion);
735 return TRUE;
738 /***********************************************************************
739 * GetWinFlags (KERNEL.132)
741 LONG GetWinFlags(void)
743 static const long cpuflags[5] =
744 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
746 long result = 0;
748 /* There doesn't seem to be any Pentium flag. */
749 #ifndef WINELIB
750 long cpuflag = cpuflags[MIN (runtime_cpu (), 4)];
751 #else
752 long cpuflag = cpuflags[4];
753 #endif
755 switch(Options.mode) {
756 case MODE_STANDARD:
757 result = (WF_STANDARD | cpuflag | WF_PMODE | WF_80x87);
758 break;
760 case MODE_ENHANCED:
761 result = (WF_ENHANCED | cpuflag | WF_PMODE | WF_80x87 | WF_PAGING);
762 break;
764 default:
765 fprintf(stderr, "Unknown mode set? This shouldn't happen. Check GetWinFlags()!\n");
766 break;
769 return result;
772 /***********************************************************************
773 * SetEnvironment (GDI.132)
775 int SetEnvironment(LPCSTR lpPortName, LPCSTR lpEnviron, WORD nCount)
777 LPENVENTRY lpNewEnv;
778 LPENVENTRY lpEnv = lpEnvList;
779 dprintf_env(stddeb, "SetEnvironment('%s', '%s', %d) !\n",
780 lpPortName, lpEnviron, nCount);
781 if (lpPortName == NULL) return -1;
782 while (lpEnv != NULL) {
783 if (lpEnv->Name != NULL && strcmp(lpEnv->Name, lpPortName) == 0) {
784 if (nCount == 0 || lpEnviron == NULL) {
785 if (lpEnv->Prev != NULL) lpEnv->Prev->Next = lpEnv->Next;
786 if (lpEnv->Next != NULL) lpEnv->Next->Prev = lpEnv->Prev;
787 free(lpEnv->Value);
788 free(lpEnv->Name);
789 free(lpEnv);
790 dprintf_env(stddeb, "SetEnvironment() // entry deleted !\n");
791 return -1;
793 free(lpEnv->Value);
794 lpEnv->Value = malloc(nCount);
795 if (lpEnv->Value == NULL) {
796 dprintf_env(stddeb, "SetEnvironment() // Error allocating entry value !\n");
797 return 0;
799 memcpy(lpEnv->Value, lpEnviron, nCount);
800 lpEnv->wSize = nCount;
801 dprintf_env(stddeb, "SetEnvironment() // entry modified !\n");
802 return nCount;
804 if (lpEnv->Next == NULL) break;
805 lpEnv = lpEnv->Next;
807 if (nCount == 0 || lpEnviron == NULL) return -1;
808 dprintf_env(stddeb, "SetEnvironment() // new entry !\n");
809 lpNewEnv = malloc(sizeof(ENVENTRY));
810 if (lpNewEnv == NULL) {
811 dprintf_env(stddeb, "SetEnvironment() // Error allocating new entry !\n");
812 return 0;
814 if (lpEnvList == NULL) {
815 lpEnvList = lpNewEnv;
816 lpNewEnv->Prev = NULL;
818 else
820 lpEnv->Next = lpNewEnv;
821 lpNewEnv->Prev = lpEnv;
823 lpNewEnv->Next = NULL;
824 lpNewEnv->Name = malloc(strlen(lpPortName) + 1);
825 if (lpNewEnv->Name == NULL) {
826 dprintf_env(stddeb, "SetEnvironment() // Error allocating entry name !\n");
827 return 0;
829 strcpy(lpNewEnv->Name, lpPortName);
830 lpNewEnv->Value = malloc(nCount);
831 if (lpNewEnv->Value == NULL) {
832 dprintf_env(stddeb, "SetEnvironment() // Error allocating entry value !\n");
833 return 0;
835 memcpy(lpNewEnv->Value, lpEnviron, nCount);
836 lpNewEnv->wSize = nCount;
837 return nCount;
841 /***********************************************************************
842 * SetEnvironmentVariable32A (KERNEL32.484)
844 BOOL32 SetEnvironmentVariable32A( LPCSTR lpName, LPCSTR lpValue )
846 int rc;
848 rc = SetEnvironment(lpName, lpValue, strlen(lpValue) + 1);
849 return (rc > 0) ? 1 : 0;
853 /***********************************************************************
854 * SetEnvironmentVariable32W (KERNEL32.485)
856 BOOL32 SetEnvironmentVariable32W( LPCWSTR lpName, LPCWSTR lpValue )
858 LPSTR lpAName, lpAValue;
859 BOOL ret;
861 lpAName = STRING32_DupUniToAnsi( lpName );
862 lpAValue = STRING32_DupUniToAnsi ( lpValue );
863 ret = SetEnvironment(lpAName, lpAValue, strlen(lpAValue) + 1);
864 free (lpAName);
865 free (lpAValue);
866 return (ret > 0) ? 1 : 0;
870 /***********************************************************************
871 * GetEnvironment (GDI.134)
873 int GetEnvironment(LPSTR lpPortName, LPSTR lpEnviron, WORD nMaxSiz)
875 WORD nCount;
876 LPENVENTRY lpEnv = lpEnvList;
877 dprintf_env(stddeb, "GetEnvironment('%s', '%s', %d) !\n",
878 lpPortName, lpEnviron, nMaxSiz);
879 while (lpEnv != NULL) {
880 if (lpEnv->Name != NULL && strcmp(lpEnv->Name, lpPortName) == 0) {
881 nCount = MIN(nMaxSiz, lpEnv->wSize);
882 memcpy(lpEnviron, lpEnv->Value, nCount);
883 dprintf_env(stddeb, "GetEnvironment() // found '%s' !\n", lpEnviron);
884 return nCount;
886 lpEnv = lpEnv->Next;
888 dprintf_env(stddeb, "GetEnvironment() // not found !\n");
889 return 0;
892 /***********************************************************************
893 * GetEnvironmentVariableA (KERNEL32.213)
895 DWORD GetEnvironmentVariableA(LPSTR lpName, LPSTR lpValue, DWORD size)
897 return GetEnvironment(lpName, lpValue, size);
900 /***********************************************************************
901 * GetEnvironmentStrings (KERNEL32.210)
903 LPVOID GetEnvironmentStrings(void)
905 int count;
906 LPENVENTRY lpEnv;
907 char *envtable, *envptr;
909 /* Count the total number of bytes we'll need for the string
910 * table. Include the trailing nuls and the final double nul.
912 count = 1;
913 lpEnv = lpEnvList;
914 while(lpEnv != NULL)
916 if(lpEnv->Name != NULL)
918 count += strlen(lpEnv->Name) + 1;
919 count += strlen(lpEnv->Value) + 1;
921 lpEnv = lpEnv->Next;
924 envtable = malloc(count);
925 if(envtable)
927 lpEnv = lpEnvList;
928 envptr = envtable;
930 while(lpEnv != NULL)
932 if(lpEnv->Name != NULL)
934 count = sprintf(envptr, "%s=%s", lpEnv->Name, lpEnv->Value);
935 envptr += count + 1;
937 lpEnv = lpEnv->Next;
939 *envptr = '\0';
942 return envtable;
946 LPVOID GetEnvironmentStringsW(void)
948 int count,len;
949 LPENVENTRY lpEnv;
950 char *envtable, *envptr;
951 WCHAR *wenvtable;
953 /* Count the total number of bytes we'll need for the string
954 * table. Include the trailing nuls and the final double nul.
956 count = 1;
957 lpEnv = lpEnvList;
958 while(lpEnv != NULL)
960 if(lpEnv->Name != NULL)
962 count += strlen(lpEnv->Name) + 1;
963 count += strlen(lpEnv->Value) + 1;
965 lpEnv = lpEnv->Next;
968 len=count;
969 envtable = malloc(count);
970 if(envtable)
972 lpEnv = lpEnvList;
973 envptr = envtable;
975 while(lpEnv != NULL)
977 if(lpEnv->Name != NULL)
979 count = sprintf(envptr, "%s=%s", lpEnv->Name, lpEnv->Value);
980 envptr += count + 1;
982 lpEnv = lpEnv->Next;
984 *envptr = '\0';
987 wenvtable = malloc(2*len);
988 for(count=0;count<len;count++)
989 wenvtable[count]=(WCHAR)envtable[count];
990 free(envtable);
992 return envtable;
995 void FreeEnvironmentStringsA(void *e)
997 free(e);
1000 void FreeEnvironmentStringsW(void* e)
1002 free(e);
1005 /***********************************************************************
1006 * GetTimerResolution (USER.14)
1008 LONG GetTimerResolution(void)
1010 return (1000);
1013 /***********************************************************************
1014 * SystemParametersInfo (USER.483)
1016 BOOL SystemParametersInfo (UINT uAction, UINT uParam, LPVOID lpvParam, UINT fuWinIni)
1018 int timeout, temp;
1019 char buffer[256];
1020 XKeyboardState keyboard_state;
1021 XKeyboardControl keyboard_value;
1024 switch (uAction) {
1025 case SPI_GETBEEP:
1026 XGetKeyboardControl(display, &keyboard_state);
1027 if (keyboard_state.bell_percent == 0)
1028 *(BOOL *) lpvParam = FALSE;
1029 else
1030 *(BOOL *) lpvParam = TRUE;
1031 break;
1033 case SPI_GETBORDER:
1034 *(INT *)lpvParam = GetSystemMetrics( SM_CXFRAME );
1035 break;
1037 case SPI_GETFASTTASKSWITCH:
1038 *(BOOL *) lpvParam = FALSE;
1039 /* FIXME GetProfileInt( "windows", "CoolSwitch", 1 ) */
1040 break;
1042 case SPI_GETGRIDGRANULARITY:
1043 *(INT *) lpvParam = 1;
1044 /* FIXME GetProfileInt( "desktop", "GridGranularity", 1 ) */
1045 break;
1047 case SPI_GETICONTITLEWRAP:
1048 *(BOOL *) lpvParam = FALSE;
1049 /* FIXME GetProfileInt( "desktop", "?", True ) */
1050 break;
1052 case SPI_GETKEYBOARDDELAY:
1053 *(INT *) lpvParam = 1;
1054 /* FIXME */
1055 break;
1057 case SPI_GETKEYBOARDSPEED:
1058 *(WORD *) lpvParam = 30;
1059 /* FIXME */
1060 break;
1062 case SPI_GETMENUDROPALIGNMENT:
1063 *(BOOL *) lpvParam = GetSystemMetrics( SM_MENUDROPALIGNMENT ); /* XXX check this */
1064 break;
1066 case SPI_GETSCREENSAVEACTIVE:
1067 /* FIXME GetProfileInt( "windows", "ScreenSaveActive", 1 ); */
1068 *(BOOL *) lpvParam = FALSE;
1069 break;
1071 case SPI_GETSCREENSAVETIMEOUT:
1072 /* FIXME GetProfileInt( "windows", "ScreenSaveTimeout", 300 ); */
1073 XGetScreenSaver(display, &timeout, &temp,&temp,&temp);
1074 *(INT *) lpvParam = timeout * 1000;
1075 break;
1077 case SPI_ICONHORIZONTALSPACING:
1078 if (lpvParam == NULL)
1079 fprintf(stderr, "SystemParametersInfo: Horizontal icon spacing set to %d\n.", uParam);
1080 else
1081 *(INT *) lpvParam = GetSystemMetrics( SM_CXICONSPACING );
1082 break;
1084 case SPI_ICONVERTICALSPACING:
1085 if (lpvParam == NULL)
1086 fprintf(stderr, "SystemParametersInfo: Vertical icon spacing set to %d\n.", uParam);
1087 else
1088 *(INT *) lpvParam = GetSystemMetrics( SM_CYICONSPACING );
1089 break;
1091 case SPI_SETBEEP:
1092 if (uParam == TRUE)
1093 keyboard_value.bell_percent = -1;
1094 else
1095 keyboard_value.bell_percent = 0;
1096 XChangeKeyboardControl(display, KBBellPercent,
1097 &keyboard_value);
1098 break;
1100 case SPI_SETSCREENSAVEACTIVE:
1101 if (uParam == TRUE)
1102 XActivateScreenSaver(display);
1103 else
1104 XResetScreenSaver(display);
1105 break;
1107 case SPI_SETSCREENSAVETIMEOUT:
1108 XSetScreenSaver(display, uParam, 60, DefaultBlanking,
1109 DefaultExposures);
1110 break;
1112 case SPI_SETDESKWALLPAPER:
1113 return (SetDeskWallPaper((LPSTR) lpvParam));
1114 break;
1116 case SPI_SETDESKPATTERN:
1117 if ((INT) uParam == -1) {
1118 GetProfileString("Desktop", "Pattern",
1119 "170 85 170 85 170 85 170 85",
1120 buffer, sizeof(buffer) );
1121 return (DESKTOP_SetPattern((LPSTR) buffer));
1122 } else
1123 return (DESKTOP_SetPattern((LPSTR) lpvParam));
1124 break;
1126 case SPI_GETICONTITLELOGFONT:
1128 /* FIXME GetProfileString( "?", "?", "?" ) */
1129 LPLOGFONT16 lpLogFont = (LPLOGFONT16)lpvParam;
1130 lpLogFont->lfHeight = 10;
1131 lpLogFont->lfWidth = 0;
1132 lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
1133 lpLogFont->lfWeight = FW_NORMAL;
1134 lpLogFont->lfItalic = lpLogFont->lfStrikeOut = lpLogFont->lfUnderline = FALSE;
1135 lpLogFont->lfCharSet = ANSI_CHARSET;
1136 lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
1137 lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
1138 lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
1139 break;
1141 case SPI_LANGDRIVER:
1142 case SPI_SETBORDER:
1143 case SPI_SETDOUBLECLKHEIGHT:
1144 case SPI_SETDOUBLECLICKTIME:
1145 case SPI_SETDOUBLECLKWIDTH:
1146 case SPI_SETFASTTASKSWITCH:
1147 case SPI_SETKEYBOARDDELAY:
1148 case SPI_SETKEYBOARDSPEED:
1149 fprintf(stderr, "SystemParametersInfo: option %d ignored.\n", uParam);
1150 break;
1152 default:
1153 fprintf(stderr, "SystemParametersInfo: unknown option %d.\n", uParam);
1154 break;
1156 return 1;
1159 /***********************************************************************
1160 * COPY (GDI.250)
1162 void Copy(LPVOID lpSource, LPVOID lpDest, WORD nBytes)
1164 memcpy(lpDest, lpSource, nBytes);
1167 /***********************************************************************
1168 * SWAPMOUSEBUTTON (USER.186)
1170 BOOL SwapMouseButton(BOOL fSwap)
1172 return 0; /* don't swap */
1175 /***********************************************************************
1176 * FileCDR (KERNEL.130)
1178 void FileCDR(FARPROC x)
1180 printf("FileCDR(%8x)\n", (int) x);
1183 /***********************************************************************
1184 * GetWinDebugInfo (KERNEL.355)
1186 BOOL GetWinDebugInfo(WINDEBUGINFO *lpwdi, UINT flags)
1188 printf("GetWinDebugInfo(%8lx,%d) stub returning 0\n", (unsigned long)lpwdi, flags);
1189 /* 0 means not in debugging mode/version */
1190 /* Can this type of debugging be used in wine ? */
1191 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
1192 return 0;
1195 /***********************************************************************
1196 * GetWinDebugInfo (KERNEL.355)
1198 BOOL SetWinDebugInfo(WINDEBUGINFO *lpwdi)
1200 printf("SetWinDebugInfo(%8lx) stub returning 0\n", (unsigned long)lpwdi);
1201 /* 0 means not in debugging mode/version */
1202 /* Can this type of debugging be used in wine ? */
1203 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
1204 return 0;