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 */
115 FALSE
/* Perfect graphics */
119 static XrmOptionDescRec optionsTable
[] =
121 { "-backingstore", ".backingstore", XrmoptionNoArg
, (caddr_t
)"on" },
122 { "-desktop", ".desktop", XrmoptionSepArg
, (caddr_t
)NULL
},
123 { "-depth", ".depth", XrmoptionSepArg
, (caddr_t
)NULL
},
124 { "-display", ".display", XrmoptionSepArg
, (caddr_t
)NULL
},
125 { "-iconic", ".iconic", XrmoptionNoArg
, (caddr_t
)"on" },
126 { "-ipc", ".ipc", XrmoptionNoArg
, (caddr_t
)"off"},
127 { "-language", ".language", XrmoptionSepArg
, (caddr_t
)"En" },
128 { "-name", ".name", XrmoptionSepArg
, (caddr_t
)NULL
},
129 { "-perfect", ".perfect", XrmoptionNoArg
, (caddr_t
)"on" },
130 { "-privatemap", ".privatemap", XrmoptionNoArg
, (caddr_t
)"on" },
131 { "-fixedmap", ".fixedmap", XrmoptionNoArg
, (caddr_t
)"on" },
132 { "-synchronous", ".synchronous", XrmoptionNoArg
, (caddr_t
)"on" },
133 { "-debug", ".debug", XrmoptionNoArg
, (caddr_t
)"on" },
134 { "-debugmsg", ".debugmsg", XrmoptionSepArg
, (caddr_t
)NULL
},
135 { "-dll", ".dll", XrmoptionSepArg
, (caddr_t
)NULL
},
136 { "-allowreadonly", ".allowreadonly", XrmoptionNoArg
, (caddr_t
)"on" },
137 { "-mode", ".mode", XrmoptionSepArg
, (caddr_t
)NULL
},
138 { "-managed", ".managed", XrmoptionNoArg
, (caddr_t
)"off"},
139 { "-winver", ".winver", XrmoptionSepArg
, (caddr_t
)NULL
}
142 #define NB_OPTIONS (sizeof(optionsTable) / sizeof(optionsTable[0]))
145 "Usage: %s [options] program_name [arguments]\n" \
148 " -allowreadonly Read only files may be opened in write mode\n" \
149 " -backingstore Turn on backing store\n" \
150 " -debug Enter debugger before starting application\n" \
151 " -debugmsg name Turn debugging-messages on or off\n" \
152 " -depth n Change the depth to use for multiple-depth screens\n" \
153 " -desktop geom Use a desktop window of the given geometry\n" \
154 " -display name Use the specified display\n" \
155 " -dll name Enable or disable built-in DLLs\n" \
156 " -fixedmap Use a \"standard\" color map\n" \
157 " -iconic Start as an icon\n" \
158 " -ipc Enable IPC facilities\n" \
159 " -language xx Set the language (one of En,Es,De,No,Fr,Fi,Da,Cz,Eo,It,Ko)\n" \
160 " -managed Allow the window manager to manage created windows\n" \
161 " -mode mode Start Wine in a particular mode (standard or enhanced)\n" \
162 " -name name Set the application name\n" \
163 " -perfect Favor correctness over speed for graphical operations\n" \
164 " -privatemap Use a private color map\n" \
165 " -synchronous Turn on synchronous display mode\n" \
166 " -winver Version to imitate (one of win31,win95,nt351)\n"
170 /***********************************************************************
174 static void MAIN_Usage( char *name
)
176 fprintf( stderr
, USAGE
, name
);
182 /***********************************************************************
183 * MAIN_GetProgramName
185 * Get the program name. The name is specified by (in order of precedence):
186 * - the option '-name'.
187 * - the environment variable 'WINE_NAME'.
188 * - the last component of argv[0].
190 static char *MAIN_GetProgramName( int argc
, char *argv
[] )
195 for (i
= 1; i
< argc
-1; i
++)
196 if (!strcmp( argv
[i
], "-name" )) return argv
[i
+1];
197 if ((p
= getenv( "WINE_NAME" )) != NULL
) return p
;
198 if ((p
= strrchr( argv
[0], '/' )) != NULL
) return p
+1;
203 /***********************************************************************
206 * Fetch the value of resource 'name' using the correct instance name.
207 * 'name' must begin with '.' or '*'
209 static int MAIN_GetResource( XrmDatabase db
, char *name
, XrmValue
*value
)
211 char *buff_instance
, *buff_class
;
215 buff_instance
= (char *)xmalloc(strlen(Options
.programName
)+strlen(name
)+1);
216 buff_class
= (char *)xmalloc( strlen(WINE_CLASS
) + strlen(name
) + 1 );
218 strcpy( buff_instance
, Options
.programName
);
219 strcat( buff_instance
, name
);
220 strcpy( buff_class
, WINE_CLASS
);
221 strcat( buff_class
, name
);
222 retval
= XrmGetResource( db
, buff_instance
, buff_class
, &dummy
, value
);
223 free( buff_instance
);
229 /***********************************************************************
232 * Turns specific debug messages on or off, according to "options".
233 * Returns TRUE if parsing was successful
237 BOOL
ParseDebugOptions(char *options
)
240 if (strlen(options
)<3)
244 if ((*options
!='+')&&(*options
!='-'))
246 if (strchr(options
,','))
247 l
=strchr(options
,',')-options
;
250 if (!lstrncmpi32A(options
+1,"all",l
-1))
253 for (i
=0;i
<sizeof(debug_msg_enabled
)/sizeof(short);i
++)
254 debug_msg_enabled
[i
]=(*options
=='+');
259 for (i
=0;i
<sizeof(debug_msg_enabled
)/sizeof(short);i
++)
260 if (debug_msg_name
&& (!lstrncmpi32A(options
+1,debug_msg_name
[i
],l
-1)))
262 debug_msg_enabled
[i
]=(*options
=='+');
265 if (i
==sizeof(debug_msg_enabled
)/sizeof(short))
270 while((*options
==',')&&(*(++options
)));
280 /***********************************************************************
281 * MAIN_ParseLanguageOption
283 * Parse -language option.
285 static void MAIN_ParseLanguageOption( char *arg
)
287 const char **p
= langNames
;
289 Options
.language
= LANG_En
; /* First language */
290 for (p
= langNames
; *p
; p
++)
292 if (!lstrcmpi32A( *p
, arg
)) return;
295 fprintf( stderr
, "Invalid language specified '%s'. Supported languages are: ", arg
);
296 for (p
= langNames
; *p
; p
++) fprintf( stderr
, "%s ", *p
);
297 fprintf( stderr
, "\n" );
302 /***********************************************************************
303 * MAIN_ParseModeOption
305 * Parse -mode option.
307 static void MAIN_ParseModeOption( char *arg
)
309 if (!lstrcmpi32A("enhanced", arg
)) Options
.mode
= MODE_ENHANCED
;
310 else if (!lstrcmpi32A("standard", arg
)) Options
.mode
= MODE_STANDARD
;
313 fprintf(stderr
, "Invalid mode '%s' specified.\n", arg
);
314 fprintf(stderr
, "Valid modes are: 'standard', 'enhanced' (default).\n");
319 /**********************************************************************
322 static void MAIN_ParseVersion( char *arg
)
324 /* If you add any other options,
325 verify the values you return on the real thing */
326 if(strcmp(arg
,"win31")==0)
328 getVersion16
= 0x06160A03;
329 /* FIXME: My Win32s installation failed to execute the
330 MSVC 4 test program. So check these values */
331 getVersion32
= 0x80000A03;
332 getVersionEx
.dwMajorVersion
=3;
333 getVersionEx
.dwMinorVersion
=10;
334 getVersionEx
.dwBuildNumber
=0;
335 getVersionEx
.dwPlatformId
=VER_PLATFORM_WIN32s
;
336 strcpy(getVersionEx
.szCSDVersion
,"Win32s 1.3");
338 else if(strcmp(arg
, "win95")==0)
340 getVersion16
= 0x07005F03;
341 getVersion32
= 0xC0000004;
342 getVersionEx
.dwMajorVersion
=4;
343 getVersionEx
.dwMinorVersion
=0;
344 getVersionEx
.dwBuildNumber
=0x40003B6;
345 getVersionEx
.dwPlatformId
=VER_PLATFORM_WIN32_WINDOWS
;
346 strcpy(getVersionEx
.szCSDVersion
,"");
348 else if(strcmp(arg
, "nt351")==0)
350 getVersion16
= 0x05000A03;
351 getVersion32
= 0x04213303;
352 getVersionEx
.dwMajorVersion
=3;
353 getVersionEx
.dwMinorVersion
=51;
354 getVersionEx
.dwBuildNumber
=0x421;
355 getVersionEx
.dwPlatformId
=VER_PLATFORM_WIN32_NT
;
356 strcpy(getVersionEx
.szCSDVersion
,"Service Pack 2");
358 else fprintf(stderr
, "Unknown winver system code - ignored\n");
361 /***********************************************************************
364 * Parse command line options and open display.
366 static void MAIN_ParseOptions( int *argc
, char *argv
[] )
370 XrmDatabase db
= XrmGetFileDatabase("/usr/lib/X11/app-defaults/Wine");
372 /* Parse command line */
373 Options
.programName
= MAIN_GetProgramName( *argc
, argv
);
374 XrmParseCommand( &db
, optionsTable
, NB_OPTIONS
,
375 Options
.programName
, argc
, argv
);
378 /* Need to assemble command line and pass it to WinMain */
380 if (*argc
< 2 || lstrcmpi32A(argv
[1], "-h") == 0)
381 MAIN_Usage( argv
[0] );
386 if (MAIN_GetResource( db
, ".display", &value
)) display_name
= value
.addr
;
387 else display_name
= NULL
;
389 if (!(display
= XOpenDisplay( display_name
)))
391 fprintf( stderr
, "%s: Can't open display: %s\n",
392 argv
[0], display_name
? display_name
: "(none specified)" );
396 /* Get all options */
397 if (MAIN_GetResource( db
, ".iconic", &value
))
398 Options
.cmdShow
= SW_SHOWMINIMIZED
;
399 if (MAIN_GetResource( db
, ".privatemap", &value
))
400 Options
.usePrivateMap
= TRUE
;
401 if (MAIN_GetResource( db
, ".fixedmap", &value
))
402 Options
.useFixedMap
= TRUE
;
403 if (MAIN_GetResource( db
, ".synchronous", &value
))
404 Options
.synchronous
= TRUE
;
405 if (MAIN_GetResource( db
, ".backingstore", &value
))
406 Options
.backingstore
= TRUE
;
407 if (MAIN_GetResource( db
, ".debug", &value
))
408 Options
.debug
= TRUE
;
409 if (MAIN_GetResource( db
, ".allowreadonly", &value
))
410 Options
.allowReadOnly
= TRUE
;
411 if (MAIN_GetResource( db
, ".ipc", &value
))
413 if (MAIN_GetResource( db
, ".perfect", &value
))
414 Options
.perfectGraphics
= TRUE
;
415 if (MAIN_GetResource( db
, ".depth", &value
))
416 screenDepth
= atoi( value
.addr
);
417 if (MAIN_GetResource( db
, ".desktop", &value
))
418 Options
.desktopGeometry
= value
.addr
;
419 if (MAIN_GetResource( db
, ".language", &value
))
420 MAIN_ParseLanguageOption( (char *)value
.addr
);
421 if (MAIN_GetResource( db
, ".managed", &value
))
422 Options
.managed
= TRUE
;
423 if (MAIN_GetResource( db
, ".mode", &value
))
424 MAIN_ParseModeOption( (char *)value
.addr
);
427 if (MAIN_GetResource( db
, ".debugoptions", &value
))
428 ParseDebugOptions((char*)value
.addr
);
430 if (MAIN_GetResource( db
, ".debugmsg", &value
))
432 #ifndef DEBUG_RUNTIME
433 fprintf(stderr
,"%s: Option \"-debugmsg\" not implemented.\n" \
434 " Recompile with DEBUG_RUNTIME in include/stddebug.h defined.\n",
438 if (ParseDebugOptions((char*)value
.addr
)==FALSE
)
441 fprintf(stderr
,"%s: Syntax: -debugmsg +xxx,... or -debugmsg -xxx,...\n",argv
[0]);
442 fprintf(stderr
,"Example: -debugmsg +all,-heap turn on all messages except heap messages\n");
443 fprintf(stderr
,"Available message types:\n");
444 fprintf(stderr
,"%-9s ","all");
445 for(i
=0;i
<sizeof(debug_msg_enabled
)/sizeof(short);i
++)
446 if(debug_msg_name
[i
])
447 fprintf(stderr
,"%-9s%c",debug_msg_name
[i
],
448 (((i
+2)%8==0)?'\n':' '));
449 fprintf(stderr
,"\n\n");
455 if(MAIN_GetResource( db
, ".dll", &value
))
458 if (!BUILTIN_ParseDLLOptions( (char*)value
.addr
))
460 fprintf(stderr
,"%s: Syntax: -dll +xxx,... or -dll -xxx,...\n",argv
[0]);
461 fprintf(stderr
,"Example: -dll -ole2 Do not use emulated OLE2.DLL\n");
462 fprintf(stderr
,"Available DLLs:\n");
467 fprintf(stderr
,"-dll not supported in libwine\n");
471 if(MAIN_GetResource( db
, ".winver", &value
))
472 MAIN_ParseVersion( (char*)value
.addr
);
476 /***********************************************************************
479 static void MAIN_CreateDesktop( int argc
, char *argv
[] )
482 unsigned int width
= 640, height
= 480; /* Default size = 640x480 */
483 char *name
= "Wine desktop";
484 XSizeHints
*size_hints
;
486 XClassHint
*class_hints
;
487 XSetWindowAttributes win_attr
;
488 XTextProperty window_name
;
489 Atom XA_WM_DELETE_WINDOW
;
491 flags
= XParseGeometry( Options
.desktopGeometry
,
492 &desktopX
, &desktopY
, &width
, &height
);
494 screenHeight
= height
;
498 win_attr
.event_mask
= ExposureMask
| KeyPressMask
| KeyReleaseMask
|
499 PointerMotionMask
| ButtonPressMask
|
500 ButtonReleaseMask
| EnterWindowMask
|
502 win_attr
.cursor
= XCreateFontCursor( display
, XC_top_left_arrow
);
504 rootWindow
= XCreateWindow( display
, DefaultRootWindow(display
),
505 desktopX
, desktopY
, width
, height
, 0,
506 CopyFromParent
, InputOutput
, CopyFromParent
,
507 CWEventMask
| CWCursor
, &win_attr
);
509 /* Set window manager properties */
511 size_hints
= XAllocSizeHints();
512 wm_hints
= XAllocWMHints();
513 class_hints
= XAllocClassHint();
514 if (!size_hints
|| !wm_hints
|| !class_hints
)
516 fprintf( stderr
, "Not enough memory for window manager hints.\n" );
519 size_hints
->min_width
= size_hints
->max_width
= width
;
520 size_hints
->min_height
= size_hints
->max_height
= height
;
521 size_hints
->flags
= PMinSize
| PMaxSize
;
522 if (flags
& (XValue
| YValue
)) size_hints
->flags
|= USPosition
;
523 if (flags
& (WidthValue
| HeightValue
)) size_hints
->flags
|= USSize
;
524 else size_hints
->flags
|= PSize
;
526 wm_hints
->flags
= InputHint
| StateHint
;
527 wm_hints
->input
= True
;
528 wm_hints
->initial_state
= NormalState
;
529 class_hints
->res_name
= argv
[0];
530 class_hints
->res_class
= "Wine";
532 XStringListToTextProperty( &name
, 1, &window_name
);
533 XSetWMProperties( display
, rootWindow
, &window_name
, &window_name
,
534 argv
, argc
, size_hints
, wm_hints
, class_hints
);
535 XA_WM_DELETE_WINDOW
= XInternAtom( display
, "WM_DELETE_WINDOW", False
);
536 XSetWMProtocols( display
, rootWindow
, &XA_WM_DELETE_WINDOW
, 1 );
539 XFree( class_hints
);
543 XMapWindow( display
, rootWindow
);
547 XKeyboardState keyboard_state
;
549 /***********************************************************************
552 static void MAIN_SaveSetup(void)
554 XGetKeyboardControl(display
, &keyboard_state
);
557 /***********************************************************************
560 static void MAIN_RestoreSetup(void)
562 XKeyboardControl keyboard_value
;
564 keyboard_value
.key_click_percent
= keyboard_state
.key_click_percent
;
565 keyboard_value
.bell_percent
= keyboard_state
.bell_percent
;
566 keyboard_value
.bell_pitch
= keyboard_state
.bell_pitch
;
567 keyboard_value
.bell_duration
= keyboard_state
.bell_duration
;
568 keyboard_value
.auto_repeat_mode
= keyboard_state
.global_auto_repeat
;
570 XChangeKeyboardControl(display
, KBKeyClickPercent
| KBBellPercent
|
571 KBBellPitch
| KBBellDuration
| KBAutoRepeatMode
, &keyboard_value
);
575 static void called_at_exit(void)
581 /***********************************************************************
584 #if defined(WINELIB) && defined(WINELIBDLL)
585 int _wine_main (int argc
, char *argv
[])
587 int main( int argc
, char *argv
[] )
595 extern int _WinMain(int argc
, char **argv
);
597 #ifdef MALLOC_DEBUGGING
601 if (!(trace
= getenv("MALLOC_TRACE")))
603 fprintf( stderr
, "MALLOC_TRACE not set. No trace generated\n" );
607 fprintf( stderr
, "malloc trace goes to %s\n", trace
);
615 setlocale(LC_CTYPE
,"");
616 gettimeofday( &tv
, NULL
);
617 MSG_WineStartTicks
= (tv
.tv_sec
* 1000) + (tv
.tv_usec
/ 1000);
621 MAIN_ParseOptions( &argc
, argv
);
623 if (Options
.desktopGeometry
&& Options
.managed
)
625 fprintf( stderr
, "%s: -managed and -desktop options cannot be used together\n",
626 Options
.programName
);
630 screen
= DefaultScreenOfDisplay( display
);
631 screenWidth
= WidthOfScreen( screen
);
632 screenHeight
= HeightOfScreen( screen
);
633 if (screenDepth
) /* -depth option specified */
635 depth_list
= XListDepths(display
,DefaultScreen(display
),&depth_count
);
636 for (i
= 0; i
< depth_count
; i
++)
637 if (depth_list
[i
] == screenDepth
) break;
639 if (i
>= depth_count
)
641 fprintf( stderr
, "%s: Depth %d not supported on this screen.\n",
642 Options
.programName
, screenDepth
);
646 else screenDepth
= DefaultDepthOfScreen( screen
);
647 if (Options
.synchronous
) XSynchronize( display
, True
);
648 if (Options
.desktopGeometry
) MAIN_CreateDesktop( argc
, argv
);
649 else rootWindow
= DefaultRootWindow( display
);
652 atexit(called_at_exit
);
654 ret_val
= _WinMain( argc
, argv
);
660 /***********************************************************************
661 * MessageBeep (USER.104)
663 void MessageBeep(WORD i
)
669 /***********************************************************************
672 BOOL32
Beep( DWORD dwFreq
, DWORD dwDur
)
674 /* dwFreq and dwDur are ignored by Win95 */
680 /***********************************************************************
681 * GetVersion (KERNEL.3)
683 LONG
GetVersion(void)
685 if (getVersion16
) return getVersion16
;
686 return MAKELONG( WINVERSION
, WINDOSVER
);
690 /***********************************************************************
693 LONG
GetVersion32(void)
695 if (getVersion32
) return getVersion32
;
696 return MAKELONG( 4, DOSVERSION
);
700 /***********************************************************************
703 BOOL32
GetVersionEx32A(OSVERSIONINFO32A
*v
)
705 if(v
->dwOSVersionInfoSize
!=sizeof(OSVERSIONINFO32A
))
707 fprintf(stddeb
,"wrong OSVERSIONINFO size from app");
712 /* Return something like NT 3.5 */
713 v
->dwMajorVersion
= 3;
714 v
->dwMinorVersion
= 5;
715 v
->dwBuildNumber
= 42;
716 v
->dwPlatformId
= VER_PLATFORM_WIN32_NT
;
717 strcpy(v
->szCSDVersion
, "Wine is not an emulator");
720 v
->dwMajorVersion
= getVersionEx
.dwMajorVersion
;
721 v
->dwMinorVersion
= getVersionEx
.dwMinorVersion
;
722 v
->dwBuildNumber
= getVersionEx
.dwBuildNumber
;
723 v
->dwPlatformId
= getVersionEx
.dwPlatformId
;
724 strcpy(v
->szCSDVersion
, getVersionEx
.szCSDVersion
);
729 /***********************************************************************
732 BOOL32
GetVersionEx32W(OSVERSIONINFO32W
*v
)
735 if(v
->dwOSVersionInfoSize
!=sizeof(OSVERSIONINFO32W
))
737 fprintf(stddeb
,"wrong OSVERSIONINFO size from app");
740 v1
.dwOSVersionInfoSize
=sizeof(v1
);
741 GetVersionEx32A(&v1
);
742 v
->dwMajorVersion
= v1
.dwMajorVersion
;
743 v
->dwMinorVersion
= v1
.dwMinorVersion
;
744 v
->dwBuildNumber
= v1
.dwBuildNumber
;
745 v
->dwPlatformId
= v1
.dwPlatformId
;
746 STRING32_AnsiToUni(v
->szCSDVersion
, v1
.szCSDVersion
);
750 /***********************************************************************
751 * GetWinFlags (KERNEL.132)
753 LONG
GetWinFlags(void)
755 static const long cpuflags
[5] =
756 { WF_CPU086
, WF_CPU186
, WF_CPU286
, WF_CPU386
, WF_CPU486
};
760 /* There doesn't seem to be any Pentium flag. */
762 long cpuflag
= cpuflags
[MIN (runtime_cpu (), 4)];
764 long cpuflag
= cpuflags
[4];
767 switch(Options
.mode
) {
769 result
= (WF_STANDARD
| cpuflag
| WF_PMODE
| WF_80x87
);
773 result
= (WF_ENHANCED
| cpuflag
| WF_PMODE
| WF_80x87
| WF_PAGING
);
777 fprintf(stderr
, "Unknown mode set? This shouldn't happen. Check GetWinFlags()!\n");
784 /***********************************************************************
785 * SetEnvironment (GDI.132)
787 int SetEnvironment(LPCSTR lpPortName
, LPCSTR lpEnviron
, WORD nCount
)
790 LPENVENTRY lpEnv
= lpEnvList
;
791 dprintf_env(stddeb
, "SetEnvironment('%s', '%s', %d) !\n",
792 lpPortName
, lpEnviron
, nCount
);
793 if (lpPortName
== NULL
) return -1;
794 while (lpEnv
!= NULL
) {
795 if (lpEnv
->Name
!= NULL
&& strcmp(lpEnv
->Name
, lpPortName
) == 0) {
796 if (nCount
== 0 || lpEnviron
== NULL
) {
797 if (lpEnv
->Prev
!= NULL
) lpEnv
->Prev
->Next
= lpEnv
->Next
;
798 if (lpEnv
->Next
!= NULL
) lpEnv
->Next
->Prev
= lpEnv
->Prev
;
802 dprintf_env(stddeb
, "SetEnvironment() // entry deleted !\n");
806 lpEnv
->Value
= malloc(nCount
);
807 if (lpEnv
->Value
== NULL
) {
808 dprintf_env(stddeb
, "SetEnvironment() // Error allocating entry value !\n");
811 memcpy(lpEnv
->Value
, lpEnviron
, nCount
);
812 lpEnv
->wSize
= nCount
;
813 dprintf_env(stddeb
, "SetEnvironment() // entry modified !\n");
816 if (lpEnv
->Next
== NULL
) break;
819 if (nCount
== 0 || lpEnviron
== NULL
) return -1;
820 dprintf_env(stddeb
, "SetEnvironment() // new entry !\n");
821 lpNewEnv
= malloc(sizeof(ENVENTRY
));
822 if (lpNewEnv
== NULL
) {
823 dprintf_env(stddeb
, "SetEnvironment() // Error allocating new entry !\n");
826 if (lpEnvList
== NULL
) {
827 lpEnvList
= lpNewEnv
;
828 lpNewEnv
->Prev
= NULL
;
832 lpEnv
->Next
= lpNewEnv
;
833 lpNewEnv
->Prev
= lpEnv
;
835 lpNewEnv
->Next
= NULL
;
836 lpNewEnv
->Name
= malloc(strlen(lpPortName
) + 1);
837 if (lpNewEnv
->Name
== NULL
) {
838 dprintf_env(stddeb
, "SetEnvironment() // Error allocating entry name !\n");
841 strcpy(lpNewEnv
->Name
, lpPortName
);
842 lpNewEnv
->Value
= malloc(nCount
);
843 if (lpNewEnv
->Value
== NULL
) {
844 dprintf_env(stddeb
, "SetEnvironment() // Error allocating entry value !\n");
847 memcpy(lpNewEnv
->Value
, lpEnviron
, nCount
);
848 lpNewEnv
->wSize
= nCount
;
853 /***********************************************************************
854 * SetEnvironmentVariable32A (KERNEL32.484)
856 BOOL32
SetEnvironmentVariable32A( LPCSTR lpName
, LPCSTR lpValue
)
860 rc
= SetEnvironment(lpName
, lpValue
, strlen(lpValue
) + 1);
861 return (rc
> 0) ? 1 : 0;
865 /***********************************************************************
866 * SetEnvironmentVariable32W (KERNEL32.485)
868 BOOL32
SetEnvironmentVariable32W( LPCWSTR lpName
, LPCWSTR lpValue
)
870 LPSTR lpAName
, lpAValue
;
873 lpAName
= STRING32_DupUniToAnsi( lpName
);
874 lpAValue
= STRING32_DupUniToAnsi ( lpValue
);
875 ret
= SetEnvironment(lpAName
, lpAValue
, strlen(lpAValue
) + 1);
878 return (ret
> 0) ? 1 : 0;
882 /***********************************************************************
883 * GetEnvironment (GDI.134)
885 int GetEnvironment(LPSTR lpPortName
, LPSTR lpEnviron
, WORD nMaxSiz
)
888 LPENVENTRY lpEnv
= lpEnvList
;
889 dprintf_env(stddeb
, "GetEnvironment('%s', '%s', %d) !\n",
890 lpPortName
, lpEnviron
, nMaxSiz
);
891 while (lpEnv
!= NULL
) {
892 if (lpEnv
->Name
!= NULL
&& strcmp(lpEnv
->Name
, lpPortName
) == 0) {
893 nCount
= MIN(nMaxSiz
, lpEnv
->wSize
);
894 memcpy(lpEnviron
, lpEnv
->Value
, nCount
);
895 dprintf_env(stddeb
, "GetEnvironment() // found '%s' !\n", lpEnviron
);
900 dprintf_env(stddeb
, "GetEnvironment() // not found !\n");
904 /***********************************************************************
905 * GetEnvironmentVariableA (KERNEL32.213)
907 DWORD
GetEnvironmentVariableA(LPSTR lpName
, LPSTR lpValue
, DWORD size
)
909 return GetEnvironment(lpName
, lpValue
, size
);
912 /***********************************************************************
913 * GetEnvironmentStrings (KERNEL32.210)
915 LPVOID
GetEnvironmentStrings(void)
919 char *envtable
, *envptr
;
921 /* Count the total number of bytes we'll need for the string
922 * table. Include the trailing nuls and the final double nul.
928 if(lpEnv
->Name
!= NULL
)
930 count
+= strlen(lpEnv
->Name
) + 1;
931 count
+= strlen(lpEnv
->Value
) + 1;
936 envtable
= malloc(count
);
944 if(lpEnv
->Name
!= NULL
)
946 count
= sprintf(envptr
, "%s=%s", lpEnv
->Name
, lpEnv
->Value
);
958 LPVOID
GetEnvironmentStringsW(void)
962 char *envtable
, *envptr
;
965 /* Count the total number of bytes we'll need for the string
966 * table. Include the trailing nuls and the final double nul.
972 if(lpEnv
->Name
!= NULL
)
974 count
+= strlen(lpEnv
->Name
) + 1;
975 count
+= strlen(lpEnv
->Value
) + 1;
981 envtable
= malloc(count
);
989 if(lpEnv
->Name
!= NULL
)
991 count
= sprintf(envptr
, "%s=%s", lpEnv
->Name
, lpEnv
->Value
);
999 wenvtable
= malloc(2*len
);
1000 for(count
=0;count
<len
;count
++)
1001 wenvtable
[count
]=(WCHAR
)envtable
[count
];
1007 void FreeEnvironmentStringsA(void *e
)
1012 void FreeEnvironmentStringsW(void* e
)
1017 /***********************************************************************
1018 * GetTimerResolution (USER.14)
1020 LONG
GetTimerResolution(void)
1025 /***********************************************************************
1026 * SystemParametersInfo (USER.483)
1028 BOOL
SystemParametersInfo (UINT uAction
, UINT uParam
, LPVOID lpvParam
, UINT fuWinIni
)
1032 XKeyboardState keyboard_state
;
1033 XKeyboardControl keyboard_value
;
1038 XGetKeyboardControl(display
, &keyboard_state
);
1039 if (keyboard_state
.bell_percent
== 0)
1040 *(BOOL
*) lpvParam
= FALSE
;
1042 *(BOOL
*) lpvParam
= TRUE
;
1046 *(INT
*)lpvParam
= GetSystemMetrics( SM_CXFRAME
);
1049 case SPI_GETFASTTASKSWITCH
:
1050 *(BOOL
*) lpvParam
= FALSE
;
1051 /* FIXME GetProfileInt( "windows", "CoolSwitch", 1 ) */
1054 case SPI_GETGRIDGRANULARITY
:
1055 *(INT
*) lpvParam
= 1;
1056 /* FIXME GetProfileInt( "desktop", "GridGranularity", 1 ) */
1059 case SPI_GETICONTITLEWRAP
:
1060 *(BOOL
*) lpvParam
= FALSE
;
1061 /* FIXME GetProfileInt( "desktop", "?", True ) */
1064 case SPI_GETKEYBOARDDELAY
:
1065 *(INT
*) lpvParam
= 1;
1069 case SPI_GETKEYBOARDSPEED
:
1070 *(WORD
*) lpvParam
= 30;
1074 case SPI_GETMENUDROPALIGNMENT
:
1075 *(BOOL
*) lpvParam
= GetSystemMetrics( SM_MENUDROPALIGNMENT
); /* XXX check this */
1078 case SPI_GETSCREENSAVEACTIVE
:
1079 /* FIXME GetProfileInt( "windows", "ScreenSaveActive", 1 ); */
1080 *(BOOL
*) lpvParam
= FALSE
;
1083 case SPI_GETSCREENSAVETIMEOUT
:
1084 /* FIXME GetProfileInt( "windows", "ScreenSaveTimeout", 300 ); */
1085 XGetScreenSaver(display
, &timeout
, &temp
,&temp
,&temp
);
1086 *(INT
*) lpvParam
= timeout
* 1000;
1089 case SPI_ICONHORIZONTALSPACING
:
1090 if (lpvParam
== NULL
)
1091 fprintf(stderr
, "SystemParametersInfo: Horizontal icon spacing set to %d\n.", uParam
);
1093 *(INT
*) lpvParam
= GetSystemMetrics( SM_CXICONSPACING
);
1096 case SPI_ICONVERTICALSPACING
:
1097 if (lpvParam
== NULL
)
1098 fprintf(stderr
, "SystemParametersInfo: Vertical icon spacing set to %d\n.", uParam
);
1100 *(INT
*) lpvParam
= GetSystemMetrics( SM_CYICONSPACING
);
1105 keyboard_value
.bell_percent
= -1;
1107 keyboard_value
.bell_percent
= 0;
1108 XChangeKeyboardControl(display
, KBBellPercent
,
1112 case SPI_SETSCREENSAVEACTIVE
:
1114 XActivateScreenSaver(display
);
1116 XResetScreenSaver(display
);
1119 case SPI_SETSCREENSAVETIMEOUT
:
1120 XSetScreenSaver(display
, uParam
, 60, DefaultBlanking
,
1124 case SPI_SETDESKWALLPAPER
:
1125 return (SetDeskWallPaper((LPSTR
) lpvParam
));
1128 case SPI_SETDESKPATTERN
:
1129 if ((INT
) uParam
== -1) {
1130 GetProfileString("Desktop", "Pattern",
1131 "170 85 170 85 170 85 170 85",
1132 buffer
, sizeof(buffer
) );
1133 return (DESKTOP_SetPattern((LPSTR
) buffer
));
1135 return (DESKTOP_SetPattern((LPSTR
) lpvParam
));
1138 case SPI_GETICONTITLELOGFONT
:
1140 /* FIXME GetProfileString( "?", "?", "?" ) */
1141 LPLOGFONT16 lpLogFont
= (LPLOGFONT16
)lpvParam
;
1142 lpLogFont
->lfHeight
= 10;
1143 lpLogFont
->lfWidth
= 0;
1144 lpLogFont
->lfEscapement
= lpLogFont
->lfOrientation
= 0;
1145 lpLogFont
->lfWeight
= FW_NORMAL
;
1146 lpLogFont
->lfItalic
= lpLogFont
->lfStrikeOut
= lpLogFont
->lfUnderline
= FALSE
;
1147 lpLogFont
->lfCharSet
= ANSI_CHARSET
;
1148 lpLogFont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
1149 lpLogFont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
1150 lpLogFont
->lfPitchAndFamily
= DEFAULT_PITCH
| FF_SWISS
;
1153 case SPI_LANGDRIVER
:
1155 case SPI_SETDOUBLECLKHEIGHT
:
1156 case SPI_SETDOUBLECLICKTIME
:
1157 case SPI_SETDOUBLECLKWIDTH
:
1158 case SPI_SETFASTTASKSWITCH
:
1159 case SPI_SETKEYBOARDDELAY
:
1160 case SPI_SETKEYBOARDSPEED
:
1161 fprintf(stderr
, "SystemParametersInfo: option %d ignored.\n", uParam
);
1165 fprintf(stderr
, "SystemParametersInfo: unknown option %d.\n", uParam
);
1171 /***********************************************************************
1174 void Copy(LPVOID lpSource
, LPVOID lpDest
, WORD nBytes
)
1176 memcpy(lpDest
, lpSource
, nBytes
);
1179 /***********************************************************************
1180 * SWAPMOUSEBUTTON (USER.186)
1182 BOOL
SwapMouseButton(BOOL fSwap
)
1184 return 0; /* don't swap */
1187 /***********************************************************************
1188 * FileCDR (KERNEL.130)
1190 void FileCDR(FARPROC16 x
)
1192 printf("FileCDR(%8x)\n", (int) x
);
1195 /***********************************************************************
1196 * GetWinDebugInfo (KERNEL.355)
1198 BOOL
GetWinDebugInfo(WINDEBUGINFO
*lpwdi
, UINT flags
)
1200 printf("GetWinDebugInfo(%8lx,%d) stub returning 0\n", (unsigned long)lpwdi
, flags
);
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 */
1207 /***********************************************************************
1208 * GetWinDebugInfo (KERNEL.355)
1210 BOOL
SetWinDebugInfo(WINDEBUGINFO
*lpwdi
)
1212 printf("SetWinDebugInfo(%8lx) stub returning 0\n", (unsigned long)lpwdi
);
1213 /* 0 means not in debugging mode/version */
1214 /* Can this type of debugging be used in wine ? */
1215 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */