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 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 */
74 WORD WINE_LanguageId
= 0;
76 #define WINE_CLASS "Wine" /* Class name for resources */
78 typedef struct tagENVENTRY
{
82 struct tagENVENTRY
*Prev
;
83 struct tagENVENTRY
*Next
;
84 } ENVENTRY
, *LPENVENTRY
;
86 LPENVENTRY lpEnvList
= NULL
;
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) */
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 */
108 FALSE
, /* AllowReadOnly */
109 MODE_ENHANCED
, /* Enhanced mode */
110 FALSE
, /* IPC enabled */
112 DEFAULT_LANG
, /* Default language */
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]))
147 "Usage: %s [options] program_name [arguments]\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 /***********************************************************************
176 static void MAIN_Usage( char *name
)
178 fprintf( stderr
, USAGE
, name
);
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
[] )
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;
205 /***********************************************************************
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
;
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
);
231 /***********************************************************************
234 * Turns specific debug messages on or off, according to "options".
235 * Returns TRUE if parsing was successful
239 BOOL
ParseDebugOptions(char *options
)
242 if (strlen(options
)<3)
246 if ((*options
!='+')&&(*options
!='-'))
248 if (strchr(options
,','))
249 l
=strchr(options
,',')-options
;
252 if (!lstrncmpi32A(options
+1,"all",l
-1))
255 for (i
=0;i
<sizeof(debug_msg_enabled
)/sizeof(short);i
++)
256 debug_msg_enabled
[i
]=(*options
=='+');
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
=='+');
267 if (i
==sizeof(debug_msg_enabled
)/sizeof(short))
272 while((*options
==',')&&(*(++options
)));
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 */
294 if (!lstrcmpi32A( p
->name
, arg
))
296 WINE_LanguageId
= p
->langid
;
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" );
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
;
319 fprintf(stderr
, "Invalid mode '%s' specified.\n", arg
);
320 fprintf(stderr
, "Valid modes are: 'standard', 'enhanced' (default).\n");
325 /**********************************************************************
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 /***********************************************************************
370 * Parse command line options and open display.
372 static void MAIN_ParseOptions( int *argc
, char *argv
[] )
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
);
384 /* Need to assemble command line and pass it to WinMain */
386 if (*argc
< 2 || lstrcmpi32A(argv
[1], "-h") == 0)
387 MAIN_Usage( argv
[0] );
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)" );
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
))
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
);
433 if (MAIN_GetResource( db
, ".debugoptions", &value
))
434 ParseDebugOptions((char*)value
.addr
);
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",
444 if (ParseDebugOptions((char*)value
.addr
)==FALSE
)
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");
461 if(MAIN_GetResource( db
, ".dll", &value
))
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");
473 fprintf(stderr
,"-dll not supported in libwine\n");
477 if(MAIN_GetResource( db
, ".winver", &value
))
478 MAIN_ParseVersion( (char*)value
.addr
);
482 /***********************************************************************
485 static void MAIN_CreateDesktop( int argc
, char *argv
[] )
488 unsigned int width
= 640, height
= 480; /* Default size = 640x480 */
489 char *name
= "Wine desktop";
490 XSizeHints
*size_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
);
500 screenHeight
= height
;
504 win_attr
.event_mask
= ExposureMask
| KeyPressMask
| KeyReleaseMask
|
505 PointerMotionMask
| ButtonPressMask
|
506 ButtonReleaseMask
| EnterWindowMask
|
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" );
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 );
545 XFree( class_hints
);
549 XMapWindow( display
, rootWindow
);
553 XKeyboardState keyboard_state
;
555 /***********************************************************************
558 static void MAIN_SaveSetup(void)
560 XGetKeyboardControl(display
, &keyboard_state
);
563 /***********************************************************************
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)
587 /***********************************************************************
590 #if defined(WINELIB) && defined(WINELIBDLL)
591 int _wine_main (int argc
, char *argv
[])
593 int main( int argc
, char *argv
[] )
601 extern int _WinMain(int argc
, char **argv
);
603 #ifdef MALLOC_DEBUGGING
607 if (!(trace
= getenv("MALLOC_TRACE")))
609 fprintf( stderr
, "MALLOC_TRACE not set. No trace generated\n" );
613 fprintf( stderr
, "malloc trace goes to %s\n", trace
);
621 setlocale(LC_CTYPE
,"");
622 gettimeofday( &tv
, NULL
);
623 MSG_WineStartTicks
= (tv
.tv_sec
* 1000) + (tv
.tv_usec
/ 1000);
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
);
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;
645 if (i
>= depth_count
)
647 fprintf( stderr
, "%s: Depth %d not supported on this screen.\n",
648 Options
.programName
, screenDepth
);
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
);
658 atexit(called_at_exit
);
660 ret_val
= _WinMain( argc
, argv
);
666 /***********************************************************************
667 * MessageBeep (USER.104)
669 void MessageBeep(WORD i
)
675 /***********************************************************************
678 BOOL32
Beep( DWORD dwFreq
, DWORD dwDur
)
680 /* dwFreq and dwDur are ignored by Win95 */
686 /***********************************************************************
687 * GetVersion16 (KERNEL.3)
689 LONG
GetVersion16(void)
691 if (getVersion16
) return getVersion16
;
692 return MAKELONG( WINVERSION
, WINDOSVER
);
696 /***********************************************************************
699 LONG
GetVersion32(void)
701 if (getVersion32
) return getVersion32
;
702 return MAKELONG( 4, DOSVERSION
);
706 /***********************************************************************
709 BOOL32
GetVersionEx32A(OSVERSIONINFO32A
*v
)
711 if(v
->dwOSVersionInfoSize
!=sizeof(OSVERSIONINFO32A
))
713 fprintf(stddeb
,"wrong OSVERSIONINFO size from app");
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");
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
);
735 /***********************************************************************
738 BOOL32
GetVersionEx32W(OSVERSIONINFO32W
*v
)
741 if(v
->dwOSVersionInfoSize
!=sizeof(OSVERSIONINFO32W
))
743 fprintf(stddeb
,"wrong OSVERSIONINFO size from app");
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
);
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
};
766 /* There doesn't seem to be any Pentium flag. */
768 long cpuflag
= cpuflags
[MIN (runtime_cpu (), 4)];
770 long cpuflag
= cpuflags
[4];
773 switch(Options
.mode
) {
775 result
= (WF_STANDARD
| cpuflag
| WF_PMODE
| WF_80x87
);
779 result
= (WF_ENHANCED
| cpuflag
| WF_PMODE
| WF_80x87
| WF_PAGING
);
783 fprintf(stderr
, "Unknown mode set? This shouldn't happen. Check GetWinFlags()!\n");
790 /***********************************************************************
791 * SetEnvironment (GDI.132)
793 int SetEnvironment(LPCSTR lpPortName
, LPCSTR lpEnviron
, WORD nCount
)
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
;
808 dprintf_env(stddeb
, "SetEnvironment() // entry deleted !\n");
812 lpEnv
->Value
= malloc(nCount
);
813 if (lpEnv
->Value
== NULL
) {
814 dprintf_env(stddeb
, "SetEnvironment() // Error allocating entry value !\n");
817 memcpy(lpEnv
->Value
, lpEnviron
, nCount
);
818 lpEnv
->wSize
= nCount
;
819 dprintf_env(stddeb
, "SetEnvironment() // entry modified !\n");
822 if (lpEnv
->Next
== NULL
) break;
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");
832 if (lpEnvList
== NULL
) {
833 lpEnvList
= lpNewEnv
;
834 lpNewEnv
->Prev
= NULL
;
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");
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");
853 memcpy(lpNewEnv
->Value
, lpEnviron
, nCount
);
854 lpNewEnv
->wSize
= nCount
;
859 /***********************************************************************
860 * SetEnvironmentVariable32A (KERNEL32.484)
862 BOOL32
SetEnvironmentVariable32A( LPCSTR lpName
, LPCSTR lpValue
)
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
;
879 lpAName
= STRING32_DupUniToAnsi( lpName
);
880 lpAValue
= STRING32_DupUniToAnsi ( lpValue
);
881 ret
= SetEnvironment(lpAName
, lpAValue
, strlen(lpAValue
) + 1);
884 return (ret
> 0) ? 1 : 0;
888 /***********************************************************************
889 * GetEnvironment (GDI.134)
891 int GetEnvironment(LPSTR lpPortName
, LPSTR lpEnviron
, WORD nMaxSiz
)
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
);
906 dprintf_env(stddeb
, "GetEnvironment() // not found !\n");
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)
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.
934 if(lpEnv
->Name
!= NULL
)
936 count
+= strlen(lpEnv
->Name
) + 1;
937 count
+= strlen(lpEnv
->Value
) + 1;
942 envtable
= malloc(count
);
950 if(lpEnv
->Name
!= NULL
)
952 count
= sprintf(envptr
, "%s=%s", lpEnv
->Name
, lpEnv
->Value
);
964 LPVOID
GetEnvironmentStringsW(void)
968 char *envtable
, *envptr
;
971 /* Count the total number of bytes we'll need for the string
972 * table. Include the trailing nuls and the final double nul.
978 if(lpEnv
->Name
!= NULL
)
980 count
+= strlen(lpEnv
->Name
) + 1;
981 count
+= strlen(lpEnv
->Value
) + 1;
987 envtable
= malloc(count
);
995 if(lpEnv
->Name
!= NULL
)
997 count
= sprintf(envptr
, "%s=%s", lpEnv
->Name
, lpEnv
->Value
);
1000 lpEnv
= lpEnv
->Next
;
1005 wenvtable
= malloc(2*len
);
1006 for(count
=0;count
<len
;count
++)
1007 wenvtable
[count
]=(WCHAR
)envtable
[count
];
1013 void FreeEnvironmentStringsA(void *e
)
1018 void FreeEnvironmentStringsW(void* e
)
1023 /***********************************************************************
1024 * GetTimerResolution (USER.14)
1026 LONG
GetTimerResolution(void)
1031 /***********************************************************************
1032 * SystemParametersInfo (USER.483)
1034 BOOL
SystemParametersInfo (UINT uAction
, UINT uParam
, LPVOID lpvParam
, UINT fuWinIni
)
1038 XKeyboardState keyboard_state
;
1039 XKeyboardControl keyboard_value
;
1044 XGetKeyboardControl(display
, &keyboard_state
);
1045 if (keyboard_state
.bell_percent
== 0)
1046 *(BOOL
*) lpvParam
= FALSE
;
1048 *(BOOL
*) lpvParam
= TRUE
;
1052 *(INT
*)lpvParam
= GetSystemMetrics( SM_CXFRAME
);
1055 case SPI_GETFASTTASKSWITCH
:
1056 *(BOOL
*) lpvParam
= FALSE
;
1057 /* FIXME GetProfileInt( "windows", "CoolSwitch", 1 ) */
1060 case SPI_GETGRIDGRANULARITY
:
1061 *(INT
*) lpvParam
= 1;
1062 /* FIXME GetProfileInt( "desktop", "GridGranularity", 1 ) */
1065 case SPI_GETICONTITLEWRAP
:
1066 *(BOOL
*) lpvParam
= FALSE
;
1067 /* FIXME GetProfileInt( "desktop", "?", True ) */
1070 case SPI_GETKEYBOARDDELAY
:
1071 *(INT
*) lpvParam
= 1;
1075 case SPI_GETKEYBOARDSPEED
:
1076 *(WORD
*) lpvParam
= 30;
1080 case SPI_GETMENUDROPALIGNMENT
:
1081 *(BOOL
*) lpvParam
= GetSystemMetrics( SM_MENUDROPALIGNMENT
); /* XXX check this */
1084 case SPI_GETSCREENSAVEACTIVE
:
1085 /* FIXME GetProfileInt( "windows", "ScreenSaveActive", 1 ); */
1086 *(BOOL
*) lpvParam
= FALSE
;
1089 case SPI_GETSCREENSAVETIMEOUT
:
1090 /* FIXME GetProfileInt( "windows", "ScreenSaveTimeout", 300 ); */
1091 XGetScreenSaver(display
, &timeout
, &temp
,&temp
,&temp
);
1092 *(INT
*) lpvParam
= timeout
* 1000;
1095 case SPI_ICONHORIZONTALSPACING
:
1096 if (lpvParam
== NULL
)
1097 fprintf(stderr
, "SystemParametersInfo: Horizontal icon spacing set to %d\n.", uParam
);
1099 *(INT
*) lpvParam
= GetSystemMetrics( SM_CXICONSPACING
);
1102 case SPI_ICONVERTICALSPACING
:
1103 if (lpvParam
== NULL
)
1104 fprintf(stderr
, "SystemParametersInfo: Vertical icon spacing set to %d\n.", uParam
);
1106 *(INT
*) lpvParam
= GetSystemMetrics( SM_CYICONSPACING
);
1111 keyboard_value
.bell_percent
= -1;
1113 keyboard_value
.bell_percent
= 0;
1114 XChangeKeyboardControl(display
, KBBellPercent
,
1118 case SPI_SETSCREENSAVEACTIVE
:
1120 XActivateScreenSaver(display
);
1122 XResetScreenSaver(display
);
1125 case SPI_SETSCREENSAVETIMEOUT
:
1126 XSetScreenSaver(display
, uParam
, 60, DefaultBlanking
,
1130 case SPI_SETDESKWALLPAPER
:
1131 return (SetDeskWallPaper((LPSTR
) lpvParam
));
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
));
1141 return (DESKTOP_SetPattern((LPSTR
) lpvParam
));
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
;
1159 case SPI_LANGDRIVER
:
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
);
1171 fprintf(stderr
, "SystemParametersInfo: unknown option %d.\n", uParam
);
1177 /***********************************************************************
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 */
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 */