4 * Copyright 1994 Alexandre Julliard
13 #ifdef MALLOC_DEBUGGING
17 #include <X11/Xresource.h>
18 #include <X11/Xutil.h>
19 #include <X11/cursorfont.h>
27 #include "registers.h"
31 #define DEBUG_DEFINE_VARIABLES
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
[] =
74 #define WINE_CLASS "Wine" /* Class name for resources */
76 typedef struct tagENVENTRY
{
80 struct tagENVENTRY
*Prev
;
81 struct tagENVENTRY
*Next
;
82 } ENVENTRY
, *LPENVENTRY
;
84 LPENVENTRY lpEnvList
= NULL
;
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) */
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 */
106 FALSE
, /* AllowReadOnly */
107 MODE_ENHANCED
, /* Enhanced mode */
108 FALSE
, /* IPC enabled */
110 DEFAULT_LANG
, /* Default language */
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]))
143 "Usage: %s [options] program_name [arguments]\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 /***********************************************************************
171 static void MAIN_Usage( char *name
)
173 fprintf( stderr
, USAGE
, name
);
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
[] )
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;
200 /***********************************************************************
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
;
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
);
226 /***********************************************************************
229 * Turns specific debug messages on or off, according to "options".
230 * Returns TRUE if parsing was successful
234 BOOL
ParseDebugOptions(char *options
)
237 if (strlen(options
)<3)
241 if ((*options
!='+')&&(*options
!='-'))
243 if (strchr(options
,','))
244 l
=strchr(options
,',')-options
;
247 if (!lstrncmpi32A(options
+1,"all",l
-1))
250 for (i
=0;i
<sizeof(debug_msg_enabled
)/sizeof(short);i
++)
251 debug_msg_enabled
[i
]=(*options
=='+');
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
=='+');
262 if (i
==sizeof(debug_msg_enabled
)/sizeof(short))
267 while((*options
==',')&&(*(++options
)));
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;
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" );
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
;
310 fprintf(stderr
, "Invalid mode '%s' specified.\n", arg
);
311 fprintf(stderr
, "Valid modes are: 'standard', 'enhanced' (default).\n");
316 /**********************************************************************
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 /***********************************************************************
361 * Parse command line options and open display.
363 static void MAIN_ParseOptions( int *argc
, char *argv
[] )
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
);
375 /* Need to assemble command line and pass it to WinMain */
377 if (*argc
< 2 || lstrcmpi32A(argv
[1], "-h") == 0)
378 MAIN_Usage( argv
[0] );
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)" );
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
))
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
);
422 if (MAIN_GetResource( db
, ".debugoptions", &value
))
423 ParseDebugOptions((char*)value
.addr
);
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",
433 if (ParseDebugOptions((char*)value
.addr
)==FALSE
)
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");
450 if(MAIN_GetResource( db
, ".dll", &value
))
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");
462 fprintf(stderr
,"-dll not supported in libwine\n");
466 if(MAIN_GetResource( db
, ".winver", &value
))
467 MAIN_ParseVersion( (char*)value
.addr
);
471 /***********************************************************************
474 static void MAIN_CreateDesktop( int argc
, char *argv
[] )
477 unsigned int width
= 640, height
= 480; /* Default size = 640x480 */
478 char *name
= "Wine desktop";
479 XSizeHints
*size_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
);
489 screenHeight
= height
;
493 win_attr
.event_mask
= ExposureMask
| KeyPressMask
| KeyReleaseMask
|
494 PointerMotionMask
| ButtonPressMask
|
495 ButtonReleaseMask
| EnterWindowMask
|
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" );
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 );
534 XFree( class_hints
);
538 XMapWindow( display
, rootWindow
);
542 XKeyboardState keyboard_state
;
544 /***********************************************************************
547 static void MAIN_SaveSetup(void)
549 XGetKeyboardControl(display
, &keyboard_state
);
552 /***********************************************************************
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)
576 /***********************************************************************
579 #if defined(WINELIB) && defined(WINELIBDLL)
580 int _wine_main (int argc
, char *argv
[])
582 int main( int argc
, char *argv
[] )
590 extern int _WinMain(int argc
, char **argv
);
592 #ifdef MALLOC_DEBUGGING
596 if (!(trace
= getenv("MALLOC_TRACE")))
598 fprintf( stderr
, "MALLOC_TRACE not set. No trace generated\n" );
602 fprintf( stderr
, "malloc trace goes to %s\n", trace
);
610 setlocale(LC_CTYPE
,"");
611 gettimeofday( &tv
, NULL
);
612 MSG_WineStartTicks
= (tv
.tv_sec
* 1000) + (tv
.tv_usec
/ 1000);
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;
627 if (i
>= depth_count
)
629 fprintf( stderr
, "%s: Depth %d not supported on this screen.\n",
630 Options
.programName
, screenDepth
);
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
);
640 atexit(called_at_exit
);
642 ret_val
= _WinMain( argc
, argv
);
648 /***********************************************************************
649 * MessageBeep (USER.104)
651 void MessageBeep(WORD i
)
657 /***********************************************************************
660 BOOL32
Beep( DWORD dwFreq
, DWORD dwDur
)
662 /* dwFreq and dwDur are ignored by Win95 */
668 /***********************************************************************
669 * GetVersion (KERNEL.3)
671 LONG
GetVersion(void)
673 if (getVersion16
) return getVersion16
;
674 return MAKELONG( WINVERSION
, WINDOSVER
);
678 /***********************************************************************
681 LONG
GetVersion32(void)
683 if (getVersion32
) return getVersion32
;
684 return MAKELONG( 4, DOSVERSION
);
688 /***********************************************************************
691 BOOL32
GetVersionEx32A(OSVERSIONINFO32A
*v
)
693 if(v
->dwOSVersionInfoSize
!=sizeof(OSVERSIONINFO32A
))
695 fprintf(stddeb
,"wrong OSVERSIONINFO size from app");
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");
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
);
717 /***********************************************************************
720 BOOL32
GetVersionEx32W(OSVERSIONINFO32W
*v
)
723 if(v
->dwOSVersionInfoSize
!=sizeof(OSVERSIONINFO32W
))
725 fprintf(stddeb
,"wrong OSVERSIONINFO size from app");
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
);
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
};
748 /* There doesn't seem to be any Pentium flag. */
750 long cpuflag
= cpuflags
[MIN (runtime_cpu (), 4)];
752 long cpuflag
= cpuflags
[4];
755 switch(Options
.mode
) {
757 result
= (WF_STANDARD
| cpuflag
| WF_PMODE
| WF_80x87
);
761 result
= (WF_ENHANCED
| cpuflag
| WF_PMODE
| WF_80x87
| WF_PAGING
);
765 fprintf(stderr
, "Unknown mode set? This shouldn't happen. Check GetWinFlags()!\n");
772 /***********************************************************************
773 * SetEnvironment (GDI.132)
775 int SetEnvironment(LPCSTR lpPortName
, LPCSTR lpEnviron
, WORD nCount
)
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
;
790 dprintf_env(stddeb
, "SetEnvironment() // entry deleted !\n");
794 lpEnv
->Value
= malloc(nCount
);
795 if (lpEnv
->Value
== NULL
) {
796 dprintf_env(stddeb
, "SetEnvironment() // Error allocating entry value !\n");
799 memcpy(lpEnv
->Value
, lpEnviron
, nCount
);
800 lpEnv
->wSize
= nCount
;
801 dprintf_env(stddeb
, "SetEnvironment() // entry modified !\n");
804 if (lpEnv
->Next
== NULL
) break;
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");
814 if (lpEnvList
== NULL
) {
815 lpEnvList
= lpNewEnv
;
816 lpNewEnv
->Prev
= NULL
;
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");
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");
835 memcpy(lpNewEnv
->Value
, lpEnviron
, nCount
);
836 lpNewEnv
->wSize
= nCount
;
841 /***********************************************************************
842 * SetEnvironmentVariable32A (KERNEL32.484)
844 BOOL32
SetEnvironmentVariable32A( LPCSTR lpName
, LPCSTR lpValue
)
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
;
861 lpAName
= STRING32_DupUniToAnsi( lpName
);
862 lpAValue
= STRING32_DupUniToAnsi ( lpValue
);
863 ret
= SetEnvironment(lpAName
, lpAValue
, strlen(lpAValue
) + 1);
866 return (ret
> 0) ? 1 : 0;
870 /***********************************************************************
871 * GetEnvironment (GDI.134)
873 int GetEnvironment(LPSTR lpPortName
, LPSTR lpEnviron
, WORD nMaxSiz
)
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
);
888 dprintf_env(stddeb
, "GetEnvironment() // not found !\n");
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)
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.
916 if(lpEnv
->Name
!= NULL
)
918 count
+= strlen(lpEnv
->Name
) + 1;
919 count
+= strlen(lpEnv
->Value
) + 1;
924 envtable
= malloc(count
);
932 if(lpEnv
->Name
!= NULL
)
934 count
= sprintf(envptr
, "%s=%s", lpEnv
->Name
, lpEnv
->Value
);
946 LPVOID
GetEnvironmentStringsW(void)
950 char *envtable
, *envptr
;
953 /* Count the total number of bytes we'll need for the string
954 * table. Include the trailing nuls and the final double nul.
960 if(lpEnv
->Name
!= NULL
)
962 count
+= strlen(lpEnv
->Name
) + 1;
963 count
+= strlen(lpEnv
->Value
) + 1;
969 envtable
= malloc(count
);
977 if(lpEnv
->Name
!= NULL
)
979 count
= sprintf(envptr
, "%s=%s", lpEnv
->Name
, lpEnv
->Value
);
987 wenvtable
= malloc(2*len
);
988 for(count
=0;count
<len
;count
++)
989 wenvtable
[count
]=(WCHAR
)envtable
[count
];
995 void FreeEnvironmentStringsA(void *e
)
1000 void FreeEnvironmentStringsW(void* e
)
1005 /***********************************************************************
1006 * GetTimerResolution (USER.14)
1008 LONG
GetTimerResolution(void)
1013 /***********************************************************************
1014 * SystemParametersInfo (USER.483)
1016 BOOL
SystemParametersInfo (UINT uAction
, UINT uParam
, LPVOID lpvParam
, UINT fuWinIni
)
1020 XKeyboardState keyboard_state
;
1021 XKeyboardControl keyboard_value
;
1026 XGetKeyboardControl(display
, &keyboard_state
);
1027 if (keyboard_state
.bell_percent
== 0)
1028 *(BOOL
*) lpvParam
= FALSE
;
1030 *(BOOL
*) lpvParam
= TRUE
;
1034 *(INT
*)lpvParam
= GetSystemMetrics( SM_CXFRAME
);
1037 case SPI_GETFASTTASKSWITCH
:
1038 *(BOOL
*) lpvParam
= FALSE
;
1039 /* FIXME GetProfileInt( "windows", "CoolSwitch", 1 ) */
1042 case SPI_GETGRIDGRANULARITY
:
1043 *(INT
*) lpvParam
= 1;
1044 /* FIXME GetProfileInt( "desktop", "GridGranularity", 1 ) */
1047 case SPI_GETICONTITLEWRAP
:
1048 *(BOOL
*) lpvParam
= FALSE
;
1049 /* FIXME GetProfileInt( "desktop", "?", True ) */
1052 case SPI_GETKEYBOARDDELAY
:
1053 *(INT
*) lpvParam
= 1;
1057 case SPI_GETKEYBOARDSPEED
:
1058 *(WORD
*) lpvParam
= 30;
1062 case SPI_GETMENUDROPALIGNMENT
:
1063 *(BOOL
*) lpvParam
= GetSystemMetrics( SM_MENUDROPALIGNMENT
); /* XXX check this */
1066 case SPI_GETSCREENSAVEACTIVE
:
1067 /* FIXME GetProfileInt( "windows", "ScreenSaveActive", 1 ); */
1068 *(BOOL
*) lpvParam
= FALSE
;
1071 case SPI_GETSCREENSAVETIMEOUT
:
1072 /* FIXME GetProfileInt( "windows", "ScreenSaveTimeout", 300 ); */
1073 XGetScreenSaver(display
, &timeout
, &temp
,&temp
,&temp
);
1074 *(INT
*) lpvParam
= timeout
* 1000;
1077 case SPI_ICONHORIZONTALSPACING
:
1078 if (lpvParam
== NULL
)
1079 fprintf(stderr
, "SystemParametersInfo: Horizontal icon spacing set to %d\n.", uParam
);
1081 *(INT
*) lpvParam
= GetSystemMetrics( SM_CXICONSPACING
);
1084 case SPI_ICONVERTICALSPACING
:
1085 if (lpvParam
== NULL
)
1086 fprintf(stderr
, "SystemParametersInfo: Vertical icon spacing set to %d\n.", uParam
);
1088 *(INT
*) lpvParam
= GetSystemMetrics( SM_CYICONSPACING
);
1093 keyboard_value
.bell_percent
= -1;
1095 keyboard_value
.bell_percent
= 0;
1096 XChangeKeyboardControl(display
, KBBellPercent
,
1100 case SPI_SETSCREENSAVEACTIVE
:
1102 XActivateScreenSaver(display
);
1104 XResetScreenSaver(display
);
1107 case SPI_SETSCREENSAVETIMEOUT
:
1108 XSetScreenSaver(display
, uParam
, 60, DefaultBlanking
,
1112 case SPI_SETDESKWALLPAPER
:
1113 return (SetDeskWallPaper((LPSTR
) lpvParam
));
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
));
1123 return (DESKTOP_SetPattern((LPSTR
) lpvParam
));
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
;
1141 case SPI_LANGDRIVER
:
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
);
1153 fprintf(stderr
, "SystemParametersInfo: unknown option %d.\n", uParam
);
1159 /***********************************************************************
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 */
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 */