Release 960428
[wine/multimedia.git] / misc / main.c
blob2cb0af4b8091c454099175647fdc3ca3a6801490
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)NULL },
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 SHELL_Init();
568 SHELL_LoadRegistry();
570 screen = DefaultScreenOfDisplay( display );
571 screenWidth = WidthOfScreen( screen );
572 screenHeight = HeightOfScreen( screen );
573 if (screenDepth) /* -depth option specified */
575 depth_list = XListDepths(display,DefaultScreen(display),&depth_count);
576 for (i = 0; i < depth_count; i++)
577 if (depth_list[i] == screenDepth) break;
578 XFree( depth_list );
579 if (i >= depth_count)
581 fprintf( stderr, "%s: Depth %d not supported on this screen.\n",
582 Options.programName, screenDepth );
583 exit(1);
586 else screenDepth = DefaultDepthOfScreen( screen );
587 if (Options.synchronous) XSynchronize( display, True );
588 if (Options.desktopGeometry) MAIN_CreateDesktop( argc, argv );
589 else rootWindow = DefaultRootWindow( display );
591 MAIN_SaveSetup();
592 atexit(called_at_exit);
594 ret_val = _WinMain( argc, argv );
596 return ret_val;
599 /***********************************************************************
600 * MessageBeep (USER.104)
602 void MessageBeep(WORD i)
604 XBell(display, 100);
607 /***********************************************************************
608 * GetVersion (KERNEL.3)
610 LONG GetVersion(void)
612 return MAKELONG( WINVERSION, WINDOSVER );
615 /***********************************************************************
616 * GetWinFlags (KERNEL.132)
618 LONG GetWinFlags(void)
620 static const long cpuflags[5] =
621 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
623 long result = 0;
625 /* There doesn't seem to be any Pentium flag. */
626 #ifndef WINELIB
627 long cpuflag = cpuflags[MIN (runtime_cpu (), 4)];
628 #else
629 long cpuflag = cpuflags[4];
630 #endif
632 switch(Options.mode) {
633 case MODE_STANDARD:
634 result = (WF_STANDARD | cpuflag | WF_PMODE | WF_80x87);
635 break;
637 case MODE_ENHANCED:
638 result = (WF_ENHANCED | cpuflag | WF_PMODE | WF_80x87 | WF_PAGING);
639 break;
641 default:
642 fprintf(stderr, "Unknown mode set? This shouldn't happen. Check GetWinFlags()!\n");
643 break;
646 return result;
649 /***********************************************************************
650 * SetEnvironment (GDI.132)
652 int SetEnvironment(LPSTR lpPortName, LPSTR lpEnviron, WORD nCount)
654 LPENVENTRY lpNewEnv;
655 LPENVENTRY lpEnv = lpEnvList;
656 dprintf_env(stddeb, "SetEnvironment('%s', '%s', %d) !\n",
657 lpPortName, lpEnviron, nCount);
658 if (lpPortName == NULL) return -1;
659 while (lpEnv != NULL) {
660 if (lpEnv->Name != NULL && strcmp(lpEnv->Name, lpPortName) == 0) {
661 if (nCount == 0 || lpEnviron == NULL) {
662 if (lpEnv->Prev != NULL) lpEnv->Prev->Next = lpEnv->Next;
663 if (lpEnv->Next != NULL) lpEnv->Next->Prev = lpEnv->Prev;
664 free(lpEnv->Value);
665 free(lpEnv->Name);
666 free(lpEnv);
667 dprintf_env(stddeb, "SetEnvironment() // entry deleted !\n");
668 return -1;
670 free(lpEnv->Value);
671 lpEnv->Value = malloc(nCount);
672 if (lpEnv->Value == NULL) {
673 dprintf_env(stddeb, "SetEnvironment() // Error allocating entry value !\n");
674 return 0;
676 memcpy(lpEnv->Value, lpEnviron, nCount);
677 lpEnv->wSize = nCount;
678 dprintf_env(stddeb, "SetEnvironment() // entry modified !\n");
679 return nCount;
681 if (lpEnv->Next == NULL) break;
682 lpEnv = lpEnv->Next;
684 if (nCount == 0 || lpEnviron == NULL) return -1;
685 dprintf_env(stddeb, "SetEnvironment() // new entry !\n");
686 lpNewEnv = malloc(sizeof(ENVENTRY));
687 if (lpNewEnv == NULL) {
688 dprintf_env(stddeb, "SetEnvironment() // Error allocating new entry !\n");
689 return 0;
691 if (lpEnvList == NULL) {
692 lpEnvList = lpNewEnv;
693 lpNewEnv->Prev = NULL;
695 else
697 lpEnv->Next = lpNewEnv;
698 lpNewEnv->Prev = lpEnv;
700 lpNewEnv->Next = NULL;
701 lpNewEnv->Name = malloc(strlen(lpPortName) + 1);
702 if (lpNewEnv->Name == NULL) {
703 dprintf_env(stddeb, "SetEnvironment() // Error allocating entry name !\n");
704 return 0;
706 strcpy(lpNewEnv->Name, lpPortName);
707 lpNewEnv->Value = malloc(nCount);
708 if (lpNewEnv->Value == NULL) {
709 dprintf_env(stddeb, "SetEnvironment() // Error allocating entry value !\n");
710 return 0;
712 memcpy(lpNewEnv->Value, lpEnviron, nCount);
713 lpNewEnv->wSize = nCount;
714 return nCount;
717 /***********************************************************************
718 * SetEnvironmentVariableA (KERNEL32.484)
720 BOOL SetEnvironmentVariableA(LPSTR lpName, LPSTR lpValue)
722 int rc;
724 rc = SetEnvironment(lpName, lpValue, strlen(lpValue) + 1);
725 return (rc > 0) ? 1 : 0;
728 /***********************************************************************
729 * GetEnvironment (GDI.134)
731 int GetEnvironment(LPSTR lpPortName, LPSTR lpEnviron, WORD nMaxSiz)
733 WORD nCount;
734 LPENVENTRY lpEnv = lpEnvList;
735 dprintf_env(stddeb, "GetEnvironment('%s', '%s', %d) !\n",
736 lpPortName, lpEnviron, nMaxSiz);
737 while (lpEnv != NULL) {
738 if (lpEnv->Name != NULL && strcmp(lpEnv->Name, lpPortName) == 0) {
739 nCount = MIN(nMaxSiz, lpEnv->wSize);
740 memcpy(lpEnviron, lpEnv->Value, nCount);
741 dprintf_env(stddeb, "GetEnvironment() // found '%s' !\n", lpEnviron);
742 return nCount;
744 lpEnv = lpEnv->Next;
746 dprintf_env(stddeb, "GetEnvironment() // not found !\n");
747 return 0;
750 /***********************************************************************
751 * GetEnvironmentVariableA (KERNEL32.213)
753 DWORD GetEnvironmentVariableA(LPSTR lpName, LPSTR lpValue, DWORD size)
755 return GetEnvironment(lpName, lpValue, size);
758 /***********************************************************************
759 * GetEnvironmentStrings (KERNEL32.210)
761 LPVOID GetEnvironmentStrings(void)
763 int count;
764 LPENVENTRY lpEnv;
765 char *envtable, *envptr;
767 /* Count the total number of bytes we'll need for the string
768 * table. Include the trailing nuls and the final double nul.
770 count = 1;
771 lpEnv = lpEnvList;
772 while(lpEnv != NULL)
774 if(lpEnv->Name != NULL)
776 count += strlen(lpEnv->Name) + 1;
777 count += strlen(lpEnv->Value) + 1;
779 lpEnv = lpEnv->Next;
782 envtable = malloc(count);
783 if(envtable)
785 lpEnv = lpEnvList;
786 envptr = envtable;
788 while(lpEnv != NULL)
790 if(lpEnv->Name != NULL)
792 count = sprintf(envptr, "%s=%s", lpEnv->Name, lpEnv->Value);
793 envptr += count + 1;
795 lpEnv = lpEnv->Next;
797 *envptr = '\0';
800 return envtable;
804 LPVOID GetEnvironmentStringsW(void)
806 int count,len;
807 LPENVENTRY lpEnv;
808 char *envtable, *envptr;
809 WCHAR *wenvtable;
811 /* Count the total number of bytes we'll need for the string
812 * table. Include the trailing nuls and the final double nul.
814 count = 1;
815 lpEnv = lpEnvList;
816 while(lpEnv != NULL)
818 if(lpEnv->Name != NULL)
820 count += strlen(lpEnv->Name) + 1;
821 count += strlen(lpEnv->Value) + 1;
823 lpEnv = lpEnv->Next;
826 len=count;
827 envtable = malloc(count);
828 if(envtable)
830 lpEnv = lpEnvList;
831 envptr = envtable;
833 while(lpEnv != NULL)
835 if(lpEnv->Name != NULL)
837 count = sprintf(envptr, "%s=%s", lpEnv->Name, lpEnv->Value);
838 envptr += count + 1;
840 lpEnv = lpEnv->Next;
842 *envptr = '\0';
845 wenvtable = malloc(2*len);
846 for(count=0;count<len;count++)
847 wenvtable[count]=(WCHAR)envtable[count];
848 free(envtable);
850 return envtable;
853 void FreeEnvironmentStringsA(void *e)
855 free(e);
858 void FreeEnvironmentStringsW(void* e)
860 free(e);
863 /***********************************************************************
864 * GetTimerResolution (USER.14)
866 LONG GetTimerResolution(void)
868 return (1000);
871 /***********************************************************************
872 * SystemParametersInfo (USER.483)
874 BOOL SystemParametersInfo (UINT uAction, UINT uParam, LPVOID lpvParam, UINT fuWinIni)
876 int timeout, temp;
877 char buffer[256];
878 XKeyboardState keyboard_state;
879 XKeyboardControl keyboard_value;
882 fprintf(stderr, "SystemParametersInfo: action %d, param %x, flag %x\n",
883 uAction, uParam, fuWinIni);
885 switch (uAction) {
886 case SPI_GETBEEP:
887 XGetKeyboardControl(display, &keyboard_state);
888 if (keyboard_state.bell_percent == 0)
889 *(BOOL *) lpvParam = FALSE;
890 else
891 *(BOOL *) lpvParam = TRUE;
892 break;
894 case SPI_GETBORDER:
895 *(INT *) lpvParam = 1;
896 break;
898 case SPI_GETFASTTASKSWITCH:
899 *(BOOL *) lpvParam = FALSE;
900 break;
902 case SPI_GETGRIDGRANULARITY:
903 *(INT *) lpvParam = 1;
904 break;
906 case SPI_GETICONTITLEWRAP:
907 *(BOOL *) lpvParam = FALSE;
908 break;
910 case SPI_GETKEYBOARDDELAY:
911 *(INT *) lpvParam = 1;
912 break;
914 case SPI_GETKEYBOARDSPEED:
915 *(WORD *) lpvParam = 30;
916 break;
918 case SPI_GETMENUDROPALIGNMENT:
919 *(BOOL *) lpvParam = FALSE;
920 break;
922 case SPI_GETSCREENSAVEACTIVE:
923 *(BOOL *) lpvParam = FALSE;
924 break;
926 case SPI_GETSCREENSAVETIMEOUT:
927 XGetScreenSaver(display, &timeout, &temp,&temp,&temp);
928 *(INT *) lpvParam = timeout * 1000;
929 break;
931 case SPI_ICONHORIZONTALSPACING:
932 if (lpvParam == NULL)
933 fprintf(stderr, "SystemParametersInfo: Horizontal icon spacing set to %d\n.", uParam);
934 else
935 *(INT *) lpvParam = 50;
936 break;
938 case SPI_ICONVERTICALSPACING:
939 if (lpvParam == NULL)
940 fprintf(stderr, "SystemParametersInfo: Vertical icon spacing set to %d\n.", uParam);
941 else
942 *(INT *) lpvParam = 50;
943 break;
945 case SPI_SETBEEP:
946 if (uParam == TRUE)
947 keyboard_value.bell_percent = -1;
948 else
949 keyboard_value.bell_percent = 0;
950 XChangeKeyboardControl(display, KBBellPercent,
951 &keyboard_value);
952 break;
954 case SPI_SETSCREENSAVEACTIVE:
955 if (uParam == TRUE)
956 XActivateScreenSaver(display);
957 else
958 XResetScreenSaver(display);
959 break;
961 case SPI_SETSCREENSAVETIMEOUT:
962 XSetScreenSaver(display, uParam, 60, DefaultBlanking,
963 DefaultExposures);
964 break;
966 case SPI_SETDESKWALLPAPER:
967 return (SetDeskWallPaper((LPSTR) lpvParam));
968 break;
970 case SPI_SETDESKPATTERN:
971 if ((INT) uParam == -1) {
972 GetProfileString("Desktop", "Pattern",
973 "170 85 170 85 170 85 170 85",
974 buffer, sizeof(buffer) );
975 return (DESKTOP_SetPattern((LPSTR) buffer));
976 } else
977 return (DESKTOP_SetPattern((LPSTR) lpvParam));
978 break;
980 case SPI_GETICONTITLELOGFONT:
982 LPLOGFONT lpLogFont = (LPLOGFONT)lpvParam;
983 lpLogFont->lfHeight = 10;
984 lpLogFont->lfWidth = 0;
985 lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
986 lpLogFont->lfWeight = FW_NORMAL;
987 lpLogFont->lfItalic = lpLogFont->lfStrikeOut = lpLogFont->lfUnderline = FALSE;
988 lpLogFont->lfCharSet = ANSI_CHARSET;
989 lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
990 lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
991 lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
992 break;
994 case SPI_LANGDRIVER:
995 case SPI_SETBORDER:
996 case SPI_SETDOUBLECLKHEIGHT:
997 case SPI_SETDOUBLECLICKTIME:
998 case SPI_SETDOUBLECLKWIDTH:
999 case SPI_SETFASTTASKSWITCH:
1000 case SPI_SETKEYBOARDDELAY:
1001 case SPI_SETKEYBOARDSPEED:
1002 fprintf(stderr, "SystemParametersInfo: option %d ignored.\n", uParam);
1003 break;
1005 default:
1006 fprintf(stderr, "SystemParametersInfo: unknown option %d.\n", uParam);
1007 break;
1009 return 1;
1012 /***********************************************************************
1013 * HMEMCPY (KERNEL.348)
1015 void hmemcpy(LPVOID hpvDest, LPCVOID hpvSource, LONG cbCopy)
1017 memcpy(hpvDest, hpvSource, cbCopy);
1020 /***********************************************************************
1021 * COPY (GDI.250)
1023 void Copy(LPVOID lpSource, LPVOID lpDest, WORD nBytes)
1025 memcpy(lpDest, lpSource, nBytes);
1028 /***********************************************************************
1029 * SWAPMOUSEBUTTON (USER.186)
1031 BOOL SwapMouseButton(BOOL fSwap)
1033 return 0; /* don't swap */
1036 /***********************************************************************
1037 * FileCDR (KERNEL.130)
1039 void FileCDR(FARPROC x)
1041 printf("FileCDR(%8x)\n", (int) x);
1044 /***********************************************************************
1045 * GetWinDebugInfo (KERNEL.355)
1047 BOOL GetWinDebugInfo(WINDEBUGINFO FAR* lpwdi, UINT flags)
1049 printf("GetWinDebugInfo(%8lx,%d) stub returning 0\n", (unsigned long)lpwdi, flags);
1050 /* 0 means not in debugging mode/version */
1051 /* Can this type of debugging be used in wine ? */
1052 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
1053 return 0;
1056 /***********************************************************************
1057 * GetWinDebugInfo (KERNEL.355)
1059 BOOL SetWinDebugInfo(WINDEBUGINFO FAR* lpwdi)
1061 printf("SetWinDebugInfo(%8lx) stub returning 0\n", (unsigned long)lpwdi);
1062 /* 0 means not in debugging mode/version */
1063 /* Can this type of debugging be used in wine ? */
1064 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
1065 return 0;