4 * Copyright 1994 Alexandre Julliard
13 #ifdef MALLOC_DEBUGGING
17 #include <X11/Xresource.h>
18 #include <X11/Xutil.h>
19 #include <X11/cursorfont.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 successfull
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 /***********************************************************************
658 * GetVersion (KERNEL.3)
660 LONG GetVersion(void)
662 if (getVersion16) return getVersion16;
663 return MAKELONG( WINVERSION, WINDOSVER );
667 /***********************************************************************
670 LONG GetVersion32(void)
672 if (getVersion32) return getVersion32;
673 return MAKELONG( 4, DOSVERSION);
677 /***********************************************************************
680 BOOL32 GetVersionEx32A(OSVERSIONINFO32A *v)
682 if(v->dwOSVersionInfoSize!=sizeof(OSVERSIONINFO32A))
684 fprintf(stddeb,"wrong OSVERSIONINFO size from app");
689 /* Return something like NT 3.5 */
690 v->dwMajorVersion = 3;
691 v->dwMinorVersion = 5;
692 v->dwBuildNumber = 42;
693 v->dwPlatformId = VER_PLATFORM_WIN32_NT;
694 strcpy(v->szCSDVersion, "Wine is not an emulator");
697 v->dwMajorVersion = getVersionEx.dwMajorVersion;
698 v->dwMinorVersion = getVersionEx.dwMinorVersion;
699 v->dwBuildNumber = getVersionEx.dwBuildNumber;
700 v->dwPlatformId = getVersionEx.dwPlatformId;
701 strcpy(v->szCSDVersion, getVersionEx.szCSDVersion);
706 /***********************************************************************
709 BOOL32 GetVersionEx32W(OSVERSIONINFO32W *v)
712 if(v->dwOSVersionInfoSize!=sizeof(OSVERSIONINFO32W))
714 fprintf(stddeb,"wrong OSVERSIONINFO size from app");
717 v1.dwOSVersionInfoSize=sizeof(v1);
718 GetVersionEx32A(&v1);
719 v->dwMajorVersion = v1.dwMajorVersion;
720 v->dwMinorVersion = v1.dwMinorVersion;
721 v->dwBuildNumber = v1.dwBuildNumber;
722 v->dwPlatformId = v1.dwPlatformId;
723 STRING32_AnsiToUni(v->szCSDVersion, v1.szCSDVersion);
727 /***********************************************************************
728 * GetWinFlags (KERNEL.132)
730 LONG GetWinFlags(void)
732 static const long cpuflags[5] =
733 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
737 /* There doesn't seem to be any Pentium flag. */
739 long cpuflag = cpuflags[MIN (runtime_cpu (), 4)];
741 long cpuflag = cpuflags[4];
744 switch(Options.mode) {
746 result = (WF_STANDARD | cpuflag | WF_PMODE | WF_80x87);
750 result = (WF_ENHANCED | cpuflag | WF_PMODE | WF_80x87 | WF_PAGING);
754 fprintf(stderr, "Unknown mode set? This shouldn't happen. Check GetWinFlags()!\n");
761 /***********************************************************************
762 * SetEnvironment (GDI.132)
764 int SetEnvironment(LPSTR lpPortName, LPSTR lpEnviron, WORD nCount)
767 LPENVENTRY lpEnv = lpEnvList;
768 dprintf_env(stddeb, "SetEnvironment('%s', '%s', %d) !\n",
769 lpPortName, lpEnviron, nCount);
770 if (lpPortName == NULL) return -1;
771 while (lpEnv != NULL) {
772 if (lpEnv->Name != NULL && strcmp(lpEnv->Name, lpPortName) == 0) {
773 if (nCount == 0 || lpEnviron == NULL) {
774 if (lpEnv->Prev != NULL) lpEnv->Prev->Next = lpEnv->Next;
775 if (lpEnv->Next != NULL) lpEnv->Next->Prev = lpEnv->Prev;
779 dprintf_env(stddeb, "SetEnvironment() // entry deleted !\n");
783 lpEnv->Value = malloc(nCount);
784 if (lpEnv->Value == NULL) {
785 dprintf_env(stddeb, "SetEnvironment() // Error allocating entry value !\n");
788 memcpy(lpEnv->Value, lpEnviron, nCount);
789 lpEnv->wSize = nCount;
790 dprintf_env(stddeb, "SetEnvironment() // entry modified !\n");
793 if (lpEnv->Next == NULL) break;
796 if (nCount == 0 || lpEnviron == NULL) return -1;
797 dprintf_env(stddeb, "SetEnvironment() // new entry !\n");
798 lpNewEnv = malloc(sizeof(ENVENTRY));
799 if (lpNewEnv == NULL) {
800 dprintf_env(stddeb, "SetEnvironment() // Error allocating new entry !\n");
803 if (lpEnvList == NULL) {
804 lpEnvList = lpNewEnv;
805 lpNewEnv->Prev = NULL;
809 lpEnv->Next = lpNewEnv;
810 lpNewEnv->Prev = lpEnv;
812 lpNewEnv->Next = NULL;
813 lpNewEnv->Name = malloc(strlen(lpPortName) + 1);
814 if (lpNewEnv->Name == NULL) {
815 dprintf_env(stddeb, "SetEnvironment() // Error allocating entry name !\n");
818 strcpy(lpNewEnv->Name, lpPortName);
819 lpNewEnv->Value = malloc(nCount);
820 if (lpNewEnv->Value == NULL) {
821 dprintf_env(stddeb, "SetEnvironment() // Error allocating entry value !\n");
824 memcpy(lpNewEnv->Value, lpEnviron, nCount);
825 lpNewEnv->wSize = nCount;
829 /***********************************************************************
830 * SetEnvironmentVariableA (KERNEL32.484)
832 BOOL SetEnvironmentVariableA(LPSTR lpName, LPSTR lpValue)
836 rc = SetEnvironment(lpName, lpValue, strlen(lpValue) + 1);
837 return (rc > 0) ? 1 : 0;
840 /***********************************************************************
841 * GetEnvironment (GDI.134)
843 int GetEnvironment(LPSTR lpPortName, LPSTR lpEnviron, WORD nMaxSiz)
846 LPENVENTRY lpEnv = lpEnvList;
847 dprintf_env(stddeb, "GetEnvironment('%s', '%s', %d) !\n",
848 lpPortName, lpEnviron, nMaxSiz);
849 while (lpEnv != NULL) {
850 if (lpEnv->Name != NULL && strcmp(lpEnv->Name, lpPortName) == 0) {
851 nCount = MIN(nMaxSiz, lpEnv->wSize);
852 memcpy(lpEnviron, lpEnv->Value, nCount);
853 dprintf_env(stddeb, "GetEnvironment() // found '%s' !\n", lpEnviron);
858 dprintf_env(stddeb, "GetEnvironment() // not found !\n");
862 /***********************************************************************
863 * GetEnvironmentVariableA (KERNEL32.213)
865 DWORD GetEnvironmentVariableA(LPSTR lpName, LPSTR lpValue, DWORD size)
867 return GetEnvironment(lpName, lpValue, size);
870 /***********************************************************************
871 * GetEnvironmentStrings (KERNEL32.210)
873 LPVOID GetEnvironmentStrings(void)
877 char *envtable, *envptr;
879 /* Count the total number of bytes we'll need for the string
880 * table. Include the trailing nuls and the final double nul.
886 if(lpEnv->Name != NULL)
888 count += strlen(lpEnv->Name) + 1;
889 count += strlen(lpEnv->Value) + 1;
894 envtable = malloc(count);
902 if(lpEnv->Name != NULL)
904 count = sprintf(envptr, "%s=%s", lpEnv->Name, lpEnv->Value);
916 LPVOID GetEnvironmentStringsW(void)
920 char *envtable, *envptr;
923 /* Count the total number of bytes we'll need for the string
924 * table. Include the trailing nuls and the final double nul.
930 if(lpEnv->Name != NULL)
932 count += strlen(lpEnv->Name) + 1;
933 count += strlen(lpEnv->Value) + 1;
939 envtable = malloc(count);
947 if(lpEnv->Name != NULL)
949 count = sprintf(envptr, "%s=%s", lpEnv->Name, lpEnv->Value);
957 wenvtable = malloc(2*len);
958 for(count=0;count<len;count++)
959 wenvtable[count]=(WCHAR)envtable[count];
965 void FreeEnvironmentStringsA(void *e)
970 void FreeEnvironmentStringsW(void* e)
975 /***********************************************************************
976 * GetTimerResolution (USER.14)
978 LONG GetTimerResolution(void)
983 /***********************************************************************
984 * SystemParametersInfo (USER.483)
986 BOOL SystemParametersInfo (UINT uAction, UINT uParam, LPVOID lpvParam, UINT fuWinIni)
990 XKeyboardState keyboard_state;
991 XKeyboardControl keyboard_value;
994 fprintf(stderr, "SystemParametersInfo: action %d, param %x, flag %x\n",
995 uAction, uParam, fuWinIni);
999 XGetKeyboardControl(display, &keyboard_state);
1000 if (keyboard_state.bell_percent == 0)
1001 *(BOOL *) lpvParam = FALSE;
1003 *(BOOL *) lpvParam = TRUE;
1007 *(INT *)lpvParam = GetSystemMetrics( SM_CXFRAME );
1010 case SPI_GETFASTTASKSWITCH:
1011 *(BOOL *) lpvParam = FALSE;
1012 /* FIXME GetProfileInt( "windows", "CoolSwitch", 1 ) */
1015 case SPI_GETGRIDGRANULARITY:
1016 *(INT *) lpvParam = 1;
1017 /* FIXME GetProfileInt( "desktop", "GridGranularity", 1 ) */
1020 case SPI_GETICONTITLEWRAP:
1021 *(BOOL *) lpvParam = FALSE;
1022 /* FIXME GetProfileInt( "desktop", "?", True ) */
1025 case SPI_GETKEYBOARDDELAY:
1026 *(INT *) lpvParam = 1;
1030 case SPI_GETKEYBOARDSPEED:
1031 *(WORD *) lpvParam = 30;
1035 case SPI_GETMENUDROPALIGNMENT:
1036 *(BOOL *) lpvParam = GetSystemMetrics( SM_MENUDROPALIGNMENT ); /* XXX check this */
1039 case SPI_GETSCREENSAVEACTIVE:
1040 /* FIXME GetProfileInt( "windows", "ScreenSaveActive", 1 ); */
1041 *(BOOL *) lpvParam = FALSE;
1044 case SPI_GETSCREENSAVETIMEOUT:
1045 /* FIXME GetProfileInt( "windows", "ScreenSaveTimeout", 300 ); */
1046 XGetScreenSaver(display, &timeout, &temp,&temp,&temp);
1047 *(INT *) lpvParam = timeout * 1000;
1050 case SPI_ICONHORIZONTALSPACING:
1051 if (lpvParam == NULL)
1052 fprintf(stderr, "SystemParametersInfo: Horizontal icon spacing set to %d\n.", uParam);
1054 *(INT *) lpvParam = GetSystemMetrics( SM_CXICONSPACING );
1057 case SPI_ICONVERTICALSPACING:
1058 if (lpvParam == NULL)
1059 fprintf(stderr, "SystemParametersInfo: Vertical icon spacing set to %d\n.", uParam);
1061 *(INT *) lpvParam = GetSystemMetrics( SM_CYICONSPACING );
1066 keyboard_value.bell_percent = -1;
1068 keyboard_value.bell_percent = 0;
1069 XChangeKeyboardControl(display, KBBellPercent,
1073 case SPI_SETSCREENSAVEACTIVE:
1075 XActivateScreenSaver(display);
1077 XResetScreenSaver(display);
1080 case SPI_SETSCREENSAVETIMEOUT:
1081 XSetScreenSaver(display, uParam, 60, DefaultBlanking,
1085 case SPI_SETDESKWALLPAPER:
1086 return (SetDeskWallPaper((LPSTR) lpvParam));
1089 case SPI_SETDESKPATTERN:
1090 if ((INT) uParam == -1) {
1091 GetProfileString("Desktop", "Pattern",
1092 "170 85 170 85 170 85 170 85",
1093 buffer, sizeof(buffer) );
1094 return (DESKTOP_SetPattern((LPSTR) buffer));
1096 return (DESKTOP_SetPattern((LPSTR) lpvParam));
1099 case SPI_GETICONTITLELOGFONT:
1101 /* FIXME GetProfileString( "?", "?", "?" ) */
1102 LPLOGFONT16 lpLogFont = (LPLOGFONT16)lpvParam;
1103 lpLogFont->lfHeight = 10;
1104 lpLogFont->lfWidth = 0;
1105 lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
1106 lpLogFont->lfWeight = FW_NORMAL;
1107 lpLogFont->lfItalic = lpLogFont->lfStrikeOut = lpLogFont->lfUnderline = FALSE;
1108 lpLogFont->lfCharSet = ANSI_CHARSET;
1109 lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
1110 lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
1111 lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
1114 case SPI_LANGDRIVER:
1116 case SPI_SETDOUBLECLKHEIGHT:
1117 case SPI_SETDOUBLECLICKTIME:
1118 case SPI_SETDOUBLECLKWIDTH:
1119 case SPI_SETFASTTASKSWITCH:
1120 case SPI_SETKEYBOARDDELAY:
1121 case SPI_SETKEYBOARDSPEED:
1122 fprintf(stderr, "SystemParametersInfo: option %d ignored.\n", uParam);
1126 fprintf(stderr, "SystemParametersInfo: unknown option %d.\n", uParam);
1132 /***********************************************************************
1135 void Copy(LPVOID lpSource, LPVOID lpDest, WORD nBytes)
1137 memcpy(lpDest, lpSource, nBytes);
1140 /***********************************************************************
1141 * SWAPMOUSEBUTTON (USER.186)
1143 BOOL SwapMouseButton(BOOL fSwap)
1145 return 0; /* don't swap */
1148 /***********************************************************************
1149 * FileCDR (KERNEL.130)
1151 void FileCDR(FARPROC x)
1153 printf("FileCDR(%8x)\n", (int) x);
1156 /***********************************************************************
1157 * GetWinDebugInfo (KERNEL.355)
1159 BOOL GetWinDebugInfo(WINDEBUGINFO *lpwdi, UINT flags)
1161 printf("GetWinDebugInfo(%8lx,%d) stub returning 0\n", (unsigned long)lpwdi, flags);
1162 /* 0 means not in debugging mode/version */
1163 /* Can this type of debugging be used in wine ? */
1164 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
1168 /***********************************************************************
1169 * GetWinDebugInfo (KERNEL.355)
1171 BOOL SetWinDebugInfo(WINDEBUGINFO *lpwdi)
1173 printf("SetWinDebugInfo(%8lx) stub returning 0\n", (unsigned long)lpwdi);
1174 /* 0 means not in debugging mode/version */
1175 /* Can this type of debugging be used in wine ? */
1176 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */