Release 960528
[wine/gsoc-2012-control.git] / misc / main.c
blob85455f7ec0e922cf07eede5b009f1f51aa4cac24
1 /*
2 * Main function.
4 * Copyright 1994 Alexandre Julliard
5 */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <unistd.h>
11 #include <ctype.h>
12 #include <locale.h>
13 #ifdef MALLOC_DEBUGGING
14 #include <malloc.h>
15 #endif
16 #include <X11/Xlib.h>
17 #include <X11/Xresource.h>
18 #include <X11/Xutil.h>
19 #include <X11/cursorfont.h>
20 #include "wine.h"
21 #include "message.h"
22 #include "module.h"
23 #include "msdos.h"
24 #include "windows.h"
25 #include "winsock.h"
26 #include "options.h"
27 #include "desktop.h"
28 #include "shell.h"
29 #define DEBUG_DEFINE_VARIABLES
30 #include "stddebug.h"
31 #include "debug.h"
32 #include "xmalloc.h"
34 const char people[] = "Wine is available thanks to the work of "
35 "Bob Amstadt, Dag Asheim, Martin Ayotte, Ross Biro, Uwe Bonnes, Erik Bos, "
36 "Fons Botman, John Brezak, Andrew Bulhak, John Burton, "
37 "Niels de Carpentier, Roman Dolejsi, Frans van Dorsselaer, Paul Falstad, "
38 "Olaf Flebbe, Peter Galbavy, Ramon Garcia, Hans de Graaff, "
39 "Charles M. Hannum, John Harvey, Cameron Heide, Jochen Hoenicke, "
40 "Onno Hovers, Jeffrey Hsu, Miguel de Icaza, Jukka Iivonen, "
41 "Alexandre Julliard, Jochen Karrer, Andreas Kirschbaum, Albrecht Kleine, "
42 "Jon Konrath, Alex Korobka, Greg Kreider, Anand Kumria, Scott A. Laird, "
43 "Martin von Loewis, Kenneth MacDonald, Peter MacDonald, William Magro, "
44 "Juergen Marquardt, Marcus Meissner, Graham Menhennitt, David Metcalfe, "
45 "Steffen Moeller, Philippe De Muyter, Itai Nahshon, Michael Patra, "
46 "Jim Peterson, Robert Pouliot, Keith Reynolds, John Richardson, "
47 "Johannes Ruscheinski, Thomas Sandford, Constantine Sapuntzakis, "
48 "Daniel Schepler, Ulrich Schmid, Bernd Schmidt, Yngvi Sigurjonsson, "
49 "Rick Sladkey, William Smith, Erik Svendsen, Tristan Tarrant, "
50 "Andrew Taylor, Duncan C Thomson, Goran Thyni, Jimmy Tirtawangsa, "
51 "Jon Tombs, Linus Torvalds, Gregory Trubetskoy, Michael Veksler, "
52 "Sven Verdoolaege, Eric Warnke, Manfred Weichel, Morten Welinder, "
53 "Jan Willamowius, Carl Williams, Karl Guenter Wuensch, Eric Youngdale, "
54 "and James Youngman. ";
56 const char *langNames[] =
58 "En", /* LANG_En */
59 "Es", /* LANG_Es */
60 "De", /* LANG_De */
61 "No", /* LANG_No */
62 "Fr", /* LANG_Fr */
63 "Fi", /* LANG_Fi */
64 "Da", /* LANG_Da */
65 "Cz", /* LANG_Cz */
66 "Eo", /* LANG_Eo */
67 "It", /* LANG_It */
68 "Ko", /* LANG_Ko */
69 NULL
72 #define WINE_CLASS "Wine" /* Class name for resources */
74 typedef struct tagENVENTRY {
75 LPSTR Name;
76 LPSTR Value;
77 WORD wSize;
78 struct tagENVENTRY *Prev;
79 struct tagENVENTRY *Next;
80 } ENVENTRY, *LPENVENTRY;
82 LPENVENTRY lpEnvList = NULL;
84 Display *display;
85 Screen *screen;
86 Window rootWindow;
87 int screenWidth = 0, screenHeight = 0; /* Desktop window dimensions */
88 int screenDepth = 0; /* Screen depth to use */
89 int desktopX = 0, desktopY = 0; /* Desktop window position (if any) */
91 struct options Options =
92 { /* default options */
93 NULL, /* desktopGeometry */
94 NULL, /* programName */
95 FALSE, /* usePrivateMap */
96 FALSE, /* useFixedMap */
97 FALSE, /* synchronous */
98 FALSE, /* backing store */
99 SW_SHOWNORMAL, /* cmdShow */
100 FALSE,
101 FALSE, /* AllowReadOnly */
102 MODE_ENHANCED, /* Enhanced mode */
103 FALSE, /* IPC enabled */
104 #ifdef DEFAULT_LANG
105 DEFAULT_LANG, /* Default language */
106 #else
107 LANG_En,
108 #endif
109 FALSE /* Managed windows */
113 static XrmOptionDescRec optionsTable[] =
115 { "-backingstore", ".backingstore", XrmoptionNoArg, (caddr_t)"on" },
116 { "-desktop", ".desktop", XrmoptionSepArg, (caddr_t)NULL },
117 { "-depth", ".depth", XrmoptionSepArg, (caddr_t)NULL },
118 { "-display", ".display", XrmoptionSepArg, (caddr_t)NULL },
119 { "-iconic", ".iconic", XrmoptionNoArg, (caddr_t)"on" },
120 { "-ipc", ".ipc", XrmoptionNoArg, (caddr_t)"off"},
121 { "-language", ".language", XrmoptionSepArg, (caddr_t)"En" },
122 { "-name", ".name", XrmoptionSepArg, (caddr_t)NULL },
123 { "-privatemap", ".privatemap", XrmoptionNoArg, (caddr_t)"on" },
124 { "-fixedmap", ".fixedmap", XrmoptionNoArg, (caddr_t)"on" },
125 { "-synchronous", ".synchronous", XrmoptionNoArg, (caddr_t)"on" },
126 { "-debug", ".debug", XrmoptionNoArg, (caddr_t)"on" },
127 { "-debugmsg", ".debugmsg", XrmoptionSepArg, (caddr_t)NULL },
128 { "-dll", ".dll", XrmoptionSepArg, (caddr_t)NULL },
129 { "-allowreadonly", ".allowreadonly", XrmoptionNoArg, (caddr_t)"on" },
130 { "-mode", ".mode", XrmoptionSepArg, (caddr_t)NULL },
131 { "-managed", ".managed", XrmoptionNoArg, (caddr_t)"off"}
134 #define NB_OPTIONS (sizeof(optionsTable) / sizeof(optionsTable[0]))
136 #define USAGE \
137 "Usage: %s [options] program_name [arguments]\n" \
138 "\n" \
139 "Options:\n" \
140 " -allowreadonly Read only files may be opened in write mode\n" \
141 " -backingstore Turn on backing store\n" \
142 " -debug Enter debugger before starting application\n" \
143 " -debugmsg name Turn debugging-messages on or off\n" \
144 " -depth n Change the depth to use for multiple-depth screens\n" \
145 " -desktop geom Use a desktop window of the given geometry\n" \
146 " -display name Use the specified display\n" \
147 " -dll name Enable or disable built-in DLLs\n" \
148 " -fixedmap Use a \"standard\" color map\n" \
149 " -iconic Start as an icon\n" \
150 " -ipc Enable IPC facilities\n" \
151 " -language xx Set the language (one of En,Es,De,No,Fr,Fi,Da,Cz,Eo,It,Ko)\n" \
152 " -managed Allow the window manager to manage created windows\n" \
153 " -mode mode Start Wine in a particular mode (standard or enhanced)\n" \
154 " -name name Set the application name\n" \
155 " -privatemap Use a private color map\n" \
156 " -synchronous Turn on synchronous display mode\n"
160 /***********************************************************************
161 * MAIN_Usage
163 #ifndef WINELIB32
164 static void MAIN_Usage( char *name )
166 fprintf( stderr, USAGE, name );
167 exit(1);
169 #endif
172 /***********************************************************************
173 * MAIN_GetProgramName
175 * Get the program name. The name is specified by (in order of precedence):
176 * - the option '-name'.
177 * - the environment variable 'WINE_NAME'.
178 * - the last component of argv[0].
180 static char *MAIN_GetProgramName( int argc, char *argv[] )
182 int i;
183 char *p;
185 for (i = 1; i < argc-1; i++)
186 if (!strcmp( argv[i], "-name" )) return argv[i+1];
187 if ((p = getenv( "WINE_NAME" )) != NULL) return p;
188 if ((p = strrchr( argv[0], '/' )) != NULL) return p+1;
189 return argv[0];
193 /***********************************************************************
194 * MAIN_GetResource
196 * Fetch the value of resource 'name' using the correct instance name.
197 * 'name' must begin with '.' or '*'
199 static int MAIN_GetResource( XrmDatabase db, char *name, XrmValue *value )
201 char *buff_instance, *buff_class;
202 char *dummy;
203 int retval;
205 buff_instance = (char *)xmalloc(strlen(Options.programName)+strlen(name)+1);
206 buff_class = (char *)xmalloc( strlen(WINE_CLASS) + strlen(name) + 1 );
208 strcpy( buff_instance, Options.programName );
209 strcat( buff_instance, name );
210 strcpy( buff_class, WINE_CLASS );
211 strcat( buff_class, name );
212 retval = XrmGetResource( db, buff_instance, buff_class, &dummy, value );
213 free( buff_instance );
214 free( buff_class );
215 return retval;
219 /***********************************************************************
220 * ParseDebugOptions
222 * Turns specific debug messages on or off, according to "options".
223 * Returns TRUE if parsing was successfull
225 #ifdef DEBUG_RUNTIME
227 BOOL ParseDebugOptions(char *options)
229 int l;
230 if (strlen(options)<3)
231 return FALSE;
234 if ((*options!='+')&&(*options!='-'))
235 return FALSE;
236 if (strchr(options,','))
237 l=strchr(options,',')-options;
238 else
239 l=strlen(options);
240 if (!lstrncmpi(options+1,"all",l-1))
242 int i;
243 for (i=0;i<sizeof(debug_msg_enabled)/sizeof(short);i++)
244 debug_msg_enabled[i]=(*options=='+');
246 else
248 int i;
249 for (i=0;i<sizeof(debug_msg_enabled)/sizeof(short);i++)
250 if (debug_msg_name && (!lstrncmpi(options+1,debug_msg_name[i],l-1)))
252 debug_msg_enabled[i]=(*options=='+');
253 break;
255 if (i==sizeof(debug_msg_enabled)/sizeof(short))
256 return FALSE;
258 options+=l;
260 while((*options==',')&&(*(++options)));
261 if (*options)
262 return FALSE;
263 else
264 return TRUE;
267 #endif
270 /***********************************************************************
271 * MAIN_ParseLanguageOption
273 * Parse -language option.
275 static void MAIN_ParseLanguageOption( char *arg )
277 const char **p = langNames;
279 Options.language = LANG_En; /* First language */
280 for (p = langNames; *p; p++)
282 if (!lstrcmpi( *p, arg )) return;
283 Options.language++;
285 fprintf( stderr, "Invalid language specified '%s'. Supported languages are: ", arg );
286 for (p = langNames; *p; p++) fprintf( stderr, "%s ", *p );
287 fprintf( stderr, "\n" );
288 exit(1);
292 /***********************************************************************
293 * MAIN_ParseModeOption
295 * Parse -mode option.
297 static void MAIN_ParseModeOption( char *arg )
299 if (!lstrcmpi("enhanced", arg)) Options.mode = MODE_ENHANCED;
300 else if (!lstrcmpi("standard", arg)) Options.mode = MODE_STANDARD;
301 else
303 fprintf(stderr, "Invalid mode '%s' specified.\n", arg);
304 fprintf(stderr, "Valid modes are: 'standard', 'enhanced' (default).\n");
305 exit(1);
310 /***********************************************************************
311 * MAIN_ParseOptions
313 * Parse command line options and open display.
315 static void MAIN_ParseOptions( int *argc, char *argv[] )
317 char *display_name;
318 XrmValue value;
319 XrmDatabase db = XrmGetFileDatabase("/usr/lib/X11/app-defaults/Wine");
321 /* Parse command line */
322 Options.programName = MAIN_GetProgramName( *argc, argv );
323 XrmParseCommand( &db, optionsTable, NB_OPTIONS,
324 Options.programName, argc, argv );
326 #ifdef WINELIB
327 /* Need to assemble command line and pass it to WinMain */
328 #else
329 if (*argc < 2 || lstrcmpi(argv[1], "-h") == 0)
330 MAIN_Usage( argv[0] );
331 #endif
333 /* Open display */
335 if (MAIN_GetResource( db, ".display", &value )) display_name = value.addr;
336 else display_name = NULL;
338 if (!(display = XOpenDisplay( display_name )))
340 fprintf( stderr, "%s: Can't open display: %s\n",
341 argv[0], display_name ? display_name : "(none specified)" );
342 exit(1);
345 /* Get all options */
346 if (MAIN_GetResource( db, ".iconic", &value ))
347 Options.cmdShow = SW_SHOWMINIMIZED;
348 if (MAIN_GetResource( db, ".privatemap", &value ))
349 Options.usePrivateMap = TRUE;
350 if (MAIN_GetResource( db, ".fixedmap", &value ))
351 Options.useFixedMap = TRUE;
352 if (MAIN_GetResource( db, ".synchronous", &value ))
353 Options.synchronous = TRUE;
354 if (MAIN_GetResource( db, ".backingstore", &value ))
355 Options.backingstore = TRUE;
356 if (MAIN_GetResource( db, ".debug", &value ))
357 Options.debug = TRUE;
358 if (MAIN_GetResource( db, ".allowreadonly", &value ))
359 Options.allowReadOnly = TRUE;
360 if (MAIN_GetResource( db, ".ipc", &value ))
361 Options.ipc = TRUE;
362 if (MAIN_GetResource( db, ".depth", &value))
363 screenDepth = atoi( value.addr );
364 if (MAIN_GetResource( db, ".desktop", &value))
365 Options.desktopGeometry = value.addr;
366 if (MAIN_GetResource( db, ".language", &value))
367 MAIN_ParseLanguageOption( (char *)value.addr );
368 if (MAIN_GetResource( db, ".managed", &value))
369 Options.managed = TRUE;
370 if (MAIN_GetResource( db, ".mode", &value))
371 MAIN_ParseModeOption( (char *)value.addr );
373 #ifdef DEBUG_RUNTIME
374 if (MAIN_GetResource( db, ".debugoptions", &value))
375 ParseDebugOptions((char*)value.addr);
376 #endif
377 if (MAIN_GetResource( db, ".debugmsg", &value))
379 #ifndef DEBUG_RUNTIME
380 fprintf(stderr,"%s: Option \"-debugmsg\" not implemented.\n" \
381 " Recompile with DEBUG_RUNTIME in include/stddebug.h defined.\n",
382 argv[0]);
383 exit(1);
384 #else
385 if (ParseDebugOptions((char*)value.addr)==FALSE)
387 int i;
388 fprintf(stderr,"%s: Syntax: -debugmsg +xxx,... or -debugmsg -xxx,...\n",argv[0]);
389 fprintf(stderr,"Example: -debugmsg +all,-heap turn on all messages except heap messages\n");
390 fprintf(stderr,"Available message types:\n");
391 fprintf(stderr,"%-9s ","all");
392 for(i=0;i<sizeof(debug_msg_enabled)/sizeof(short);i++)
393 if(debug_msg_name[i])
394 fprintf(stderr,"%-9s%c",debug_msg_name[i],
395 (((i+2)%8==0)?'\n':' '));
396 fprintf(stderr,"\n\n");
397 exit(1);
399 #endif
402 if(MAIN_GetResource( db, ".dll", &value))
404 #ifndef WINELIB
405 if (!BUILTIN_ParseDLLOptions( (char*)value.addr ))
407 fprintf(stderr,"%s: Syntax: -dll +xxx,... or -dll -xxx,...\n",argv[0]);
408 fprintf(stderr,"Example: -dll -ole2 Do not use emulated OLE2.DLL\n");
409 fprintf(stderr,"Available DLLs:\n");
410 BUILTIN_PrintDLLs();
411 exit(1);
413 #else
414 fprintf(stderr,"-dll not supported in libwine\n");
415 #endif
420 /***********************************************************************
421 * MAIN_CreateDesktop
423 static void MAIN_CreateDesktop( int argc, char *argv[] )
425 int flags;
426 unsigned int width = 640, height = 480; /* Default size = 640x480 */
427 char *name = "Wine desktop";
428 XSizeHints *size_hints;
429 XWMHints *wm_hints;
430 XClassHint *class_hints;
431 XSetWindowAttributes win_attr;
432 XTextProperty window_name;
433 Atom XA_WM_DELETE_WINDOW;
435 flags = XParseGeometry( Options.desktopGeometry,
436 &desktopX, &desktopY, &width, &height );
437 screenWidth = width;
438 screenHeight = height;
440 /* Create window */
442 win_attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
443 PointerMotionMask | ButtonPressMask |
444 ButtonReleaseMask | EnterWindowMask |
445 StructureNotifyMask;
446 win_attr.cursor = XCreateFontCursor( display, XC_top_left_arrow );
448 rootWindow = XCreateWindow( display, DefaultRootWindow(display),
449 desktopX, desktopY, width, height, 0,
450 CopyFromParent, InputOutput, CopyFromParent,
451 CWEventMask | CWCursor, &win_attr );
453 /* Set window manager properties */
455 size_hints = XAllocSizeHints();
456 wm_hints = XAllocWMHints();
457 class_hints = XAllocClassHint();
458 if (!size_hints || !wm_hints || !class_hints)
460 fprintf( stderr, "Not enough memory for window manager hints.\n" );
461 exit(1);
463 size_hints->min_width = size_hints->max_width = width;
464 size_hints->min_height = size_hints->max_height = height;
465 size_hints->flags = PMinSize | PMaxSize;
466 if (flags & (XValue | YValue)) size_hints->flags |= USPosition;
467 if (flags & (WidthValue | HeightValue)) size_hints->flags |= USSize;
468 else size_hints->flags |= PSize;
470 wm_hints->flags = InputHint | StateHint;
471 wm_hints->input = True;
472 wm_hints->initial_state = NormalState;
473 class_hints->res_name = argv[0];
474 class_hints->res_class = "Wine";
476 XStringListToTextProperty( &name, 1, &window_name );
477 XSetWMProperties( display, rootWindow, &window_name, &window_name,
478 argv, argc, size_hints, wm_hints, class_hints );
479 XA_WM_DELETE_WINDOW = XInternAtom( display, "WM_DELETE_WINDOW", False );
480 XSetWMProtocols( display, rootWindow, &XA_WM_DELETE_WINDOW, 1 );
481 XFree( size_hints );
482 XFree( wm_hints );
483 XFree( class_hints );
485 /* Map window */
487 XMapWindow( display, rootWindow );
491 XKeyboardState keyboard_state;
493 /***********************************************************************
494 * MAIN_SaveSetup
496 static void MAIN_SaveSetup(void)
498 XGetKeyboardControl(display, &keyboard_state);
501 /***********************************************************************
502 * MAIN_RestoreSetup
504 static void MAIN_RestoreSetup(void)
506 XKeyboardControl keyboard_value;
508 keyboard_value.key_click_percent = keyboard_state.key_click_percent;
509 keyboard_value.bell_percent = keyboard_state.bell_percent;
510 keyboard_value.bell_pitch = keyboard_state.bell_pitch;
511 keyboard_value.bell_duration = keyboard_state.bell_duration;
512 keyboard_value.auto_repeat_mode = keyboard_state.global_auto_repeat;
514 XChangeKeyboardControl(display, KBKeyClickPercent | KBBellPercent |
515 KBBellPitch | KBBellDuration | KBAutoRepeatMode, &keyboard_value);
519 static void called_at_exit(void)
521 MAIN_RestoreSetup();
522 WSACleanup();
525 /***********************************************************************
526 * main
528 #if defined(WINELIB) && defined(WINELIBDLL)
529 int _wine_main (int argc, char *argv[])
530 #else
531 int main( int argc, char *argv[] )
532 #endif
534 int ret_val;
535 int depth_count, i;
536 int *depth_list;
537 struct timeval tv;
539 extern int _WinMain(int argc, char **argv);
541 #ifdef MALLOC_DEBUGGING
542 char *trace;
544 mcheck(NULL);
545 if (!(trace = getenv("MALLOC_TRACE")))
547 fprintf( stderr, "MALLOC_TRACE not set. No trace generated\n" );
549 else
551 fprintf( stderr, "malloc trace goes to %s\n", trace );
552 mtrace();
554 #endif
556 setbuf(stdout,NULL);
557 setbuf(stderr,NULL);
559 setlocale(LC_CTYPE,"");
560 gettimeofday( &tv, NULL);
561 MSG_WineStartTicks = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
563 XrmInitialize();
565 MAIN_ParseOptions( &argc, argv );
567 screen = DefaultScreenOfDisplay( display );
568 screenWidth = WidthOfScreen( screen );
569 screenHeight = HeightOfScreen( screen );
570 if (screenDepth) /* -depth option specified */
572 depth_list = XListDepths(display,DefaultScreen(display),&depth_count);
573 for (i = 0; i < depth_count; i++)
574 if (depth_list[i] == screenDepth) break;
575 XFree( depth_list );
576 if (i >= depth_count)
578 fprintf( stderr, "%s: Depth %d not supported on this screen.\n",
579 Options.programName, screenDepth );
580 exit(1);
583 else screenDepth = DefaultDepthOfScreen( screen );
584 if (Options.synchronous) XSynchronize( display, True );
585 if (Options.desktopGeometry) MAIN_CreateDesktop( argc, argv );
586 else rootWindow = DefaultRootWindow( display );
588 MAIN_SaveSetup();
589 atexit(called_at_exit);
591 ret_val = _WinMain( argc, argv );
593 return ret_val;
596 /***********************************************************************
597 * MessageBeep (USER.104)
599 void MessageBeep(WORD i)
601 XBell(display, 100);
604 /***********************************************************************
605 * GetVersion (KERNEL.3)
607 LONG GetVersion(void)
609 return MAKELONG( WINVERSION, WINDOSVER );
612 /***********************************************************************
613 * GetWinFlags (KERNEL.132)
615 LONG GetWinFlags(void)
617 static const long cpuflags[5] =
618 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
620 long result = 0;
622 /* There doesn't seem to be any Pentium flag. */
623 #ifndef WINELIB
624 long cpuflag = cpuflags[MIN (runtime_cpu (), 4)];
625 #else
626 long cpuflag = cpuflags[4];
627 #endif
629 switch(Options.mode) {
630 case MODE_STANDARD:
631 result = (WF_STANDARD | cpuflag | WF_PMODE | WF_80x87);
632 break;
634 case MODE_ENHANCED:
635 result = (WF_ENHANCED | cpuflag | WF_PMODE | WF_80x87 | WF_PAGING);
636 break;
638 default:
639 fprintf(stderr, "Unknown mode set? This shouldn't happen. Check GetWinFlags()!\n");
640 break;
643 return result;
646 /***********************************************************************
647 * SetEnvironment (GDI.132)
649 int SetEnvironment(LPSTR lpPortName, LPSTR lpEnviron, WORD nCount)
651 LPENVENTRY lpNewEnv;
652 LPENVENTRY lpEnv = lpEnvList;
653 dprintf_env(stddeb, "SetEnvironment('%s', '%s', %d) !\n",
654 lpPortName, lpEnviron, nCount);
655 if (lpPortName == NULL) return -1;
656 while (lpEnv != NULL) {
657 if (lpEnv->Name != NULL && strcmp(lpEnv->Name, lpPortName) == 0) {
658 if (nCount == 0 || lpEnviron == NULL) {
659 if (lpEnv->Prev != NULL) lpEnv->Prev->Next = lpEnv->Next;
660 if (lpEnv->Next != NULL) lpEnv->Next->Prev = lpEnv->Prev;
661 free(lpEnv->Value);
662 free(lpEnv->Name);
663 free(lpEnv);
664 dprintf_env(stddeb, "SetEnvironment() // entry deleted !\n");
665 return -1;
667 free(lpEnv->Value);
668 lpEnv->Value = malloc(nCount);
669 if (lpEnv->Value == NULL) {
670 dprintf_env(stddeb, "SetEnvironment() // Error allocating entry value !\n");
671 return 0;
673 memcpy(lpEnv->Value, lpEnviron, nCount);
674 lpEnv->wSize = nCount;
675 dprintf_env(stddeb, "SetEnvironment() // entry modified !\n");
676 return nCount;
678 if (lpEnv->Next == NULL) break;
679 lpEnv = lpEnv->Next;
681 if (nCount == 0 || lpEnviron == NULL) return -1;
682 dprintf_env(stddeb, "SetEnvironment() // new entry !\n");
683 lpNewEnv = malloc(sizeof(ENVENTRY));
684 if (lpNewEnv == NULL) {
685 dprintf_env(stddeb, "SetEnvironment() // Error allocating new entry !\n");
686 return 0;
688 if (lpEnvList == NULL) {
689 lpEnvList = lpNewEnv;
690 lpNewEnv->Prev = NULL;
692 else
694 lpEnv->Next = lpNewEnv;
695 lpNewEnv->Prev = lpEnv;
697 lpNewEnv->Next = NULL;
698 lpNewEnv->Name = malloc(strlen(lpPortName) + 1);
699 if (lpNewEnv->Name == NULL) {
700 dprintf_env(stddeb, "SetEnvironment() // Error allocating entry name !\n");
701 return 0;
703 strcpy(lpNewEnv->Name, lpPortName);
704 lpNewEnv->Value = malloc(nCount);
705 if (lpNewEnv->Value == NULL) {
706 dprintf_env(stddeb, "SetEnvironment() // Error allocating entry value !\n");
707 return 0;
709 memcpy(lpNewEnv->Value, lpEnviron, nCount);
710 lpNewEnv->wSize = nCount;
711 return nCount;
714 /***********************************************************************
715 * SetEnvironmentVariableA (KERNEL32.484)
717 BOOL SetEnvironmentVariableA(LPSTR lpName, LPSTR lpValue)
719 int rc;
721 rc = SetEnvironment(lpName, lpValue, strlen(lpValue) + 1);
722 return (rc > 0) ? 1 : 0;
725 /***********************************************************************
726 * GetEnvironment (GDI.134)
728 int GetEnvironment(LPSTR lpPortName, LPSTR lpEnviron, WORD nMaxSiz)
730 WORD nCount;
731 LPENVENTRY lpEnv = lpEnvList;
732 dprintf_env(stddeb, "GetEnvironment('%s', '%s', %d) !\n",
733 lpPortName, lpEnviron, nMaxSiz);
734 while (lpEnv != NULL) {
735 if (lpEnv->Name != NULL && strcmp(lpEnv->Name, lpPortName) == 0) {
736 nCount = MIN(nMaxSiz, lpEnv->wSize);
737 memcpy(lpEnviron, lpEnv->Value, nCount);
738 dprintf_env(stddeb, "GetEnvironment() // found '%s' !\n", lpEnviron);
739 return nCount;
741 lpEnv = lpEnv->Next;
743 dprintf_env(stddeb, "GetEnvironment() // not found !\n");
744 return 0;
747 /***********************************************************************
748 * GetEnvironmentVariableA (KERNEL32.213)
750 DWORD GetEnvironmentVariableA(LPSTR lpName, LPSTR lpValue, DWORD size)
752 return GetEnvironment(lpName, lpValue, size);
755 /***********************************************************************
756 * GetEnvironmentStrings (KERNEL32.210)
758 LPVOID GetEnvironmentStrings(void)
760 int count;
761 LPENVENTRY lpEnv;
762 char *envtable, *envptr;
764 /* Count the total number of bytes we'll need for the string
765 * table. Include the trailing nuls and the final double nul.
767 count = 1;
768 lpEnv = lpEnvList;
769 while(lpEnv != NULL)
771 if(lpEnv->Name != NULL)
773 count += strlen(lpEnv->Name) + 1;
774 count += strlen(lpEnv->Value) + 1;
776 lpEnv = lpEnv->Next;
779 envtable = malloc(count);
780 if(envtable)
782 lpEnv = lpEnvList;
783 envptr = envtable;
785 while(lpEnv != NULL)
787 if(lpEnv->Name != NULL)
789 count = sprintf(envptr, "%s=%s", lpEnv->Name, lpEnv->Value);
790 envptr += count + 1;
792 lpEnv = lpEnv->Next;
794 *envptr = '\0';
797 return envtable;
801 LPVOID GetEnvironmentStringsW(void)
803 int count,len;
804 LPENVENTRY lpEnv;
805 char *envtable, *envptr;
806 WCHAR *wenvtable;
808 /* Count the total number of bytes we'll need for the string
809 * table. Include the trailing nuls and the final double nul.
811 count = 1;
812 lpEnv = lpEnvList;
813 while(lpEnv != NULL)
815 if(lpEnv->Name != NULL)
817 count += strlen(lpEnv->Name) + 1;
818 count += strlen(lpEnv->Value) + 1;
820 lpEnv = lpEnv->Next;
823 len=count;
824 envtable = malloc(count);
825 if(envtable)
827 lpEnv = lpEnvList;
828 envptr = envtable;
830 while(lpEnv != NULL)
832 if(lpEnv->Name != NULL)
834 count = sprintf(envptr, "%s=%s", lpEnv->Name, lpEnv->Value);
835 envptr += count + 1;
837 lpEnv = lpEnv->Next;
839 *envptr = '\0';
842 wenvtable = malloc(2*len);
843 for(count=0;count<len;count++)
844 wenvtable[count]=(WCHAR)envtable[count];
845 free(envtable);
847 return envtable;
850 void FreeEnvironmentStringsA(void *e)
852 free(e);
855 void FreeEnvironmentStringsW(void* e)
857 free(e);
860 /***********************************************************************
861 * GetTimerResolution (USER.14)
863 LONG GetTimerResolution(void)
865 return (1000);
868 /***********************************************************************
869 * SystemParametersInfo (USER.483)
871 BOOL SystemParametersInfo (UINT uAction, UINT uParam, LPVOID lpvParam, UINT fuWinIni)
873 int timeout, temp;
874 char buffer[256];
875 XKeyboardState keyboard_state;
876 XKeyboardControl keyboard_value;
879 fprintf(stderr, "SystemParametersInfo: action %d, param %x, flag %x\n",
880 uAction, uParam, fuWinIni);
882 switch (uAction) {
883 case SPI_GETBEEP:
884 XGetKeyboardControl(display, &keyboard_state);
885 if (keyboard_state.bell_percent == 0)
886 *(BOOL *) lpvParam = FALSE;
887 else
888 *(BOOL *) lpvParam = TRUE;
889 break;
891 case SPI_GETBORDER:
892 *(INT *)lpvParam = GetSystemMetrics( SM_CXFRAME );
893 break;
895 case SPI_GETFASTTASKSWITCH:
896 *(BOOL *) lpvParam = FALSE;
897 /* FIXME GetProfileInt( "windows", "CoolSwitch", 1 ) */
898 break;
900 case SPI_GETGRIDGRANULARITY:
901 *(INT *) lpvParam = 1;
902 /* FIXME GetProfileInt( "desktop", "GridGranularity", 1 ) */
903 break;
905 case SPI_GETICONTITLEWRAP:
906 *(BOOL *) lpvParam = FALSE;
907 /* FIXME GetProfileInt( "desktop", "?", True ) */
908 break;
910 case SPI_GETKEYBOARDDELAY:
911 *(INT *) lpvParam = 1;
912 /* FIXME */
913 break;
915 case SPI_GETKEYBOARDSPEED:
916 *(WORD *) lpvParam = 30;
917 /* FIXME */
918 break;
920 case SPI_GETMENUDROPALIGNMENT:
921 *(BOOL *) lpvParam = GetSystemMetrics( SM_MENUDROPALIGNMENT ); /* XXX check this */
922 break;
924 case SPI_GETSCREENSAVEACTIVE:
925 /* FIXME GetProfileInt( "windows", "ScreenSaveActive", 1 ); */
926 *(BOOL *) lpvParam = FALSE;
927 break;
929 case SPI_GETSCREENSAVETIMEOUT:
930 /* FIXME GetProfileInt( "windows", "ScreenSaveTimeout", 300 ); */
931 XGetScreenSaver(display, &timeout, &temp,&temp,&temp);
932 *(INT *) lpvParam = timeout * 1000;
933 break;
935 case SPI_ICONHORIZONTALSPACING:
936 if (lpvParam == NULL)
937 fprintf(stderr, "SystemParametersInfo: Horizontal icon spacing set to %d\n.", uParam);
938 else
939 *(INT *) lpvParam = GetSystemMetrics( SM_CXICONSPACING );
940 break;
942 case SPI_ICONVERTICALSPACING:
943 if (lpvParam == NULL)
944 fprintf(stderr, "SystemParametersInfo: Vertical icon spacing set to %d\n.", uParam);
945 else
946 *(INT *) lpvParam = GetSystemMetrics( SM_CYICONSPACING );
947 break;
949 case SPI_SETBEEP:
950 if (uParam == TRUE)
951 keyboard_value.bell_percent = -1;
952 else
953 keyboard_value.bell_percent = 0;
954 XChangeKeyboardControl(display, KBBellPercent,
955 &keyboard_value);
956 break;
958 case SPI_SETSCREENSAVEACTIVE:
959 if (uParam == TRUE)
960 XActivateScreenSaver(display);
961 else
962 XResetScreenSaver(display);
963 break;
965 case SPI_SETSCREENSAVETIMEOUT:
966 XSetScreenSaver(display, uParam, 60, DefaultBlanking,
967 DefaultExposures);
968 break;
970 case SPI_SETDESKWALLPAPER:
971 return (SetDeskWallPaper((LPSTR) lpvParam));
972 break;
974 case SPI_SETDESKPATTERN:
975 if ((INT) uParam == -1) {
976 GetProfileString("Desktop", "Pattern",
977 "170 85 170 85 170 85 170 85",
978 buffer, sizeof(buffer) );
979 return (DESKTOP_SetPattern((LPSTR) buffer));
980 } else
981 return (DESKTOP_SetPattern((LPSTR) lpvParam));
982 break;
984 case SPI_GETICONTITLELOGFONT:
986 /* FIXME GetProfileString( "?", "?", "?" ) */
987 LPLOGFONT lpLogFont = (LPLOGFONT)lpvParam;
988 lpLogFont->lfHeight = 10;
989 lpLogFont->lfWidth = 0;
990 lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
991 lpLogFont->lfWeight = FW_NORMAL;
992 lpLogFont->lfItalic = lpLogFont->lfStrikeOut = lpLogFont->lfUnderline = FALSE;
993 lpLogFont->lfCharSet = ANSI_CHARSET;
994 lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
995 lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
996 lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
997 break;
999 case SPI_LANGDRIVER:
1000 case SPI_SETBORDER:
1001 case SPI_SETDOUBLECLKHEIGHT:
1002 case SPI_SETDOUBLECLICKTIME:
1003 case SPI_SETDOUBLECLKWIDTH:
1004 case SPI_SETFASTTASKSWITCH:
1005 case SPI_SETKEYBOARDDELAY:
1006 case SPI_SETKEYBOARDSPEED:
1007 fprintf(stderr, "SystemParametersInfo: option %d ignored.\n", uParam);
1008 break;
1010 default:
1011 fprintf(stderr, "SystemParametersInfo: unknown option %d.\n", uParam);
1012 break;
1014 return 1;
1017 /***********************************************************************
1018 * HMEMCPY (KERNEL.348)
1020 void hmemcpy(LPVOID hpvDest, LPCVOID hpvSource, LONG cbCopy)
1022 memcpy(hpvDest, hpvSource, cbCopy);
1025 /***********************************************************************
1026 * COPY (GDI.250)
1028 void Copy(LPVOID lpSource, LPVOID lpDest, WORD nBytes)
1030 memcpy(lpDest, lpSource, nBytes);
1033 /***********************************************************************
1034 * SWAPMOUSEBUTTON (USER.186)
1036 BOOL SwapMouseButton(BOOL fSwap)
1038 return 0; /* don't swap */
1041 /***********************************************************************
1042 * FileCDR (KERNEL.130)
1044 void FileCDR(FARPROC x)
1046 printf("FileCDR(%8x)\n", (int) x);
1049 /***********************************************************************
1050 * GetWinDebugInfo (KERNEL.355)
1052 BOOL GetWinDebugInfo(WINDEBUGINFO *lpwdi, UINT flags)
1054 printf("GetWinDebugInfo(%8lx,%d) stub returning 0\n", (unsigned long)lpwdi, flags);
1055 /* 0 means not in debugging mode/version */
1056 /* Can this type of debugging be used in wine ? */
1057 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
1058 return 0;
1061 /***********************************************************************
1062 * GetWinDebugInfo (KERNEL.355)
1064 BOOL SetWinDebugInfo(WINDEBUGINFO *lpwdi)
1066 printf("SetWinDebugInfo(%8lx) stub returning 0\n", (unsigned long)lpwdi);
1067 /* 0 means not in debugging mode/version */
1068 /* Can this type of debugging be used in wine ? */
1069 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
1070 return 0;