Merge trunk-1.3-3 SDL-1.3
authorSam Lantinga <slouken@libsdl.org>
Wed, 17 May 2006 08:18:28 +0000
branchSDL-1.3
changeset 165914717b52abc0
parent 1658 e49147870aac
child 1660 8b9d79e7eacf
Merge trunk-1.3-3
CWprojects.sea.bin
Makefile.in
README
README.MacOSX
README.OS2
README.SVN
README.Watcom
SDL.spec.in
TODO
VisualCE.zip
Watcom-OS2.zip
Watcom-Win32.zip
WhatsNew
autogen.sh
build-scripts/fatbuild.sh
build-scripts/ltmain.sh
configure.in
docs.html
docs/images/rainbow.gif
docs/index.html
include/SDL_config.h.in
include/SDL_config_macos.h
include/SDL_config_macosx.h
include/SDL_platform.h
include/SDL_stdinc.h
include/SDL_syswm.h
sdl.m4
src/SDL_error.c
src/SDL_error_c.h
src/audio/SDL_audio.c
src/audio/SDL_audio_c.h
src/audio/SDL_audiocvt.c
src/audio/SDL_wave.c
src/audio/SDL_wave.h
src/audio/mint/SDL_mintaudio.c
src/audio/mint/SDL_mintaudio.h
src/cdrom/macosx/AudioFilePlayer.c
src/cdrom/macosx/SDL_syscdrom.c
src/events/SDL_events.c
src/events/SDL_keyboard.c
src/file/SDL_rwops.c
src/joystick/linux/SDL_sysjoystick.c
src/joystick/win32/SDL_mmjoystick.c
src/loadso/macosx/SDL_dlcompat.c
src/loadso/macosx/SDL_sysloadso.c
src/main/dummy/SDL_dummy_main.c
src/main/macosx/SDLMain.m
src/main/win32/SDL_win32_main.c
src/stdlib/SDL_string.c
src/thread/SDL_thread.c
src/thread/pth/SDL_systhread.c
src/thread/win32/SDL_systhread.c
src/timer/SDL_timer.c
src/timer/macos/FastTimes.c
src/timer/macos/SDL_systimer.c
src/video/SDL_blit_A.c
src/video/SDL_blit_N.c
src/video/ataricommon/SDL_ikbdinterrupt_s.h
src/video/ataricommon/SDL_xbiosinterrupt_s.h
src/video/dga/SDL_dgavideo.c
src/video/dga/SDL_dgavideo.h
src/video/directfb/SDL_DirectFB_events.c
src/video/directfb/SDL_DirectFB_video.c
src/video/directfb/SDL_DirectFB_yuv.c
src/video/fbcon/SDL_fb3dfx.c
src/video/fbcon/SDL_fbevents.c
src/video/fbcon/SDL_fbmatrox.c
src/video/fbcon/SDL_fbriva.c
src/video/fbcon/SDL_fbvideo.c
src/video/fbcon/SDL_fbvideo.h
src/video/maccommon/SDL_macgl.c
src/video/maccommon/SDL_macgl_c.h
src/video/macdsp/SDL_dspvideo.c
src/video/macrom/SDL_romvideo.c
src/video/ps2gs/SDL_gsyuv.c
src/video/quartz/SDL_QuartzVideo.m
src/video/quartz/SDL_QuartzWM.m
src/video/quartz/SDL_QuartzYUV.m
src/video/wincommon/SDL_wingl.c
src/video/windib/SDL_dibvideo.c
src/video/windx5/SDL_dx5video.c
src/video/x11/SDL_x11dyn.c
src/video/x11/SDL_x11events.c
src/video/x11/SDL_x11events_c.h
src/video/x11/SDL_x11gl.c
src/video/x11/SDL_x11modes.c
src/video/x11/SDL_x11sym.h
src/video/x11/SDL_x11video.c
src/video/x11/SDL_x11video.h
src/video/x11/SDL_x11wm.c
src/video/x11/SDL_x11wm_c.h
src/video/xbios/SDL_xbios.c
test/acinclude.m4
test/autogen.sh
test/configure.in
test/gcc-fat.sh
test/loopwave.c
test/testalpha.c
test/testdyngl.c
test/testerror.c
test/testfile.c
test/testgl.c
test/testhread.c
test/testlock.c
test/testpalette.c
test/testsem.c
test/testtimer.c
test/testwin.c
test/testwm.c
test/threadwin.c
test/torturethread.c
     1.1 Binary file CWprojects.sea.bin has changed
     2.1 --- a/Makefile.in	Mon May 01 06:58:33 2006 +0000
     2.2 +++ b/Makefile.in	Wed May 17 08:18:28 2006 +0000
     2.3 @@ -38,7 +38,7 @@
     2.4  SDLMAIN_SOURCES = @SDLMAIN_SOURCES@
     2.5  SDLMAIN_OBJECTS = @SDLMAIN_OBJECTS@
     2.6  
     2.7 -DIST = acinclude.m4 autogen.sh Borland.html Borland.zip BUGS build-scripts configure configure.in COPYING CREDITS CWprojects.sea.bin docs docs.html EpocBuildFiles.zip include INSTALL Makefile.dc Makefile.minimal Makefile.in MPWmake.sea.bin README* sdl-config.in sdl.m4 SDL.qpg.in SDL.spec SDL.spec.in src test TODO VisualCE.zip VisualC.html VisualC.zip Watcom-OS2.zip WhatsNew Xcode.tar.gz
     2.8 +DIST = acinclude.m4 autogen.sh Borland.html Borland.zip BUGS build-scripts configure configure.in COPYING CREDITS CWprojects.sea.bin docs docs.html EpocBuildFiles.zip include INSTALL Makefile.dc Makefile.minimal Makefile.in MPWmake.sea.bin README* sdl-config.in sdl.m4 SDL.qpg.in SDL.spec SDL.spec.in src test TODO VisualCE.zip VisualC.html VisualC.zip Watcom-OS2.zip Watcom-Win32.zip WhatsNew Xcode.tar.gz
     2.9  
    2.10  LT_AGE      = @LT_AGE@
    2.11  LT_CURRENT  = @LT_CURRENT@
    2.12 @@ -78,7 +78,7 @@
    2.13  	$(AR) cru $@ $(SDLMAIN_OBJECTS)
    2.14  	$(RANLIB) $@
    2.15  
    2.16 -install: install-bin install-hdrs install-lib install-data install-man
    2.17 +install: all install-bin install-hdrs install-lib install-data install-man
    2.18  install-bin:
    2.19  	$(SHELL) $(auxdir)/mkinstalldirs $(bindir)
    2.20  	$(INSTALL) -m 755 sdl-config $(bindir)/sdl-config
    2.21 @@ -131,7 +131,6 @@
    2.22  
    2.23  distclean: clean
    2.24  	rm -f Makefile include/SDL_config.h sdl-config
    2.25 -	rm -f include/SDL_config.h sdl-config
    2.26  	rm -f SDL.qpg
    2.27  	rm -f config.status config.cache config.log libtool $(depend)
    2.28  	rm -rf $(srcdir)/autom4te*
    2.29 @@ -151,8 +150,15 @@
    2.30  	tar cf - $(DIST) | (cd $(distdir); tar xf -)
    2.31  	cp $(distdir)/include/SDL_config.h.default $(distdir)/include/SDL_config.h
    2.32  	rm -rf `find $(distdir) -name .svn`
    2.33 -	rm -f `find $(distdir) -name '.#*'`
    2.34 -	rmdir `find $(distdir) -type d -empty`
    2.35 +	find $(distdir) \( \
    2.36 +	    -name '*~' -o \
    2.37 +	    -name '*.bak' -o \
    2.38 +	    -name '*.old' -o \
    2.39 +	    -name '*.rej' -o \
    2.40 +	    -name '*.orig' -o \
    2.41 +	    -name '.#*' \) \
    2.42 +	    -exec rm -f {} \;
    2.43 +	if test -f $(distdir)/test/Makefile; then (cd $(distdir)/test && make distclean); fi
    2.44  	tar cvf - $(distdir) | gzip --best >$(distfile)
    2.45  	rm -rf $(distdir)
    2.46  
     3.1 --- a/README	Mon May 01 06:58:33 2006 +0000
     3.2 +++ b/README	Wed May 17 08:18:28 2006 +0000
     3.3 @@ -12,14 +12,15 @@
     3.4  level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL,
     3.5  and 2D framebuffer across multiple platforms.
     3.6  
     3.7 +The current version supports Linux, Windows, Windows CE, BeOS, MacOS,
     3.8 +Mac OS X, FreeBSD, NetBSD, OpenBSD, BSD/OS, Solaris, IRIX, and QNX.
     3.9 +The code contains support for AmigaOS, Dreamcast, Atari, AIX, OSF/Tru64,
    3.10 +RISC OS, SymbianOS, and OS/2, but these are not officially supported.
    3.11 +
    3.12  SDL is written in C, but works with C++ natively, and has bindings to
    3.13 -several other languages, including Ada, C#, Eiffel, Java, Lua, ML,
    3.14 -Objective C, Pascal, Perl, PHP, Pike, Python, and Ruby.
    3.15 -
    3.16 -The current version supports Linux, Windows, BeOS, MacOS, Mac OS X,
    3.17 -FreeBSD, OpenBSD, BSD/OS, Solaris, IRIX, and QNX.  The code contains
    3.18 -support for Windows CE, AmigaOS, Dreamcast, Atari, NetBSD, AIX, OSF/Tru64,
    3.19 -RISC OS, SymbianOS, and OS/2, but these are not officially supported.
    3.20 +several other languages, including Ada, C#, Eiffel, Erlang, Euphoria,
    3.21 +Guile, Haskell, Java, Lisp, Lua, ML, Objective C, Pascal, Perl, PHP,
    3.22 +Pike, Pliant, Python, Ruby, and Smalltalk.
    3.23  
    3.24  This library is distributed under GNU LGPL version 2, which can be
    3.25  found in the file  "COPYING".  This license allows you to use SDL
    3.26 @@ -29,7 +30,9 @@
    3.27  The best way to learn how to use SDL is to check out the header files in
    3.28  the "include" subdirectory and the programs in the "test" subdirectory.
    3.29  The header files and test programs are well commented and always up to date.
    3.30 -More documentation is available in HTML format in "./docs/index.html"
    3.31 +More documentation is available in HTML format in "docs/index.html", and
    3.32 +a documentation wiki is available online at:
    3.33 +	http://www.libsdl.org/cgi/docwiki.cgi
    3.34  
    3.35  The test programs in the "test" subdirectory are in the public domain.
    3.36  
     4.1 --- a/README.MacOSX	Mon May 01 06:58:33 2006 +0000
     4.2 +++ b/README.MacOSX	Wed May 17 08:18:28 2006 +0000
     4.3 @@ -21,6 +21,10 @@
     4.4  the fatbuild.sh script in build-scripts:
     4.5  	sh build-scripts/fatbuild.sh
     4.6  	sudo build-scripts/fatbuild.sh install
     4.7 +This script builds SDL with 10.2 ABI compatibility on PowerPC and 10.4
     4.8 +ABI compatibility on Intel architectures.  For best compatibility you
     4.9 +should compile your application the same way.  A script which wraps
    4.10 +gcc to make this easy is provided in test/gcc-fat.sh
    4.11  
    4.12  To use the library once it's built, you essential have two possibilities:
    4.13  use the traditional autoconf/automake/make method, or use Xcode.
     5.1 --- a/README.OS2	Mon May 01 06:58:33 2006 +0000
     5.2 +++ b/README.OS2	Wed May 17 08:18:28 2006 +0000
     5.3 @@ -3,7 +3,7 @@
     5.4  SDL on OS/2
     5.5  ===========
     5.6  
     5.7 -Last updated on Feb. 26, 2006.
     5.8 +Last updated on May. 1, 2006.
     5.9  
    5.10  
    5.11  1. How to compile?
    5.12 @@ -16,10 +16,9 @@
    5.13  - The FSLib library
    5.14    (ftp://ftp.netlabs.org/pub/SDL)
    5.15  
    5.16 -First of all, you have to put the OS/2-specific Watcom makefiles into the
    5.17 -source code tree by unzipping the file Watcom-OS2.zip here.  This will
    5.18 -result in a Watcom.mif and a setvars.cmd file in this folder, and several
    5.19 -Makefile.wat files in the src\ folder and in some of its subfolders.
    5.20 +First of all, you have to unzip the Watcom-OS2.zip file. This will result in a 
    5.21 +file called "makefile" and a file called "setvars.cmd" in this folder (and some
    5.22 +more files...).
    5.23  
    5.24  Please edit the second, fourth and fifth lines of setvars.cmd file
    5.25  to set the folders where the toolkit, the OW compiler and the FSLib are. 
    5.26 @@ -27,23 +26,22 @@
    5.27  Run setvars.cmd, and you should get a shell in which you can
    5.28  compile SDL.
    5.29  
    5.30 -Check the "Watcom.mif" file. This is the file which is included by all the
    5.31 -Watcom makefiles, so changes here will affect the whole build process.
    5.32 -There is a line in there which determines if the resulting SDL.DLL will be
    5.33 -a 'debug' or a 'release' build. The 'debug' version is full of printf()'s,
    5.34 -so if something goes wrong, its output can help a lot for debugging.
    5.35 +Check the "makefile" file. There is a line in there which determines if the 
    5.36 +resulting SDL.DLL will be a 'debug' or a 'release' build. The 'debug' version 
    5.37 +is full of printf()'s, so if something goes wrong, its output can help a lot
    5.38 +for debugging.
    5.39  
    5.40 -Then go to the 'src' folder, and run "wmake -f makefile.wat".
    5.41 -This should create the SDL.DLL and the corresponding SDL.LIB file there.
    5.42 +Then run "wmake".
    5.43 +This should create the SDL.DLL and the corresponding SDL.LIB file here.
    5.44  
    5.45  To test applications, it's a good idea to use the 'debug' build of SDL, and
    5.46  redirect the standard output and standard error output to files, to see what
    5.47  happens internally in SDL.
    5.48  (like: testsprite >stdout.txt 2>stderr.txt)
    5.49  
    5.50 -To rebuild SDL, use the following commands in 'src' folder:
    5.51 -wmake -f makefile.wat clean
    5.52 -wmake -f makefile.wat
    5.53 +To rebuild SDL, use the following commands in this folder:
    5.54 +wmake clean
    5.55 +wmake
    5.56  
    5.57  
    5.58  
    5.59 @@ -53,7 +51,7 @@
    5.60  Once you have SDL.DLL compiled, navigate into the 'test' folder, copy in there
    5.61  the newly built SDL.DLL, and copy in there FSLib.DLL.
    5.62  
    5.63 -Then run "wmake -f makefile.wat" in there to compile some of the testapps.
    5.64 +Then run "wmake" in there to compile some of the testapps.
    5.65  
    5.66  
    5.67  
    5.68 @@ -193,6 +191,10 @@
    5.69  10. Changelog of the OS/2 port
    5.70  ------------------------------
    5.71  
    5.72 +Version 1.2 - 2006-05-01  - Doodle
    5.73 + - Modified makefile system to have only one makefile
    5.74 + - Included FSLib headers, DLL and LIB file
    5.75 +
    5.76  Version 1.2 - 2006-02-26  - Doodle
    5.77   - Updated the official SDL version with the OS/2 specific changes.
    5.78   - Added support for real unicode keycode conversion.
     6.1 --- a/README.SVN	Mon May 01 06:58:33 2006 +0000
     6.2 +++ b/README.SVN	Wed May 17 08:18:28 2006 +0000
     6.3 @@ -9,10 +9,12 @@
     6.4  
     6.5    svn checkout svn://libsdl.org/trunk/SDL
     6.6  
     6.7 -When you check out a fresh copy of SDL out via svn, you need to
     6.8 -generate the files used by make by running the "autogen.sh"
     6.9 -script, which will run aclocal, automake, autoconf and then
    6.10 -run configure.
    6.11 +If you are building SDL with an IDE, you will need to copy the file
    6.12 +include/SDL_config.h.default to include/SDL_config.h before building.
    6.13  
    6.14 -There is a web interface to svn at http://www.libsdl.org/wsvn
    6.15 +If you are building SDL via configure, you will need to run autogen.sh
    6.16 +before running configure.
    6.17  
    6.18 +There is a web interface to the subversion repository at:
    6.19 +	http://www.libsdl.org/cgi/viewvc.cgi
    6.20 +
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/README.Watcom	Wed May 17 08:18:28 2006 +0000
     7.3 @@ -0,0 +1,129 @@
     7.4 +
     7.5 +Using SDL under Windows with the OpenWatcom compiler
     7.6 +====================================================
     7.7 +
     7.8 +Prerequisites
     7.9 +-------------
    7.10 +
    7.11 +I have done the port under Windows XP Home with SP2 installed. Windows
    7.12 +2000 should also be working. I'm not so sure about ancient Windows NT,
    7.13 +since only DirectX 3 is available there. Building should be possible,
    7.14 +but running the compiled applications will probalbly fail with
    7.15 +SDL_VIDEODRIVER=directx. The windib driver should work, though.
    7.16 +
    7.17 +To compile and use the SDL with Open Watcom you will need the following:
    7.18 +- Open Watcom compiler. I used version 1.5. The environment variables
    7.19 +  PATH, WATCOM and INCLUDE need to be set appropriately - please consult
    7.20 +  the OpenWatcom documentation and instructions given during the
    7.21 +  installation of the compiler.
    7.22 +  My setup looks like this in owvars.bat:
    7.23 +    set WATCOM=C:\watcom
    7.24 +    set INCLUDE=%WATCOM%\h;%WATCOM%\h\nt
    7.25 +    set PATH=%PATH%;%WATCOM%\binnt;%WATCOM%\binw
    7.26 +- A fairly recent DirectX SDK. The original unmodified DX8 SDK works, as
    7.27 +  well as the minimal DirectX 7 SDK from the Allegro download site
    7.28 +  (<http://alleg.sourceforge.net/files/dx70_min.zip>).
    7.29 +- The SDL sources from Subversion
    7.30 +- The file Watcom-Win32.zip (now available in Subversion)
    7.31 +
    7.32 +
    7.33 +Building the Library
    7.34 +--------------------
    7.35 +
    7.36 +1) In the SDL base directory extract the archive Watcom-Win32.zip. This
    7.37 +   creates a subdirectory named 'watcom'.
    7.38 +2) The makefile expects the environment variable DXDIR to be set to the
    7.39 +   base directory of a DirectX SDK. I have tried a stock DX8 SDK from
    7.40 +   Microsoft as well as the minimal DirectX 7 SDK from the Allegro
    7.41 +   download site.
    7.42 +   You can also edit the makefile directly and hard code your path to
    7.43 +   the SDK on your system.
    7.44 +   I have this in my setup:
    7.45 +     set DXDIR=D:\devel\DX8_SDK
    7.46 +3) Enter the watcom directory and run
    7.47 +     wmake sdl
    7.48 +4) All tests from the test directory are working and can be built by
    7.49 +   running
    7.50 +     wmake tests
    7.51 +
    7.52 +Notes:
    7.53 +
    7.54 + The makefile offers some options to tweak the way the library is built.
    7.55 + You have at your disposal the option to build a static (default)
    7.56 + library, or a DLL (with tgt=dll). You can also choose whether to build
    7.57 + a Release (default) or a Debug version (with build=debug) of the tests
    7.58 + and library. Please consult the usage comment at the top of the
    7.59 + makefile for usage instructions.
    7.60 +
    7.61 + If you specify a test target (i.e. 'wmake tests' for all tests, or
    7.62 + selected targets like 'wmake testgl testvidinfo testoverlay2'), the
    7.63 + tests are always freshly compiled and linked. This is done to
    7.64 + minimise hassle when switching between library versions (static vs.
    7.65 + DLL), because they require subtly different options.
    7.66 + Also, the test executables are put directly into the test directory,
    7.67 + so they can find their data files. The clean target of the makefile
    7.68 + removes the test executables and the SDL.dll file from the test
    7.69 + directory.
    7.70 +
    7.71 + To use the library in your own projects with Open Watcom, you can use
    7.72 + the way the tests are built as base of your own build environment.
    7.73 +
    7.74 +
    7.75 +Test applications
    7.76 +-----------------
    7.77 +
    7.78 +I've tried to make all tests work. The following table gives an overview
    7.79 +of the current status.
    7.80 +
    7.81 + Testname        Status
    7.82 +~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    7.83 +checkkeys       +
    7.84 +graywin         +
    7.85 +loopwave        +
    7.86 +testalpha       +
    7.87 +testbitmap      +
    7.88 +testdyngl       +
    7.89 +testerror       +
    7.90 +testfile        +
    7.91 +testgamma       +
    7.92 +testgl          +
    7.93 +testhread       +
    7.94 +testiconv       - (all failed)
    7.95 +testkeys        +
    7.96 +testlock        +
    7.97 +testoverlay     + (needs 'set SDL_VIDEODRIVER=directx')
    7.98 +testoverlay2    + (needs 'set SDL_VIDEODRIVER=directx')
    7.99 +testpalette     +
   7.100 +testplatform    +
   7.101 +testsem         +
   7.102 +testsprite      +
   7.103 +testtimer       +
   7.104 +testver         +
   7.105 +testvidinfo     +
   7.106 +testwin         - (fading doesn't seem right)
   7.107 +testwm          +
   7.108 +torturethread   +
   7.109 +testcdrom       +
   7.110 +testjoystick    not tested
   7.111 +threadwin       +
   7.112 +
   7.113 +
   7.114 +TODO
   7.115 +----
   7.116 +
   7.117 +There is room for further improvement:
   7.118 +- Test joystick functionality.
   7.119 +- Investigate fading issue in 'testwin' test.
   7.120 +- Fix the UTF-8 support.
   7.121 +- Adapt the makefile/object file list to support more target systems
   7.122 +- Use "#pragma aux" syntax for the CPU info functions.
   7.123 +
   7.124 +
   7.125 +Questions and Comments
   7.126 +----------------------
   7.127 +
   7.128 +Please direct any questions or comments to me:  <mailto:macpete@gmx.de>
   7.129 +
   7.130 +   Happy Coding!
   7.131 +
   7.132 +   Marc Peter
     8.1 --- a/SDL.spec.in	Mon May 01 06:58:33 2006 +0000
     8.2 +++ b/SDL.spec.in	Wed May 17 08:18:28 2006 +0000
     8.3 @@ -9,9 +9,12 @@
     8.4  BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot
     8.5  Prefix: %{_prefix}
     8.6  %ifos linux
     8.7 -Provides: libSDL-1.1.so.0
     8.8 +Provides: libSDL-1.2.so.0
     8.9  %endif
    8.10  
    8.11 +%define __defattr %defattr(-,root,root)
    8.12 +%define __soext so
    8.13 +
    8.14  %description
    8.15  This is the Simple DirectMedia Layer, a generic API that provides low
    8.16  level access to audio, keyboard, mouse, and display framebuffer across
    8.17 @@ -59,25 +62,13 @@
    8.18  %clean
    8.19  rm -rf $RPM_BUILD_ROOT
    8.20  
    8.21 -%ifnos darwin
    8.22 -%define __defattr %defattr(-,root,root)
    8.23 -%define __soext so
    8.24 -%else
    8.25 -%define __defattr %defattr(-,root,wheel)
    8.26 -%define __soext dylib
    8.27 -%endif
    8.28 -
    8.29  %files
    8.30  %{__defattr}
    8.31  %doc README-SDL.txt COPYING CREDITS BUGS
    8.32 -%ifnos darwin
    8.33  %{_libdir}/lib*.%{__soext}.*
    8.34 -%else
    8.35 -%{_libdir}/lib*.*.%{__soext}
    8.36 -%endif
    8.37  
    8.38  %files devel
    8.39 -%defattr(-,root,root)
    8.40 +%{__defattr}
    8.41  %doc README README-SDL.txt COPYING CREDITS BUGS WhatsNew docs.html
    8.42  %doc docs/index.html docs/html
    8.43  %{_bindir}/*-config
    8.44 @@ -90,6 +81,9 @@
    8.45  %{_mandir}/man3/*
    8.46  
    8.47  %changelog
    8.48 +* Tue May 16 2006 Sam Lantinga <slouken@libsdl.org>
    8.49 +- Removed support for Darwin, due to build problems on ps2linux
    8.50 +
    8.51  * Mon Jan 03 2004 Anders Bjorklund <afb@algonet.se>
    8.52  - Added support for Darwin, updated spec file
    8.53  
     9.1 --- a/TODO	Mon May 01 06:58:33 2006 +0000
     9.2 +++ b/TODO	Wed May 17 08:18:28 2006 +0000
     9.3 @@ -2,6 +2,7 @@
     9.4  Wish list for the 1.3 development branch:
     9.5  http://bugzilla.libsdl.org/
     9.6  
     9.7 + * Add internal support for adding video modes and refresh rates
     9.8   * Support querying and setting refresh rate with video modes
     9.9   * Add mousewheel events (new unified event architecture?)
    9.10   * DirectInput joystick support needs to be implemented
    10.1 Binary file VisualCE.zip has changed
    11.1 Binary file Watcom-OS2.zip has changed
    12.1 Binary file Watcom-Win32.zip has changed
    13.1 --- a/WhatsNew	Mon May 01 06:58:33 2006 +0000
    13.2 +++ b/WhatsNew	Wed May 17 08:18:28 2006 +0000
    13.3 @@ -4,6 +4,19 @@
    13.4  Version 1.0:
    13.5  
    13.6  1.2.10:
    13.7 +	If SDL_OpenAudio() is passed zero for the desired format
    13.8 +	fields, the following environment variables will be used
    13.9 +	to fill them in:
   13.10 +		SDL_AUDIO_FREQUENCY
   13.11 +		SDL_AUDIO_FORMAT
   13.12 +		SDL_AUDIO_CHANNELS
   13.13 +		SDL_AUDIO_SAMPLES
   13.14 +	If an environment variable is not specified, it will be set
   13.15 +	to a reasonable default value.
   13.16 +
   13.17 +	Added support for the SDL_VIDEO_FULLSCREEN_HEAD environment
   13.18 +	variable, currently supported on X11 Xinerama configurations.
   13.19 +
   13.20  	Added SDL_GL_SWAP_CONTROL to wait for vsync in OpenGL applications.
   13.21  
   13.22  	Added SDL_GL_ACCELERATED_VISUAL to guarantee hardware acceleration.
    14.1 --- a/autogen.sh	Mon May 01 06:58:33 2006 +0000
    14.2 +++ b/autogen.sh	Wed May 17 08:18:28 2006 +0000
    14.3 @@ -6,7 +6,7 @@
    14.4  # Regenerate configuration files
    14.5  cp acinclude.m4 aclocal.m4
    14.6  found=false
    14.7 -for autoconf in autoconf autoconf259
    14.8 +for autoconf in autoconf autoconf259 autoconf-2.59
    14.9  do if which $autoconf >/dev/null 2>&1; then $autoconf && found=true; break; fi
   14.10  done
   14.11  if test x$found = xfalse; then
    15.1 --- a/build-scripts/fatbuild.sh	Mon May 01 06:58:33 2006 +0000
    15.2 +++ b/build-scripts/fatbuild.sh	Wed May 17 08:18:28 2006 +0000
    15.3 @@ -10,7 +10,12 @@
    15.4  # Generic, cross-platform CFLAGS you always want go here.
    15.5  CFLAGS="-O3 -g -pipe"
    15.6  
    15.7 -# PowerPC compiler flags (10.2 runtime compatibility)
    15.8 +# PowerPC configure flags (10.2 runtime compatibility)
    15.9 +# We dynamically load X11, so using the system X11 headers is fine.
   15.10 +CONFIG_PPC="--build=`uname -p`-apple-darwin --host=powerpc-apple-darwin \
   15.11 +--x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib"
   15.12 +
   15.13 +# PowerPC compiler flags
   15.14  CC_PPC="gcc-3.3 -arch ppc"
   15.15  CXX_PPC="g++-3.3 -arch ppc"
   15.16  CFLAGS_PPC=""
   15.17 @@ -26,7 +31,12 @@
   15.18  -F/Developer/SDKs/MacOSX10.2.8.sdk/System/Library/Frameworks \
   15.19  -Wl,-syslibroot,/Developer/SDKs/MacOSX10.2.8.sdk"
   15.20  
   15.21 -# Intel compiler flags (10.4 runtime compatibility)
   15.22 +# Intel configure flags (10.4 runtime compatibility)
   15.23 +# We dynamically load X11, so using the system X11 headers is fine.
   15.24 +CONFIG_X86="--build=`uname -p`-apple-darwin --host=i386-apple-darwin \
   15.25 +--x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib"
   15.26 +
   15.27 +# Intel compiler flags
   15.28  CC_X86="gcc-4.0 -arch i386"
   15.29  CXX_X86="g++-4.0 -arch i386"
   15.30  CFLAGS_X86="-mmacosx-version-min=10.4"
   15.31 @@ -158,7 +168,7 @@
   15.32  #
   15.33  if test x$configure_ppc = xyes; then
   15.34      (cd build/ppc && \
   15.35 -     sh ../../configure --build=`uname -p`-apple-darwin --host=powerpc-apple-darwin CC="$CC_PPC" CXX="$CXX_PPC" CFLAGS="$CFLAGS $CFLAGS_PPC" CPPFLAGS="$CPPFLAGS_PPC" LDFLAGS="$LFLAGS_PPC") || exit 2
   15.36 +     sh ../../configure $CONFIG_PPC CC="$CC_PPC" CXX="$CXX_PPC" CFLAGS="$CFLAGS $CFLAGS_PPC" CPPFLAGS="$CPPFLAGS_PPC" LDFLAGS="$LFLAGS_PPC") || exit 2
   15.37  fi
   15.38  if test x$make_ppc = xyes; then
   15.39      (cd build/ppc && ls include && make -j$NJOB) || exit 3
   15.40 @@ -169,7 +179,7 @@
   15.41  #
   15.42  if test x$configure_x86 = xyes; then
   15.43      (cd build/x86 && \
   15.44 -     sh ../../configure --build=`uname -p`-apple-darwin --host=i386-apple-darwin CC="$CC_X86" CXX="$CXX_X86" CFLAGS="$CFLAGS $CFLAGS_X86" CPPFLAGS="$CPPFLAGS_X86" LDFLAGS="$LFLAGS_X86") || exit 2
   15.45 +     sh ../../configure $CONFIG_X86 CC="$CC_X86" CXX="$CXX_X86" CFLAGS="$CFLAGS $CFLAGS_X86" CPPFLAGS="$CPPFLAGS_X86" LDFLAGS="$LFLAGS_X86") || exit 2
   15.46  fi
   15.47  if test x$make_x86 = xyes; then
   15.48      (cd build/x86 && make -j$NJOB) || exit 3
    16.1 --- a/build-scripts/ltmain.sh	Mon May 01 06:58:33 2006 +0000
    16.2 +++ b/build-scripts/ltmain.sh	Wed May 17 08:18:28 2006 +0000
    16.3 @@ -5008,7 +5008,7 @@
    16.4  EOF
    16.5  
    16.6              case $host_os in
    16.7 -              mingw*)
    16.8 +	      *cygwin* | *mingw* )
    16.9                  cat >> $cwrappersource <<EOF
   16.10    execv("$SHELL",(char const **)newargz);
   16.11  EOF
    17.1 --- a/configure.in	Mon May 01 06:58:33 2006 +0000
    17.2 +++ b/configure.in	Wed May 17 08:18:28 2006 +0000
    17.3 @@ -74,14 +74,15 @@
    17.4  EXTRA_CFLAGS="$INCLUDE $BASE_CFLAGS"
    17.5  BUILD_LDFLAGS="$LDFLAGS"
    17.6  EXTRA_LDFLAGS="$BASE_LDFLAGS"
    17.7 -for path in /usr/local; do
    17.8 -    if test -d $path/include; then
    17.9 -        EXTRA_CFLAGS="$EXTRA_CFLAGS -I$path/include"
   17.10 -    fi
   17.11 -    if test -d $path/lib; then
   17.12 -        EXTRA_LDFLAGS="$EXTRA_LDFLAGS -L$path/lib"
   17.13 -    fi
   17.14 -done
   17.15 +# I can't remember why I added this.  I'm sure it'll come to me...
   17.16 +#for path in /usr/local; do
   17.17 +#    if test -d $path/include; then
   17.18 +#        EXTRA_CFLAGS="$EXTRA_CFLAGS -I$path/include"
   17.19 +#    fi
   17.20 +#    if test -d $path/lib; then
   17.21 +#        EXTRA_LDFLAGS="$EXTRA_LDFLAGS -L$path/lib"
   17.22 +#    fi
   17.23 +#done
   17.24  SDL_CFLAGS="$BASE_CFLAGS"
   17.25  SDL_LIBS="-lSDL $BASE_LDFLAGS"
   17.26  CPPFLAGS="$CPPFLAGS $EXTRA_CFLAGS"
   17.27 @@ -715,7 +716,9 @@
   17.28      save_CFLAGS="$CFLAGS"
   17.29      CFLAGS="$save_CFLAGS $visibility_CFLAGS"
   17.30      AC_TRY_COMPILE([
   17.31 -        int placeholder = 1;
   17.32 +    #if !defined(__GNUC__) || __GNUC__ < 4
   17.33 +    #error SDL only uses visibility attributes in GCC 4 or newer
   17.34 +    #endif
   17.35      ],[
   17.36      ],[
   17.37      have_gcc_fvisibility=yes
   17.38 @@ -786,6 +789,15 @@
   17.39  AC_HELP_STRING([--enable-video-x11], [use X11 video driver [[default=yes]]]),
   17.40                    , enable_video_x11=yes)
   17.41      if test x$enable_video = xyes -a x$enable_video_x11 = xyes; then
   17.42 +        case "$host" in
   17.43 +            *-*-darwin*)
   17.44 +                # This isn't necessary for X11, but fixes GLX detection
   17.45 +                if test "x$x_includes" = xNONE && test "x$x_libraries" = xNONE; then
   17.46 +                    x_includes="/usr/X11R6/include"
   17.47 +                    x_libraries="/usr/X11R6/lib"
   17.48 +                fi
   17.49 +                ;;
   17.50 +        esac
   17.51          AC_PATH_X
   17.52          AC_PATH_XTRA
   17.53          if test x$have_x = xyes; then
   17.54 @@ -813,15 +825,27 @@
   17.55                      for path in $x11_lib_path /usr/lib /usr/X11/lib /usr/X11R6/lib; do
   17.56                          if test "x$x11_lib" = "x"; then
   17.57                              x11_lib=[`ls -- $path/libX11.so.[0-9] 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
   17.58 +							if test "x$x11_lib" = "x"; then
   17.59 +								x11_lib=[`ls -- $path/libX11.so.[0-9]* 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
   17.60 +							fi
   17.61                          fi
   17.62                          if test "x$x11ext_lib" = "x"; then
   17.63                              x11ext_lib=[`ls -- $path/libXext.so.[0-9] 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
   17.64 +							if test "x$x11ext_lib" = "x"; then
   17.65 +								x11ext_lib=[`ls -- $path/libXext.so.[0-9]* 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
   17.66 +							fi
   17.67                          fi
   17.68                          if test "x$xrender_lib" = "x"; then
   17.69                              xrender_lib=[`ls -- $path/libXrender.so.[0-9] 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
   17.70 +							if test "x$xrender_lib" = "x"; then
   17.71 +								xrender_lib=[`ls -- $path/libXrender.so.[0-9]* 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
   17.72 +							fi
   17.73                          fi
   17.74                          if test "x$xrandr_lib" = "x"; then
   17.75                              xrandr_lib=[`ls -- $path/libXrandr.so.[0-9] 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
   17.76 +							if test "x$xrandr_lib" = "x"; then
   17.77 +								xrandr_lib=[`ls -- $path/libXrandr.so.[0-9]* 2>/dev/null | sort -r | sed 's/.*\/\(.*\)/\1/; q'`]
   17.78 +							fi
   17.79                          fi
   17.80                      done
   17.81                      ;;
   17.82 @@ -831,6 +855,8 @@
   17.83              if test x$ac_cv_func_shmat != xyes; then
   17.84                  X_CFLAGS="$X_CFLAGS -DNO_SHARED_MEMORY"
   17.85              fi
   17.86 +            CFLAGS="$CFLAGS $X_CFLAGS"
   17.87 +            LDFLAGS="$LDFLAGS $X_LIBS"
   17.88  
   17.89              AC_DEFINE(SDL_VIDEO_DRIVER_X11)
   17.90              SOURCES="$SOURCES $srcdir/src/video/x11/*.c"
   17.91 @@ -925,10 +951,22 @@
   17.92                      fi
   17.93                  fi
   17.94              fi
   17.95 -
   17.96              if test x$definitely_enable_video_x11_xrandr = xyes; then
   17.97                  AC_DEFINE(SDL_VIDEO_DRIVER_X11_XRANDR)
   17.98              fi
   17.99 +            AC_ARG_ENABLE(video-x11-dpms,
  17.100 +AC_HELP_STRING([--enable-video-x11-dpms], [enable X11 DPMS extension [[default=yes]]]),
  17.101 +                            , enable_video_x11_dpms=yes)
  17.102 +            if test x$enable_video_x11_dpms = xyes; then
  17.103 +                AC_CHECK_HEADER(X11/extensions/dpms.h,
  17.104 +                                have_dpms_h_hdr=yes,
  17.105 +                                have_dpms_h_hdr=no,
  17.106 +                                [#include <X11/Xlib.h>
  17.107 +                                ])
  17.108 +                if test x$have_dpms_h_hdr = xyes; then
  17.109 +                    AC_DEFINE(SDL_VIDEO_DRIVER_X11_DPMS)
  17.110 +                fi
  17.111 +            fi
  17.112          fi
  17.113      fi
  17.114  }
  17.115 @@ -1197,6 +1235,8 @@
  17.116           #include <vgl.h>
  17.117          ],[
  17.118           VGLBitmap bitmap;
  17.119 +         bitmap.Type = VIDBUF32;
  17.120 +         bitmap.PixelBytes = 4;
  17.121           exit(bitmap.Bitmap);
  17.122          ],[
  17.123          video_vgl=yes
  17.124 @@ -1359,7 +1399,7 @@
  17.125              video_gem=yes
  17.126              AC_DEFINE(SDL_VIDEO_DRIVER_GEM)
  17.127              SOURCES="$SOURCES $srcdir/src/video/gem/*.c"
  17.128 -            EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lgem"
  17.129 +            SDL_LIBS="$SDL_LIBS -lgem"
  17.130              have_video=yes
  17.131          fi
  17.132      fi
  17.133 @@ -1494,8 +1534,8 @@
  17.134          fi
  17.135          AC_DEFINE(SDL_VIDEO_OPENGL)
  17.136          AC_DEFINE(SDL_VIDEO_OPENGL_OSMESA)
  17.137 -        EXTRA_CFLAGS="$EXTRA_CFLAGS $OSMESA_CFLAGS"
  17.138 -        EXTRA_LDFLAGS="$EXTRA_LDFLAGS $OSMESA_LIBS"
  17.139 +        SDL_CFLAGS="$SDL_CFLAGS $OSMESA_CFLAGS"
  17.140 +        SDL_LIBS="$SDL_LIBS $OSMESA_LIBS"
  17.141  
  17.142          AC_ARG_ENABLE(osmesa-shared,
  17.143  AC_HELP_STRING([--enable-osmesa-shared], [dynamically load OSMesa OpenGL support [[default=yes]]]),
  17.144 @@ -1597,7 +1637,7 @@
  17.145  AC_HELP_STRING([--enable-pthread-sem], [use pthread semaphores [[default=yes]]]),
  17.146                    , enable_pthread_sem=yes)
  17.147      case "$host" in
  17.148 -        *-*-linux*)
  17.149 +        *-*-linux*|*-*-uclinux*)
  17.150              pthread_cflags="-D_REENTRANT"
  17.151              pthread_lib="-lpthread"
  17.152              ;;
  17.153 @@ -1865,7 +1905,7 @@
  17.154          if test x$have_ldg_hdr = xyes -a x$have_ldg_lib = xyes; then
  17.155              AC_DEFINE(SDL_LOADSO_LDG)
  17.156              SOURCES="$SOURCES $srcdir/src/loadso/mint/*.c"
  17.157 -            EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lldg -lgem"
  17.158 +            SDL_LIBS="$SDL_LIBS -lldg -lgem"
  17.159              have_loadso=yes
  17.160          fi
  17.161      fi
  17.162 @@ -2048,9 +2088,10 @@
  17.163              have_timers=yes
  17.164          fi
  17.165          ;;
  17.166 -    *-*-linux*|*-*-gnu*|*-*-k*bsd*-gnu|*-*-bsdi*|*-*-freebsd*|*-*-dragonfly*|*-*-netbsd*|*-*-openbsd*|*-*-sysv5*|*-*-solaris*|*-*-hpux*|*-*-irix*|*-*-aix*|*-*-osf*)
  17.167 +    *-*-linux*|*-*-uclinux*|*-*-gnu*|*-*-k*bsd*-gnu|*-*-bsdi*|*-*-freebsd*|*-*-dragonfly*|*-*-netbsd*|*-*-openbsd*|*-*-sysv5*|*-*-solaris*|*-*-hpux*|*-*-irix*|*-*-aix*|*-*-osf*)
  17.168          case "$host" in
  17.169              *-*-linux*)         ARCH=linux ;;
  17.170 +            *-*-uclinux*)       ARCH=linux ;;
  17.171              *-*-kfreebsd*-gnu)  ARCH=kfreebsd-gnu ;;
  17.172              *-*-knetbsd*-gnu)   ARCH=knetbsd-gnu ;;
  17.173              *-*-kopenbsd*-gnu)  ARCH=kopenbsd-gnu ;;
  17.174 @@ -2570,9 +2611,6 @@
  17.175      if test x$enable_video = xyes -a x$enable_video_carbon = xyes; then
  17.176        SDL_LIBS="$SDL_LIBS -Wl,-framework,Carbon"
  17.177      fi
  17.178 -    if test x$enable_video = xyes -a x$enable_video_opengl = xyes; then
  17.179 -      SDL_LIBS="$SDL_LIBS -Wl,-framework,OpenGL"
  17.180 -    fi
  17.181      # Evil hack to allow static linking on Mac OS X
  17.182      SDL_STATIC_LIBS="\${exec_prefix}/lib/libSDLmain.a \${exec_prefix}/lib/libSDL.a $EXTRA_LDFLAGS"
  17.183      ;;
    18.1 --- a/docs.html	Mon May 01 06:58:33 2006 +0000
    18.2 +++ b/docs.html	Wed May 17 08:18:28 2006 +0000
    18.3 @@ -11,779 +11,165 @@
    18.4  The latest stable release may be found on the
    18.5  	<a href="http://www.libsdl.org/">SDL website</A>.
    18.6  </P>
    18.7 -<P>
    18.8  
    18.9  <H2> <A HREF="docs/index.html">API Documentation</A> </H2>
   18.10 +
   18.11 +<H2> SDL 1.2.10 Release Notes </H2>
   18.12  <P>
   18.13 -
   18.14 -<H2>
   18.15 -Major changes since SDL 1.0.0:
   18.16 -</H2>
   18.17 +SDL 1.2.10 is a major release, featuring a revamp of the build system and many API improvements and bug fixes.
   18.18 +</P>
   18.19 +<H3> API enhancements </H3>
   18.20  <UL>
   18.21 -	<LI> 1.2.9: Numerous improvements to the Atari port (thanks Patrice!)
   18.22 -	<LI> 1.2.9: SIGTERM and SIGINT handlers are reset when SDL shuts down
   18.23 -	<LI> 1.2.9: Added support for Visual C++ 2005 (Express Beta 2) to VisualC.zip
   18.24 -	<LI> 1.2.9: Fixed crash trying to allocate hardware surfaces on MacOS X (thanks Ryan!)
   18.25 -	<LI> 1.2.9: SDL.dll works on Windows 95 again
   18.26 -	<LI> 1.2.9: Dropping a document onto an SDL app passes it as a command line parameter in MacOS X (thanks Ryan!)
   18.27 -	<LI> 1.2.9: Fixed short read problem with SDL_RWFromMem() (thanks Antonio!)
   18.28 -	<LI> 1.2.9: Added support for SDL_VIDEO_X11_NODIRECTCOLOR on OpenGL visuals
   18.29 -	<LI> 1.2.9: Altivec optimized blitters (thanks Bob!)
   18.30 -	<LI> 1.2.9: YUV mmx code should compile with gcc 2.x and 3.x (thanks Stephane!)
   18.31 -	<LI> 1.2.9: Fixed hang on shutdown using framebuffer console on ia64 (thanks Jesse!)
   18.32 -	<LI> 1.2.9: Improved RISC OS support (thanks Peter and Alan!)
   18.33 -	<LI> 1.2.9: Added support for direct color 8-bpp surfaces
   18.34 -	<LI> 1.2.9: Fixed gcc parse errors in SDL_audio.h on Windows
   18.35 -	<LI> 1.2.9: Fixed potential crash in multi-threaded timers
   18.36 -	<LI> 1.2.9: Added support for Tru64 UNIX 4.X (thanks Hayashi!)
   18.37 -	<LI> 1.2.9: SDL_OPENGLBLIT has been renamed SDL_OPENGLBLIT_OBSOLETE
   18.38 -	<LI> 1.2.8: Fixed pitch vs width bug in SDL_SaveBMP() (thanks Jonathan!)
   18.39 -	<LI> 1.2.8: Build ALSA support when building RPM files
   18.40 -	<LI> 1.2.8: Added support for MacOS X Xcode environment (thanks Eric!)
   18.41 -	<LI> 1.2.8: Fixed compiling SDL under Linux 2.6.9 (thanks Stephane!)
   18.42 -	<LI> 1.2.8: Added m68k assembly routines for endianness conversion
   18.43 -	<LI> 1.2.8: Added OSMesa support to the Atari port (thanks Patrice!)
   18.44 -	<LI> 1.2.8: Fixed MacOS X mouse coordinate inversion (thanks Eric!)
   18.45 -	<LI> 1.2.8: Fixed Win32 window centering when resettting video mode (thanks Gautier!)
   18.46 -	<LI> 1.2.8: Fixed DirectInput intitialization with SDL_WINDOWID (thanks Trevor!)
   18.47 -	<LI> 1.2.8: Fixed NSWindow release count bug on MacOS X (thanks Bob!)
   18.48 -	<LI> 1.2.8: Video modes are sorted by width first, then by height
   18.49 -	<LI> 1.2.8: Improved Atari audio drivers (thanks Patrice!)
   18.50 -	<LI> 1.2.8: Improved OSS audio support, contributed by OpenSound.com
   18.51 -	<LI> 1.2.8: Added MacOS X menu options for SDL apps built without a nib (thanks Max!)
   18.52 -	<LI> 1.2.8: aRts audio driver has been renamed "arts" instead of "artsc"
   18.53 -	<LI> 1.2.8: Added thread support on RISC OS (thanks Alan!)
   18.54 -	<LI> 1.2.8: Added support for UTF-8 window titles on MacOS X (thanks Tomas!)
   18.55 -	<LI> 1.2.8: Set XV_AUTOPAINT_COLORKEY property for X11 YUV support (thanks Christian!)
   18.56 -	<LI> 1.2.8: Updated libtool support to libtool 1.5.8
   18.57 -	<LI> 1.2.8: Fixed problem compiling without nasm with new versions of gcc
   18.58 -	<LI> 1.2.8: Check for malloc() returning NULL in a few places
   18.59 -	<LI> 1.2.8: Added 4/6 channel surround sound support on ALSA (not 3D audio)
   18.60 -	<LI> 1.2.8: Added SDL_FB_BROKEN_MODES environment variable
   18.61 -	<LI> 1.2.8: Fixed memory corruption when allocating large surfaces (fails now)
   18.62 -	<LI> 1.2.8: Show correct joystick names on Windows (thanks Eckhard!)
   18.63 -	<LI> 1.2.8: Added a CoreAudio driver for MacOS X (thanks Max!)
   18.64 -	<LI> 1.2.8: Added support for right handed modifier keys on Panther (thanks Eric!)
   18.65 -	<LI> 1.2.8: Finally fixed OpenGL coordinate inversion on MacOS X (thanks Eric!)
   18.66 -	<LI> 1.2.8: Worked around a crash in aRts audio detection (thanks Yves!)
   18.67 -	<LI> 1.2.8: Lots more Atari video fixes (thanks Patrice!)
   18.68 -	<LI> 1.2.8: Allow UTF-8 strings in X11 window captions
   18.69 -	<LI> 1.2.8: Fixed basic type collision on Tru64 (thanks Hayashi!)
   18.70 -	<LI> 1.2.8: Improved keyboard and mouse handling on BeOS (thanks Marcin!)
   18.71 -	<LI> 1.2.8: Added missing window manager and OpenGL functions on BeOS
   18.72 -	<LI> 1.2.8: Fixed resuming CD-ROM playback on Windows (thanks Andreas!)
   18.73 -	<LI> 1.2.8: Fixed compiling on IRIX 5.3
   18.74 -	<LI> 1.2.8: Fixed crash if software stretch is used on hardware surfaces
   18.75 -	<LI> 1.2.8: Fixed crash on exit in framebuffer console driver
   18.76 -	<LI> 1.2.8: Added support for logical joysticks on Linux
   18.77 -	<LI> 1.2.8: Added OpenGL accum buffer support on MacOS X (thanks Christian!)
   18.78 -	<LI> 1.2.8: Fixed pixmap leak in X11 cursor code (thanks Paul!)
   18.79 -	<LI> 1.2.8: Fixed compilation problems with newer versions of gcc
   18.80 -	<LI> 1.2.8: Updated QNX support for QNX6 (thanks Mike!)
   18.81 -	<LI> 1.2.8: Fixed testdyngl crash on Windows (thanks Damien!)
   18.82 -	<LI> 1.2.8: Compile most of the blitter assembly on Opteron
   18.83 -	<LI> 1.2.8: Compile CPU detection code on Opteron
   18.84 -	<LI> 1.2.8: Fixed floating point exception with Linux 2.6 joysticks
   18.85 -	<LI> 1.2.8: Fixed toggling SDL_NOFRAME on X11 video modes
   18.86 -	<LI> 1.2.8: Fixed loading ESD and aRts function pointers
   18.87 -	<LI> 1.2.8: IRIX uses libGL.so, not libGL.so.1
   18.88 -	<LI> 1.2.8: Fixed typo in fatal signal handling code
   18.89 -	<LI> 1.2.8: Fix potential deadlock in MacOS X joystick code
   18.90 -	<LI> 1.2.8: Build FSAA code on all versions of MacOS X (thanks tigital!)
   18.91 -	<LI> 1.2.8: Avoid using kernel headers for byte swapping macros
   18.92 -	<LI> 1.2.7: Added a test program for dynamically loading OpenGL
   18.93 -	<LI> 1.2.7: Increased sensitivity of the Windows joystick driver 
   18.94 -	<LI> 1.2.7: Added support for SDL_VIDEO_WINDOW_POS and SDL_VIDEO_CENTERED on Windows 
   18.95 -	<LI> 1.2.7: Added fullscreen toggle support in testwm for Windows, etc. 
   18.96 -	<LI> 1.2.7: Fixed mouse focus events after resetting video mode on Windows 
   18.97 -	<LI> 1.2.7: Added colorkey blit tests to testvidinfo (thanks Mike!) 
   18.98 -	<LI> 1.2.7: Added video hardware acceleration support on QNX (thanks Mike!) 
   18.99 -	<LI> 1.2.7: SDL no longer sets a fatal signal handler for SIGPIPE 
  18.100 -	<LI> 1.2.7: Fixed modifier key state on MacOS X (thanks Max!) 
  18.101 -	<LI> 1.2.7: Added support for remote XVideo (thanks Frederic!) 
  18.102 -	<LI> 1.2.7: Try to use higher refresh rate by default in DirectX driver (thanks Dmitry!) 
  18.103 -	<LI> 1.2.7: Fixed static linking on MacOS X (thanks Max!) 
  18.104 -	<LI> 1.2.7: Various Atari video driver improvements (thanks Patrice!) 
  18.105 -	<LI> 1.2.7: Fixed compiling with broken Linux 2.6 headers 
  18.106 -	<LI> 1.2.7: Fixed mouse cursor visibility and focus events on MacOS X (thanks Max!) 
  18.107 -	<LI> 1.2.7: Added support for /dev/joy* on Free/Net/OpenBSD (thanks Christian!) 
  18.108 -	<LI> 1.2.7: Fixed problems with CD-ROM audio playback on MacOS X 10.1 
  18.109 -	<LI> 1.2.7: Added dynamic GL library loading to MacOS Carbon support (thanks Anders!) 
  18.110 -	<LI> 1.2.7: Added the ability to hide the cursor in the DirectFB driver (thanks Pete!) 
  18.111 -	<LI> 1.2.7: Added minor cleanup for Embedded Visual C++ 3.0 (thanks Andy!) 
  18.112 -	<LI> 1.2.7: Fixed high CPU usage with ALSA audio driver (thanks Michel!) 
  18.113 -	<LI> 1.2.7: Added function to create RWops from const memory: SDL_RWFromConstMem() 
  18.114 -	<LI> 1.2.7: Fixed compiling with ALSA 1.0 (thanks Stephane!) 
  18.115 -	<LI> 1.2.7: Added YUV overlay support on BeOS (thanks Andrew!) 
  18.116 -	<LI> 1.2.7: Fixed build problems with newer versions of automake
  18.117 -	<LI> 1.2.7: Fixed MacOS X libtool framework support (thanks Max!) 
  18.118 -	<LI> 1.2.7: Added CPU feature detection functions to SDL_cpuinfo.h
  18.119 -	<LI> 1.2.7: Fixed illegal instruction crash using 3DNow on Intel processors 
  18.120 -	<LI> 1.2.7: Fixed asm issues with mmx.h and gcc 3.3 (thanks Stephane!) 
  18.121 -	<LI> 1.2.7: Updated libtool support so Mingw32 builds work. 
  18.122 -	<LI> 1.2.7: Disable screen saver in Windows DIB video driver 
  18.123 -	<LI> 1.2.7: Added Atari CD-ROM support (thanks Patrice!) 
  18.124 -	<LI> 1.2.7: Fixed crash calling app defined window proc (thanks Scott!) 
  18.125 -	<LI> 1.2.7: Fixed long long constant warnings in GCC 3.3.1 (thanks Stephane!) 
  18.126 -	<LI> 1.2.7: Added configure.in support for K*BSD (thanks Robert!) 
  18.127 -	<LI> 1.2.7: Added QNX package and audio fixes (thanks Mike!) 
  18.128 -	<LI> 1.2.7: Fixed joystick open problems on BSD (thanks SUGIMOTO!) 
  18.129 -	<LI> 1.2.7: Fixed X11 mode line crash with only one video mode (thanks Alan!) 
  18.130 -	<LI> 1.2.6: Fixed bugs in the Nano-X video driver
  18.131 -	<LI> 1.2.6: Fixed use of SDL with XInitThreads()
  18.132 -	<LI> 1.2.6: Added MMX and 3DNow! optimized alpha blitters (thanks Stephane!)
  18.133 -	<LI> 1.2.6: Turned dynamic loading of ESD and aRts on by default
  18.134 -	<LI> 1.2.6: Fixed fullscreen mouse click bug in Quartz events (thanks Max!)
  18.135 -	<LI> 1.2.6: Added an environment variable SDL_VIDEO_WINDOW_POS for MacOS X
  18.136 -	<LI> 1.2.6: Added SDL_GL_MULTISAMPLEBUFFERS and SDL_GL_MULTISAMPLESAMPLES for FSAA support (thanks Shawn and Ryan!)
  18.137 -	<LI> 1.2.6: Added audio and CD-ROM support for OSF/Tru64 (thanks Hayashi!)
  18.138 -	<LI> 1.2.6: Added SDL_LoadObject(), SDL_LoadFunction(), and SDL_UnloadObject()
  18.139 -	<LI> 1.2.6: Added new Atari audio drivers (thanks Patrice!)
  18.140 -	<LI> 1.2.6: Added more-than-three mouse button support for the Quartz target
  18.141 -	<LI> 1.2.6: Fixed compile problem in SDL_stretch.c with gcc 3.3
  18.142 -	<LI> 1.2.6: Added initial support for RISC OS (thanks Peter and Alan!)
  18.143 -	<LI> 1.2.6: Improved video mode selection under XFree86 (thanks Despair!)
  18.144 -	<LI> 1.2.6: Added support for HID sliders wheels and dials on MacOS X
  18.145 -	<LI> 1.2.6: Added m68k assembly routines for audio mixing (thanks Patrice!)
  18.146 -	<LI> 1.2.6: Updated FreeBSD joystick USBHID support (thanks Matthew!)
  18.147 -	<LI> 1.2.6: Fixed video intitialization problem on Qtopia (thanks David!)
  18.148 -	<LI> 1.2.6: Fixed refresh rate issue with XFree86 4.3.0 (thanks Stephen!)
  18.149 -	<LI> 1.2.6: Fixed lost cursor bug under MacOS X (thanks Darrell!)
  18.150 -	<LI> 1.2.6: Fixed crash in SDL_SetIcon() under Quartz (thanks Darrell!)
  18.151 -	<LI> 1.2.6: Darrell added support for emulated SDL_DOUBLEBUF on MacOSX
  18.152 -	<LI> 1.2.6: Cth converted the MMX audio mixing routines to VC++ syntax
  18.153 -	<LI> 1.2.6: David MacCormack fixed a bug in window sizing with Windows menus
  18.154 -	<LI> 1.2.6: Enable the glXGetProcAddressARB code on X11 (fixes NVidia issues)
  18.155 -	<LI> 1.2.6: Added support for SDL_WM_GrabInput and SDL_WM_IconifyWindow on Qtopia (thanks David!)
  18.156 -	<LI> 1.2.6: Almost completely rewritten and improved QNX code (thanks Mike and Julian!)
  18.157 -	<LI> 1.2.6: Fixed left/right shift detection on Windows (thanks Mike!)
  18.158 -	<LI> 1.2.6: Fixed invalid memory access in DGA video driver (thanks ldb!)
  18.159 -	<LI> 1.2.6: Generate an expose event on MacOS X after power save (thanks Darrell!)
  18.160 -	<LI> 1.2.6: Updated Atari port for new system headers (thanks Patrice!)
  18.161 -	<LI> 1.2.6: Linux joystick cleanups from Alan Swanson
  18.162 -	<LI> 1.2.6: *BSD joystick cleanups from Wilbern Cobb
  18.163 -	<LI> 1.2.6: Worked around Visual C++ 7 optimizer bug in blit code
  18.164 -	<LI> 1.2.6: Open ALSA devices in non-blocking mode (thanks Aleksey!)
  18.165 -	<LI> 1.2.6: Updated for DirectDB 0.9.15 (thanks Denis!)
  18.166 -	<LI> 1.2.6: Fixed building SDL DLL with Watcom C++ (thanks Jean-Pierre)
  18.167 -	<LI> 1.2.6: Support 1-bit alpha on surfaces passed to SDL_WM_SetIcon() (thanks Glenn!)
  18.168 -	<LI> 1.2.6: Greatly improved X11 DGA video speed (thanks Cezary!)
  18.169 -	<LI> 1.2.6: Added MMX audio mixing code for gcc (thanks Stephane!)
  18.170 -	<LI> 1.2.6: Fixed potential dropped events under DirectInput
  18.171 -	<LI> 1.2.6: Fixed alpha blending bug (thanks Glenn!)
  18.172 -	<LI> 1.2.6: Fixed joystick detection on Windows XP (thanks Maciej!)
  18.173 -	<LI> 1.2.6: Fixed a crash blitting RLE surfaces to RLE surfaces
  18.174 -	<LI> 1.2.6: Fixed mouse warp position bug with offset video modes
  18.175 -	<LI> 1.2.6: Fixed windows event handling for ActiveX controls
  18.176 -	<LI> 1.2.6: Added Visual C++ 7 (.NET) projects (thanks James!)
  18.177 -	<LI> 1.2.5: Added an environment variable SDL_HAS3BUTTONMOUSE for Quartz
  18.178 -	<LI> 1.2.5: Added initial support for Dreamcast (thanks HERO!) 
  18.179 -	<LI> 1.2.5: Implemented resizing Cocoa windows (thanks Darrell!) 
  18.180 -	<LI> 1.2.5: Updated Quartz video code for MacOS X 10.2 (thanks Darrell!) 
  18.181 -	<LI> 1.2.5: Added an environment variable SDL_VIDEO_WINDOW_POS for X11
  18.182 -	<LI> 1.2.5: Fixed mouse focus problems caused by X11 'unclutter' hack 
  18.183 -	<LI> 1.2.5: Applied John's fix for left-handed mice under Windows. 
  18.184 -	<LI> 1.2.5: Gamepads and other HID devices should work under MacOS X 
  18.185 -	<LI> 1.2.5: Fixed missing cursor after shadow buffer flip (thanks Jan!) 
  18.186 -	<LI> 1.2.5: Updated MacOS projects with "enums as int" build option 
  18.187 -	<LI> 1.2.5: Added -benchmark flag to testvidinfo for testing video speed 
  18.188 -	<LI> 1.2.5: Added accelerated YUV code to DirectFB driver (thanks Denis!) 
  18.189 -	<LI> 1.2.5: Command line apps on MacOS X go to forground (thanks Max!) 
  18.190 -	<LI> 1.2.5: Fixed aRts runtime sound daemon detection 
  18.191 -	<LI> 1.2.5: Improved the Nano-X video support (thanks Greg!) 
  18.192 -	<LI> 1.2.5: Updated Borland projects for Kylix 3 (thanks Dominique) 
  18.193 -	<LI> 1.2.5: Added compile-time checking for the size of enums 
  18.194 -	<LI> 1.2.5: Fixed offset bug in hardware accelerated fills and blits 
  18.195 -	<LI> 1.2.5: Fixed serious bugs in BSD HID joystick code (thanks Krister!) 
  18.196 -	<LI> 1.2.5: Added project files for embedded Visual C++ 4.0 
  18.197 -	<LI> 1.2.5: Added SDL_BUTTON_WHEELUP (4) and SDL_BUTTON_WHEELDOWN (5) 
  18.198 -	<LI> 1.2.5: Added SDL_GL_STEREO for stereoscopic OpenGL contexts 
  18.199 -	<LI> 1.2.5: Added the environment variable SDL_VIDEO_X11_WMCLASS 
  18.200 -	<LI> 1.2.5: Fullscreen windows are always topmost in Windows 
  18.201 -	<LI> 1.2.5: Fixed mouse grab going fullscreen to windowed in Windows 
  18.202 -	<LI> 1.2.5: Fixed VidMode error when running on XFree86 3.3 
  18.203 -	<LI> 1.2.5: Fixed Quartz mouse motion and window centering bugs 
  18.204 -	<LI> 1.2.5: Updated configure.in for automake 1.6.2 
  18.205 -	<LI> 1.2.5: Fixed building Windows DLL with latest native Cygwin tools 
  18.206 -	<LI> 1.2.5: Added a way to get the Windows OpenGL context in SDL_syswm.h 
  18.207 -	<LI> 1.2.5: Removed DDFLIP_WAIT flag from DirectX flip for performance 
  18.208 -	<LI> 1.2.5: Zeroed SDL_Surface::unused1 so glSDL will work on stock SDL 
  18.209 -	<LI> 1.2.5: Only modifier key state is noted when X11 window opens 
  18.210 -	<LI> 1.2.5: Added initial support for PicoGUI (thanks Micah!) 
  18.211 -	<LI> 1.2.5: Fixed SDL_DisplayFormatAlpha() on RGB surfaces with alpha 
  18.212 -	<LI> 1.2.5: Added pthread detection for HP-UX 11.X 
  18.213 -	<LI> 1.2.5: SDL_Init(SDL_INIT_JOYSTICK) on MacOS X works with no joystick 
  18.214 -	<LI> 1.2.5: Fixed DirectX software surface memory leak 
  18.215 -	<LI> 1.2.5: Fixed video initialization crash on Windows CE 
  18.216 -	<LI> 1.2.5: Updated the QNX audio code for QNX 6.2 (thanks Travis!) 
  18.217 -	<LI> 1.2.5: Fixed building with pthread and pth support on UNIX 
  18.218 -	<LI> 1.2.5: Added detection of several joysticks to Linux code 
  18.219 -	<LI> 1.2.5: Fixed thread detection and joystick code for NetBSD 
  18.220 -	<LI> 1.2.5: Added support for audio in the Atari port (thanks Patrice!) 
  18.221 -	<LI> 1.2.5: Added check for ENOMEDIUM to the Linux CDROM code 
  18.222 -	<LI> 1.2.5: Added YUV hardware acceleration on MacOS X (thanks Darrell!) 
  18.223 -	<LI> 1.2.5: Fixed building shared libraries on MacOS X (thanks Max!) 
  18.224 -	<LI> 1.2.5: Use secondary audio buffers in DirectSound by default 
  18.225 -	<LI> 1.2.5: Fixed window tab on Windows taskbar after application quit 
  18.226 -	<LI> 1.2.5: Fixed setting OpenGL mode multiple times on Windows 
  18.227 -	<LI> 1.2.5: Added Zaurus PDA (Qtopia) support by David Hedbor 
  18.228 -	<LI> 1.2.5: Removed README.OpenBSD - SDL works out of the box on OpenBSD 
  18.229 -	<LI> 1.2.5: Fixed crash in QZ_SetCaption() (thanks Darrell) 
  18.230 -	<LI> 1.2.5: Updated ALSA audio support for ALSA 0.9 
  18.231 -	<LI> 1.2.5: Don't build RPM archives with ALSA library dependencies 
  18.232 -	<LI> 1.2.5: SDL_PollEvent()/SDL_WaitEvent() return values now match docs 
  18.233 -	<LI> 1.2.4: Added initial support for Atari (thanks Patrice!)
  18.234 -	<LI> 1.2.4: Added support for building SDL for EPOC/SymbianOS 6.0
  18.235 -	<LI> 1.2.4: SDL now compiles and works cleanly on stock BSDI
  18.236 -	<LI> 1.2.4: Added support for joysticks on *BSD (thanks Wilbern!)
  18.237 -	<LI> 1.2.4: Added support for Xi Graphics XME fullscreen extension
  18.238 -	<LI> 1.2.4: Incorporated XFree86 extension libraries into the source
  18.239 -	<LI> 1.2.4: Dynamically load sound daemon audio drivers on UNIX
  18.240 -	<LI> 1.2.4: David Snopek added Borland compiler support
  18.241 -	<LI> 1.2.4: Updated for Watcom and LCC compilers (thanks Jean-Pierre)
  18.242 -	<LI> 1.2.4: Added a YUV overlay test program (thanks Jon!)
  18.243 -	<LI> 1.2.4: Fixed gamma ramps in DirectX windowed and OpenGL modes
  18.244 -	<LI> 1.2.4: John Popplewell fixed mousewheel support on Windows
  18.245 -	<LI> 1.2.4: Disabled QueryPerformanceCounter() due to problems on Win2K
  18.246 -	<LI> 1.2.4: Fixed Windows OpenGL mouse cursor/position mismatch bug
  18.247 -	<LI> 1.2.4: Fixed display settings with ALT-tab and OpenGL on Windows
  18.248 -	<LI> 1.2.4: Fixed timeout in Linux condition variable implementation
  18.249 -	<LI> 1.2.4: Fixed bug in joystick detection code under Linux
  18.250 -	<LI> 1.2.4: Fix crash with Linux supermount fstab entries (thanks Erno!)
  18.251 -	<LI> 1.2.4: Fixed X11 crash updating rectangles of zero height (thanks Mattias!)
  18.252 -	<LI> 1.2.4: Fixed spurious keypress at startup on BeOS
  18.253 -	<LI> 1.2.4: MacOS audio locking has been implemented by Ryan Gordon
  18.254 -	<LI> 1.2.4: Fixed "short jump out of range" error in MMX code (thanks Steven)
  18.255 -	<LI> 1.2.4: Specify the SDL API calling convention (C by default)
  18.256 -	<LI> 1.2.4: Updated autogen.sh for new versions of automake
  18.257 -	<LI> 1.2.4: Fixed SDL 1.1 RPM dependency problem (thanks Edward!)
  18.258 -	<LI> 1.2.3: Added X11 Xinerama support - fullscreen starts on screen 0
  18.259 -	<LI> 1.2.3: Added platform independent OpenGL header - SDL_opengl.h
  18.260 -	<LI> 1.2.3: Fixed flashing the screen when creating a window on BeOS
  18.261 -	<LI> 1.2.3: Added double-buffering support for SVGAlib (thanks Kutak!)
  18.262 -	<LI> 1.2.3: Fixed crash when using double-buffering with DGA
  18.263 -	<LI> 1.2.3: Fixed resuming a paused CD on Win2K (thanks Aragorn)
  18.264 -	<LI> 1.2.3: Improved MacOS international keyboard handling (thanks Max!)
  18.265 -	<LI> 1.2.3: Added support for the GNU Pth thread lib (thanks Mandin!)
  18.266 -	<LI> 1.2.3: Added the Undo key for the Atari keyboard (thanks Mandin!)
  18.267 -	<LI> 1.2.3: Fixed XVideo on GeForce by using last available adaptor
  18.268 -	<LI> 1.2.3: Added CD-ROM support for BSD/OS (thanks Steven!)
  18.269 -	<LI> 1.2.3: Added library version information to the Windows DLL
  18.270 -	<LI> 1.2.3: Added initial support for EPOC/Symbian OS (thanks Hannu!)
  18.271 -	<LI> 1.2.3: Added a joystick driver for MacOS X (thanks Max!)
  18.272 -	<LI> 1.2.3: Improved MacOS X international keyboard handling
  18.273 -	<LI> 1.2.3: Added support for DirectFB video on Linux (thanks Denis!)
  18.274 -	<LI> 1.2.3: Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!)
  18.275 -	<LI> 1.2.3: Fixed the system dependent SDL_WINDOWID hack on Windows
  18.276 -	<LI> 1.2.3: Added 640x480 as a scaled resolution for NTSC/PAL output 
  18.277 -	<LI> 1.2.3: Added support for TV output on the Linux PlayStation Beta
  18.278 -	<LI> 1.2.3: Added initial NVidia acceleration on framebuffer console
  18.279 -	<LI> 1.2.3: Fixed audio format selection for OpenBSD (thanks Peter!)
  18.280 -	<LI> 1.2.2: Fixed crash when quitting fullscreen mode on MacOS X
  18.281 -	<LI> 1.2.2: Fixed fullscreen mouse events on MacOS X
  18.282 -	<LI> 1.2.2: Now returns an error if unable to open audio on BeOS
  18.283 -	<LI> 1.2.2: Fixed keyboard input translation on WinCE (thanks Rainer!)
  18.284 -	<LI> 1.2.2: Now gets correct keyboard state when starting up on X11
  18.285 -	<LI> 1.2.2: Improved the DGA 2.0 and framebuffer console drivers
  18.286 -	<LI> 1.2.2: Improved the OpenBSD port (native audio default, etc.)
  18.287 -	<LI> 1.2.2: Improved OSS audio driver support, thanks to 4Front Tech.
  18.288 -	<LI> 1.2.2: Improved X11 fullscreen support, works better with KDE
  18.289 -	<LI> 1.2.2: Improved SDL_GetTicks() resolution on W2K (thanks Holger!)
  18.290 -	<LI> 1.2.2: Added FreeBSD VGL video driver from FreeBSD ports
  18.291 -	<LI> 1.2.1: Added Linux PlayStation 2 Graphics Synthesizer support
  18.292 -	<LI> 1.2.1: Added an audio driver that writes to disk (thanks Ryan!)
  18.293 -	<LI> 1.2.1: Mouse wheel sends mouse button (4/5) events on Windows
  18.294 -	<LI> 1.2.1: Added MacOS X Project Builder projects (thanks Darrell!)
  18.295 -	<LI> 1.2.1: Added initial support for Quartz video (thanks Darrell!)
  18.296 -	<LI> 1.2.1: Disabled Linux /dev/event joystick interface by default
  18.297 -	<LI> 1.2.1: Added native OpenBSD audio driver (thanks vedge!)
  18.298 -	<LI> 1.2.1: Added detection of Open Sound System on Solaris x86
  18.299 -	<LI> 1.2.1: Added initial support for Nano-X (thanks Hsieh-Fu!)
  18.300 -	<LI> 1.2.1: Fixed endian detection on IA64 architectures (thanks Bill!)
  18.301 -	<LI> 1.2.1: Added --disable-dga configure option to disable DGA
  18.302 -	<LI> 1.2.1: Fixed stuck keys when changing the video mode
  18.303 -	<LI> 1.2.1: Fixed double-mouse event bug on Windows using OpenGL
  18.304 -	<LI> 1.2.1: Fixed 320x200 video mode on framebuffer console
  18.305 -	<LI> 1.2.1: Improved robustness for the ELO touchpad (thanks Alex!)
  18.306 -	<LI> 1.2.1: Added support for building under Cygwin on Windows
  18.307 -	<LI> 1.2.1: Added a dummy video driver for benchmarking (thanks Ryan!)
  18.308 -	<LI> 1.2.1: Fixed fullscreen cursor offset bug on BeOS
  18.309 -	<LI> 1.2.0: Added initial support for HP-UX (thanks Stephanie)
  18.310 -	<LI> 1.2.0: Added initial support for BSDI (thanks Kurt)
  18.311 -	<LI> 1.2.0: Fixed blitting 32-bit ARGB images to SDL_OPENGLBLIT screens
  18.312 -	<LI> 1.2.0: Fixed automake build dependencies (thanks Markus!)
  18.313 -	<LI> 1.2.0: Added 24 bpp support to software YUV display functions
  18.314 -	<LI> 1.2.0: Don't bomb trying to get DGA mouse on XFree86 4.0
  18.315 -	<LI> 1.2.0: Added initial support for OSF/Tru64 (thanks Anders)
  18.316 -	<LI> 1.1.8: Fixed joystick hat motion on MacOS
  18.317 -	<LI> 1.1.8: Don't detect mouse and keyboard as joystick on MacOS
  18.318 -	<LI> 1.1.8: Check for OpenGL 1.2 before using 16-bit SDL_OPENGLBLIT
  18.319 -	<LI> 1.1.8: Added support for /dev/sound/* in Linux 2.4
  18.320 -	<LI> 1.1.8: Fixed crash when blitting to RLE encoded surfaces
  18.321 -	<LI> 1.1.8: Fixed 8-bit audio on MacOS X
  18.322 -	<LI> 1.1.8: Fixed keyboard handling on MacOS X and MacOS classic
  18.323 -	<LI> 1.1.8: Fixed mouse cursor visibility when switching apps on MacOS
  18.324 -	<LI> 1.1.8: Implemented semaphore support on MacOS X
  18.325 -	<LI> 1.1.8: Worked around broken sem_getvalue() on MacOS X
  18.326 -	<LI> 1.1.8: Fixed 16-bit big-endian audio on MacOS X and MacOS classic
  18.327 -	<LI> 1.1.8: Fixed mutex locking on Linux glibc 2.0
  18.328 -	<LI> 1.1.8: SDL_Quit() removes the parachute signal handlers
  18.329 -	<LI> 1.1.8: Added NAS audio server support (thanks Erik!)
  18.330 -	<LI> 1.1.8: Added SDL_NOFRAME for frameless windows (thanks Andreas)
  18.331 -	<LI> 1.1.8: Added support for resizable windows on MacOS
  18.332 -	<LI> 1.1.8: Added a function to query the surface clip rectangle
  18.333 -	<LI> 1.1.8: Added a function to query the current event filter
  18.334 -	<LI> 1.1.8: The X11 XVideo adapter is now locked (thanks Jeffrey)
  18.335 -	<LI> 1.1.8: Improved the speed of fullscreen OpenGL on Windows
  18.336 -	<LI> 1.1.8: Added ELO touchscreen support for fbcon (thanks Alex)
  18.337 -	<LI> 1.1.8: Added accelerated MacOS X OpenGL support
  18.338 -	<LI> 1.1.8: Surface lock and unlock operations can now be nested
  18.339 -	<LI> 1.1.8: Optimized fillrect for PPC video memory (thanks Mattias)
  18.340 -	<LI> 1.1.8: Work around "blackout" problem with XVideo acceleration
  18.341 -	<LI> 1.1.8: Obtain correct key state on X11 focus (thanks Mattias)
  18.342 -	<LI> 1.1.8: Fixed keyboard handling on the framebuffer console
  18.343 -	<LI> 1.1.8: Added basic support for VGA16 framebuffer console
  18.344 -	<LI> 1.1.8: Open a new virtual terminal if possible on fbcon
  18.345 -	<LI> 1.1.8: Fixed default audio driver on FreeBSD (thanks Maxim)
  18.346 -	<LI> 1.1.8: Fixed joystick crash on Windows (thanks Pete)
  18.347 -	<LI> 1.1.7: Expanded documentation from the SDL Documentation Project
  18.348 -	<LI> 1.1.7: Report X11 client message events if SYSWMEVENTS enabled
  18.349 -	<LI> 1.1.7: Added support for a single hat on Windows joysticks
  18.350 -	<LI> 1.1.7: The gamma ramp routines now take arrays of Uint16 values
  18.351 -	<LI> 1.1.7: Added initial support for QNX RTP (thanks Patrick)
  18.352 -	<LI> 1.1.7: Added ALSA sound driver (thanks Patrick Trainor)
  18.353 -	<LI> 1.1.7: Added aRts UNIX sound driver (thanks Neil Stevens)
  18.354 -	<LI> 1.1.7: Get keyboard modifier state on input focus on Win32
  18.355 -	<LI> 1.1.7: SDL_ConvertSurface() now accepts SDL_RLEACCEL as a flag
  18.356 -	<LI> 1.1.7: Added initial UnixWare 7 support (thanks rr)
  18.357 -	<LI> 1.1.7: Added working YUY -> RGB conversion code (thanks Eugene)
  18.358 -	<LI> 1.1.7: Fixed video initialization crash on IRIX
  18.359 -	<LI> 1.1.7: Fixed MacOS fullscreen palette code (thanks Darrell)
  18.360 -	<LI> 1.1.7: Fixed background brush flicker on Win32 (thanks Gautier)
  18.361 -	<LI> 1.1.7: Fixed incorrect pitch when switching to window on Win32
  18.362 -	<LI> 1.1.7: Fixed memory leak when switching video modes on Win32
  18.363 -	<LI> 1.1.7: Init of fbcon shouldn't automatically set graphics mode
  18.364 -	<LI> 1.1.6: Allow SDL_VIDEO_INIT when built without thread support
  18.365 -	<LI> 1.1.6: Fixed palette problems with non-X11 fullscreen displays
  18.366 -	<LI> 1.1.6: Fixed Win32 crash with SDL_OPENGLBLIT and GL functions
  18.367 -	<LI> 1.1.6: Improved default MacOS millisecond time resolution
  18.368 -	<LI> 1.1.6: Fixed X11 overlapping endian blit bug (thanks Mattias)
  18.369 -	<LI> 1.1.6: Fixed starting directory on BeOS (thanks Samuel)
  18.370 -	<LI> 1.1.6: Integrated FreeBSD SVGAlib support (thanks folks)
  18.371 -	<LI> 1.1.6: Fixed middle-button handling on DirectInput
  18.372 -	<LI> 1.1.6: Added SDL_GetThreadID() to get a specific thread's ID
  18.373 -	<LI> 1.1.6: Worked around a crash in pthreads on RedHat 7
  18.374 -	<LI> 1.1.6: Fixed a brown-bag crash in clipping code
  18.375 -	<LI> 1.1.5: Convert from '/' to ':' opening files on MacOS
  18.376 -	<LI> 1.1.5: Clean up empty output files on Win32 and MacOS 
  18.377 -	<LI> 1.1.5: Run command dialog if command key on startup on MacOS
  18.378 -	<LI> 1.1.5: Initial NetBSD support (thanks Krister Walfridsson)
  18.379 -	<LI> 1.1.5: Expanded the YUV overlay to handle odd (ATI) hardware
  18.380 -	<LI> 1.1.5: Fixed MacOS GL attribute selection (thanks Darrell)
  18.381 -	<LI> 1.1.5: Implemented gamma correction on 8-bit hardware displays
  18.382 -	<LI> 1.1.5: Performed logical/physical palette split (thanks Mattias)
  18.383 -	<LI> 1.1.5: Added initial MacOS X support (thanks Stan)
  18.384 -	<LI> 1.1.5: SDL_WarpMouse() now works on BeOS (thanks Christian)
  18.385 -	<LI> 1.1.5: Windows GDI driver now supports 565 modes (thanks Ben)
  18.386 -	<LI> 1.1.5: Correctly load OpenGL extensions on Win32 (thanks Beosil)
  18.387 -	<LI> 1.1.5: Fixed crash with some threaded audio drivers
  18.388 -	<LI> 1.1.5: Audio is now closed in SDL_Quit(), if necessary
  18.389 -	<LI> 1.1.5: Win32 version now uses MSVC multi-threaded DLL runtime
  18.390 -	<LI> 1.1.5: Replaced useless SDL_SetClipping() with SDL_SetClipRect()
  18.391 -	<LI> 1.1.5: Added a flag to YUV overlays to show hardware support
  18.392 -	<LI> 1.1.5: Added SDL_WasInit() to see what is currently initialized
  18.393 -	<LI> 1.1.5: YUV overlays can now be accelerated with DirectX
  18.394 -	<LI> 1.1.5: YUV overlays now have working pitch (thanks Vivien)
  18.395 -	<LI> 1.1.5: Prompt the user if MacOS mode change may damage hardware
  18.396 -	<LI> 1.1.5: Fixed DrawSprocket video mode lists and mode changes
  18.397 -	<LI> 1.1.5: Added DrawSprocket acceleration of colorkey blits
  18.398 -	<LI> 1.1.5: MacOS event handling is much more responsive by default
  18.399 -	<LI> 1.1.5: MacOS modifier keys now generate key events
  18.400 -	<LI> 1.1.5: Mattias Engdegård did the "Great Alpha Flip"
  18.401 -	<LI> 1.1.5: Added SDL_DisplayFormatAlpha() for fast alpha blits
  18.402 -	<LI> 1.1.5: Added SDL_MapRGBA() and SDL_GetRGBA() to handle alpha
  18.403 -	<LI> 1.1.5: SDL_SetAlpha() now accepts the SDL_RLEACCEL flag
  18.404 -	<LI> 1.1.5: Blit semantics involving alpha are now well defined
  18.405 -	<LI> 1.1.5: Added support for X11 DirectColor visuals for gamma API
  18.406 -	<LI> 1.1.5: Added initial AmigaOS support (thanks Gabriele Greco)
  18.407 -	<LI> 1.1.5: Added an initial gamma correction API (thanks Daniel)
  18.408 -	<LI> 1.1.5: Disable DGA mouse while X11 application is iconified
  18.409 -	<LI> 1.1.5: Allow 16-bit audio on Solaris (thanks Mattias)
  18.410 -	<LI> 1.1.5: Added RLE acceleration of alpha blits (thanks Mattias)
  18.411 -	<LI> 1.1.5: New documentation from the SDL Documentation Project
  18.412 -	<LI> 1.1.4: Work around window resize bug in KDE 1.2
  18.413 -	<LI> 1.1.4: Command-click is interpreted as right click on MacOS
  18.414 -	<LI> 1.1.4: Removed ESounD detection on Solaris
  18.415 -	<LI> 1.1.4: Updated to libtool 1.3.5 and latest config.guess
  18.416 -	<LI> 1.1.4: testgl now works on 8-bit displays under X11
  18.417 -	<LI> 1.1.4: SDL_WINDOWID hack now works with OpenGL on Linux
  18.418 -	<LI> 1.1.4: Builds correctly on UNIX without X11 installed
  18.419 -	<LI> 1.1.4: Fixed default GL driver loading on Win32
  18.420 -	<LI> 1.1.4: Implemented fullscreen toggle on BeOS (thanks David)
  18.421 -	<LI> 1.1.4: No longer use DirectDraw with OpenGL modes on Win32
  18.422 -	<LI> 1.1.4: Added support for 320x200x8 in SVGAlib (thanks Michele)
  18.423 -	<LI> 1.1.4: Implemented resizable windows on BeOS (thanks David)
  18.424 -	<LI> 1.1.4: RLE colorkey encoding reduces memory use (thanks Mattias)
  18.425 -	<LI> 1.1.4: The CD track length variable is now 32-bits (thanks Martin)
  18.426 -	<LI> 1.1.4: Fixed crashing bug in Win32 semaphores (thanks Markus)
  18.427 -	<LI> 1.1.4: Disabled aggresive gcc optimizations on X86
  18.428 -	<LI> 1.1.4: Added support for blitting with GL (thanks Daniel Vogel)
  18.429 -	<LI> 1.1.4: Improved the speed of the 16-bit colorkey copy blit
  18.430 -	<LI> 1.1.4: Fixed pthread condition variable timeout
  18.431 -	<LI> 1.1.3: Use timeGetTime() instead of GetTickCount() on Win32
  18.432 -	<LI> 1.1.3: Release mouse when popped out of fullscreen on X11
  18.433 -	<LI> 1.1.3: IRIX 6.5 and FreeBSD 4.0 are now officially supported
  18.434 -	<LI> 1.1.3: Added optimization flags when compiling on x86 with gcc
  18.435 -	<LI> 1.1.3: On BeOS, change to app directory when launched by Tracker
  18.436 -	<LI> 1.1.3: Hold the option key on launch to get dialog on MacOS
  18.437 -	<LI> 1.1.3: Added DrawSprockets on MacOS (thanks Darrell Walisser)
  18.438 -	<LI> 1.1.3: Added support for Linux 2.4 input interface (HID)
  18.439 -	<LI> 1.1.3: Fixed 24-bpp blits on big-endian systems (thanks Mattias)
  18.440 -	<LI> 1.1.3: Don't try to use DGA mouse support on XFree86 4.00
  18.441 -	<LI> 1.1.3: Don't create an X11 shared memory buffer for GL displays
  18.442 -	<LI> 1.1.3: Framebuffer console acceleration disabled (broken) on G200
  18.443 -	<LI> 1.1.3: Allow maximize on resizable Win32 surfaces (thanks Randi)
  18.444 -	<LI> 1.1.3: Much faster RLE colorkey blit (thanks Xark and Mattias)
  18.445 -	<LI> 1.1.3: Fixed some problems with iconification and focus in X11
  18.446 -	<LI> 1.1.3: Added IMPS/2 protocol support for framebuffer console
  18.447 -	<LI> 1.1.3: Added user-resizable video mode support
  18.448 -	<LI> 1.1.3: Added arbitrary scaling of YUV overlay surfaces
  18.449 -	<LI> 1.1.3: Added support for semaphores and condition variables
  18.450 -	<LI> 1.1.3: Added SDL_ASYNCBLIT flag for asynchronous video updates
  18.451 -	<LI> 1.1.3: Don't let the WM place window in X11 fullscreen mode
  18.452 -	<LI> 1.1.3: Unload GL library after X11 display has closed
  18.453 -	<LI> 1.1.3: Fixed X11 error when a clipped rectangle is updated
  18.454 -	<LI> 1.1.3: Fixed crash when surface memory can't be allocated
  18.455 -	<LI> 1.1.3: Added a check for DirectX 5 audio (thanks Markus)
  18.456 -	<LI> 1.1.3: Added inline MMX assembly for YUV -> RGB conversion
  18.457 -	<LI> 1.1.3: Fixed startup crash in X11_RefreshDisplay()
  18.458 -	<LI> 1.1.3: SDL_Init(SDL_INIT_AUDIO) no longer fails with no soundcard
  18.459 -	<LI> 1.1.3: Initial YUV video overlay support (supports XvImages)
  18.460 -	<LI> 1.1.3: Fixed BadMatch X11 error with GLX 1.3
  18.461 -	<LI> 1.1.3: Worked around incompatibilities with XFree86 4.0 vidmode
  18.462 -	<LI> 1.1.3: The audio Makefile no longer takes forever to create
  18.463 -	<LI> 1.1.3: The joystick hat positions changed to constants
  18.464 -	<LI> 1.1.3: Fixed overlapping copy blit with odd widths
  18.465 -	<LI> 1.1.3: Fix for SDL_WINDOWID crash contributed by Mattias
  18.466 -	<LI> 1.1.3: Speeded up 32-bit alpha channel blits by nearly 100%
  18.467 -	<LI> 1.1.3: Added experimental DGA 2.0 support (set SDL_VIDEODRIVER)
  18.468 -	<LI> 1.1.2: Fixed crash running on NT with a read-only filesystem
  18.469 -	<LI> 1.1.2: Re-use thread creation mutex on glibc-2.0 systems
  18.470 -	<LI> 1.1.2: SDL_WM_SetIcon() now uses icon colorkey if mask is NULL
  18.471 -	<LI> 1.1.2: Win32 relative mouse mode fixes (thanks Randi Relander)
  18.472 -	<LI> 1.1.2: Not being able to set audio frags is no longer fatal
  18.473 -	<LI> 1.1.2: Added support for multiple timers (thanks Stephane Peter)
  18.474 -	<LI> 1.1.2: Copy blits optimized using inline assembly on x86 Linux
  18.475 -	<LI> 1.1.2: Copy blit can now handle overlapping blits
  18.476 -	<LI> 1.1.2: Fixed GL direct rendering on Utah GLX (thanks John Fulmer)
  18.477 -	<LI> 1.1.2: Added unofficial support for AIX (thanks Carsten Griwodz)
  18.478 -	<LI> 1.1.2: Enabled X11 VidMode extension on remote displays
  18.479 -	<LI> 1.1.2: Load libGL.so.1 under X11 if an app isn't linked with GL
  18.480 -	<LI> 1.1.2: Don't restack windows in the X11 environment
  18.481 -	<LI> 1.1.2: Multiple X11 visual support (thanks Mattias Engdegård)
  18.482 -	<LI> 1.1.0: Internal event state is updated before filter is called
  18.483 -	<LI> 1.1.0: Worked around DGA mouse cursor bug in Voodoo X server
  18.484 -	<LI> 1.1.0: Added SDL OpenGL documentation (thanks Nicholas Vining)
  18.485 -	<LI> 1.1.0: Added AAlib video driver support (thanks Stephane Peter)
  18.486 -	<LI> 1.1.0: Added fullscreen support for Win32 GDI video driver
  18.487 -	<LI> 1.1.0: Added SDL_GetAudioState() to get current audio status
  18.488 -	<LI> 1.1.0: Added SDL_GetRelativeMouseState() to get relative motion
  18.489 -	<LI> 1.1.0: Added 32-bit PII MMX optimized blitters from Hermes
  18.490 -	<LI> 1.1.0: Added SDL_bool datatype for functions returning true/false
  18.491 -	<LI> 1.1.0: Improved alpha blend speed (thanks Alexandre Courbot)
  18.492 -	<LI> 1.1.0: Added function to queue events: SDL_PushEvent()
  18.493 -	<LI> 1.1.0: Added user-defined event type to SDL_Event structure
  18.494 -	<LI> 1.1.0: Added SDL_InitSubSystem() and SDL_QuitSubSystem()
  18.495 -	<LI> 1.1.0: Added BDirectWindow fullscreen support on BeOS
  18.496 -	<LI> 1.1.0: Added initial joystick support (Linux, Win32, BeOS, MacOS)
  18.497 -	<LI> 1.1.0: The timer now runs in a separate thread if possible
  18.498 -	<LI> 1.1.0: Added initial OpenGL support (Linux, Win32, BeOS, MacOS)
  18.499 -	<LI> 1.0.9: Avoid potential crash in Win32 mouse handling (thanks Cliff)
  18.500 -	<LI> 1.0.9: Fixed bug where /dev/dsp was incorrectly marked available
  18.501 -	<LI> 1.0.9: Fixed DirectX crash if video height is larger than width
  18.502 -	<LI> 1.0.9: Fixed win32 timer error message typo (thanks Martin Dvorak)
  18.503 -	<LI> 1.0.8: Fixed deadlock if SDL_LockAudio() called from audio thread
  18.504 -	<LI> 1.0.8: Fixed a race condition in thread creation
  18.505 -	<LI> 1.0.7: Added detection for Linux supermount CD-ROM drives
  18.506 -	<LI> 1.0.6: Added --static-libs option to sdl-config
  18.507 -	<LI> 1.0.6: Fixed a clipping bug in the RLE colorkey blitting
  18.508 -	<LI> 1.0.6: Mouse window manager routines implemented on MacOS
  18.509 -	<LI> 1.0.6: Fixed SDL_HWPALETTE in fullscreen X11 video driver
  18.510 -	<LI> 1.0.6: Improved relative mouse warping in X11 video driver
  18.511 -	<LI> 1.0.6: DGA mouse mode is now enabled by SDL_VIDEO_X11_DGAMOUSE
  18.512 -	<LI> 1.0.6: Grab input by default in fullscreen mode
  18.513 -	<LI> 1.0.6: Detect hanging (incorrectly configured) Linux soundcard
  18.514 -	<LI> 1.0.6: If ESPEAKER env variable is set, use ESD audio driver
  18.515 -	<LI> 1.0.5: Fixed audio structure alignment for packing compilers
  18.516 -	<LI> 1.0.5: Exposed SDL_AudioInit() and SDL_VideoInit()
  18.517 -	<LI> 1.0.5: Added SDL_WM_ToggleFullScreen(), implemented for X11
  18.518 -	<LI> 1.0.5: Removed ALT-Enter functionality - should be in apps
  18.519 -	<LI> 1.0.5: The DSP audio driver is used by default on Linux
  18.520 -	<LI> 1.0.4: Added optional DMA support for the Linux audio driver
  18.521 -	<LI> 1.0.4: Fixed CD-ROM opening on the iBook under MacOS
  18.522 -	<LI> 1.0.4: Fixed a crash in 8-bit mode when using X11 video
  18.523 -	<LI> 1.0.4: Initial audio support on MacOS (thanks Darrell Walisser)
  18.524 -	<LI> 1.0.4: The audio thread runs at high priority on Win32
  18.525 -	<LI> 1.0.4: ESD audio support is now a separate selectable driver
  18.526 -	<LI> 1.0.4: Initial OpenBSD support (thanks Federico Schwindt)
  18.527 -	<LI> 1.0.4: Fixed hang when closing audio on Windows 2000
  18.528 -	<LI> 1.0.4: Warn about monochrome X displays (thanks Christian Bauer)
  18.529 -	<LI> 1.0.4: Fixed spurious X11 mouse focus events at ALT-ENTER
  18.530 -	<LI> 1.0.4: Perform input ungrab at video quit, just in case
  18.531 -	<LI> 1.0.4: Corrected X11 depth reporting in SDL_VideoModeOK()
  18.532 -	<LI> 1.0.3: Disable mouse threshold when X11 mouse is in warp mode
  18.533 -	<LI> 1.0.3: Fixed black-screen on exit in fbcon video driver
  18.534 -	<LI> 1.0.3: Much improved console switching in fbcon video driver
  18.535 -	<LI> 1.0.3: Fixed X11 UNICODE translation bug (thanks Andreas Arens)
  18.536 -	<LI> 1.0.3: Fixed WaveOut mutex logic bug (thanks Markus Oberhum)
  18.537 -	<LI> 1.0.3: Use X11 mouse warping when cursor hidden and input grabbed
  18.538 -	<LI> 1.0.3: Doesn't try to use TrackMouseEvent() on Win95
  18.539 -	<LI> 1.0.3: DirectColor support in fbcon driver (thanks Adam Meyerowitz)
  18.540 -	<LI> 1.0.3: Fixed ALT-ENTER key state problem on X11
  18.541 -	<LI> 1.0.2: Fixed Win32 code to run on VMWare with DIB video driver
  18.542 -	<LI> 1.0.2: Added window manager function: SDL_WM_GrabInput()
  18.543 -	<LI> 1.0.2: Added window manager function: SDL_WM_IconifyWindow()
  18.544 -	<LI> 1.0.2: Added ALT-ENTER fullscreen toggle for X11 video driver
  18.545 -	<LI> 1.0.2: X11 fullscreen mode uses DGA mouse if cursor is hidden
  18.546 -	<LI> 1.0.2: New X11 fullscreen code doesn't require root
  18.547 -	<LI> 1.0.2: Mouse focus and position is now updated at video mode set
  18.548 -	<LI> 1.0.2: Mouse focus loss is now detected under Win32
  18.549 -	<LI> 1.0.2: Menubar hiding is more robust on MacOS (thanks Matt Slott)
  18.550 -	<LI> 1.0.2: Added CD-ROM support on MacOS (thanks Matt Slott)
  18.551 -	<LI> 1.0.2: Added non-root fullscreen modes under X11 (thanks Stephane)
  18.552 -	<LI> 1.0.2: Added docs for time functions (thanks Christian Biesinger)
  18.553 -	<LI> 1.0.2: Squeezed a little more speed out of blitters (Duff's device)
  18.554 -	<LI> 1.0.2: Added hardware acceleration for 3Dfx to fbcon driver.
  18.555 -	<LI> 1.0.2: Added hardware acceleration for Matrox to fbcon driver.
  18.556 -	<LI> 1.0.2: Windows mouse driver now recognizes the middle button.
  18.557 -	<LI> 1.0.2: X11 driver now recognizes the "unix:0" display as local.
  18.558 -	<LI> 1.0.2: Fixed a bug in DGA support which crashed some X servers.
  18.559 -	<LI> 1.0.2: Added GPM repeater support (gpm -R) to fbcon driver
  18.560 -	<LI> 1.0.2: Added support for hardware surfaces to fbcon driver
  18.561 -	<LI> 1.0.2: Implemented console switching in fbcon driver
  18.562 -	<LI> 1.0.2: Implemented graphics mode detection in fbcon driver
  18.563 -	<LI> 1.0.2: Added SDL_EnableKeyRepeat() (thanks Jim Kutter)
  18.564 -	<LI> 1.0.2: Enabled DirectSound on Windows 2000
  18.565 -	<LI> 1.0.1: Fixed the frame buffer video driver on LinuxPPC
  18.566 -	<LI> 1.0.1: Stopped using DirectSound on Windows NT.
  18.567 -	<LI> 1.0.1: Stopped using DirectX when DINPUT.DLL is not installed.
  18.568 -	<LI> 1.0.1: Added pthread detection to configure.in for FreeBSD.
  18.569 -	<LI> 1.0.1: Updated the Solaris audio code for the 1.0 API
  18.570 -	<LI> 1.0.1: Updated the MacOS code for the 1.0 internal API
  18.571 +<LI>
  18.572 +	If SDL_OpenAudio() is passed zero for the desired format
  18.573 +	fields, the following environment variables will be used
  18.574 +	to fill them in:
  18.575 +<pre><code>
  18.576 +		SDL_AUDIO_FREQUENCY
  18.577 +		SDL_AUDIO_FORMAT
  18.578 +		SDL_AUDIO_CHANNELS
  18.579 +		SDL_AUDIO_SAMPLES
  18.580 +</code></pre>
  18.581 +	If an environment variable is not specified, it will be set
  18.582 +	to a reasonable default value.
  18.583 +<LI>
  18.584 +	SDL_SetVideoMode() now accepts 0 for width or height and will use
  18.585 +	the current video mode (or the desktop mode if no mode has been set.)
  18.586 +<LI>
  18.587 +	Added current_w and current_h to the SDL_VideoInfo structure,
  18.588 +	which is set to the desktop resolution during video intialization,
  18.589 +	and then set to the current resolution when a video mode is set.
  18.590 +<LI>
  18.591 +	SDL_GL_LoadLibrary() will load the system default OpenGL library
  18.592 +	if it is passed NULL as a parameter.
  18.593 +<LI>
  18.594 +	Added SDL_GL_SWAP_CONTROL to wait for vsync in OpenGL applications.
  18.595 +<LI>
  18.596 +	Added SDL_GL_ACCELERATED_VISUAL to guarantee hardware acceleration.
  18.597 +<LI>
  18.598 +	SDL_WM_SetCaption() now officially takes UTF-8 title and icon strings, and displays international characters on supported platforms.
  18.599 +<LI>
  18.600 +	Added SDL_GetKeyRepeat() to query the key repeat settings.
  18.601 +<LI>
  18.602 +	Added the "dummy" audio driver, which can be used to emulate audio
  18.603 +	output without a sound card.
  18.604 +<LI>
  18.605 +	Added SDL_config.h, with defaults for various build environments.
  18.606  </UL>
  18.607  
  18.608 -<H2>
  18.609 -Major changes since SDL 0.10.0:
  18.610 -</H2>
  18.611 -<UL>
  18.612 -	<LI> 0.11.5: Fixed mouse warping in fullscreen mode
  18.613 -	<LI> 0.11.5: Added a new function SDL_GetVideoSurface()
  18.614 -	<LI> 0.11.5: Renamed SDL_AllocSurface() SDL_CreateRGBSurface()
  18.615 -	<LI> 0.11.5: Added a new function SDL_CreateRGBSurfaceFrom()
  18.616 -	<LI> 0.11.4: Added support for multiple compiled-in video drivers
  18.617 -	<LI> 0.11.3: Fixed 16 --> 32 bpp blitting - using C instead of Hermes. 
  18.618 -	<LI> 0.11.3: Fixed double-buffering bug in the DirectX driver
  18.619 -	<LI> 0.11.3: Added GGI video driver (thanks Jon Taylor)
  18.620 -	<LI> 0.11.2: Added automake/aclocal/autoconf support
  18.621 -	<LI> 0.11.1: Added an initial (buggy) MacOS CD-ROM driver
  18.622 -	<LI> 0.11.1: Improved Linux CD-ROM detection
  18.623 -	<LI> 0.11.1: Added a workaround for DGA mouse bug on Voodoo 3
  18.624 -	<LI> 0.11.1: Fixed 24bpp --> 8bpp blit crash
  18.625 -	<LI> 0.11.1: Fixed a bug in blit mapping when palette changed
  18.626 -	<LI> 0.11.1: Added a Linux SBLive beta driver workaround
  18.627 -	<LI> 0.11.1: Fixed Win32 cross-compile problem with mingw32
  18.628 -	<LI> 0.11.1: Loss of keyboard focus now causes keys to be reset
  18.629 -	<LI> 0.11.1: DGA DirectMouse is conditionally compiled (default off)
  18.630 -</UL>
  18.631 +<H3> General Notes </H3>
  18.632  
  18.633 -<H2>
  18.634 -Major changes since SDL 0.8.0:
  18.635 -</H2>
  18.636 -<UL>
  18.637 -	<LI> 0.9.16: Made SDL error messages thread-safe
  18.638 -	<LI> 0.9.15: If you have r/w access to /dev/mem, DGA works on Linux
  18.639 -	<LI> 0.9.15: Added support for Linux on the ARM (Netwinder)
  18.640 -	<LI> 0.9.14: Removed color cursor support, fixed b/w cursors
  18.641 -	<LI> 0.9.14: Fixed long-standing X11 DGA colormap problem
  18.642 -	<LI> 0.9.13: Added dynamic load function: SDL_SetLibraryPath()
  18.643 -	<LI> 0.9.13: Added unofficial support for MacOS
  18.644 -	<LI> 0.9.13: Added unofficial support for FreeBSD
  18.645 -	<LI> 0.9.13: Added unofficial support for IRIX
  18.646 -	<LI> 0.9.13: Updated support for BeOS from R3 to R4.5
  18.647 -	<LI> 0.9.13: Added SDL_SetLibraryPath() function (thanks Karsten Laux)
  18.648 -	<LI> 0.9.13: Fixed 8-bit audio conversion when using SDL_MixAudio()
  18.649 -	<LI> 0.9.13: Fixed audio thread lingering when app dies on Linux
  18.650 -	<LI> 0.9.13: Fixed color problem in X display to other-endian systems
  18.651 -	<LI> 0.9.13: Finally able to detect X11 key repeat (thanks GII team!)
  18.652 -	<LI> 0.9.13: Added support for Visual C++ 5.0 development environment
  18.653 -	<LI> 0.9.13: Added support for Linux on the Alpha
  18.654 -	<LI> 0.9.13: Added support for international keyboards (see WhatsNew)
  18.655 -	<LI> 0.9.12: Added support for loading IMA ADPCM compressed WAV files
  18.656 -	<LI> 0.9.12: Fixed bug when mixing 8-bit audio in SDL_MixAudio()
  18.657 -	<LI> 0.9.12: Added Enlightenment Sound Daemon audio support on Linux
  18.658 -	<LI> 0.9.12: Added MTRR support for Linux/X11 (thanks David Barth)
  18.659 -	<LI> 0.9.12: Added support for LinuxPPC 5.0
  18.660 -	<LI> 0.9.12: Fixed place where some audio conversions aren't detected
  18.661 -	<LI> 0.9.12: Fixed serious bug in installation script
  18.662 -	<LI> 0.9.12: Added SDL_FreeWAV() function for freeing DLL memory
  18.663 -	<LI> 0.9.12: Fixed potential memory leak in SDL_LoadWAV_RW()
  18.664 -	<LI> 0.9.11: Freeing video surface has no longer crashes SDL_Quit()
  18.665 -	<LI> 0.9.11: Included new asm blitters from Hermes library 1.2.4
  18.666 -	<LI> 0.9.11: SDL_WaitThread() now gets the thread's return status
  18.667 -	<LI> 0.9.11: SDL_MixAudio() takes a larger volume range (0-128)
  18.668 -	<LI> 0.9.11: SDL no longer changes the X11 keyboard repeat
  18.669 -	<LI> 0.9.11: Added a data source abstraction for loading/saving data
  18.670 -	<LI> 0.9.11: Added three built in data abstractions:<BR>
  18.671 -	               SDL_RWFromFile(), SDL_RWFromFP(), SDL_RWFromMem()
  18.672 -	<LI> 0.9.11: Added stdio-like functions for using data sources:<BR>
  18.673 -	               SDL_RWseek(), SDL_RWread(), SDL_RWwrite(), SDL_RWclose()
  18.674 -	<LI> 0.9.11: Replaced SDL_CalculateEndian() with SDL_BYTEORDER macro
  18.675 -	<LI> 0.9.11: Endian swapping functions are now macros, for speed.
  18.676 -	<LI> 0.9.11: Endian read/write functions now use data sources
  18.677 -	<LI> 0.9.11: Added function SDL_LoadWAV_RW() for data sources
  18.678 -	<LI> 0.9.11: Added function SDL_LoadBMP_RW() for data sources
  18.679 -	<LI> 0.9.11: Added function SDL_SaveBMP_RW() for data sources
  18.680 -	<LI> 0.9.10: Mixer no longer fails if timidity isn't installed
  18.681 -	<LI> 0.9.10: Mixer restarts MOD files on play (thanks Bill Kendrick)
  18.682 -	<LI> 0.9.10: Fixed occasional crashing of the mixer library
  18.683 -	<LI> 0.9.10: Fixed icon display on Afterstep under Linux
  18.684 -	<LI> 0.9.10: Fixed occasional crash in mixer example
  18.685 -	<LI> 0.9.10: Linux cdrom list now comes from /etc/fstab
  18.686 -	<LI> 0.9.10: Fixed support for UK keyboard (thanks John Elliott)
  18.687 -	<LI> 0.9.10: The event queue is now thread-safe
  18.688 -	<LI> 0.9.10: Added event queue pump function: SDL_PumpEvents()
  18.689 -	<LI> 0.9.10: Added low level event function: SDL_PeepEvents()
  18.690 -	<LI> 0.9.10: Added a new thread function: SDL_ThreadID()
  18.691 -	<LI> 0.9.10: Fixed an audio rate conversion memory overrun
  18.692 -	<LI> 0.9.10: Fixed crash with RLE acceleration on big surfaces
  18.693 -	<LI> 0.9.10: Improved MacOS display driver - added fullscreen
  18.694 -	<LI> 0.9.10: Removed spurious warnings from Linux X11 driver
  18.695 -	<LI> 0.9.10: Fixed memory leak in SDL_InvalidateMap()
  18.696 -	<LI> 0.9.10: Fixed right button of 2-button mice on Win32
  18.697 -	<LI> 0.9.10: Enabled XFree86 mode changes on older servers
  18.698 -	<LI> 0.9.9: SDL_LoadBMP() handles BMP files created with GIMP
  18.699 -	<LI> 0.9.9: SDL_LoadWAV() handles WAV files with "LIST" chunks
  18.700 -	<LI> 0.9.9: Fixed problem with audio underflow on Solaris
  18.701 -	<LI> 0.9.9: Initial support for 4-speaker audio output devices
  18.702 -	<LI> 0.9.8: Fixed corrupt VC++ 5.0 desktop file
  18.703 -	<LI> 0.9.8: Now detects fixed version of Metro-X X11 server
  18.704 -	<LI> 0.9.8: Fixed XFree86 DGA banked mode update
  18.705 -	<LI> 0.9.8: Fixed mouse press viewport shift on XFree86 DGA
  18.706 -	<LI> 0.9.7: Fixed problem with displaying remotely via X11
  18.707 -	<LI> 0.9.7: Win32 uses software cursor when fullscreen
  18.708 -	<LI> 0.9.7: Win32 mouse uses DirectInput when fullscreen
  18.709 -	<LI> 0.9.7: Added OpenGL software rendering via Mesa (demos archive)
  18.710 -	<LI> 0.9.7: Fixed memory leak in ADPCM WAV decoding
  18.711 -	<LI> 0.9.6: Added CD-ROM audio API documentation
  18.712 -	<LI> 0.9.6: Fixed potential BeOS audio-related crash
  18.713 -	<LI> 0.9.6: Fixed crash when resetting the video mode in DirectX
  18.714 -	<LI> 0.9.6: Fixed errors compiling with the SparcWorks compiler
  18.715 -	<LI> 0.9.6: Replaced SDL_GetDisplayFormat() with SDL_GetVideoInfo()
  18.716 -	<LI> 0.9.6: Added a new fast fill function: SDL_FillRect()
  18.717 -	<LI> 0.9.6: Added blit acceleration flags to SDL_AllocSurface()
  18.718 -	<LI> 0.9.6: Added new double-buffering function: SDL_Flip()
  18.719 -	<LI> 0.9.6: Fixed problem with buggy Metro-X X11 server
  18.720 -	<LI> 0.9.6: Fixed 8-bit audio on Solaris with dbri hardware
  18.721 -	<LI> 0.9.6: Fixed alarm clock problem with Solaris pthreads
  18.722 -	<LI> 0.9.6: Fixed BeOS compilation problem
  18.723 -	<LI> 0.9.5: Added tools to create Win32 icons in directx/icon/
  18.724 -	<LI> 0.9.5: You can now pass a NULL mask to SDL_WM_SetIcon()
  18.725 -	<LI> 0.9.5: Added support files for compiling with VC++ 5.0
  18.726 -	<LI> 0.9.5: Fixed icon color bug under Win32
  18.727 -	<LI> 0.9.5: Re-added SDL_LowerBlit() - not safe for use on display
  18.728 -	<LI> 0.9.5: Fixed 0.9.x cursor blit deadlock
  18.729 -	<LI> 0.9.5: Added SDL_FPLoadWAV(), SDL_FPLoadBMP(), SDL_FPSaveBMP()
  18.730 -	<LI> 0.9.5: Added Linux, Win32, and BeOS CD audio support
  18.731 -	<LI> 0.9.5: MMX accelerated blit disabled -- temporarily broken
  18.732 -	<LI> 0.9.4: Fixed endianness issue with BeOS x86 blitting
  18.733 -	<LI> 0.9.4: Fixed quit interrupt delivery on BeOS
  18.734 -	<LI> 0.9.4: Fixed dynamic loading on BeOS
  18.735 -	<LI> 0.9.4: Fixed DirectX audio on Win98
  18.736 -	<LI> 0.9.4: Fixed possible sound-related crash on Linux PPC
  18.737 -	<LI> 0.9.3: Mouse motion arrives as absolute and relative coordinates
  18.738 -	<LI> 0.9.3: Fixed Visual C++ structure packing
  18.739 -	<LI> 0.9.3: Fixed UNIX dynamic link library installation
  18.740 -	<LI> 0.9.2: DirectX audio no longer hangs when app loses focus
  18.741 -	<LI> 0.9.2: Fixed DirectX HiColor crash (palette bug)
  18.742 -	<LI> 0.9.1: Fixed DirectX &lt;ALT&gt; key handling
  18.743 -	<LI> 0.9.1: Fixed DirectX windowed palette problems
  18.744 -	<LI> 0.9.1: Removed SDL_MapSurface() and SDL_UnmapSurface()
  18.745 -	<LI> 0.9.0: Initial port to IRIX 6.x
  18.746 -	<LI> 0.9.0: Initial port to OSF/1 3.2       (no sound yet)
  18.747 -	<LI> 0.9.0: MacOS port in progress
  18.748 -</UL>
  18.749 +<BLOCKQUOTE>
  18.750 +<P>
  18.751 +	The SDL website now has an <A HREF="http://www.libsdl.org/rss/rss.xml">RSS feed</A>!
  18.752 +<P>
  18.753 +	The SDL development source code is now managed with <A HREF="http://www.libsdl.org/svn.php">Subversion</A>.
  18.754 +<P>
  18.755 +	SDL now uses the Bugzilla <A HREF="http://bugzilla.libsdl.org/">bug tracking system</A>, hosted by icculus.org.
  18.756 +<P>
  18.757 +	SDL is licensed under version 2.1 of the GNU Lesser General Public License.
  18.758 +<P>
  18.759 +	The entire build system has been revamped to make it much more portable, including versions of C library functions to make it possible to run SDL on a minimal embedded environment.  See README.Porting in the SDL source distribution for information on how to port SDL to a new platform.
  18.760 +<P>
  18.761 +	SDL_opengl.h has been updated with the latest glext.h from <A HREF="http://oss.sgi.com/projects/ogl-sample/registry/">http://oss.sgi.com/projects/ogl-sample/registry/</A>
  18.762 +<P>
  18.763 +	Alex Volkov contributed highly optimized RGB <-> RGBA blitters.
  18.764 +</BLOCKQUOTE>
  18.765  
  18.766 -<H2>
  18.767 -Major changes since SDL 0.7:
  18.768 -</H2>
  18.769 -<UL>
  18.770 -	<LI>	Separated the demos and examples into a separate archive
  18.771 -	<LI>	Added support for loading Microsoft compressed WAV files
  18.772 -	<LI>	Added "soft" application crash recovery (signal handlers)
  18.773 -	<LI>	Fixed POSIX signal handling interaction with threads
  18.774 -	<LI>	Fixed audio output on MKLinux
  18.775 -	<LI>	Added dynamic library version checking
  18.776 -	<LI>	Updated for DirectX 6.0
  18.777 -	<LI>	Cleaned up dynamic linking and added static linking
  18.778 -	<LI>	Added automatic audio format and rate conversion
  18.779 -	<LI>	Optimized some blitter cases (8 --> 16/32 and 32 --> 16/8)
  18.780 -	<LI>	Removed precalculated alpha blending acceleration
  18.781 -	<LI>	Key and mouse button events are split into up/down events
  18.782 -	<LI>	It is now much easier to set an optimal video mode
  18.783 -</UL>
  18.784 +<H3> Unix Notes </H3>
  18.785  
  18.786 -<H2>
  18.787 -Major changes since SDL 0.5:
  18.788 -</H2>
  18.789 -<UL>
  18.790 -	<LI>	Ported to Solaris 2.6
  18.791 -	<LI>	Added XFree86 Direct Graphic Access support
  18.792 -	<LI>	Supports LinuxPPC without threads
  18.793 -	<LI>	Completely rewritten video/surface API -- see SDL_video.h
  18.794 -	<LI>	Completely rewritten event API
  18.795 -	<LI>	Optimized black-white cursor creation
  18.796 -	<LI>	Added support for run-length-encoded colorkeying
  18.797 -	<LI>	Added support for hardware accelerated blits
  18.798 -	<LI>	Added support for blitting from 1-bit surfaces (bitmaps)
  18.799 -	<LI>	Added a function to simplify setting video modes
  18.800 -	<LI>	Added support for loading WAV files
  18.801 -	<LI>	Added endian swapping functions for memory values
  18.802 -	<LI>	Added alpha blending using alpha value or channel
  18.803 -	<LI>	Added precalculated alpha blending acceleration
  18.804 -	<LI>	Added function to return current time in milliseconds
  18.805 -	<LI>	New event type SDL_ACTIVEEVENT, to detect iconification
  18.806 -	<LI>	New event type SDL_SYSWMEVENT, for custom window hooks
  18.807 -	<LI>	Added a platform dependent function to get window handle
  18.808 -	<LI>	Added a function to check the run-time version of SDL
  18.809 -	<LI>	Added periodic timer support at 10 ms resolution
  18.810 -	<LI>	Added support for the SDL_DEBUG environment variable
  18.811 -	<LI>	Miscellaneous internal cleanups
  18.812 -</UL>
  18.813 +<BLOCKQUOTE>
  18.814 +<P>
  18.815 +	The X11 libraries are dynamically loaded at runtime by default.  This allows the distributed version of SDL to run on systems without X11 libraries installed.
  18.816 +<P>
  18.817 +	The XiG XME extension code is now included in the X11 video driver by default.
  18.818 +<P>
  18.819 +	XRandR support for video mode switching has been added to the X11 driver, but is disabled because of undesired interactions with window managers.  You can enable this by setting the environment variable SDL_VIDEO_X11_XRANDR to 1.
  18.820 +<P>
  18.821 +	Xinerama multi-head displays are properly handled now, and the SDL_VIDEO_FULLSCREEN_HEAD environment variable can be used to select the screen used for fullscreen video modes.  Note that changing the video modes only works on screen 0.
  18.822 +<P>
  18.823 +	XVidMode video modes are now sorted so they maintain the refresh rates specified in the X11 configuration file.
  18.824 +<P>
  18.825 +	SDL windows are no longer transparent in X11 compositing systems like XGL.
  18.826 +<P>
  18.827 +	The mouse is properly released by the X11 video driver if the fullscreen window loses focus.
  18.828 +<P>
  18.829 +	The X11 input driver now uses XIM to handle international input.
  18.830 +<P>
  18.831 +	The screensaver and DPMS monitor blanking are disabled while SDL games are running under the X11 and DGA video drivers.  This behavior will be formalized and selectable in SDL 1.3.
  18.832 +<P>
  18.833 +	Fixed a bug preventing stereo OpenGL contexts from being selected on the X11 driver.
  18.834 +<P>
  18.835 +	The DGA video driver now waits for pending blits involving surfaces before they are freed.  This prevents display oddities when using SDL_DisplayFormat() to convert many images.
  18.836 +<P>
  18.837 +	The framebuffer console video driver now has a parser for /etc/fb.modes for improved video mode handling.
  18.838 +<P>
  18.839 +	The framebuffer console video driver now allows asynchronous VT switching, and restores the full contents of the screen when switched back.
  18.840 +<P>
  18.841 +	The framebuffer console now uses CTRL-ALT-FN to switch virtual terminals, to avoid collisions with application key bindings.
  18.842 +<P>
  18.843 +	The framebuffer console input driver correctly sets IMPS/2 mode for wheel mice.  It also properly detects when gpm is in IMPS/2 protocol mode, or passing raw protocol from an IMPS/2 mouse.
  18.844 +<P>
  18.845 +	The SVGAlib video driver now has support for banked (non-linear) video modes.
  18.846 +<P>
  18.847 +	A video driver for OpenBSD on the Sharp Zaurus has been contributed by Staffan Ulfberg.  See the file README.wscons in the SDL source distribution for details.
  18.848 +<P>
  18.849 +	Many patches have been incorporated from *BSD ports.
  18.850 +</BLOCKQUOTE>
  18.851  
  18.852 -<H2>
  18.853 -Major changes since SDL 0.4:
  18.854 -</H2>
  18.855 -<UL>
  18.856 -	<LI>	SDL library code is now dynamically loaded
  18.857 -	<LI>	Added support for pthreads (Linux glibc2)
  18.858 -	<LI>	Removed SDL_mutexN() and SDL_mutexIncr()
  18.859 -</UL>
  18.860 +<H3> Windows Notes </H3>
  18.861  
  18.862 -<H2>
  18.863 -Major changes since SDL 0.3:
  18.864 -</H2>
  18.865 -<UL>
  18.866 -	<LI>	Added support for DirectX 5.0
  18.867 -	<LI>	Added support for surfaces in video memory
  18.868 -	<LI>	Added support for source color-key blitting
  18.869 -	<LI>	Added support for single-rectangle clipping
  18.870 -	<LI>	Added support for warping (moving) the cursor
  18.871 -	<LI>	Added support for color cursors
  18.872 -	<LI>	Greatly simplified internal event queue
  18.873 -	<LI>	Minor bug-fixes
  18.874 -</UL>
  18.875 +<BLOCKQUOTE>
  18.876 +<P>
  18.877 +	The "windib" video driver is the default now, to prevent problems with certain laptops, 64-bit Windows, and Windows Vista.  The DirectX driver is still available, and can be selected by setting the environment variable SDL_VIDEODRIVER to "directx".
  18.878 +<P>
  18.879 +	SDL has been ported to 64-bit Windows.
  18.880 +<P>
  18.881 +	Dmitry Yakimov contributed a GAPI video driver for Windows CE.
  18.882 +<P>
  18.883 +	The default fullscreen refresh rate has been increased to match the desktop refresh rate, when using equivalent resolutions.  A full API for querying and selecting refresh rates is planned for SDL 1.3.
  18.884 +<P>
  18.885 +	Dialog boxes are now shown when SDL is in windowed OpenGL mode.
  18.886 +<P>
  18.887 +	The SDL window is recreated when necessary to maintain OpenGL context attributes, when switching between windowed and fullscreen modes.
  18.888 +<P>
  18.889 +	An SDL_VIDEORESIZE event is properly sent when the SDL window is maximized and restored.
  18.890 +<P>
  18.891 +	Window positions are retained when switching between fullscreen and windowed modes.
  18.892 +<P>
  18.893 +	ToUnicode() is used, when available, for improved handling of international keyboard input.
  18.894 +<P>
  18.895 +	The PrtScrn is now treated normally with both key down and key up events.
  18.896 +<P>
  18.897 +	Pressing ALT-F4 now delivers an SDL_QUIT event to SDL applications.
  18.898 +<P>
  18.899 +	Joystick names are now correct for joysticks which have been unplugged and then plugged back in since booting.
  18.900 +<P>
  18.901 +	An MCI error when playing the last track on a CD-ROM has been fixed.
  18.902 +<P>
  18.903 +	OpenWatcom projects for building SDL have been provided by Marc Peter.
  18.904 +</BLOCKQUOTE>
  18.905  
  18.906 +<H3> Mac OS X Notes </H3>
  18.907 +
  18.908 +<BLOCKQUOTE>
  18.909  <P>
  18.910 +	SDL now supports building Universal binaries, both through Xcode projects and when using configure/make.  See README.MacOSX in the SDL source archive for details.
  18.911 +<P>
  18.912 +	The X11 video driver with GLX support can be built on Mac OS X, if the X11 development SDK is installed.
  18.913 +<P>
  18.914 +	Transitions between fullscreen resolutions and windowed mode now use a much faster asynchronous fade to hide desktop flicker.
  18.915 +<P>
  18.916 +	Icons set with SDL_WM_SetIcon() now have the proper colors on Intel Macs.
  18.917 +</BLOCKQUOTE>
  18.918 +
  18.919 +<H3> OS/2 Notes </H3>
  18.920 +
  18.921 +<BLOCKQUOTE>
  18.922 +<P>
  18.923 +	Projects for building SDL on OS/2 with OpenWatcom have been contributed by Doodle.  See the file README.OS2 in the SDL source distribution for details.
  18.924 +</BLOCKQUOTE>
  18.925 +
  18.926  <IMG SRC="docs/images/rainbow.gif" ALT="[separator]" WIDTH="100%">
  18.927  
  18.928  </BODY>
    19.1 Binary file docs/images/rainbow.gif has changed
    20.1 --- a/docs/index.html	Mon May 01 06:58:33 2006 +0000
    20.2 +++ b/docs/index.html	Wed May 17 08:18:28 2006 +0000
    20.3 @@ -1,102 +1,36 @@
    20.4  <!DOCTYPE HTML PUBLIC "-//Norman Walsh//DTD DocBook HTML 1.0//EN">
    20.5 -<HTML
    20.6 -><HEAD
    20.7 -><TITLE
    20.8 ->Introduction</TITLE
    20.9 ->
   20.10 -</HEAD
   20.11 -><BODY
   20.12 -BGCOLOR="#FFF8DC"
   20.13 -TEXT="#000000"
   20.14 -LINK="#0000ee"
   20.15 -VLINK="#551a8b"
   20.16 -ALINK="#ff0000"
   20.17 -><DIV
   20.18 -CLASS="NAVHEADER"
   20.19 ->
   20.20 -<HR
   20.21 -ALIGN="LEFT"
   20.22 -WIDTH="100%"></DIV
   20.23 -><DIV
   20.24 -CLASS="PREFACE"
   20.25 -><H1
   20.26 -><A
   20.27 -NAME="AEN8"
   20.28 ->Introduction</A
   20.29 -></H1
   20.30 -><P
   20.31 ->This library is designed to make it easy to write games that run on Linux,
   20.32 -Win32 and BeOS using the various native high-performance media interfaces,
   20.33 +<HTML>
   20.34 +<HEAD><TITLE>Simple DirectMedia Layer Introduction</TITLE></HEAD>
   20.35 +<BODY BGCOLOR="#FFF8DC" TEXT="#000000" LINK="#0000ee" VLINK="#551a8b" ALINK="#ff0000">
   20.36 +<DIV CLASS="NAVHEADER">
   20.37 +<HR ALIGN="LEFT" WIDTH="100%">
   20.38 +</DIV>
   20.39 +<DIV CLASS="PREFACE">
   20.40 +<H2><A NAME="AEN8">Simple DirectMedia Layer Introduction</A></H2>
   20.41 +<P>
   20.42 +This library is designed to make it easy to write games that run on many
   20.43 +different platforms using the various native high-performance media interfaces,
   20.44  (for video, audio, etc) and presenting a single source-code level API to
   20.45  your application.  This is a fairly low level API, but using this, completely
   20.46 -portable applications can be written with a great deal of flexibility.</P
   20.47 -><P
   20.48 ->The library is loaded as a dynamically linked library on its native
   20.49 -platform, and is currently compiled natively for Linux, compiled for
   20.50 -Win32 using a Linux hosted GCC
   20.51 -<A
   20.52 -HREF="http://www.libsdl.org/Xmingw32/"
   20.53 -TARGET="_top"
   20.54 ->cross-compilation</A
   20.55 ->
   20.56 -environment, and compiled using the EGCS C++ compiler under BeOS.</P
   20.57 -><P
   20.58 ->An introduction to SDL can be found online at:
   20.59 -<A
   20.60 -HREF="http://www.libsdl.org/intro/toc.html"
   20.61 -TARGET="_top"
   20.62 ->http://www.libsdl.org/intro/</A
   20.63 ->&#13;</P
   20.64 -><P
   20.65 ->There are code examples on each of the main library pages, and there are
   20.66 -fully fleshed example C++ classes and programs in the examples archive,
   20.67 -available on the
   20.68 -<A
   20.69 -HREF="http://www.libsdl.org/download.html"
   20.70 -TARGET="_top"
   20.71 ->SDL download page</A
   20.72 ->.</P
   20.73 -><P
   20.74 ->For an introduction to basic multi-media programming concepts, you might try
   20.75 -some of the following links:
   20.76 -<P
   20.77 -></P
   20.78 -><UL
   20.79 -><LI
   20.80 -><P
   20.81 -><A
   20.82 -HREF="http://www.ziron.com/links/"
   20.83 -TARGET="_top"
   20.84 ->Game Programming Links</A
   20.85 -></P
   20.86 -></LI
   20.87 -><LI
   20.88 -><P
   20.89 -><A
   20.90 -HREF="http://developer.dungeon-crawl.com/"
   20.91 -TARGET="_top"
   20.92 ->Game Developer Search Engine</A
   20.93 -></P
   20.94 -></LI
   20.95 -></UL
   20.96 -></P
   20.97 -><P
   20.98 ->Enjoy!</P
   20.99 -><P
  20.100 ->&nbsp;&nbsp;&nbsp; Sam Lantinga
  20.101 -<TT
  20.102 -CLASS="EMAIL"
  20.103 ->&#60;<A
  20.104 -HREF="mailto:slouken@libsdl.org"
  20.105 -><A
  20.106 -HREF="mailto:slouken@libsdl.org"
  20.107 -TARGET="_top"
  20.108 ->slouken@libsdl.org</A
  20.109 -></A
  20.110 ->&#62;</TT
  20.111 -></P
  20.112 ->
  20.113 -<P>
  20.114 +portable applications can be written with a great deal of flexibility.
  20.115 +</P><P>
  20.116 +An introduction to SDL can be found online at:
  20.117 +<A HREF="http://www.libsdl.org/intro.php" TARGET="_top">
  20.118 +         http://www.libsdl.org/intro.php</A>
  20.119 +</P><P>
  20.120 +Tutorials on a variety of topics can be found online at:
  20.121 +<A HREF="http://www.libsdl.org/tutorials.php" TARGET="_top">
  20.122 +         http://www.libsdl.org/tutorials.php</A>
  20.123 +</P><P>
  20.124 +Documentation in Wiki form can be found online at:
  20.125 +<A HREF="http://www.libsdl.org/cgi/docwiki.cgi/" TARGET="_top">
  20.126 +         http://www.libsdl.org/cgi/docwiki.cgi/</A>
  20.127 +</P><P>
  20.128 +Enjoy!
  20.129 +</P><P>
  20.130 +&nbsp;&nbsp;&nbsp; Sam Lantinga
  20.131 +<TT CLASS="EMAIL">&#60;<A HREF="mailto:slouken@libsdl.org"><A HREF="mailto:slouken@libsdl.org" TARGET="_top" >slouken@libsdl.org</A></A>&#62;</TT>
  20.132 +</P> <P>
  20.133  <br><br><HR>
  20.134  <H1>Table of Contents</H1>
  20.135  <UL>
    21.1 --- a/include/SDL_config.h.in	Mon May 01 06:58:33 2006 +0000
    21.2 +++ b/include/SDL_config.h.in	Wed May 17 08:18:28 2006 +0000
    21.3 @@ -279,6 +279,7 @@
    21.4  #undef SDL_VIDEO_DRIVER_WSCONS
    21.5  #undef SDL_VIDEO_DRIVER_X11
    21.6  #undef SDL_VIDEO_DRIVER_X11_DGAMOUSE
    21.7 +#undef SDL_VIDEO_DRIVER_X11_DPMS
    21.8  #undef SDL_VIDEO_DRIVER_X11_DYNAMIC
    21.9  #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT
   21.10  #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR
    22.1 --- a/include/SDL_config_macos.h	Mon May 01 06:58:33 2006 +0000
    22.2 +++ b/include/SDL_config_macos.h	Wed May 17 08:18:28 2006 +0000
    22.3 @@ -27,14 +27,20 @@
    22.4  
    22.5  /* This is a set of defines to configure the SDL features */
    22.6  
    22.7 -typedef signed char	int8_t;
    22.8 -typedef unsigned char	uint8_t;
    22.9 -typedef signed short	int16_t;
   22.10 -typedef unsigned short	uint16_t;
   22.11 -typedef signed long	int32_t;
   22.12 -typedef unsigned long	uint32_t;
   22.13 +#include <MacTypes.h>
   22.14 +
   22.15 +typedef SInt8	int8_t;
   22.16 +typedef UInt8	uint8_t;
   22.17 +typedef SInt16	int16_t;
   22.18 +typedef UInt16	uint16_t;
   22.19 +typedef SInt32	int32_t;
   22.20 +typedef UInt32	uint32_t;
   22.21 +typedef SInt64	int64_t;
   22.22 +typedef UInt64	uint64_t;
   22.23  typedef unsigned long	uintptr_t;
   22.24  
   22.25 +#define SDL_HAS_64BIT_TYPE	1
   22.26 +
   22.27  /* Useful headers */
   22.28  #define HAVE_STDIO_H	1
   22.29  #define STDC_HEADERS	1
   22.30 @@ -73,10 +79,18 @@
   22.31  #define SDL_AUDIO_DRIVER_DUMMY	1
   22.32  
   22.33  /* Enable various cdrom drivers */
   22.34 -#define SDL_CDROM_MACOS	1
   22.35 +#if TARGET_API_MAC_CARBON
   22.36 +#define SDL_CDROM_DUMMY		1
   22.37 +#else
   22.38 +#define SDL_CDROM_MACOS		1
   22.39 +#endif
   22.40  
   22.41  /* Enable various input drivers */
   22.42 +#if TARGET_API_MAC_CARBON
   22.43 +#define SDL_JOYSTICK_DUMMY	1
   22.44 +#else
   22.45  #define SDL_JOYSTICK_MACOS	1
   22.46 +#endif
   22.47  
   22.48  /* Enable various shared object loading systems */
   22.49  #define SDL_LOADSO_MACOS	1
    23.1 --- a/include/SDL_config_macosx.h	Mon May 01 06:58:33 2006 +0000
    23.2 +++ b/include/SDL_config_macosx.h	Wed May 17 08:18:28 2006 +0000
    23.3 @@ -30,7 +30,10 @@
    23.4  #define SDL_HAS_64BIT_TYPE	1
    23.5  
    23.6  /* Useful headers */
    23.7 +/* If we specified an SDK or have a post-PowerPC chip, then alloca.h exists. */
    23.8 +#if ( (MAC_OS_X_VERSION_MIN_REQUIRED >= 1030) || (!defined(__POWERPC__)) )
    23.9  #define HAVE_ALLOCA_H		1
   23.10 +#endif
   23.11  #define HAVE_SYS_TYPES_H	1
   23.12  #define HAVE_STDIO_H	1
   23.13  #define STDC_HEADERS	1
   23.14 @@ -46,12 +49,7 @@
   23.15  #define HAVE_CALLOC	1
   23.16  #define HAVE_REALLOC	1
   23.17  #define HAVE_FREE	1
   23.18 -
   23.19 -/* If we specified an SDK or have a post-PowerPC chip, then alloca.h exists. */
   23.20 -#if ( (MAC_OS_X_VERSION_MIN_REQUIRED >= 1030) || (!defined(__POWERPC__)) )
   23.21  #define HAVE_ALLOCA	1
   23.22 -#endif
   23.23 -
   23.24  #define HAVE_GETENV	1
   23.25  #define HAVE_PUTENV	1
   23.26  #define HAVE_UNSETENV	1
   23.27 @@ -116,8 +114,11 @@
   23.28  
   23.29  /* Enable various video drivers */
   23.30  #define SDL_VIDEO_DRIVER_DUMMY	1
   23.31 -#define SDL_VIDEO_DRIVER_GLSDL	1
   23.32 +#if TARGET_API_MAC_CARBON
   23.33 +#define SDL_VIDEO_DRIVER_TOOLBOX	1
   23.34 +#else
   23.35  #define SDL_VIDEO_DRIVER_QUARTZ	1
   23.36 +#endif
   23.37  
   23.38  /* Enable OpenGL support */
   23.39  #define SDL_VIDEO_OPENGL	1
    24.1 --- a/include/SDL_platform.h	Mon May 01 06:58:33 2006 +0000
    24.2 +++ b/include/SDL_platform.h	Wed May 17 08:18:28 2006 +0000
    24.3 @@ -61,13 +61,12 @@
    24.4  #undef __LINUX__
    24.5  #define __LINUX__	1
    24.6  #endif
    24.7 -#if defined(macintosh)
    24.8 -#undef __MACOS__
    24.9 -#define __MACOS__	1
   24.10 -#endif
   24.11  #if defined(__APPLE__)
   24.12  #undef __MACOSX__
   24.13  #define __MACOSX__	1
   24.14 +#elif defined(macintosh)
   24.15 +#undef __MACOS__
   24.16 +#define __MACOS__	1
   24.17  #endif
   24.18  #if defined(__NetBSD__)
   24.19  #undef __NETBSD__
    25.1 --- a/include/SDL_stdinc.h	Mon May 01 06:58:33 2006 +0000
    25.2 +++ b/include/SDL_stdinc.h	Wed May 17 08:18:28 2006 +0000
    25.3 @@ -168,8 +168,12 @@
    25.4  # elif defined(_MSC_VER)
    25.5  #  include <malloc.h>
    25.6  #  define alloca _alloca
    25.7 +# elif defined(__WATCOMC__)
    25.8 +#  include <malloc.h>
    25.9  # elif defined(__AIX__)
   25.10    #pragma alloca
   25.11 +# elif defined(__MRC__)
   25.12 +   void *alloca (unsigned);
   25.13  # else
   25.14     char *alloca ();
   25.15  # endif
    26.1 --- a/include/SDL_syswm.h	Mon May 01 06:58:33 2006 +0000
    26.2 +++ b/include/SDL_syswm.h	Wed May 17 08:18:28 2006 +0000
    26.3 @@ -115,7 +115,7 @@
    26.4  	GR_WINDOW_ID window ;	/* The display window */
    26.5  } SDL_SysWMinfo;
    26.6  
    26.7 -#elif defined(SDL_VIDEO_DRIVER_WINDIB) || defined(SDL_VIDEO_DRIVER_DDRAW)
    26.8 +#elif defined(SDL_VIDEO_DRIVER_WINDIB) || defined(SDL_VIDEO_DRIVER_DDRAW) || defined(SDL_VIDEO_DRIVER_GAPI)
    26.9  #define WIN32_LEAN_AND_MEAN
   26.10  #include <windows.h>
   26.11  
    27.1 --- a/sdl.m4	Mon May 01 06:58:33 2006 +0000
    27.2 +++ b/sdl.m4	Wed May 17 08:18:28 2006 +0000
    27.3 @@ -20,19 +20,21 @@
    27.4  		    , enable_sdltest=yes)
    27.5  
    27.6    if test x$sdl_exec_prefix != x ; then
    27.7 -     sdl_args="$sdl_args --exec-prefix=$sdl_exec_prefix"
    27.8 -     if test x${SDL_CONFIG+set} != xset ; then
    27.9 -        SDL_CONFIG=$sdl_exec_prefix/bin/sdl-config
   27.10 -     fi
   27.11 +    sdl_args="$sdl_args --exec-prefix=$sdl_exec_prefix"
   27.12 +    if test x${SDL_CONFIG+set} != xset ; then
   27.13 +      SDL_CONFIG=$sdl_exec_prefix/bin/sdl-config
   27.14 +    fi
   27.15    fi
   27.16    if test x$sdl_prefix != x ; then
   27.17 -     sdl_args="$sdl_args --prefix=$sdl_prefix"
   27.18 -     if test x${SDL_CONFIG+set} != xset ; then
   27.19 -        SDL_CONFIG=$sdl_prefix/bin/sdl-config
   27.20 -     fi
   27.21 +    sdl_args="$sdl_args --prefix=$sdl_prefix"
   27.22 +    if test x${SDL_CONFIG+set} != xset ; then
   27.23 +      SDL_CONFIG=$sdl_prefix/bin/sdl-config
   27.24 +    fi
   27.25    fi
   27.26  
   27.27 -  PATH="$prefix/bin:$prefix/usr/bin:$PATH"
   27.28 +  if test "x$prefix" != xNONE; then
   27.29 +    PATH="$prefix/bin:$prefix/usr/bin:$PATH"
   27.30 +  fi
   27.31    AC_PATH_PROG(SDL_CONFIG, sdl-config, no, [$PATH])
   27.32    min_sdl_version=ifelse([$1], ,0.11.0,$1)
   27.33    AC_MSG_CHECKING(for SDL - version >= $min_sdl_version)
    28.1 --- a/src/SDL_error.c	Mon May 01 06:58:33 2006 +0000
    28.2 +++ b/src/SDL_error.c	Wed May 17 08:18:28 2006 +0000
    28.3 @@ -39,15 +39,10 @@
    28.4  
    28.5  /* Private functions */
    28.6  
    28.7 -static void SDL_LookupString(const Uint8 *key, Uint16 *buf, int buflen)
    28.8 +static const char *SDL_LookupString(const char *key)
    28.9  {
   28.10  	/* FIXME: Add code to lookup key in language string hash-table */
   28.11 -
   28.12 -	/* Key not found in language string hash-table */
   28.13 -	while ( *key && (--buflen > 0) ) {
   28.14 -		*buf++ = *key++;
   28.15 -	}
   28.16 -	*buf = 0;	/* NULL terminate string */
   28.17 +	return key;
   28.18  }
   28.19  
   28.20  /* Public functions */
   28.21 @@ -66,17 +61,20 @@
   28.22  	error->argc = 0;
   28.23  	while ( *fmt ) {
   28.24  		if ( *fmt++ == '%' ) {
   28.25 +			while ( *fmt == '.' || (*fmt >= '0' && *fmt <= '9') ) {
   28.26 +				++fmt;
   28.27 +			}
   28.28  			switch (*fmt++) {
   28.29  			    case 0:  /* Malformed format string.. */
   28.30  				--fmt;
   28.31  				break;
   28.32 -#if 0	/* What is a character anyway?  (UNICODE issues) */
   28.33  			    case 'c':
   28.34 -				error->args[error->argc++].value_c =
   28.35 -						va_arg(ap, unsigned char);
   28.36 -				break;
   28.37 -#endif
   28.38 +			    case 'i':
   28.39  			    case 'd':
   28.40 +			    case 'u':
   28.41 +			    case 'o':
   28.42 +			    case 'x':
   28.43 +			    case 'X':
   28.44  				error->args[error->argc++].value_i =
   28.45  							va_arg(ap, int);
   28.46  				break;
   28.47 @@ -114,124 +112,67 @@
   28.48  #endif
   28.49  }
   28.50  
   28.51 -/* Print out an integer value to a UNICODE buffer */
   28.52 -static int PrintInt(Uint16 *str, unsigned int maxlen, int value)
   28.53 -{
   28.54 -	char tmp[128];
   28.55 -	int len, i;
   28.56 -
   28.57 -	SDL_snprintf(tmp, SDL_arraysize(tmp), "%d", value);
   28.58 -	len = 0;
   28.59 -	if ( SDL_strlen(tmp) < maxlen ) {
   28.60 -		for ( i=0; tmp[i]; ++i ) {
   28.61 -			*str++ = tmp[i];
   28.62 -			++len;
   28.63 -		}
   28.64 -	}
   28.65 -	return(len);
   28.66 -}
   28.67 -/* Print out a double value to a UNICODE buffer */
   28.68 -static int PrintDouble(Uint16 *str, unsigned int maxlen, double value)
   28.69 -{
   28.70 -	char tmp[128];
   28.71 -	int len, i;
   28.72 -
   28.73 -	SDL_snprintf(tmp, SDL_arraysize(tmp), "%f", value);
   28.74 -	len = 0;
   28.75 -	if ( SDL_strlen(tmp) < maxlen ) {
   28.76 -		for ( i=0; tmp[i]; ++i ) {
   28.77 -			*str++ = tmp[i];
   28.78 -			++len;
   28.79 -		}
   28.80 -	}
   28.81 -	return(len);
   28.82 -}
   28.83 -/* Print out a pointer value to a UNICODE buffer */
   28.84 -static int PrintPointer(Uint16 *str, unsigned int maxlen, void *value)
   28.85 -{
   28.86 -	char tmp[128];
   28.87 -	int len, i;
   28.88 -
   28.89 -	SDL_snprintf(tmp, SDL_arraysize(tmp), "%p", value);
   28.90 -	len = 0;
   28.91 -	if ( SDL_strlen(tmp) < maxlen ) {
   28.92 -		for ( i=0; tmp[i]; ++i ) {
   28.93 -			*str++ = tmp[i];
   28.94 -			++len;
   28.95 -		}
   28.96 -	}
   28.97 -	return(len);
   28.98 -}
   28.99 -
  28.100  /* This function has a bit more overhead than most error functions
  28.101     so that it supports internationalization and thread-safe errors.
  28.102  */
  28.103 -Uint16 *SDL_GetErrorMsgUNICODE(Uint16 *errstr, unsigned int maxlen)
  28.104 +char *SDL_GetErrorMsg(char *errstr, unsigned int maxlen)
  28.105  {
  28.106  	SDL_error *error;
  28.107  
  28.108  	/* Clear the error string */
  28.109 -	*errstr = 0; --maxlen;
  28.110 +	*errstr = '\0'; --maxlen;
  28.111  
  28.112  	/* Get the thread-safe error, and print it out */
  28.113  	error = SDL_GetErrBuf();
  28.114  	if ( error->error ) {
  28.115 -		Uint16 translated[ERR_MAX_STRLEN], *fmt, *msg;
  28.116 +		const char *fmt;
  28.117 +		char *msg = errstr;
  28.118  		int len;
  28.119  		int argi;
  28.120  
  28.121 -		/* Print out the UNICODE error message */
  28.122 -		SDL_LookupString(error->key, translated, sizeof(translated));
  28.123 -		msg = errstr;
  28.124 +		fmt = SDL_LookupString(error->key);
  28.125  		argi = 0;
  28.126 -		for ( fmt=translated; *fmt && (maxlen > 0); ) {
  28.127 +		while ( *fmt && (maxlen > 0) ) {
  28.128  			if ( *fmt == '%' ) {
  28.129 -				switch (fmt[1]) {
  28.130 -				    case 'S':	/* Special SKIP operand */
  28.131 -					argi += (fmt[2] - '0');
  28.132 -					++fmt;
  28.133 -					break;
  28.134 +				char tmp[32], *spot = tmp;
  28.135 +				*spot++ = *fmt++;
  28.136 +				while ( (*fmt == '.' || (*fmt >= '0' && *fmt <= '9')) && spot < (tmp+SDL_arraysize(tmp)-2) ) {
  28.137 +					*spot++ = *fmt++;
  28.138 +				}
  28.139 +				*spot++ = *fmt++;
  28.140 +				*spot++ = '\0';
  28.141 +				switch (spot[-2]) {
  28.142  				    case '%':
  28.143  					*msg++ = '%';
  28.144  					maxlen -= 1;
  28.145  					break;
  28.146 -#if 0	/* What is a character anyway?  (UNICODE issues) */
  28.147  				    case 'c':
  28.148 -                                        *msg++ = (unsigned char)
  28.149 -					         error->args[argi++].value_c;
  28.150 -					maxlen -= 1;
  28.151 -					break;
  28.152 -#endif
  28.153 -				    case 'd':
  28.154 -					len = PrintInt(msg, maxlen,
  28.155 -						error->args[argi++].value_i);
  28.156 +				    case 'i':
  28.157 +			            case 'd':
  28.158 +			            case 'u':
  28.159 +			            case 'o':
  28.160 +				    case 'x':
  28.161 +				    case 'X':
  28.162 +					len = SDL_snprintf(msg, maxlen, tmp, error->args[argi++].value_i);
  28.163  					msg += len;
  28.164  					maxlen -= len;
  28.165  					break;
  28.166  				    case 'f':
  28.167 -					len = PrintDouble(msg, maxlen,
  28.168 -						error->args[argi++].value_f);
  28.169 +					len = SDL_snprintf(msg, maxlen, tmp, error->args[argi++].value_f);
  28.170  					msg += len;
  28.171  					maxlen -= len;
  28.172  					break;
  28.173  				    case 'p':
  28.174 -					len = PrintPointer(msg, maxlen,
  28.175 -						error->args[argi++].value_ptr);
  28.176 +					len = SDL_snprintf(msg, maxlen, tmp, error->args[argi++].value_ptr);
  28.177  					msg += len;
  28.178  					maxlen -= len;
  28.179  					break;
  28.180 -				    case 's': /* UNICODE string */
  28.181 -					{ Uint16 buf[ERR_MAX_STRLEN], *str;
  28.182 -					  SDL_LookupString(error->args[argi++].buf, buf, sizeof(buf));
  28.183 -					  str = buf;
  28.184 -					  while ( *str && (maxlen > 0) ) {
  28.185 -						*msg++ = *str++;
  28.186 -						maxlen -= 1;
  28.187 -					  }
  28.188 -					}
  28.189 +				    case 's':
  28.190 +					len = SDL_snprintf(msg, maxlen, tmp, SDL_LookupString(error->args[argi++].buf));
  28.191 +					msg += len;
  28.192 +					maxlen -= len;
  28.193  					break;
  28.194  				}
  28.195 -				fmt += 2;
  28.196  			} else {
  28.197  				*msg++ = *fmt++;
  28.198  				maxlen -= 1;
  28.199 @@ -242,38 +183,12 @@
  28.200  	return(errstr);
  28.201  }
  28.202  
  28.203 -Uint8 *SDL_GetErrorMsg(Uint8 *errstr, unsigned int maxlen)
  28.204 -{
  28.205 -	Uint16 *errstr16;
  28.206 -	unsigned int i;
  28.207 -
  28.208 -	/* Allocate the UNICODE buffer */
  28.209 -	errstr16 = (Uint16 *)SDL_malloc(maxlen * (sizeof *errstr16));
  28.210 -	if ( ! errstr16 ) {
  28.211 -		SDL_strlcpy((char *)errstr, "Out of memory", maxlen);
  28.212 -		return(errstr);
  28.213 -	}
  28.214 -
  28.215 -	/* Get the error message */
  28.216 -	SDL_GetErrorMsgUNICODE(errstr16, maxlen);
  28.217 -
  28.218 -	/* Convert from UNICODE to Latin1 encoding */
  28.219 -	for ( i=0; i<maxlen; ++i ) {
  28.220 -		errstr[i] = (Uint8)errstr16[i];
  28.221 -	}
  28.222 -
  28.223 -	/* Free UNICODE buffer (if necessary) */
  28.224 -	SDL_free(errstr16);
  28.225 -
  28.226 -	return(errstr);
  28.227 -}
  28.228 -
  28.229  /* Available for backwards compatibility */
  28.230  char *SDL_GetError (void)
  28.231  {
  28.232  	static char errmsg[SDL_ERRBUFIZE];
  28.233  
  28.234 -	return((char *)SDL_GetErrorMsg((unsigned char *)errmsg, SDL_ERRBUFIZE));
  28.235 +	return((char *)SDL_GetErrorMsg(errmsg, SDL_ERRBUFIZE));
  28.236  }
  28.237  
  28.238  void SDL_ClearError(void)
    29.1 --- a/src/SDL_error_c.h	Mon May 01 06:58:33 2006 +0000
    29.2 +++ b/src/SDL_error_c.h	Wed May 17 08:18:28 2006 +0000
    29.3 @@ -40,7 +40,7 @@
    29.4  	   is not in the hashtable, or no hashtable is available, the key is
    29.5  	   used directly as an error message format string.
    29.6  	*/
    29.7 -	unsigned char key[ERR_MAX_STRLEN];
    29.8 +	char key[ERR_MAX_STRLEN];
    29.9  
   29.10  	/* These are the arguments for the error functions */
   29.11  	int argc;
   29.12 @@ -51,7 +51,7 @@
   29.13  #endif
   29.14  		int value_i;
   29.15  		double value_f;
   29.16 -		unsigned char buf[ERR_MAX_STRLEN];
   29.17 +		char buf[ERR_MAX_STRLEN];
   29.18  	} args[ERR_MAX_ARGS];
   29.19  } SDL_error;
   29.20  
    30.1 --- a/src/audio/SDL_audio.c	Mon May 01 06:58:33 2006 +0000
    30.2 +++ b/src/audio/SDL_audio.c	Wed May 17 08:18:28 2006 +0000
    30.3 @@ -120,13 +120,13 @@
    30.4  #endif
    30.5  
    30.6  /* The general mixing thread function */
    30.7 -int SDL_RunAudio(void *audiop)
    30.8 +int SDLCALL SDL_RunAudio(void *audiop)
    30.9  {
   30.10  	SDL_AudioDevice *audio = (SDL_AudioDevice *)audiop;
   30.11  	Uint8 *stream;
   30.12  	int    stream_len;
   30.13  	void  *udata;
   30.14 -	void (*fill)(void *userdata,Uint8 *stream, int len);
   30.15 +	void (SDLCALL *fill)(void *userdata,Uint8 *stream, int len);
   30.16  	int    silence;
   30.17  #if SDL_AUDIO_DRIVER_AHI
   30.18  	int started = 0;
   30.19 @@ -285,6 +285,51 @@
   30.20  	SDL_mutexV(audio->mixer_lock);
   30.21  }
   30.22  
   30.23 +static Uint16 SDL_ParseAudioFormat(const char *string)
   30.24 +{
   30.25 +	Uint16 format = 0;
   30.26 +
   30.27 +	switch (*string) {
   30.28 +	    case 'U':
   30.29 +		++string;
   30.30 +		format |= 0x0000;
   30.31 +		break;
   30.32 +	    case 'S':
   30.33 +		++string;
   30.34 +		format |= 0x8000;
   30.35 +		break;
   30.36 +	    default:
   30.37 +		return 0;
   30.38 +	}
   30.39 +	switch (SDL_atoi(string)) {
   30.40 +	    case 8:
   30.41 +		string += 1;
   30.42 +		format |= 8;
   30.43 +		break;
   30.44 +	    case 16:
   30.45 +		string += 2;
   30.46 +		format |= 16;
   30.47 +		if ( SDL_strcmp(string, "LSB") == 0
   30.48 +#if SDL_BYTEORDER == SDL_LIL_ENDIAN
   30.49 +		     || SDL_strcmp(string, "SYS") == 0
   30.50 +#endif
   30.51 +		    ) {
   30.52 +			format |= 0x0000;
   30.53 +		}
   30.54 +		if ( SDL_strcmp(string, "MSB") == 0
   30.55 +#if SDL_BYTEORDER == SDL_BIG_ENDIAN
   30.56 +		     || SDL_strcmp(string, "SYS") == 0
   30.57 +#endif
   30.58 +		    ) {
   30.59 +			format |= 0x1000;
   30.60 +		}
   30.61 +		break;
   30.62 +	    default:
   30.63 +		return 0;
   30.64 +	}
   30.65 +	return format;
   30.66 +}
   30.67 +
   30.68  int SDL_AudioInit(const char *driver_name)
   30.69  {
   30.70  	SDL_AudioDevice *audio;
   30.71 @@ -386,6 +431,7 @@
   30.72  int SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained)
   30.73  {
   30.74  	SDL_AudioDevice *audio;
   30.75 +	const char *env;
   30.76  
   30.77  	/* Start up the audio driver, if necessary */
   30.78  	if ( ! current_audio ) {
   30.79 @@ -402,9 +448,35 @@
   30.80  	}
   30.81  
   30.82  	/* Verify some parameters */
   30.83 -	if ( desired->callback == NULL ) {
   30.84 -		SDL_SetError("SDL_OpenAudio() passed a NULL callback");
   30.85 -		return(-1);
   30.86 +	if ( desired->freq == 0 ) {
   30.87 +		env = SDL_getenv("SDL_AUDIO_FREQUENCY");
   30.88 +		if ( env ) {
   30.89 +			desired->freq = SDL_atoi(env);
   30.90 +		}
   30.91 +	}
   30.92 +	if ( desired->freq == 0 ) {
   30.93 +		/* Pick some default audio frequency */
   30.94 +		desired->freq = 22050;
   30.95 +	}
   30.96 +	if ( desired->format == 0 ) {
   30.97 +		env = SDL_getenv("SDL_AUDIO_FORMAT");
   30.98 +		if ( env ) {
   30.99 +			desired->format = SDL_ParseAudioFormat(env);
  30.100 +		}
  30.101 +	}
  30.102 +	if ( desired->format == 0 ) {
  30.103 +		/* Pick some default audio format */
  30.104 +		desired->format = AUDIO_S16;
  30.105 +	}
  30.106 +	if ( desired->channels == 0 ) {
  30.107 +		env = SDL_getenv("SDL_AUDIO_CHANNELS");
  30.108 +		if ( env ) {
  30.109 +			desired->channels = SDL_atoi(env);
  30.110 +		}
  30.111 +	}
  30.112 +	if ( desired->channels == 0 ) {
  30.113 +		/* Pick a default number of channels */
  30.114 +		desired->channels = 2;
  30.115  	}
  30.116  	switch ( desired->channels ) {
  30.117  	    case 1:	/* Mono */
  30.118 @@ -416,6 +488,25 @@
  30.119  		SDL_SetError("1 (mono) and 2 (stereo) channels supported");
  30.120  		return(-1);
  30.121  	}
  30.122 +	if ( desired->samples == 0 ) {
  30.123 +		env = SDL_getenv("SDL_AUDIO_SAMPLES");
  30.124 +		if ( env ) {
  30.125 +			desired->samples = SDL_atoi(env);
  30.126 +		}
  30.127 +	}
  30.128 +	if ( desired->samples == 0 ) {
  30.129 +		/* Pick a default of ~46 ms at desired frequency */
  30.130 +		int samples = (desired->freq / 1000) * 46;
  30.131 +		int power2 = 1;
  30.132 +		while ( power2 < samples ) {
  30.133 +			power2 *= 2;
  30.134 +		}
  30.135 +		desired->samples = power2;
  30.136 +	}
  30.137 +	if ( desired->callback == NULL ) {
  30.138 +		SDL_SetError("SDL_OpenAudio() passed a NULL callback");
  30.139 +		return(-1);
  30.140 +	}
  30.141  
  30.142  #if defined(__MACOS__) || (defined(__RISCOS__) && SDL_THREADS_DISABLED)
  30.143  	/* FIXME: Need to implement PPC interrupt asm for SDL_LockAudio() */
    31.1 --- a/src/audio/SDL_audio_c.h	Mon May 01 06:58:33 2006 +0000
    31.2 +++ b/src/audio/SDL_audio_c.h	Wed May 17 08:18:28 2006 +0000
    31.3 @@ -31,4 +31,4 @@
    31.4  extern void SDL_CalculateAudioSpec(SDL_AudioSpec *spec);
    31.5  
    31.6  /* The actual mixing thread function */
    31.7 -extern int SDL_RunAudio(void *audiop);
    31.8 +extern int SDLCALL SDL_RunAudio(void *audiop);
    32.1 --- a/src/audio/SDL_audiocvt.c	Mon May 01 06:58:33 2006 +0000
    32.2 +++ b/src/audio/SDL_audiocvt.c	Wed May 17 08:18:28 2006 +0000
    32.3 @@ -27,7 +27,7 @@
    32.4  
    32.5  
    32.6  /* Effectively mix right and left channels into a single channel */
    32.7 -void SDL_ConvertMono(SDL_AudioCVT *cvt, Uint16 format)
    32.8 +void SDLCALL SDL_ConvertMono(SDL_AudioCVT *cvt, Uint16 format)
    32.9  {
   32.10  	int i;
   32.11  	Sint32 sample;
   32.12 @@ -169,7 +169,7 @@
   32.13  }
   32.14  
   32.15  /* Discard top 4 channels */
   32.16 -void SDL_ConvertStrip(SDL_AudioCVT *cvt, Uint16 format)
   32.17 +void SDLCALL SDL_ConvertStrip(SDL_AudioCVT *cvt, Uint16 format)
   32.18  {
   32.19  	int i;
   32.20  	Sint32 lsample, rsample;
   32.21 @@ -285,7 +285,7 @@
   32.22  
   32.23  
   32.24  /* Discard top 2 channels of 6 */
   32.25 -void SDL_ConvertStrip_2(SDL_AudioCVT *cvt, Uint16 format)
   32.26 +void SDLCALL SDL_ConvertStrip_2(SDL_AudioCVT *cvt, Uint16 format)
   32.27  {
   32.28  	int i;
   32.29  	Sint32 lsample, rsample;
   32.30 @@ -400,7 +400,7 @@
   32.31  }
   32.32  
   32.33  /* Duplicate a mono channel to both stereo channels */
   32.34 -void SDL_ConvertStereo(SDL_AudioCVT *cvt, Uint16 format)
   32.35 +void SDLCALL SDL_ConvertStereo(SDL_AudioCVT *cvt, Uint16 format)
   32.36  {
   32.37  	int i;
   32.38  
   32.39 @@ -438,7 +438,7 @@
   32.40  
   32.41  
   32.42  /* Duplicate a stereo channel to a pseudo-5.1 stream */
   32.43 -void SDL_ConvertSurround(SDL_AudioCVT *cvt, Uint16 format)
   32.44 +void SDLCALL SDL_ConvertSurround(SDL_AudioCVT *cvt, Uint16 format)
   32.45  {
   32.46  	int i;
   32.47  
   32.48 @@ -615,7 +615,7 @@
   32.49  
   32.50  
   32.51  /* Duplicate a stereo channel to a pseudo-4.0 stream */
   32.52 -void SDL_ConvertSurround_4(SDL_AudioCVT *cvt, Uint16 format)
   32.53 +void SDLCALL SDL_ConvertSurround_4(SDL_AudioCVT *cvt, Uint16 format)
   32.54  {
   32.55  	int i;
   32.56  
   32.57 @@ -768,7 +768,7 @@
   32.58  
   32.59  
   32.60  /* Convert 8-bit to 16-bit - LSB */
   32.61 -void SDL_Convert16LSB(SDL_AudioCVT *cvt, Uint16 format)
   32.62 +void SDLCALL SDL_Convert16LSB(SDL_AudioCVT *cvt, Uint16 format)
   32.63  {
   32.64  	int i;
   32.65  	Uint8 *src, *dst;
   32.66 @@ -791,7 +791,7 @@
   32.67  	}
   32.68  }
   32.69  /* Convert 8-bit to 16-bit - MSB */
   32.70 -void SDL_Convert16MSB(SDL_AudioCVT *cvt, Uint16 format)
   32.71 +void SDLCALL SDL_Convert16MSB(SDL_AudioCVT *cvt, Uint16 format)
   32.72  {
   32.73  	int i;
   32.74  	Uint8 *src, *dst;
   32.75 @@ -815,7 +815,7 @@
   32.76  }
   32.77  
   32.78  /* Convert 16-bit to 8-bit */
   32.79 -void SDL_Convert8(SDL_AudioCVT *cvt, Uint16 format)
   32.80 +void SDLCALL SDL_Convert8(SDL_AudioCVT *cvt, Uint16 format)
   32.81  {
   32.82  	int i;
   32.83  	Uint8 *src, *dst;
   32.84 @@ -841,7 +841,7 @@
   32.85  }
   32.86  
   32.87  /* Toggle signed/unsigned */
   32.88 -void SDL_ConvertSign(SDL_AudioCVT *cvt, Uint16 format)
   32.89 +void SDLCALL SDL_ConvertSign(SDL_AudioCVT *cvt, Uint16 format)
   32.90  {
   32.91  	int i;
   32.92  	Uint8 *data;
   32.93 @@ -870,7 +870,7 @@
   32.94  }
   32.95  
   32.96  /* Toggle endianness */
   32.97 -void SDL_ConvertEndian(SDL_AudioCVT *cvt, Uint16 format)
   32.98 +void SDLCALL SDL_ConvertEndian(SDL_AudioCVT *cvt, Uint16 format)
   32.99  {
  32.100  	int i;
  32.101  	Uint8 *data, tmp;
  32.102 @@ -892,7 +892,7 @@
  32.103  }
  32.104  
  32.105  /* Convert rate up by multiple of 2 */
  32.106 -void SDL_RateMUL2(SDL_AudioCVT *cvt, Uint16 format)
  32.107 +void SDLCALL SDL_RateMUL2(SDL_AudioCVT *cvt, Uint16 format)
  32.108  {
  32.109  	int i;
  32.110  	Uint8 *src, *dst;
  32.111 @@ -930,7 +930,7 @@
  32.112  
  32.113  
  32.114  /* Convert rate up by multiple of 2, for stereo */
  32.115 -void SDL_RateMUL2_c2(SDL_AudioCVT *cvt, Uint16 format)
  32.116 +void SDLCALL SDL_RateMUL2_c2(SDL_AudioCVT *cvt, Uint16 format)
  32.117  {
  32.118  	int i;
  32.119  	Uint8 *src, *dst;
  32.120 @@ -973,7 +973,7 @@
  32.121  }
  32.122  
  32.123  /* Convert rate up by multiple of 2, for quad */
  32.124 -void SDL_RateMUL2_c4(SDL_AudioCVT *cvt, Uint16 format)
  32.125 +void SDLCALL SDL_RateMUL2_c4(SDL_AudioCVT *cvt, Uint16 format)
  32.126  {
  32.127  	int i;
  32.128  	Uint8 *src, *dst;
  32.129 @@ -1029,7 +1029,7 @@
  32.130  
  32.131  
  32.132  /* Convert rate up by multiple of 2, for 5.1 */
  32.133 -void SDL_RateMUL2_c6(SDL_AudioCVT *cvt, Uint16 format)
  32.134 +void SDLCALL SDL_RateMUL2_c6(SDL_AudioCVT *cvt, Uint16 format)
  32.135  {
  32.136  	int i;
  32.137  	Uint8 *src, *dst;
  32.138 @@ -1096,7 +1096,7 @@
  32.139  }
  32.140  
  32.141  /* Convert rate down by multiple of 2 */
  32.142 -void SDL_RateDIV2(SDL_AudioCVT *cvt, Uint16 format)
  32.143 +void SDLCALL SDL_RateDIV2(SDL_AudioCVT *cvt, Uint16 format)
  32.144  {
  32.145  	int i;
  32.146  	Uint8 *src, *dst;
  32.147 @@ -1131,7 +1131,7 @@
  32.148  
  32.149  
  32.150  /* Convert rate down by multiple of 2, for stereo */
  32.151 -void SDL_RateDIV2_c2(SDL_AudioCVT *cvt, Uint16 format)
  32.152 +void SDLCALL SDL_RateDIV2_c2(SDL_AudioCVT *cvt, Uint16 format)
  32.153  {
  32.154  	int i;
  32.155  	Uint8 *src, *dst;
  32.156 @@ -1169,7 +1169,7 @@
  32.157  
  32.158  
  32.159  /* Convert rate down by multiple of 2, for quad */
  32.160 -void SDL_RateDIV2_c4(SDL_AudioCVT *cvt, Uint16 format)
  32.161 +void SDLCALL SDL_RateDIV2_c4(SDL_AudioCVT *cvt, Uint16 format)
  32.162  {
  32.163  	int i;
  32.164  	Uint8 *src, *dst;
  32.165 @@ -1212,7 +1212,7 @@
  32.166  }
  32.167  
  32.168  /* Convert rate down by multiple of 2, for 5.1 */
  32.169 -void SDL_RateDIV2_c6(SDL_AudioCVT *cvt, Uint16 format)
  32.170 +void SDLCALL SDL_RateDIV2_c6(SDL_AudioCVT *cvt, Uint16 format)
  32.171  {
  32.172  	int i;
  32.173  	Uint8 *src, *dst;
  32.174 @@ -1261,7 +1261,7 @@
  32.175  }
  32.176  
  32.177  /* Very slow rate conversion routine */
  32.178 -void SDL_RateSLOW(SDL_AudioCVT *cvt, Uint16 format)
  32.179 +void SDLCALL SDL_RateSLOW(SDL_AudioCVT *cvt, Uint16 format)
  32.180  {
  32.181  	double ipos;
  32.182  	int i, clen;
  32.183 @@ -1474,7 +1474,7 @@
  32.184  		Uint32 hi_rate, lo_rate;
  32.185  		int len_mult;
  32.186  		double len_ratio;
  32.187 -		void (*rate_cvt)(SDL_AudioCVT *cvt, Uint16 format);
  32.188 +		void (SDLCALL *rate_cvt)(SDL_AudioCVT *cvt, Uint16 format);
  32.189  
  32.190  		if ( src_rate > dst_rate ) {
  32.191  			hi_rate = src_rate;
    33.1 --- a/src/audio/SDL_wave.c	Mon May 01 06:58:33 2006 +0000
    33.2 +++ b/src/audio/SDL_wave.c	Wed May 17 08:18:28 2006 +0000
    33.3 @@ -478,6 +478,11 @@
    33.4  			}
    33.5  			IMA_ADPCM_encoded = 1;
    33.6  			break;
    33.7 +		case MP3_CODE:
    33.8 +			SDL_SetError("MPEG Layer 3 data not supported",
    33.9 +					SDL_SwapLE16(format->encoding));
   33.10 +			was_error = 1;
   33.11 +			goto done;
   33.12  		default:
   33.13  			SDL_SetError("Unknown WAVE data format: 0x%.4x",
   33.14  					SDL_SwapLE16(format->encoding));
    34.1 --- a/src/audio/SDL_wave.h	Mon May 01 06:58:33 2006 +0000
    34.2 +++ b/src/audio/SDL_wave.h	Wed May 17 08:18:28 2006 +0000
    34.3 @@ -35,6 +35,7 @@
    34.4  #define PCM_CODE	0x0001
    34.5  #define MS_ADPCM_CODE	0x0002
    34.6  #define IMA_ADPCM_CODE	0x0011
    34.7 +#define MP3_CODE	0x0055
    34.8  #define WAVE_MONO	1
    34.9  #define WAVE_STEREO	2
   34.10  
    35.1 --- a/src/audio/mint/SDL_mintaudio.c	Mon May 01 06:58:33 2006 +0000
    35.2 +++ b/src/audio/mint/SDL_mintaudio.c	Wed May 17 08:18:28 2006 +0000
    35.3 @@ -42,9 +42,9 @@
    35.4  SDL_AudioDevice *SDL_MintAudio_device;
    35.5  Uint8 *SDL_MintAudio_audiobuf[2];	/* Pointers to buffers */
    35.6  unsigned long SDL_MintAudio_audiosize;		/* Length of audio buffer=spec->size */
    35.7 -unsigned short SDL_MintAudio_numbuf;		/* Buffer to play */
    35.8 -unsigned short SDL_MintAudio_mutex;
    35.9 -unsigned long SDL_MintAudio_clocktics;
   35.10 +volatile unsigned short SDL_MintAudio_numbuf;		/* Buffer to play */
   35.11 +volatile unsigned short SDL_MintAudio_mutex;
   35.12 +volatile unsigned long SDL_MintAudio_clocktics;
   35.13  cookie_stfa_t	*SDL_MintAudio_stfa;
   35.14  
   35.15  /* MiNT thread variables */
    36.1 --- a/src/audio/mint/SDL_mintaudio.h	Mon May 01 06:58:33 2006 +0000
    36.2 +++ b/src/audio/mint/SDL_mintaudio.h	Wed May 17 08:18:28 2006 +0000
    36.3 @@ -119,10 +119,10 @@
    36.4  extern SDL_AudioDevice *SDL_MintAudio_device;
    36.5  extern Uint8 *SDL_MintAudio_audiobuf[2];	/* Pointers to buffers */
    36.6  extern unsigned long SDL_MintAudio_audiosize;		/* Length of audio buffer=spec->size */
    36.7 -extern unsigned short SDL_MintAudio_numbuf;		/* Buffer to play */
    36.8 -extern unsigned short SDL_MintAudio_mutex;
    36.9 +extern volatile unsigned short SDL_MintAudio_numbuf;		/* Buffer to play */
   36.10 +extern volatile unsigned short SDL_MintAudio_mutex;
   36.11  extern cookie_stfa_t *SDL_MintAudio_stfa;
   36.12 -extern unsigned long SDL_MintAudio_clocktics;
   36.13 +extern volatile unsigned long SDL_MintAudio_clocktics;
   36.14  
   36.15  /* MiNT thread variables */
   36.16  extern SDL_bool	SDL_MintAudio_mint_present;
    37.1 --- a/src/cdrom/macosx/AudioFilePlayer.c	Mon May 01 06:58:33 2006 +0000
    37.2 +++ b/src/cdrom/macosx/AudioFilePlayer.c	Wed May 17 08:18:28 2006 +0000
    37.3 @@ -153,7 +153,7 @@
    37.4          }
    37.5      
    37.6          if (afp->mForkRefNum) {
    37.7 -            FSClose (afp->mForkRefNum);
    37.8 +            FSCloseFork (afp->mForkRefNum);
    37.9              afp->mForkRefNum = 0;
   37.10          }
   37.11          SDL_free(afp);
    38.1 --- a/src/cdrom/macosx/SDL_syscdrom.c	Mon May 01 06:58:33 2006 +0000
    38.2 +++ b/src/cdrom/macosx/SDL_syscdrom.c	Wed May 17 08:18:28 2006 +0000
    38.3 @@ -453,8 +453,8 @@
    38.4  static int SDL_SYS_CDEject(SDL_CD *cdrom)
    38.5  {
    38.6      OSStatus err;
    38.7 -	HParamBlockRec  pb;
    38.8 -    
    38.9 +    pid_t dissenter;
   38.10 +
   38.11      if (fakeCD) {
   38.12          SDL_SetError (kErrorFakeDevice);
   38.13          return -1;
   38.14 @@ -475,9 +475,7 @@
   38.15      status = CD_STOPPED;
   38.16      
   38.17  	/* Eject the volume */
   38.18 -	pb.ioParam.ioNamePtr = NULL;
   38.19 -	pb.ioParam.ioVRefNum = volumes[cdrom->id];
   38.20 -	err = PBUnmountVol((ParamBlockRec *) &pb);
   38.21 +	err = FSEjectVolumeSync(volumes[cdrom->id], kNilOptions, &dissenter);
   38.22  
   38.23  	if (err != noErr) {
   38.24          Unlock ();
    39.1 --- a/src/events/SDL_events.c	Mon May 01 06:58:33 2006 +0000
    39.2 +++ b/src/events/SDL_events.c	Wed May 17 08:18:28 2006 +0000
    39.3 @@ -87,7 +87,7 @@
    39.4  #include <time.h>
    39.5  #endif
    39.6  
    39.7 -static int SDL_GobbleEvents(void *unused)
    39.8 +static int SDLCALL SDL_GobbleEvents(void *unused)
    39.9  {
   39.10  	event_thread = SDL_ThreadID();
   39.11  
    40.1 --- a/src/events/SDL_keyboard.c	Mon May 01 06:58:33 2006 +0000
    40.2 +++ b/src/events/SDL_keyboard.c	Wed May 17 08:18:28 2006 +0000
    40.3 @@ -59,7 +59,7 @@
    40.4  
    40.5  	/* Initialize the tables */
    40.6  	SDL_ModState = KMOD_NONE;
    40.7 -	SDL_memset(keynames, 0, sizeof(keynames));
    40.8 +	SDL_memset((void*)keynames, 0, sizeof(keynames));
    40.9  	SDL_memset(SDL_KeyState, 0, sizeof(SDL_KeyState));
   40.10  	video->InitOSKeymap(this);
   40.11  
    41.1 --- a/src/file/SDL_rwops.c	Mon May 01 06:58:33 2006 +0000
    41.2 +++ b/src/file/SDL_rwops.c	Wed May 17 08:18:28 2006 +0000
    41.3 @@ -43,7 +43,7 @@
    41.4  #define INVALID_SET_FILE_POINTER 0xFFFFFFFF
    41.5  #endif
    41.6  
    41.7 -static int win32_file_open(SDL_RWops *context, const char *filename, const char *mode)
    41.8 +static int SDLCALL win32_file_open(SDL_RWops *context, const char *filename, const char *mode)
    41.9  {
   41.10  #ifndef _WIN32_WCE
   41.11  	UINT	old_error_mode;
   41.12 @@ -108,7 +108,7 @@
   41.13  	
   41.14  	return 0; /* ok */
   41.15  }
   41.16 -static int win32_file_seek(SDL_RWops *context, int offset, int whence)
   41.17 +static int SDLCALL win32_file_seek(SDL_RWops *context, int offset, int whence)
   41.18  {
   41.19  	DWORD win32whence;
   41.20  	int   file_pos;
   41.21 @@ -138,7 +138,7 @@
   41.22  	SDL_Error(SDL_EFSEEK);
   41.23  	return -1; /* error */
   41.24  }
   41.25 -static int win32_file_read(SDL_RWops *context, void *ptr, int size, int maxnum)
   41.26 +static int SDLCALL win32_file_read(SDL_RWops *context, void *ptr, int size, int maxnum)
   41.27  {
   41.28  	
   41.29  	int		total_bytes; 
   41.30 @@ -156,7 +156,7 @@
   41.31  	nread = byte_read/size;
   41.32  	return nread;
   41.33  }
   41.34 -static int win32_file_write(SDL_RWops *context, const void *ptr, int size, int num)
   41.35 +static int SDLCALL win32_file_write(SDL_RWops *context, const void *ptr, int size, int num)
   41.36  {
   41.37  	
   41.38  	int		total_bytes; 
   41.39 @@ -183,7 +183,7 @@
   41.40  	nwritten = byte_written/size;
   41.41  	return nwritten;
   41.42  }
   41.43 -static int win32_file_close(SDL_RWops *context)
   41.44 +static int SDLCALL win32_file_close(SDL_RWops *context)
   41.45  {
   41.46  	
   41.47  	if ( context ) {								
   41.48 @@ -201,7 +201,7 @@
   41.49  
   41.50  /* Functions to read/write stdio file pointers */
   41.51  
   41.52 -static int stdio_seek(SDL_RWops *context, int offset, int whence)
   41.53 +static int SDLCALL stdio_seek(SDL_RWops *context, int offset, int whence)
   41.54  {
   41.55  	if ( fseek(context->hidden.stdio.fp, offset, whence) == 0 ) {
   41.56  		return(ftell(context->hidden.stdio.fp));
   41.57 @@ -210,7 +210,7 @@
   41.58  		return(-1);
   41.59  	}
   41.60  }
   41.61 -static int stdio_read(SDL_RWops *context, void *ptr, int size, int maxnum)
   41.62 +static int SDLCALL stdio_read(SDL_RWops *context, void *ptr, int size, int maxnum)
   41.63  {
   41.64  	size_t nread;
   41.65  
   41.66 @@ -220,7 +220,7 @@
   41.67  	}
   41.68  	return(nread);
   41.69  }
   41.70 -static int stdio_write(SDL_RWops *context, const void *ptr, int size, int num)
   41.71 +static int SDLCALL stdio_write(SDL_RWops *context, const void *ptr, int size, int num)
   41.72  {
   41.73  	size_t nwrote;
   41.74  
   41.75 @@ -230,7 +230,7 @@
   41.76  	}
   41.77  	return(nwrote);
   41.78  }
   41.79 -static int stdio_close(SDL_RWops *context)
   41.80 +static int SDLCALL stdio_close(SDL_RWops *context)
   41.81  {
   41.82  	if ( context ) {
   41.83  		if ( context->hidden.stdio.autoclose ) {
   41.84 @@ -245,7 +245,7 @@
   41.85  
   41.86  /* Functions to read/write memory pointers */
   41.87  
   41.88 -static int mem_seek(SDL_RWops *context, int offset, int whence)
   41.89 +static int SDLCALL mem_seek(SDL_RWops *context, int offset, int whence)
   41.90  {
   41.91  	Uint8 *newpos;
   41.92  
   41.93 @@ -272,7 +272,7 @@
   41.94  	context->hidden.mem.here = newpos;
   41.95  	return(context->hidden.mem.here-context->hidden.mem.base);
   41.96  }
   41.97 -static int mem_read(SDL_RWops *context, void *ptr, int size, int maxnum)
   41.98 +static int SDLCALL mem_read(SDL_RWops *context, void *ptr, int size, int maxnum)
   41.99  {
  41.100  	size_t total_bytes;
  41.101  	size_t mem_available;
  41.102 @@ -292,7 +292,7 @@
  41.103  
  41.104  	return (total_bytes / size);
  41.105  }
  41.106 -static int mem_write(SDL_RWops *context, const void *ptr, int size, int num)
  41.107 +static int SDLCALL mem_write(SDL_RWops *context, const void *ptr, int size, int num)
  41.108  {
  41.109  	if ( (context->hidden.mem.here + (num*size)) > context->hidden.mem.stop ) {
  41.110  		num = (context->hidden.mem.stop-context->hidden.mem.here)/size;
  41.111 @@ -301,12 +301,12 @@
  41.112  	context->hidden.mem.here += num*size;
  41.113  	return(num);
  41.114  }
  41.115 -static int mem_writeconst(SDL_RWops *context, const void *ptr, int size, int num)
  41.116 +static int SDLCALL mem_writeconst(SDL_RWops *context, const void *ptr, int size, int num)
  41.117  {
  41.118  	SDL_SetError("Can't write to read-only memory");
  41.119  	return(-1);
  41.120  }
  41.121 -static int mem_close(SDL_RWops *context)
  41.122 +static int SDLCALL mem_close(SDL_RWops *context)
  41.123  {
  41.124  	if ( context ) {
  41.125  		SDL_FreeRW(context);
    42.1 --- a/src/joystick/linux/SDL_sysjoystick.c	Mon May 01 06:58:33 2006 +0000
    42.2 +++ b/src/joystick/linux/SDL_sysjoystick.c	Wed May 17 08:18:28 2006 +0000
    42.3 @@ -30,9 +30,6 @@
    42.4  #include <fcntl.h>
    42.5  #include <sys/ioctl.h>
    42.6  #include <limits.h>		/* For the definition of PATH_MAX */
    42.7 -#ifdef __arm__
    42.8 -#include <linux/limits.h> /* Arm cross-compiler needs this */
    42.9 -#endif
   42.10  #include <linux/joystick.h>
   42.11  #if SDL_INPUT_LINUXEV
   42.12  #include <linux/input.h>
   42.13 @@ -980,7 +977,8 @@
   42.14  #ifndef NO_LOGICAL_JOYSTICKS
   42.15  	if (SDL_joylist[joystick->index].fname == NULL) {
   42.16  		SDL_joylist_head(i, joystick->index);
   42.17 -		return JS_HandleEvents(SDL_joylist[i].joy);
   42.18 +		JS_HandleEvents(SDL_joylist[i].joy);
   42.19 +		return;
   42.20  	}
   42.21  #endif
   42.22  
    43.1 --- a/src/joystick/win32/SDL_mmjoystick.c	Mon May 01 06:58:33 2006 +0000
    43.2 +++ b/src/joystick/win32/SDL_mmjoystick.c	Wed May 17 08:18:28 2006 +0000
    43.3 @@ -154,34 +154,26 @@
    43.4  	JOYCAPS	joycaps;
    43.5  	MMRESULT result;
    43.6  
    43.7 -	numdevs = 0;
    43.8 -	maxdevs = joyGetNumDevs();
    43.9 -
   43.10 -	if ( maxdevs > MAX_JOYSTICKS ) {
   43.11 -		maxdevs = MAX_JOYSTICKS;
   43.12 -	}
   43.13 -
   43.14 -
   43.15 -	for ( i = 0; i < MAX_JOYSTICKS; i++ ) {
   43.16 -		SYS_JoystickID[i] = JOYSTICKID1 + i;
   43.17 +	/* Reset the joystick ID & name mapping tables */
   43.18 +	for ( i = 0; i < MAX_JOYSTICKS; ++i ) {
   43.19 +		SYS_JoystickID[i] = 0;
   43.20  		SYS_JoystickName[i] = NULL;
   43.21  	}
   43.22  
   43.23 -
   43.24 -	for ( i = 0; (i < maxdevs); ++i ) {
   43.25 +	/* Loop over all potential joystick devices */
   43.26 +	numdevs = 0;
   43.27 +	maxdevs = joyGetNumDevs();
   43.28 +	for ( i = JOYSTICKID1; i < maxdevs && numdevs < MAX_JOYSTICKS; ++i ) {
   43.29  		
   43.30 -		/* added 8/31/2001 By Vitaliy Mikitchenko */
   43.31  		joyinfo.dwSize = sizeof(joyinfo);
   43.32  		joyinfo.dwFlags = JOY_RETURNALL;
   43.33 -		/* end addition */
   43.34 -
   43.35  		result = joyGetPosEx(SYS_JoystickID[i], &joyinfo);
   43.36  		if ( result == JOYERR_NOERROR ) {
   43.37 -			result = joyGetDevCaps(SYS_JoystickID[i], &joycaps, sizeof(joycaps));
   43.38 +			result = joyGetDevCaps(i, &joycaps, sizeof(joycaps));
   43.39  			if ( result == JOYERR_NOERROR ) {
   43.40 -				SYS_JoystickID[numdevs] = SYS_JoystickID[i];
   43.41 +				SYS_JoystickID[numdevs] = i;
   43.42  				SYS_Joystick[numdevs] = joycaps;
   43.43 -				SYS_JoystickName[numdevs] = GetJoystickName(numdevs, joycaps.szRegKey);
   43.44 +				SYS_JoystickName[numdevs] = GetJoystickName(i, joycaps.szRegKey);
   43.45  				numdevs++;
   43.46  			}
   43.47  		}
    44.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    44.2 +++ b/src/loadso/macosx/SDL_dlcompat.c	Wed May 17 08:18:28 2006 +0000
    44.3 @@ -0,0 +1,1407 @@
    44.4 +/*
    44.5 +    SDL - Simple DirectMedia Layer
    44.6 +    Copyright (C) 1997-2006 Sam Lantinga
    44.7 +
    44.8 +    This library is free software; you can redistribute it and/or
    44.9 +    modify it under the terms of the GNU Lesser General Public
   44.10 +    License as published by the Free Software Foundation; either
   44.11 +    version 2.1 of the License, or (at your option) any later version.
   44.12 +
   44.13 +    This library is distributed in the hope that it will be useful,
   44.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   44.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   44.16 +    Lesser General Public License for more details.
   44.17 +
   44.18 +    You should have received a copy of the GNU Lesser General Public
   44.19 +    License along with this library; if not, write to the Free Software
   44.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   44.21 +
   44.22 +    Sam Lantinga
   44.23 +    slouken@libsdl.org
   44.24 +*/
   44.25 +#include "SDL_config.h"
   44.26 +
   44.27 +#ifdef SDL_LOADSO_DLCOMPAT
   44.28 +
   44.29 +/* Please note that dlcompat apparently ships in current Mac OS X versions
   44.30 + *  as a system library that provides compatibility with the Unix "dlopen"
   44.31 + *  interface. In order to allow SDL to work on older OS X releases and also
   44.32 + *  not conflict with the system lib on newer versions, we include dlcompat
   44.33 + *  in SDL and change the symbols to prevent symbol clash with any existing
   44.34 + *  system libraries.  --ryan.
   44.35 + */
   44.36 +
   44.37 +/* here is the dlcompat license: */
   44.38 +
   44.39 +/*
   44.40 +Copyright (c) 2002 Jorge Acereda  <jacereda@users.sourceforge.net> &
   44.41 +                   Peter O'Gorman <ogorman@users.sourceforge.net>
   44.42 +                   
   44.43 +Portions may be copyright others, see the AUTHORS file included with this
   44.44 +distribution.
   44.45 +
   44.46 +Maintained by Peter O'Gorman <ogorman@users.sourceforge.net>
   44.47 +
   44.48 +Bug Reports and other queries should go to <ogorman@users.sourceforge.net>
   44.49 +
   44.50 +Permission is hereby granted, free of charge, to any person obtaining
   44.51 +a copy of this software and associated documentation files (the
   44.52 +"Software"), to deal in the Software without restriction, including
   44.53 +without limitation the rights to use, copy, modify, merge, publish,
   44.54 +distribute, sublicense, and/or sell copies of the Software, and to
   44.55 +permit persons to whom the Software is furnished to do so, subject to
   44.56 +the following conditions:
   44.57 +
   44.58 +The above copyright notice and this permission notice shall be
   44.59 +included in all copies or substantial portions of the Software.
   44.60 +
   44.61 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
   44.62 +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   44.63 +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
   44.64 +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
   44.65 +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
   44.66 +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
   44.67 +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   44.68 +*/
   44.69 +
   44.70 +#include <pthread.h>
   44.71 +#include <sys/types.h>
   44.72 +#include <sys/stat.h>
   44.73 +#include <stdarg.h>
   44.74 +#include <limits.h>
   44.75 +#include <mach-o/dyld.h>
   44.76 +#include <mach-o/nlist.h>
   44.77 +#include <mach-o/getsect.h>
   44.78 +
   44.79 +#include "SDL_stdinc.h"
   44.80 +
   44.81 +/* Just playing to see if it would compile with the freebsd headers, it does,
   44.82 + * but because of the different values for RTLD_LOCAL etc, it would break binary
   44.83 + * compat... oh well
   44.84 + */
   44.85 +#ifndef __BSD_VISIBLE
   44.86 +#define __BSD_VISIBLE 1
   44.87 +#endif
   44.88 +
   44.89 +/*include "dlfcn.h"*/
   44.90 +#ifdef __cplusplus
   44.91 +extern "C" {
   44.92 +#endif
   44.93 +
   44.94 +#if defined (__GNUC__) && __GNUC__ > 3
   44.95 +#define dl_restrict __restrict
   44.96 +#else
   44.97 +#define dl_restrict
   44.98 +#endif
   44.99 +
  44.100 +#if 0
  44.101 +#ifndef _POSIX_SOURCE
  44.102 +/*
  44.103 + * Structure filled in by dladdr().
  44.104 + */
  44.105 +typedef struct SDL_OSX_dl_info {
  44.106 +        const char      *dli_fname;     /* Pathname of shared object */
  44.107 +        void            *dli_fbase;     /* Base address of shared object */
  44.108 +        const char      *dli_sname;     /* Name of nearest symbol */
  44.109 +        void            *dli_saddr;     /* Address of nearest symbol */
  44.110 +} SDL_OSX_Dl_info;
  44.111 +
  44.112 +static int SDL_OSX_dladdr(const void * dl_restrict, SDL_OSX_Dl_info * dl_restrict);
  44.113 +#endif /* ! _POSIX_SOURCE */
  44.114 +#endif /* 0 */
  44.115 +
  44.116 +static int SDL_OSX_dlclose(void * handle);
  44.117 +static const char * SDL_OSX_dlerror(void);
  44.118 +static void * SDL_OSX_dlopen(const char *path, int mode);
  44.119 +static void * SDL_OSX_dlsym(void * dl_restrict handle, const char * dl_restrict symbol);
  44.120 +
  44.121 +#define RTLD_LAZY	0x1
  44.122 +#define RTLD_NOW	0x2
  44.123 +#define RTLD_LOCAL	0x4
  44.124 +#define RTLD_GLOBAL	0x8
  44.125 +
  44.126 +#ifndef _POSIX_SOURCE
  44.127 +#define RTLD_NOLOAD	0x10
  44.128 +#define RTLD_NODELETE	0x80
  44.129 +
  44.130 +/*
  44.131 + * Special handle arguments for SDL_OSX_dlsym().
  44.132 + */
  44.133 +#define	RTLD_NEXT		((void *) -1)	/* Search subsequent objects. */
  44.134 +#define	RTLD_DEFAULT	((void *) -2)	/* Use default search algorithm. */
  44.135 +#endif /* ! _POSIX_SOURCE */
  44.136 +
  44.137 +#ifdef __cplusplus
  44.138 +}
  44.139 +#endif
  44.140 +
  44.141 +#ifndef dl_restrict
  44.142 +#define dl_restrict __restrict
  44.143 +#endif
  44.144 +/* This is not available on 10.1 */
  44.145 +#ifndef LC_LOAD_WEAK_DYLIB
  44.146 +#define	LC_LOAD_WEAK_DYLIB (0x18 | LC_REQ_DYLD)
  44.147 +#endif
  44.148 +
  44.149 +/* With this stuff here, this thing may actually compile/run on 10.0 systems
  44.150 + * Not that I have a 10.0 system to test it on anylonger
  44.151 + */
  44.152 +#ifndef LC_REQ_DYLD
  44.153 +#define LC_REQ_DYLD 0x80000000
  44.154 +#endif
  44.155 +#ifndef NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED
  44.156 +#define NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED 0x4
  44.157 +#endif
  44.158 +#ifndef NSADDIMAGE_OPTION_RETURN_ON_ERROR
  44.159 +#define NSADDIMAGE_OPTION_RETURN_ON_ERROR 0x1
  44.160 +#endif
  44.161 +#ifndef NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
  44.162 +#define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND 0x0
  44.163 +#endif
  44.164 +#ifndef NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR
  44.165 +#define NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR 0x4
  44.166 +#endif
  44.167 +/* These symbols will be looked for in dyld */
  44.168 +static const struct mach_header *(*dyld_NSAddImage) (const char *, unsigned long) = 0;
  44.169 +static int (*dyld_NSIsSymbolNameDefinedInImage) (const struct mach_header *, const char *) = 0;
  44.170 +static NSSymbol(*dyld_NSLookupSymbolInImage)
  44.171 +	(const struct mach_header *, const char *, unsigned long) = 0;
  44.172 +
  44.173 +/* Define this to make dlcompat reuse data block. This way in theory we save
  44.174 + * a little bit of overhead. However we then couldn't correctly catch excess
  44.175 + * calls to SDL_OSX_dlclose(). Hence we don't use this feature
  44.176 + */
  44.177 +#undef REUSE_STATUS
  44.178 +
  44.179 +/* Size of the internal error message buffer (used by dlerror()) */
  44.180 +#define ERR_STR_LEN			251
  44.181 +
  44.182 +/* Maximum number of search paths supported by getSearchPath */
  44.183 +#define MAX_SEARCH_PATHS	32
  44.184 +
  44.185 +
  44.186 +#define MAGIC_DYLIB_OFI ((NSObjectFileImage) 'DYOF')
  44.187 +#define MAGIC_DYLIB_MOD ((NSModule) 'DYMO')
  44.188 +
  44.189 +/* internal flags */
  44.190 +#define DL_IN_LIST 0x01
  44.191 +
  44.192 +/* our mutex */
  44.193 +static pthread_mutex_t dlcompat_mutex;
  44.194 +/* Our thread specific storage
  44.195 + */
  44.196 +static pthread_key_t dlerror_key;
  44.197 +
  44.198 +struct dlthread
  44.199 +{
  44.200 +	int lockcnt;
  44.201 +	unsigned char errset;
  44.202 +	char errstr[ERR_STR_LEN];
  44.203 +};
  44.204 +
  44.205 +/* This is our central data structure. Whenever a module is loaded via
  44.206 + * SDL_OSX_dlopen(), we create such a struct.
  44.207 + */
  44.208 +struct dlstatus
  44.209 +{
  44.210 +	struct dlstatus *next;		/* pointer to next element in the linked list */
  44.211 +	NSModule module;
  44.212 +	const struct mach_header *lib;
  44.213 +	int refs;					/* reference count */
  44.214 +	int mode;					/* mode in which this module was loaded */
  44.215 +	dev_t device;
  44.216 +	ino_t inode;
  44.217 +	int flags;					/* Any internal flags we may need */
  44.218 +};
  44.219 +
  44.220 +/* Head node of the dlstatus list */
  44.221 +static struct dlstatus mainStatus = { 0, MAGIC_DYLIB_MOD, NULL, -1, RTLD_GLOBAL, 0, 0, 0 };
  44.222 +static struct dlstatus *stqueue = &mainStatus;
  44.223 +
  44.224 +
  44.225 +/* Storage for the last error message (used by dlerror()) */
  44.226 +/* static char err_str[ERR_STR_LEN]; */
  44.227 +/* static int err_filled = 0; */
  44.228 +
  44.229 +/* Prototypes to internal functions */
  44.230 +static void debug(const char *fmt, ...);
  44.231 +static void error(const char *str, ...);
  44.232 +static const char *safegetenv(const char *s);
  44.233 +static const char *searchList(void);
  44.234 +static const char *getSearchPath(int i);
  44.235 +static const char *getFullPath(int i, const char *file);
  44.236 +static const struct stat *findFile(const char *file, const char **fullPath);
  44.237 +static int isValidStatus(struct dlstatus *status);
  44.238 +static inline int isFlagSet(int mode, int flag);
  44.239 +static struct dlstatus *lookupStatus(const struct stat *sbuf);
  44.240 +static void insertStatus(struct dlstatus *dls, const struct stat *sbuf);
  44.241 +static int promoteLocalToGlobal(struct dlstatus *dls);
  44.242 +static void *reference(struct dlstatus *dls, int mode);
  44.243 +static void *dlsymIntern(struct dlstatus *dls, const char *symbol, int canSetError);
  44.244 +static struct dlstatus *allocStatus(void);
  44.245 +static struct dlstatus *loadModule(const char *path, const struct stat *sbuf, int mode);
  44.246 +static NSSymbol search_linked_libs(const struct mach_header *mh, const char *symbol);
  44.247 +static const char *get_lib_name(const struct mach_header *mh);
  44.248 +static const struct mach_header *get_mach_header_from_NSModule(NSModule mod);
  44.249 +static void dlcompat_init_func(void);
  44.250 +static inline void dlcompat_init_check(void);
  44.251 +static inline void dolock(void);
  44.252 +static inline void dounlock(void);
  44.253 +static void dlerrorfree(void *data);
  44.254 +static void resetdlerror(void);
  44.255 +static const struct mach_header *my_find_image(const char *name);
  44.256 +static const struct mach_header *image_for_address(const void *address);
  44.257 +static inline char *dyld_error_str(void);
  44.258 +
  44.259 +#if FINK_BUILD
  44.260 +/* Two Global Functions */
  44.261 +static void *dlsym_prepend_underscore(void *handle, const char *symbol);
  44.262 +static void *dlsym_auto_underscore(void *handle, const char *symbol);
  44.263 +
  44.264 +/* And their _intern counterparts */
  44.265 +static void *dlsym_prepend_underscore_intern(void *handle, const char *symbol);
  44.266 +static void *dlsym_auto_underscore_intern(void *handle, const char *symbol);
  44.267 +#endif
  44.268 +
  44.269 +/* Functions */
  44.270 +
  44.271 +static void debug(const char *fmt, ...)
  44.272 +{
  44.273 +#if DEBUG > 1
  44.274 +	va_list arg;
  44.275 +	va_start(arg, fmt);
  44.276 +	fprintf(stderr, "DLDEBUG: ");
  44.277 +	vfprintf(stderr, fmt, arg);
  44.278 +	fprintf(stderr, "\n");
  44.279 +	fflush(stderr);
  44.280 +	va_end(arg);
  44.281 +#endif
  44.282 +}
  44.283 +
  44.284 +static void error(const char *str, ...)
  44.285 +{
  44.286 +	va_list arg;
  44.287 +	struct dlthread  *tss;
  44.288 +	char * err_str;
  44.289 +	va_start(arg, str);
  44.290 +	tss = pthread_getspecific(dlerror_key);
  44.291 +	err_str = tss->errstr;
  44.292 +	SDL_strlcpy(err_str, "dlcompat: ", ERR_STR_LEN);
  44.293 +	vsnprintf(err_str + 10, ERR_STR_LEN - 10, str, arg);
  44.294 +	va_end(arg);
  44.295 +	debug("ERROR: %s\n", err_str);
  44.296 +	tss->errset = 1;
  44.297 +}
  44.298 +
  44.299 +static void warning(const char *str)
  44.300 +{
  44.301 +#if DEBUG > 0
  44.302 +	fprintf(stderr, "WARNING: dlcompat: %s\n", str);
  44.303 +#endif
  44.304 +}
  44.305 +
  44.306 +static const char *safegetenv(const char *s)
  44.307 +{
  44.308 +	const char *ss = SDL_getenv(s);
  44.309 +	return ss ? ss : "";
  44.310 +}
  44.311 +
  44.312 +/* because this is only used for debugging and error reporting functions, we
  44.313 + * don't really care about how elegant it is... it could use the load
  44.314 + * commands to find the install name of the library, but...
  44.315 + */
  44.316 +static const char *get_lib_name(const struct mach_header *mh)
  44.317 +{
  44.318 +	unsigned long count = _dyld_image_count();
  44.319 +	unsigned long i;
  44.320 +	const char *val = NULL;
  44.321 +	if (mh)
  44.322 +	{
  44.323 +		for (i = 0; i < count; i++)
  44.324 +		{
  44.325 +			if (mh == _dyld_get_image_header(i))
  44.326 +			{
  44.327 +				val = _dyld_get_image_name(i);
  44.328 +				break;
  44.329 +			}
  44.330 +		}
  44.331 +	}
  44.332 +	return val;
  44.333 +}
  44.334 +
  44.335 +/* Returns the mach_header for the module bu going through all the loaded images
  44.336 + * and finding the one with the same name as the module. There really ought to be
  44.337 + * an api for doing this, would be faster, but there isn't one right now
  44.338 + */
  44.339 +static const struct mach_header *get_mach_header_from_NSModule(NSModule mod)
  44.340 +{
  44.341 +	const char *mod_name = NSNameOfModule(mod);
  44.342 +	const struct mach_header *mh = NULL;
  44.343 +	unsigned long count = _dyld_image_count();
  44.344 +	unsigned long i;
  44.345 +	debug("Module name: %s", mod_name);
  44.346 +	for (i = 0; i < count; i++)
  44.347 +	{
  44.348 +		if (!SDL_strcmp(mod_name, _dyld_get_image_name(i)))
  44.349 +		{
  44.350 +			mh = _dyld_get_image_header(i);
  44.351 +			break;
  44.352 +		}
  44.353 +	}
  44.354 +	return mh;
  44.355 +}
  44.356 +
  44.357 +
  44.358 +/* Compute and return a list of all directories that we should search when
  44.359 + * trying to locate a module. We first look at the values of LD_LIBRARY_PATH
  44.360 + * and DYLD_LIBRARY_PATH, and then finally fall back to looking into
  44.361 + * /usr/lib and /lib. Since both of the environments variables can contain a
  44.362 + * list of colon seperated paths, we simply concat them and the two other paths
  44.363 + * into one big string, which we then can easily parse.
  44.364 + * Splitting this string into the actual path list is done by getSearchPath()
  44.365 + */
  44.366 +static const char *searchList()
  44.367 +{
  44.368 +	size_t buf_size;
  44.369 +	static char *buf=NULL;
  44.370 +	const char *ldlp = safegetenv("LD_LIBRARY_PATH");
  44.371 +	const char *dyldlp = safegetenv("DYLD_LIBRARY_PATH");
  44.372 +	const char *stdpath = SDL_getenv("DYLD_FALLBACK_LIBRARY_PATH");
  44.373 +	if (!stdpath)
  44.374 +		stdpath = "/usr/local/lib:/lib:/usr/lib";
  44.375 +	if (!buf)
  44.376 +	{	
  44.377 +		buf_size = SDL_strlen(ldlp) + SDL_strlen(dyldlp) + SDL_strlen(stdpath) + 4;
  44.378 +		buf = SDL_malloc(buf_size);
  44.379 +		SDL_snprintf(buf, buf_size, "%s%s%s%s%s%c", dyldlp, (dyldlp[0] ? ":" : ""), ldlp, (ldlp[0] ? ":" : ""),
  44.380 +				 stdpath, '\0');
  44.381 +	}
  44.382 +	return buf;
  44.383 +}
  44.384 +
  44.385 +/* Returns the ith search path from the list as computed by searchList() */
  44.386 +static const char *getSearchPath(int i)
  44.387 +{
  44.388 +	static const char *list = 0;
  44.389 +	static char **path = (char **)0;
  44.390 +	static int end = 0;
  44.391 +	static int numsize = MAX_SEARCH_PATHS;
  44.392 +	static char **tmp;
  44.393 +	/* So we can call SDL_free() in the "destructor" we use i=-1 to return the alloc'd array */
  44.394 +	if (i == -1)
  44.395 +	{
  44.396 +		return (const char*)path;
  44.397 +	}
  44.398 +	if (!path)
  44.399 +	{
  44.400 +		path = (char **)SDL_calloc(MAX_SEARCH_PATHS, sizeof(char **));
  44.401 +	}
  44.402 +	if (!list && !end)
  44.403 +		list = searchList();
  44.404 +	if (i >= (numsize))
  44.405 +	{
  44.406 +		debug("Increasing size for long PATH");
  44.407 +		tmp = (char **)SDL_calloc((MAX_SEARCH_PATHS + numsize), sizeof(char **));
  44.408 +		if (tmp)
  44.409 +		{
  44.410 +			SDL_memcpy(tmp, path, sizeof(char **) * numsize);
  44.411 +			SDL_free(path);
  44.412 +			path = tmp;
  44.413 +			numsize += MAX_SEARCH_PATHS;
  44.414 +		}
  44.415 +		else
  44.416 +		{
  44.417 +			return 0;
  44.418 +		}
  44.419 +	}
  44.420 +
  44.421 +	while (!path[i] && !end)
  44.422 +	{
  44.423 +		path[i] = strsep((char **)&list, ":");
  44.424 +
  44.425 +		if (path[i][0] == 0)
  44.426 +			path[i] = 0;
  44.427 +		end = (list == 0);
  44.428 +	}
  44.429 +	return path[i];
  44.430 +}
  44.431 +
  44.432 +static const char *getFullPath(int i, const char *file)
  44.433 +{
  44.434 +	static char buf[PATH_MAX];
  44.435 +	const char *path = getSearchPath(i);
  44.436 +	if (path)
  44.437 +	{
  44.438 +		SDL_snprintf(buf, PATH_MAX, "%s/%s", path, file);
  44.439 +	}
  44.440 +	return path ? buf : 0;
  44.441 +}
  44.442 +
  44.443 +/* Given a file name, try to determine the full path for that file. Starts
  44.444 + * its search in the current directory, and then tries all paths in the 
  44.445 + * search list in the order they are specified there.
  44.446 + */
  44.447 +static const struct stat *findFile(const char *file, const char **fullPath)
  44.448 +{
  44.449 +	int i = 0;
  44.450 +	static struct stat sbuf;
  44.451 +	char *fileName;
  44.452 +	debug("finding file %s", file);
  44.453 +	*fullPath = file;
  44.454 +	if (0 == stat(file, &sbuf))
  44.455 +		return &sbuf;
  44.456 +	if (SDL_strchr(file, '/'))
  44.457 +		return 0;				/* If the path had a / we don't look in env var places */
  44.458 +	fileName = NULL;
  44.459 +	if (!fileName)
  44.460 +		fileName = (char *)file;
  44.461 +	while ((*fullPath = getFullPath(i++, fileName)))
  44.462 +	{
  44.463 +		if (0 == stat(*fullPath, &sbuf))
  44.464 +			return &sbuf;
  44.465 +	}
  44.466 +	;
  44.467 +	return 0;
  44.468 +}
  44.469 +
  44.470 +/* Determine whether a given dlstatus is valid or not */
  44.471 +static int isValidStatus(struct dlstatus *status)
  44.472 +{
  44.473 +	/* Walk the list to verify status is contained in it */
  44.474 +	struct dlstatus *dls = stqueue;
  44.475 +	while (dls && status != dls)
  44.476 +		dls = dls->next;
  44.477 +	if (dls == 0)
  44.478 +		error("invalid handle");
  44.479 +	else if ((dls->module == 0) || (dls->refs == 0))
  44.480 +		error("handle to closed library");
  44.481 +	else
  44.482 +		return TRUE;
  44.483 +	return FALSE;
  44.484 +}
  44.485 +
  44.486 +static inline int isFlagSet(int mode, int flag)
  44.487 +{
  44.488 +	return (mode & flag) == flag;
  44.489 +}
  44.490 +
  44.491 +static struct dlstatus *lookupStatus(const struct stat *sbuf)
  44.492 +{
  44.493 +	struct dlstatus *dls = stqueue;
  44.494 +	debug("looking for status");
  44.495 +	while (dls && ( /* isFlagSet(dls->mode, RTLD_UNSHARED) */ 0
  44.496 +				   || sbuf->st_dev != dls->device || sbuf->st_ino != dls->inode))
  44.497 +		dls = dls->next;
  44.498 +	return dls;
  44.499 +}
  44.500 +
  44.501 +static void insertStatus(struct dlstatus *dls, const struct stat *sbuf)
  44.502 +{
  44.503 +	debug("inserting status");
  44.504 +	dls->inode = sbuf->st_ino;
  44.505 +	dls->device = sbuf->st_dev;
  44.506 +	dls->refs = 0;
  44.507 +	dls->mode = 0;
  44.508 +	if ((dls->flags & DL_IN_LIST) == 0)
  44.509 +	{
  44.510 +		dls->next = stqueue;
  44.511 +		stqueue = dls;
  44.512 +		dls->flags |= DL_IN_LIST;
  44.513 +	}
  44.514 +}
  44.515 +
  44.516 +static struct dlstatus *allocStatus()
  44.517 +{
  44.518 +	struct dlstatus *dls;
  44.519 +#ifdef REUSE_STATUS
  44.520 +	dls = stqueue;
  44.521 +	while (dls && dls->module)
  44.522 +		dls = dls->next;
  44.523 +	if (!dls)
  44.524 +#endif
  44.525 +		dls = SDL_calloc(sizeof(*dls),1);
  44.526 +	return dls;
  44.527 +}
  44.528 +
  44.529 +static int promoteLocalToGlobal(struct dlstatus *dls)
  44.530 +{
  44.531 +	static int (*p) (NSModule module) = 0;
  44.532 +	debug("promoting");
  44.533 +	if (!p)
  44.534 +		_dyld_func_lookup("__dyld_NSMakePrivateModulePublic", (void **)&p);
  44.535 +	return (dls->module == MAGIC_DYLIB_MOD) || (p && p(dls->module));
  44.536 +}
  44.537 +
  44.538 +static void *reference(struct dlstatus *dls, int mode)
  44.539 +{
  44.540 +	if (dls)
  44.541 +	{
  44.542 +		if (dls->module == MAGIC_DYLIB_MOD && isFlagSet(mode, RTLD_LOCAL))
  44.543 +		{
  44.544 +			warning("trying to open a .dylib with RTLD_LOCAL");
  44.545 +			error("unable to open a .dylib with RTLD_LOCAL");
  44.546 +			return NULL;
  44.547 +		}
  44.548 +		if (isFlagSet(mode, RTLD_GLOBAL) &&
  44.549 +			!isFlagSet(dls->mode, RTLD_GLOBAL) && !promoteLocalToGlobal(dls))
  44.550 +		{
  44.551 +			error("unable to promote local module to global");
  44.552 +			return NULL;
  44.553 +		}
  44.554 +		dls->mode |= mode;
  44.555 +		dls->refs++;
  44.556 +	}
  44.557 +	else
  44.558 +		debug("reference called with NULL argument");
  44.559 +
  44.560 +	return dls;
  44.561 +}
  44.562 +
  44.563 +static const struct mach_header *my_find_image(const char *name)
  44.564 +{
  44.565 +	const struct mach_header *mh = 0;
  44.566 +	const char *id = NULL;
  44.567 +	int i = _dyld_image_count();
  44.568 +	int j;
  44.569 +	mh = (struct mach_header *)
  44.570 +		dyld_NSAddImage(name, NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED |
  44.571 +						NSADDIMAGE_OPTION_RETURN_ON_ERROR);
  44.572 +	if (!mh)
  44.573 +	{
  44.574 +		for (j = 0; j < i; j++)
  44.575 +		{
  44.576 +			id = _dyld_get_image_name(j);
  44.577 +			if (!SDL_strcmp(id, name))
  44.578 +			{
  44.579 +				mh = _dyld_get_image_header(j);
  44.580 +				break;
  44.581 +			}
  44.582 +		}
  44.583 +	}
  44.584 +	return mh;
  44.585 +}
  44.586 +
  44.587 +/*
  44.588 + * dyld adds libraries by first adding the directly dependant libraries in link order, and
  44.589 + * then adding the dependencies for those libraries, so we should do the same... but we don't
  44.590 + * bother adding the extra dependencies, if the symbols are neither in the loaded image nor
  44.591 + * any of it's direct dependencies, then it probably isn't there.
  44.592 + */
  44.593 +static NSSymbol search_linked_libs(const struct mach_header * mh, const char *symbol)
  44.594 +{
  44.595 +	unsigned int n;
  44.596 +	struct load_command *lc = 0;
  44.597 +	struct mach_header *wh;
  44.598 +	NSSymbol nssym = 0;
  44.599 +	if (dyld_NSAddImage && dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage)
  44.600 +	{
  44.601 +		lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
  44.602 +		for (n = 0; n < mh->ncmds; n++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
  44.603 +		{
  44.604 +			if ((LC_LOAD_DYLIB == lc->cmd) || (LC_LOAD_WEAK_DYLIB == lc->cmd))
  44.605 +			{
  44.606 +				if ((wh = (struct mach_header *)
  44.607 +					 my_find_image((char *)(((struct dylib_command *)lc)->dylib.name.offset +
  44.608 +											(char *)lc))))
  44.609 +				{
  44.610 +					if (dyld_NSIsSymbolNameDefinedInImage(wh, symbol))
  44.611 +					{
  44.612 +						nssym = dyld_NSLookupSymbolInImage(wh,
  44.613 +														   symbol,
  44.614 +														   NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
  44.615 +														   NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
  44.616 +						break;
  44.617 +					}
  44.618 +				}
  44.619 +			}
  44.620 +		}
  44.621 +		if ((!nssym) && NSIsSymbolNameDefined(symbol))
  44.622 +		{
  44.623 +			/* I've never seen this debug message...*/
  44.624 +			debug("Symbol \"%s\" is defined but was not found", symbol);
  44.625 +		}
  44.626 +	}
  44.627 +	return nssym;
  44.628 +}
  44.629 +
  44.630 +/* Up to the caller to SDL_free() returned string */
  44.631 +static inline char *dyld_error_str()
  44.632 +{
  44.633 +	NSLinkEditErrors dylder;
  44.634 +	int dylderno;
  44.635 +	const char *dylderrstr;
  44.636 +	const char *dyldfile;
  44.637 +	char* retStr = NULL;
  44.638 +	NSLinkEditError(&dylder, &dylderno, &dyldfile, &dylderrstr);
  44.639 +	if (dylderrstr && *dylderrstr)
  44.640 +	{
  44.641 +		retStr = SDL_strdup(dylderrstr);
  44.642 +	}
  44.643 +	return retStr;
  44.644 +}
  44.645 +
  44.646 +static void *dlsymIntern(struct dlstatus *dls, const char *symbol, int canSetError)
  44.647 +{
  44.648 +  NSSymbol nssym = 0;
  44.649 +#ifdef __GCC__  
  44.650 +	void *caller = __builtin_return_address(1);	/* Be *very* careful about inlining */
  44.651 +#else
  44.652 +	void *caller = NULL;
  44.653 +#endif
  44.654 +	const struct mach_header *caller_mh = 0;
  44.655 +	char *savedErrorStr = NULL;
  44.656 +	resetdlerror();
  44.657 +#ifndef RTLD_SELF
  44.658 +#define	RTLD_SELF		((void *) -3)
  44.659 +#endif
  44.660 +	if (NULL == dls)
  44.661 +		dls = RTLD_SELF;
  44.662 +	if ((RTLD_NEXT == dls) || (RTLD_SELF == dls))
  44.663 +	{
  44.664 +		if (dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage && caller)
  44.665 +		  {
  44.666 +			caller_mh = image_for_address(caller);
  44.667 +			if (RTLD_SELF == dls)
  44.668 +			{
  44.669 +				/* FIXME: We should be using the NSModule api, if SELF is an MH_BUNDLE
  44.670 +				 * But it appears to work anyway, and looking at the code in dyld_libfuncs.c
  44.671 +				 * this is acceptable.
  44.672 +				 */
  44.673 +				if (dyld_NSIsSymbolNameDefinedInImage(caller_mh, symbol))
  44.674 +				{
  44.675 +					nssym = dyld_NSLookupSymbolInImage(caller_mh,
  44.676 +													   symbol,
  44.677 +													   NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
  44.678 +													   NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
  44.679 +				}
  44.680 +			}
  44.681 +			if (!nssym)
  44.682 +			{
  44.683 +				if (RTLD_SELF == dls)
  44.684 +					savedErrorStr = dyld_error_str();
  44.685 +				nssym = search_linked_libs(caller_mh, symbol);
  44.686 +			}
  44.687 +		}
  44.688 +		else
  44.689 +		{
  44.690 +			if (canSetError)
  44.691 +				error("RTLD_SELF and RTLD_NEXT are not supported");
  44.692 +			return NULL;
  44.693 +		}
  44.694 +	}
  44.695 +	if (!nssym)
  44.696 +	{
  44.697 +
  44.698 +		if (RTLD_DEFAULT == dls)
  44.699 +		{
  44.700 +			dls = &mainStatus;
  44.701 +		}
  44.702 +		if (!isValidStatus(dls))
  44.703 +			return NULL;
  44.704 +
  44.705 +		if (dls->module != MAGIC_DYLIB_MOD)
  44.706 +		{
  44.707 +			nssym = NSLookupSymbolInModule(dls->module, symbol);
  44.708 +			if (!nssym && NSIsSymbolNameDefined(symbol))
  44.709 +			{
  44.710 +				debug("Searching dependencies");
  44.711 +				savedErrorStr = dyld_error_str();
  44.712 +				nssym = search_linked_libs(get_mach_header_from_NSModule(dls->module), symbol);
  44.713 +			}
  44.714 +		}
  44.715 +		else if (dls->lib && dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage)
  44.716 +		{
  44.717 +			if (dyld_NSIsSymbolNameDefinedInImage(dls->lib, symbol))
  44.718 +			{
  44.719 +				nssym = dyld_NSLookupSymbolInImage(dls->lib,
  44.720 +												   symbol,
  44.721 +												   NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
  44.722 +												   NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
  44.723 +			}
  44.724 +			else if (NSIsSymbolNameDefined(symbol))
  44.725 +			{
  44.726 +				debug("Searching dependencies");
  44.727 +				savedErrorStr = dyld_error_str();
  44.728 +				nssym = search_linked_libs(dls->lib, symbol);
  44.729 +			}
  44.730 +		}
  44.731 +		else if (dls->module == MAGIC_DYLIB_MOD)
  44.732 +		{
  44.733 +			/* Global context, use NSLookupAndBindSymbol */
  44.734 +			if (NSIsSymbolNameDefined(symbol))
  44.735 +			{
  44.736 +				/* There doesn't seem to be a return on error option for this call???
  44.737 +				   this is potentially broken, if binding fails, it will improperly
  44.738 +				   exit the application. */
  44.739 +				nssym = NSLookupAndBindSymbol(symbol);
  44.740 +			}
  44.741 +			else
  44.742 +			{
  44.743 +				if (savedErrorStr)
  44.744 +					SDL_free(savedErrorStr);			
  44.745 +				savedErrorStr = SDL_malloc(256);
  44.746 +				SDL_snprintf(savedErrorStr, 256, "Symbol \"%s\" not in global context",symbol);	
  44.747 +			}
  44.748 +		}
  44.749 +	}
  44.750 +	/* Error reporting */
  44.751 +	if (!nssym)
  44.752 +	{
  44.753 +		if (!savedErrorStr || !SDL_strlen(savedErrorStr))
  44.754 +		{
  44.755 +			if (savedErrorStr)
  44.756 +				SDL_free(savedErrorStr);
  44.757 +			savedErrorStr = SDL_malloc(256);
  44.758 +			SDL_snprintf(savedErrorStr, 256,"Symbol \"%s\" not found",symbol);
  44.759 +		}
  44.760 +		if (canSetError)
  44.761 +		{
  44.762 +			error(savedErrorStr);
  44.763 +		}
  44.764 +		else
  44.765 +		{
  44.766 +			debug(savedErrorStr);
  44.767 +		}
  44.768 +		if (savedErrorStr)
  44.769 +			SDL_free(savedErrorStr);
  44.770 +		return NULL;
  44.771 +	}
  44.772 +	return NSAddressOfSymbol(nssym);
  44.773 +}
  44.774 +
  44.775 +static struct dlstatus *loadModule(const char *path, const struct stat *sbuf, int mode)
  44.776 +{
  44.777 +	NSObjectFileImage ofi = 0;
  44.778 +	NSObjectFileImageReturnCode ofirc;
  44.779 +	struct dlstatus *dls;
  44.780 +	NSLinkEditErrors ler;
  44.781 +	int lerno;
  44.782 +	const char *errstr;
  44.783 +	const char *file;
  44.784 +	void (*init) (void);
  44.785 +
  44.786 +	ofirc = NSCreateObjectFileImageFromFile(path, &ofi);
  44.787 +	switch (ofirc)
  44.788 +	{
  44.789 +		case NSObjectFileImageSuccess:
  44.790 +			break;
  44.791 +		case NSObjectFileImageInappropriateFile:
  44.792 +			if (dyld_NSAddImage && dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage)
  44.793 +			{	
  44.794 +				if (isFlagSet(mode, RTLD_LOCAL))
  44.795 +				{
  44.796 +					warning("trying to open a .dylib with RTLD_LOCAL");
  44.797 +					error("unable to open this file with RTLD_LOCAL");
  44.798 +					return NULL;
  44.799 +				}
  44.800 +			}
  44.801 +			else
  44.802 +			{
  44.803 +				error("opening this file is unsupported on this system");
  44.804 +				return NULL;
  44.805 +			}
  44.806 +			break;
  44.807 +		case NSObjectFileImageFailure:
  44.808 +			error("object file setup failure");
  44.809 +			return NULL;
  44.810 +		case NSObjectFileImageArch:
  44.811 +			error("no object for this architecture");
  44.812 +			return NULL;
  44.813 +		case NSObjectFileImageFormat:
  44.814 +			error("bad object file format");
  44.815 +			return NULL;
  44.816 +		case NSObjectFileImageAccess:
  44.817 +			error("can't read object file");
  44.818 +			return NULL;
  44.819 +		default:
  44.820 +			error("unknown error from NSCreateObjectFileImageFromFile()");
  44.821 +			return NULL;
  44.822 +	}
  44.823 +	dls = lookupStatus(sbuf);
  44.824 +	if (!dls)
  44.825 +	{
  44.826 +		dls = allocStatus();
  44.827 +	}
  44.828 +	if (!dls)
  44.829 +	{
  44.830 +		error("unable to allocate memory");
  44.831 +		return NULL;
  44.832 +	}
  44.833 +	//	dls->lib = 0;
  44.834 +	if (ofirc == NSObjectFileImageInappropriateFile)
  44.835 +	{
  44.836 +		if ((dls->lib = dyld_NSAddImage(path, NSADDIMAGE_OPTION_RETURN_ON_ERROR)))
  44.837 +		{
  44.838 +			debug("Dynamic lib loaded at %ld", dls->lib);
  44.839 +			ofi = MAGIC_DYLIB_OFI;
  44.840 +			dls->module = MAGIC_DYLIB_MOD;
  44.841 +			ofirc = NSObjectFileImageSuccess;
  44.842 +			/* Although it is possible with a bit of work to modify this so it works and
  44.843 +			   functions with RTLD_NOW, I don't deem it necessary at the moment */
  44.844 +		}
  44.845 +		if (!(dls->module))
  44.846 +		{
  44.847 +			NSLinkEditError(&ler, &lerno, &file, &errstr);
  44.848 +			if (!errstr || (!SDL_strlen(errstr)))
  44.849 +				error("Can't open this file type");
  44.850 +			else
  44.851 +				error(errstr);
  44.852 +			if ((dls->flags & DL_IN_LIST) == 0)
  44.853 +			{
  44.854 +				SDL_free(dls);
  44.855 +			}
  44.856 +			return NULL;
  44.857 +		}
  44.858 +	}
  44.859 +	else
  44.860 +	{
  44.861 +		dls->module = NSLinkModule(ofi, path,
  44.862 +								   NSLINKMODULE_OPTION_RETURN_ON_ERROR |
  44.863 +								   NSLINKMODULE_OPTION_PRIVATE |
  44.864 +								   (isFlagSet(mode, RTLD_NOW) ? NSLINKMODULE_OPTION_BINDNOW : 0));
  44.865 +		NSDestroyObjectFileImage(ofi);
  44.866 +		if (dls->module)
  44.867 +		{
  44.868 +			dls->lib = get_mach_header_from_NSModule(dls->module);
  44.869 +		}
  44.870 +	}
  44.871 +	if (!dls->module)
  44.872 +	{
  44.873 +		NSLinkEditError(&ler, &lerno, &file, &errstr);
  44.874 +		if ((dls->flags & DL_IN_LIST) == 0)
  44.875 +		{
  44.876 +			SDL_free(dls);
  44.877 +		}
  44.878 +		error(errstr);
  44.879 +		return NULL;
  44.880 +	}
  44.881 +
  44.882 +	insertStatus(dls, sbuf);
  44.883 +	dls = reference(dls, mode);
  44.884 +	if ((init = dlsymIntern(dls, "__init", 0)))
  44.885 +	{
  44.886 +		debug("calling _init()");
  44.887 +		init();
  44.888 +	}
  44.889 +	return dls;
  44.890 +}
  44.891 +
  44.892 +inline static void dlcompat_init_check(void)
  44.893 +{
  44.894 +	static pthread_mutex_t l = PTHREAD_MUTEX_INITIALIZER;
  44.895 +	static int init_done = 0;
  44.896 +
  44.897 +	pthread_mutex_lock(&l);
  44.898 +	if (!init_done) {
  44.899 +		dlcompat_init_func();
  44.900 +		init_done = 1;
  44.901 +	}
  44.902 +	pthread_mutex_unlock(&l);
  44.903 +}
  44.904 +
  44.905 +static void dlcompat_init_func(void)
  44.906 +{
  44.907 +        _dyld_func_lookup("__dyld_NSAddImage", (void **)&dyld_NSAddImage);
  44.908 +	_dyld_func_lookup("__dyld_NSIsSymbolNameDefinedInImage",
  44.909 +			  (void **)&dyld_NSIsSymbolNameDefinedInImage);
  44.910 +	_dyld_func_lookup("__dyld_NSLookupSymbolInImage", (void **)&dyld_NSLookupSymbolInImage);
  44.911 +	if (pthread_mutex_init(&dlcompat_mutex, NULL))
  44.912 +	    exit(1);
  44.913 +	if (pthread_key_create(&dlerror_key, &dlerrorfree))
  44.914 +	    exit(1);
  44.915 +}
  44.916 +
  44.917 +static void resetdlerror()
  44.918 +{
  44.919 +	struct dlthread *tss;
  44.920 +	tss = pthread_getspecific(dlerror_key);
  44.921 +	tss->errset = 0;
  44.922 +}
  44.923 +
  44.924 +static void dlerrorfree(void *data)
  44.925 +{
  44.926 +	SDL_free(data);
  44.927 +}
  44.928 +
  44.929 +/* We kind of want a recursive lock here, but meet a little trouble
  44.930 + * because they are not available pre OS X 10.2, so we fake it
  44.931 + * using thread specific storage to keep a lock count
  44.932 + */ 
  44.933 +static inline void dolock(void)
  44.934 +{
  44.935 +	int err = 0;
  44.936 +	struct dlthread *tss;
  44.937 +	dlcompat_init_check();
  44.938 +	tss = pthread_getspecific(dlerror_key);
  44.939 +	if (!tss)
  44.940 +	{
  44.941 +		tss = SDL_malloc(sizeof(struct dlthread));
  44.942 +		tss->lockcnt = 0;
  44.943 +		tss->errset = 0;
  44.944 +		if (pthread_setspecific(dlerror_key, tss))
  44.945 +		{
  44.946 +			fprintf(stderr,"dlcompat: pthread_setspecific failed\n");
  44.947 +			exit(1);
  44.948 +		}
  44.949 +	}
  44.950 +	if (!tss->lockcnt)
  44.951 +		err = pthread_mutex_lock(&dlcompat_mutex);
  44.952 +	tss->lockcnt = tss->lockcnt +1;	
  44.953 +	if (err)
  44.954 +		exit(err);
  44.955 +}
  44.956 +
  44.957 +static inline void dounlock(void)
  44.958 +{
  44.959 +	int err = 0;
  44.960 +	struct dlthread *tss;
  44.961 +	tss = pthread_getspecific(dlerror_key);
  44.962 +	tss->lockcnt = tss->lockcnt -1;
  44.963 +	if (!tss->lockcnt)
  44.964 +		err = pthread_mutex_unlock(&dlcompat_mutex);
  44.965 +	if (err)
  44.966 +		exit(err);
  44.967 +}
  44.968 +
  44.969 +static void *SDL_OSX_dlopen(const char *path, int mode)
  44.970 +{
  44.971 +	const struct stat *sbuf;
  44.972 +	struct dlstatus *dls;
  44.973 +	const char *fullPath;
  44.974 +
  44.975 +	dolock();
  44.976 +	resetdlerror();
  44.977 +	if (!path)
  44.978 +	{
  44.979 +		dls = &mainStatus;
  44.980 +		goto dlopenok;
  44.981 +	}
  44.982 +	if (!(sbuf = findFile(path, &fullPath)))
  44.983 +	{
  44.984 +		error("file \"%s\" not found", path);
  44.985 +		goto dlopenerror;
  44.986 +	}
  44.987 +	/* Now checks that it hasn't been closed already */
  44.988 +	if ((dls = lookupStatus(sbuf)) && (dls->refs > 0))
  44.989 +	{
  44.990 +		/* debug("status found"); */
  44.991 +		dls = reference(dls, mode);
  44.992 +		goto dlopenok;
  44.993 +	}
  44.994 +#ifdef 	RTLD_NOLOAD
  44.995 +	if (isFlagSet(mode, RTLD_NOLOAD))
  44.996 +	{
  44.997 +		error("no existing handle and RTLD_NOLOAD specified");
  44.998 +		goto dlopenerror;
  44.999 +	}
 44.1000 +#endif
 44.1001 +	if (isFlagSet(mode, RTLD_LAZY) && isFlagSet(mode, RTLD_NOW))
 44.1002 +	{
 44.1003 +		error("how can I load something both RTLD_LAZY and RTLD_NOW?");
 44.1004 +		goto dlopenerror;
 44.1005 +	}
 44.1006 +	dls = loadModule(fullPath, sbuf, mode);
 44.1007 +	
 44.1008 +  dlopenok:
 44.1009 +	dounlock();
 44.1010 +	return (void *)dls;
 44.1011 +  dlopenerror:
 44.1012 +	dounlock();
 44.1013 +	return NULL;
 44.1014 +}
 44.1015 +
 44.1016 +#if !FINK_BUILD
 44.1017 +static void *SDL_OSX_dlsym(void * dl_restrict handle, const char * dl_restrict symbol)
 44.1018 +{
 44.1019 +	int sym_len = SDL_strlen(symbol);
 44.1020 +	void *value = NULL;
 44.1021 +	char *malloc_sym = NULL;
 44.1022 +	dolock();
 44.1023 +	malloc_sym = SDL_malloc(sym_len + 2);
 44.1024 +	if (malloc_sym)
 44.1025 +	{
 44.1026 +		SDL_snprintf(malloc_sym, sym_len+2, "_%s", symbol);
 44.1027 +		value = dlsymIntern(handle, malloc_sym, 1);
 44.1028 +		SDL_free(malloc_sym);
 44.1029 +	}
 44.1030 +	else
 44.1031 +	{
 44.1032 +		error("Unable to allocate memory");
 44.1033 +		goto dlsymerror;
 44.1034 +	}
 44.1035 +	dounlock();
 44.1036 +	return value;
 44.1037 +  dlsymerror:
 44.1038 +	dounlock();
 44.1039 +	return NULL;
 44.1040 +}
 44.1041 +#endif
 44.1042 +
 44.1043 +#if FINK_BUILD
 44.1044 +
 44.1045 +static void *dlsym_prepend_underscore(void *handle, const char *symbol)
 44.1046 +{
 44.1047 +	void *answer;
 44.1048 +	dolock();
 44.1049 +	answer = dlsym_prepend_underscore_intern(handle, symbol);
 44.1050 +	dounlock();
 44.1051 +	return answer;
 44.1052 +}
 44.1053 +
 44.1054 +static void *dlsym_prepend_underscore_intern(void *handle, const char *symbol)
 44.1055 +{
 44.1056 +/*
 44.1057 + *	A quick and easy way for porting packages which call dlsym(handle,"sym")
 44.1058 + *	If the porter adds -Ddlsym=dlsym_prepend_underscore to the CFLAGS then
 44.1059 + *	this function will be called, and will add the required underscore.
 44.1060 + *	
 44.1061 + *	Note that I haven't figured out yet which should be "standard", prepend
 44.1062 + *	the underscore always, or not at all. These global functions need to go away
 44.1063 + *	for opendarwin.
 44.1064 + */
 44.1065 +	int sym_len = SDL_strlen(symbol);
 44.1066 +	void *value = NULL;
 44.1067 +	char *malloc_sym = NULL;
 44.1068 +	malloc_sym = SDL_malloc(sym_len + 2);
 44.1069 +	if (malloc_sym)
 44.1070 +	{
 44.1071 +		SDL_snprintf(malloc_sym, sym_len+2, "_%s", symbol);
 44.1072 +		value = dlsymIntern(handle, malloc_sym, 1);
 44.1073 +		SDL_free(malloc_sym);
 44.1074 +	}
 44.1075 +	else
 44.1076 +	{
 44.1077 +		error("Unable to allocate memory");
 44.1078 +	}
 44.1079 +	return value;
 44.1080 +}
 44.1081 +
 44.1082 +static void *dlsym_auto_underscore(void *handle, const char *symbol)
 44.1083 +{
 44.1084 +	void *answer;
 44.1085 +	dolock();
 44.1086 +	answer = dlsym_auto_underscore_intern(handle, symbol);
 44.1087 +	dounlock();
 44.1088 +	return answer;
 44.1089 +
 44.1090 +}
 44.1091 +static void *dlsym_auto_underscore_intern(void *handle, const char *symbol)
 44.1092 +{
 44.1093 +	struct dlstatus *dls = handle;
 44.1094 +	void *addr = 0;
 44.1095 +	addr = dlsymIntern(dls, symbol, 0);
 44.1096 +	if (!addr)
 44.1097 +		addr = dlsym_prepend_underscore_intern(handle, symbol);
 44.1098 +	return addr;
 44.1099 +}
 44.1100 +
 44.1101 +
 44.1102 +static void *SDL_OSX_dlsym(void * dl_restrict handle, const char * dl_restrict symbol)
 44.1103 +{
 44.1104 +	struct dlstatus *dls = handle;
 44.1105 +	void *addr = 0;
 44.1106 +	dolock();
 44.1107 +	addr = dlsymIntern(dls, symbol, 1);
 44.1108 +	dounlock();
 44.1109 +	return addr;
 44.1110 +}
 44.1111 +#endif
 44.1112 +
 44.1113 +static int SDL_OSX_dlclose(void *handle)
 44.1114 +{
 44.1115 +	struct dlstatus *dls = handle;
 44.1116 +	dolock();
 44.1117 +	resetdlerror();
 44.1118 +	if (!isValidStatus(dls))
 44.1119 +	{
 44.1120 +		goto dlcloseerror;
 44.1121 +	}
 44.1122 +	if (dls->module == MAGIC_DYLIB_MOD)
 44.1123 +	{
 44.1124 +		const char *name;
 44.1125 +		if (!dls->lib)
 44.1126 +		{
 44.1127 +			name = "global context";
 44.1128 +		}
 44.1129 +		else
 44.1130 +		{
 44.1131 +			name = get_lib_name(dls->lib);
 44.1132 +		}
 44.1133 +		warning("trying to close a .dylib!");
 44.1134 +		error("Not closing \"%s\" - dynamic libraries cannot be closed", name);
 44.1135 +		goto dlcloseerror;
 44.1136 +	}
 44.1137 +	if (!dls->module)
 44.1138 +	{
 44.1139 +		error("module already closed");
 44.1140 +		goto dlcloseerror;
 44.1141 +	}
 44.1142 +	
 44.1143 +	if (dls->refs == 1)
 44.1144 +	{
 44.1145 +		unsigned long options = 0;
 44.1146 +		void (*fini) (void);
 44.1147 +		if ((fini = dlsymIntern(dls, "__fini", 0)))
 44.1148 +		{
 44.1149 +			debug("calling _fini()");
 44.1150 +			fini();
 44.1151 +		}
 44.1152 +		options |= NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES;
 44.1153 +#ifdef RTLD_NODELETE
 44.1154 +		if (isFlagSet(dls->mode, RTLD_NODELETE))
 44.1155 +			options |= NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED;
 44.1156 +#endif
 44.1157 +		if (!NSUnLinkModule(dls->module, options))
 44.1158 +		{
 44.1159 +			error("unable to unlink module");
 44.1160 +			goto dlcloseerror;
 44.1161 +		}
 44.1162 +		dls->refs--;
 44.1163 +		dls->module = 0;
 44.1164 +		/* Note: the dlstatus struct dls is neither removed from the list
 44.1165 +		 * nor is the memory it occupies freed. This shouldn't pose a 
 44.1166 +		 * problem in mostly all cases, though.
 44.1167 +		 */
 44.1168 +	}
 44.1169 +	dounlock();
 44.1170 +	return 0;
 44.1171 +  dlcloseerror:
 44.1172 +	dounlock();
 44.1173 +	return 1;
 44.1174 +}
 44.1175 +
 44.1176 +static const char *SDL_OSX_dlerror(void)
 44.1177 +{
 44.1178 +	struct dlthread  *tss;
 44.1179 +	const char * err_str = NULL;
 44.1180 +	dlcompat_init_check();
 44.1181 +	tss = pthread_getspecific(dlerror_key);
 44.1182 +	if (tss != NULL && tss->errset != 0) {
 44.1183 +		tss->errset = 0;	
 44.1184 +		err_str = tss->errstr;
 44.1185 +	}
 44.1186 +	return (err_str);
 44.1187 +}
 44.1188 +
 44.1189 +/* Given an address, return the mach_header for the image containing it
 44.1190 + * or zero if the given address is not contained in any loaded images.
 44.1191 + */
 44.1192 +static const struct mach_header *image_for_address(const void *address)
 44.1193 +{
 44.1194 +	unsigned long i;
 44.1195 +	unsigned long j;
 44.1196 +	unsigned long count = _dyld_image_count();
 44.1197 +	const struct mach_header *mh = 0;
 44.1198 +	struct load_command *lc = 0;
 44.1199 +	unsigned long addr = 0;
 44.1200 +	for (i = 0; i < count; i++)
 44.1201 +	{
 44.1202 +		addr = (unsigned long)address - _dyld_get_image_vmaddr_slide(i);
 44.1203 +		mh = _dyld_get_image_header(i);
 44.1204 +		if (mh)
 44.1205 +		{
 44.1206 +			lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
 44.1207 +			for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
 44.1208 +			{
 44.1209 +				if (LC_SEGMENT == lc->cmd &&
 44.1210 +					addr >= ((struct segment_command *)lc)->vmaddr &&
 44.1211 +					addr <
 44.1212 +					((struct segment_command *)lc)->vmaddr + ((struct segment_command *)lc)->vmsize)
 44.1213 +				{
 44.1214 +					goto image_found;
 44.1215 +				}
 44.1216 +			}
 44.1217 +		}
 44.1218 +		mh = 0;
 44.1219 +	}
 44.1220 +  image_found:
 44.1221 +	return mh;
 44.1222 +}
 44.1223 +
 44.1224 +#if 0 /* unused */
 44.1225 +static int SDL_OSX_dladdr(const void * dl_restrict p, SDL_OSX_Dl_info * dl_restrict info)
 44.1226 +{
 44.1227 +/*
 44.1228 +	FIXME: USe the routine image_for_address.
 44.1229 +*/
 44.1230 +	unsigned long i;
 44.1231 +	unsigned long j;
 44.1232 +	unsigned long count = _dyld_image_count();
 44.1233 +	struct mach_header *mh = 0;
 44.1234 +	struct load_command *lc = 0;
 44.1235 +	unsigned long addr = NULL;
 44.1236 +	unsigned long table_off = (unsigned long)0;
 44.1237 +	int found = 0;
 44.1238 +	if (!info)
 44.1239 +		return 0;
 44.1240 +	dolock();
 44.1241 +	resetdlerror();
 44.1242 +	info->dli_fname = 0;
 44.1243 +	info->dli_fbase = 0;
 44.1244 +	info->dli_sname = 0;
 44.1245 +	info->dli_saddr = 0;
 44.1246 +/* Some of this was swiped from code posted by Douglas Davidson <ddavidso AT apple DOT com>
 44.1247 + * to darwin-development AT lists DOT apple DOT com and slightly modified
 44.1248 + */
 44.1249 +	for (i = 0; i < count; i++)
 44.1250 +	{
 44.1251 +		addr = (unsigned long)p - _dyld_get_image_vmaddr_slide(i);
 44.1252 +		mh = _dyld_get_image_header(i);
 44.1253 +		if (mh)
 44.1254 +		{
 44.1255 +			lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
 44.1256 +			for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
 44.1257 +			{
 44.1258 +				if (LC_SEGMENT == lc->cmd &&
 44.1259 +					addr >= ((struct segment_command *)lc)->vmaddr &&
 44.1260 +					addr <
 44.1261 +					((struct segment_command *)lc)->vmaddr + ((struct segment_command *)lc)->vmsize)
 44.1262 +				{
 44.1263 +					info->dli_fname = _dyld_get_image_name(i);
 44.1264 +					info->dli_fbase = (void *)mh;
 44.1265 +					found = 1;
 44.1266 +					break;
 44.1267 +				}
 44.1268 +			}
 44.1269 +			if (found)
 44.1270 +				break;
 44.1271 +		}
 44.1272 +	}
 44.1273 +	if (!found)
 44.1274 +	{
 44.1275 +		dounlock();
 44.1276 +		return 0;
 44.1277 +	}
 44.1278 +	lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
 44.1279 +	for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
 44.1280 +	{
 44.1281 +		if (LC_SEGMENT == lc->cmd)
 44.1282 +		{
 44.1283 +			if (!SDL_strcmp(((struct segment_command *)lc)->segname, "__LINKEDIT"))
 44.1284 +				break;
 44.1285 +		}
 44.1286 +	}
 44.1287 +	table_off =
 44.1288 +		((unsigned long)((struct segment_command *)lc)->vmaddr) -
 44.1289 +		((unsigned long)((struct segment_command *)lc)->fileoff) + _dyld_get_image_vmaddr_slide(i);
 44.1290 +	debug("table off %x", table_off);
 44.1291 +
 44.1292 +	lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
 44.1293 +	for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
 44.1294 +	{
 44.1295 +		if (LC_SYMTAB == lc->cmd)
 44.1296 +		{
 44.1297 +
 44.1298 +			struct nlist *symtable = (struct nlist *)(((struct symtab_command *)lc)->symoff + table_off);
 44.1299 +			unsigned long numsyms = ((struct symtab_command *)lc)->nsyms;
 44.1300 +			struct nlist *nearest = NULL;
 44.1301 +			unsigned long diff = 0xffffffff;
 44.1302 +			unsigned long strtable = (unsigned long)(((struct symtab_command *)lc)->stroff + table_off);
 44.1303 +			debug("symtable %x", symtable);
 44.1304 +			for (i = 0; i < numsyms; i++)
 44.1305 +			{
 44.1306 +				/* Ignore the following kinds of Symbols */
 44.1307 +				if ((!symtable->n_value)	/* Undefined */
 44.1308 +					|| (symtable->n_type >= N_PEXT)	/* Debug symbol */
 44.1309 +					|| (!(symtable->n_type & N_EXT))	/* Local Symbol */
 44.1310 +					)
 44.1311 +				{
 44.1312 +					symtable++;
 44.1313 +					continue;
 44.1314 +				}
 44.1315 +				if ((addr >= symtable->n_value) && (diff >= (symtable->n_value - addr)))
 44.1316 +				{
 44.1317 +					diff = (unsigned long)symtable->n_value - addr;
 44.1318 +					nearest = symtable;
 44.1319 +				}
 44.1320 +				symtable++;
 44.1321 +			}
 44.1322 +			if (nearest)
 44.1323 +			{
 44.1324 +				info->dli_saddr = nearest->n_value + ((void *)p - addr);
 44.1325 +				info->dli_sname = (char *)(strtable + nearest->n_un.n_strx);
 44.1326 +			}
 44.1327 +		}
 44.1328 +	}
 44.1329 +	dounlock();
 44.1330 +	return 1;
 44.1331 +}
 44.1332 +#endif
 44.1333 +
 44.1334 +/*
 44.1335 + * Implement the dlfunc() interface, which behaves exactly the same as
 44.1336 + * dlsym() except that it returns a function pointer instead of a data
 44.1337 + * pointer.  This can be used by applications to avoid compiler warnings
 44.1338 + * about undefined behavior, and is intended as prior art for future
 44.1339 + * POSIX standardization.  This function requires that all pointer types
 44.1340 + * have the same representation, which is true on all platforms FreeBSD
 44.1341 + * runs on, but is not guaranteed by the C standard.
 44.1342 + */
 44.1343 +#if 0 
 44.1344 +static dlfunc_t SDL_OSX_dlfunc(void * dl_restrict handle, const char * dl_restrict symbol)
 44.1345 +{
 44.1346 +	union
 44.1347 +	{
 44.1348 +		void *d;
 44.1349 +		dlfunc_t f;
 44.1350 +	} rv;
 44.1351 +	int sym_len = SDL_strlen(symbol);
 44.1352 +	char *malloc_sym = NULL;
 44.1353 +	dolock();
 44.1354 +	malloc_sym = SDL_malloc(sym_len + 2);
 44.1355 +	if (malloc_sym)
 44.1356 +	{
 44.1357 +		SDL_snprintf(malloc_sym, sym_len+2, "_%s", symbol);
 44.1358 +		rv.d = dlsymIntern(handle, malloc_sym, 1);
 44.1359 +		SDL_free(malloc_sym);
 44.1360 +	}
 44.1361 +	else
 44.1362 +	{
 44.1363 +		error("Unable to allocate memory");
 44.1364 +		goto dlfuncerror;
 44.1365 +	}
 44.1366 +	dounlock();
 44.1367 +	return rv.f;
 44.1368 +  dlfuncerror:
 44.1369 +	dounlock();
 44.1370 +	return NULL;
 44.1371 +}
 44.1372 +#endif
 44.1373 +
 44.1374 +
 44.1375 +
 44.1376 +/* dlcompat ends, here's the SDL interface...  --ryan.  */
 44.1377 +
 44.1378 +
 44.1379 +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 44.1380 +/* System dependent library loading routines                           */
 44.1381 +
 44.1382 +#include "SDL_loadso.h"
 44.1383 +
 44.1384 +void *SDL_LoadObject(const char *sofile)
 44.1385 +{
 44.1386 +	void *handle = SDL_OSX_dlopen(sofile, RTLD_NOW);
 44.1387 +	const char *loaderror = SDL_OSX_dlerror();
 44.1388 +	if ( handle == NULL ) {
 44.1389 +		SDL_SetError("Failed loading %s: %s", sofile, loaderror);
 44.1390 +	}
 44.1391 +	return(handle);
 44.1392 +}
 44.1393 +
 44.1394 +void *SDL_LoadFunction(void *handle, const char *name)
 44.1395 +{
 44.1396 +	void *symbol = SDL_OSX_dlsym(handle, name);
 44.1397 +	if ( symbol == NULL ) {
 44.1398 +		SDL_SetError("Failed loading %s: %s", name, SDL_OSX_dlerror());
 44.1399 +	}
 44.1400 +	return(symbol);
 44.1401 +}
 44.1402 +
 44.1403 +void SDL_UnloadObject(void *handle)
 44.1404 +{
 44.1405 +	if ( handle != NULL ) {
 44.1406 +		SDL_OSX_dlclose(handle);
 44.1407 +	}
 44.1408 +}
 44.1409 +
 44.1410 +#endif /* SDL_LOADSO_DLCOMPAT */
    45.1 --- a/src/loadso/macosx/SDL_sysloadso.c	Mon May 01 06:58:33 2006 +0000
    45.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    45.3 @@ -1,1404 +0,0 @@
    45.4 -/*
    45.5 -    SDL - Simple DirectMedia Layer
    45.6 -    Copyright (C) 1997-2006 Sam Lantinga
    45.7 -
    45.8 -    This library is free software; you can redistribute it and/or
    45.9 -    modify it under the terms of the GNU Lesser General Public
   45.10 -    License as published by the Free Software Foundation; either
   45.11 -    version 2.1 of the License, or (at your option) any later version.
   45.12 -
   45.13 -    This library is distributed in the hope that it will be useful,
   45.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   45.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   45.16 -    Lesser General Public License for more details.
   45.17 -
   45.18 -    You should have received a copy of the GNU Lesser General Public
   45.19 -    License along with this library; if not, write to the Free Software
   45.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   45.21 -
   45.22 -    Sam Lantinga
   45.23 -    slouken@libsdl.org
   45.24 -*/
   45.25 -#include "SDL_config.h"
   45.26 -
   45.27 -#ifdef SDL_LOADSO_DLCOMPAT
   45.28 -
   45.29 -/* Please note that dlcompat apparently ships in current Mac OS X versions
   45.30 - *  as a system library that provides compatibility with the Unix "dlopen"
   45.31 - *  interface. In order to allow SDL to work on older OS X releases and also
   45.32 - *  not conflict with the system lib on newer versions, we include dlcompat
   45.33 - *  in SDL and change the symbols to prevent symbol clash with any existing
   45.34 - *  system libraries.  --ryan.
   45.35 - */
   45.36 -
   45.37 -/* here is the dlcompat license: */
   45.38 -
   45.39 -/*
   45.40 -Copyright (c) 2002 Jorge Acereda  <jacereda@users.sourceforge.net> &
   45.41 -                   Peter O'Gorman <ogorman@users.sourceforge.net>
   45.42 -                   
   45.43 -Portions may be copyright others, see the AUTHORS file included with this
   45.44 -distribution.
   45.45 -
   45.46 -Maintained by Peter O'Gorman <ogorman@users.sourceforge.net>
   45.47 -
   45.48 -Bug Reports and other queries should go to <ogorman@users.sourceforge.net>
   45.49 -
   45.50 -Permission is hereby granted, free of charge, to any person obtaining
   45.51 -a copy of this software and associated documentation files (the
   45.52 -"Software"), to deal in the Software without restriction, including
   45.53 -without limitation the rights to use, copy, modify, merge, publish,
   45.54 -distribute, sublicense, and/or sell copies of the Software, and to
   45.55 -permit persons to whom the Software is furnished to do so, subject to
   45.56 -the following conditions:
   45.57 -
   45.58 -The above copyright notice and this permission notice shall be
   45.59 -included in all copies or substantial portions of the Software.
   45.60 -
   45.61 -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
   45.62 -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   45.63 -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
   45.64 -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
   45.65 -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
   45.66 -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
   45.67 -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   45.68 -*/
   45.69 -
   45.70 -#include <pthread.h>
   45.71 -#include <sys/types.h>
   45.72 -#include <sys/stat.h>
   45.73 -#include <stdarg.h>
   45.74 -#include <limits.h>
   45.75 -#include <mach-o/dyld.h>
   45.76 -#include <mach-o/nlist.h>
   45.77 -#include <mach-o/getsect.h>
   45.78 -
   45.79 -#include "SDL_stdinc.h"
   45.80 -
   45.81 -/* Just playing to see if it would compile with the freebsd headers, it does,
   45.82 - * but because of the different values for RTLD_LOCAL etc, it would break binary
   45.83 - * compat... oh well
   45.84 - */
   45.85 -#ifndef __BSD_VISIBLE
   45.86 -#define __BSD_VISIBLE 1
   45.87 -#endif
   45.88 -
   45.89 -/*include "dlfcn.h"*/
   45.90 -#ifdef __cplusplus
   45.91 -extern "C" {
   45.92 -#endif
   45.93 -
   45.94 -#if defined (__GNUC__) && __GNUC__ > 3
   45.95 -#define dl_restrict __restrict
   45.96 -#else
   45.97 -#define dl_restrict
   45.98 -#endif
   45.99 -
  45.100 -#ifndef _POSIX_SOURCE
  45.101 -/*
  45.102 - * Structure filled in by dladdr().
  45.103 - */
  45.104 -typedef struct SDL_OSX_dl_info {
  45.105 -        const char      *dli_fname;     /* Pathname of shared object */
  45.106 -        void            *dli_fbase;     /* Base address of shared object */
  45.107 -        const char      *dli_sname;     /* Name of nearest symbol */
  45.108 -        void            *dli_saddr;     /* Address of nearest symbol */
  45.109 -} SDL_OSX_Dl_info;
  45.110 -
  45.111 -static int SDL_OSX_dladdr(const void * dl_restrict, SDL_OSX_Dl_info * dl_restrict);
  45.112 -#endif /* ! _POSIX_SOURCE */
  45.113 -
  45.114 -static int SDL_OSX_dlclose(void * handle);
  45.115 -static const char * SDL_OSX_dlerror(void);
  45.116 -static void * SDL_OSX_dlopen(const char *path, int mode);
  45.117 -static void * SDL_OSX_dlsym(void * dl_restrict handle, const char * dl_restrict symbol);
  45.118 -
  45.119 -#define RTLD_LAZY	0x1
  45.120 -#define RTLD_NOW	0x2
  45.121 -#define RTLD_LOCAL	0x4
  45.122 -#define RTLD_GLOBAL	0x8
  45.123 -
  45.124 -#ifndef _POSIX_SOURCE
  45.125 -#define RTLD_NOLOAD	0x10
  45.126 -#define RTLD_NODELETE	0x80
  45.127 -
  45.128 -/*
  45.129 - * Special handle arguments for SDL_OSX_dlsym().
  45.130 - */
  45.131 -#define	RTLD_NEXT		((void *) -1)	/* Search subsequent objects. */
  45.132 -#define	RTLD_DEFAULT	((void *) -2)	/* Use default search algorithm. */
  45.133 -#endif /* ! _POSIX_SOURCE */
  45.134 -
  45.135 -#ifdef __cplusplus
  45.136 -}
  45.137 -#endif
  45.138 -
  45.139 -#ifndef dl_restrict
  45.140 -#define dl_restrict __restrict
  45.141 -#endif
  45.142 -/* This is not available on 10.1 */
  45.143 -#ifndef LC_LOAD_WEAK_DYLIB
  45.144 -#define	LC_LOAD_WEAK_DYLIB (0x18 | LC_REQ_DYLD)
  45.145 -#endif
  45.146 -
  45.147 -/* With this stuff here, this thing may actually compile/run on 10.0 systems
  45.148 - * Not that I have a 10.0 system to test it on anylonger
  45.149 - */
  45.150 -#ifndef LC_REQ_DYLD
  45.151 -#define LC_REQ_DYLD 0x80000000
  45.152 -#endif
  45.153 -#ifndef NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED
  45.154 -#define NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED 0x4
  45.155 -#endif
  45.156 -#ifndef NSADDIMAGE_OPTION_RETURN_ON_ERROR
  45.157 -#define NSADDIMAGE_OPTION_RETURN_ON_ERROR 0x1
  45.158 -#endif
  45.159 -#ifndef NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
  45.160 -#define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND 0x0
  45.161 -#endif
  45.162 -#ifndef NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR
  45.163 -#define NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR 0x4
  45.164 -#endif
  45.165 -/* These symbols will be looked for in dyld */
  45.166 -static const struct mach_header *(*dyld_NSAddImage) (const char *, unsigned long) = 0;
  45.167 -static int (*dyld_NSIsSymbolNameDefinedInImage) (const struct mach_header *, const char *) = 0;
  45.168 -static NSSymbol(*dyld_NSLookupSymbolInImage)
  45.169 -	(const struct mach_header *, const char *, unsigned long) = 0;
  45.170 -
  45.171 -/* Define this to make dlcompat reuse data block. This way in theory we save
  45.172 - * a little bit of overhead. However we then couldn't correctly catch excess
  45.173 - * calls to SDL_OSX_dlclose(). Hence we don't use this feature
  45.174 - */
  45.175 -#undef REUSE_STATUS
  45.176 -
  45.177 -/* Size of the internal error message buffer (used by dlerror()) */
  45.178 -#define ERR_STR_LEN			251
  45.179 -
  45.180 -/* Maximum number of search paths supported by getSearchPath */
  45.181 -#define MAX_SEARCH_PATHS	32
  45.182 -
  45.183 -
  45.184 -#define MAGIC_DYLIB_OFI ((NSObjectFileImage) 'DYOF')
  45.185 -#define MAGIC_DYLIB_MOD ((NSModule) 'DYMO')
  45.186 -
  45.187 -/* internal flags */
  45.188 -#define DL_IN_LIST 0x01
  45.189 -
  45.190 -/* our mutex */
  45.191 -static pthread_mutex_t dlcompat_mutex;
  45.192 -/* Our thread specific storage
  45.193 - */
  45.194 -static pthread_key_t dlerror_key;
  45.195 -
  45.196 -struct dlthread
  45.197 -{
  45.198 -	int lockcnt;
  45.199 -	unsigned char errset;
  45.200 -	char errstr[ERR_STR_LEN];
  45.201 -};
  45.202 -
  45.203 -/* This is our central data structure. Whenever a module is loaded via
  45.204 - * SDL_OSX_dlopen(), we create such a struct.
  45.205 - */
  45.206 -struct dlstatus
  45.207 -{
  45.208 -	struct dlstatus *next;		/* pointer to next element in the linked list */
  45.209 -	NSModule module;
  45.210 -	const struct mach_header *lib;
  45.211 -	int refs;					/* reference count */
  45.212 -	int mode;					/* mode in which this module was loaded */
  45.213 -	dev_t device;
  45.214 -	ino_t inode;
  45.215 -	int flags;					/* Any internal flags we may need */
  45.216 -};
  45.217 -
  45.218 -/* Head node of the dlstatus list */
  45.219 -static struct dlstatus mainStatus = { 0, MAGIC_DYLIB_MOD, NULL, -1, RTLD_GLOBAL, 0, 0, 0 };
  45.220 -static struct dlstatus *stqueue = &mainStatus;
  45.221 -
  45.222 -
  45.223 -/* Storage for the last error message (used by dlerror()) */
  45.224 -/* static char err_str[ERR_STR_LEN]; */
  45.225 -/* static int err_filled = 0; */
  45.226 -
  45.227 -/* Prototypes to internal functions */
  45.228 -static void debug(const char *fmt, ...);
  45.229 -static void error(const char *str, ...);
  45.230 -static const char *safegetenv(const char *s);
  45.231 -static const char *searchList(void);
  45.232 -static const char *getSearchPath(int i);
  45.233 -static const char *getFullPath(int i, const char *file);
  45.234 -static const struct stat *findFile(const char *file, const char **fullPath);
  45.235 -static int isValidStatus(struct dlstatus *status);
  45.236 -static inline int isFlagSet(int mode, int flag);
  45.237 -static struct dlstatus *lookupStatus(const struct stat *sbuf);
  45.238 -static void insertStatus(struct dlstatus *dls, const struct stat *sbuf);
  45.239 -static int promoteLocalToGlobal(struct dlstatus *dls);
  45.240 -static void *reference(struct dlstatus *dls, int mode);
  45.241 -static void *dlsymIntern(struct dlstatus *dls, const char *symbol, int canSetError);
  45.242 -static struct dlstatus *allocStatus(void);
  45.243 -static struct dlstatus *loadModule(const char *path, const struct stat *sbuf, int mode);
  45.244 -static NSSymbol *search_linked_libs(const struct mach_header *mh, const char *symbol);
  45.245 -static const char *get_lib_name(const struct mach_header *mh);
  45.246 -static const struct mach_header *get_mach_header_from_NSModule(NSModule * mod);
  45.247 -static void dlcompat_init_func(void);
  45.248 -static inline void dlcompat_init_check(void);
  45.249 -static inline void dolock(void);
  45.250 -static inline void dounlock(void);
  45.251 -static void dlerrorfree(void *data);
  45.252 -static void resetdlerror(void);
  45.253 -static const struct mach_header *my_find_image(const char *name);
  45.254 -static const struct mach_header *image_for_address(const void *address);
  45.255 -static inline char *dyld_error_str(void);
  45.256 -
  45.257 -#if FINK_BUILD
  45.258 -/* Two Global Functions */
  45.259 -static void *dlsym_prepend_underscore(void *handle, const char *symbol);
  45.260 -static void *dlsym_auto_underscore(void *handle, const char *symbol);
  45.261 -
  45.262 -/* And their _intern counterparts */
  45.263 -static void *dlsym_prepend_underscore_intern(void *handle, const char *symbol);
  45.264 -static void *dlsym_auto_underscore_intern(void *handle, const char *symbol);
  45.265 -#endif
  45.266 -
  45.267 -/* Functions */
  45.268 -
  45.269 -static void debug(const char *fmt, ...)
  45.270 -{
  45.271 -#if DEBUG > 1
  45.272 -	va_list arg;
  45.273 -	va_start(arg, fmt);
  45.274 -	fprintf(stderr, "DLDEBUG: ");
  45.275 -	vfprintf(stderr, fmt, arg);
  45.276 -	fprintf(stderr, "\n");
  45.277 -	fflush(stderr);
  45.278 -	va_end(arg);
  45.279 -#endif
  45.280 -}
  45.281 -
  45.282 -static void error(const char *str, ...)
  45.283 -{
  45.284 -	va_list arg;
  45.285 -	struct dlthread  *tss;
  45.286 -	char * err_str;
  45.287 -	va_start(arg, str);
  45.288 -	tss = pthread_getspecific(dlerror_key);
  45.289 -	err_str = tss->errstr;
  45.290 -	SDL_strlcpy(err_str, "dlcompat: ", ERR_STR_LEN);
  45.291 -	vsnprintf(err_str + 10, ERR_STR_LEN - 10, str, arg);
  45.292 -	va_end(arg);
  45.293 -	debug("ERROR: %s\n", err_str);
  45.294 -	tss->errset = 1;
  45.295 -}
  45.296 -
  45.297 -static void warning(const char *str)
  45.298 -{
  45.299 -#if DEBUG > 0
  45.300 -	fprintf(stderr, "WARNING: dlcompat: %s\n", str);
  45.301 -#endif
  45.302 -}
  45.303 -
  45.304 -static const char *safegetenv(const char *s)
  45.305 -{
  45.306 -	const char *ss = SDL_getenv(s);
  45.307 -	return ss ? ss : "";
  45.308 -}
  45.309 -
  45.310 -/* because this is only used for debugging and error reporting functions, we
  45.311 - * don't really care about how elegant it is... it could use the load
  45.312 - * commands to find the install name of the library, but...
  45.313 - */
  45.314 -static const char *get_lib_name(const struct mach_header *mh)
  45.315 -{
  45.316 -	unsigned long count = _dyld_image_count();
  45.317 -	unsigned long i;
  45.318 -	const char *val = NULL;
  45.319 -	if (mh)
  45.320 -	{
  45.321 -		for (i = 0; i < count; i++)
  45.322 -		{
  45.323 -			if (mh == _dyld_get_image_header(i))
  45.324 -			{
  45.325 -				val = _dyld_get_image_name(i);
  45.326 -				break;
  45.327 -			}
  45.328 -		}
  45.329 -	}
  45.330 -	return val;
  45.331 -}
  45.332 -
  45.333 -/* Returns the mach_header for the module bu going through all the loaded images
  45.334 - * and finding the one with the same name as the module. There really ought to be
  45.335 - * an api for doing this, would be faster, but there isn't one right now
  45.336 - */
  45.337 -static const struct mach_header *get_mach_header_from_NSModule(NSModule * mod)
  45.338 -{
  45.339 -	const char *mod_name = NSNameOfModule(mod);
  45.340 -	struct mach_header *mh = NULL;
  45.341 -	unsigned long count = _dyld_image_count();
  45.342 -	unsigned long i;
  45.343 -	debug("Module name: %s", mod_name);
  45.344 -	for (i = 0; i < count; i++)
  45.345 -	{
  45.346 -		if (!SDL_strcmp(mod_name, _dyld_get_image_name(i)))
  45.347 -		{
  45.348 -			mh = _dyld_get_image_header(i);
  45.349 -			break;
  45.350 -		}
  45.351 -	}
  45.352 -	return mh;
  45.353 -}
  45.354 -
  45.355 -
  45.356 -/* Compute and return a list of all directories that we should search when
  45.357 - * trying to locate a module. We first look at the values of LD_LIBRARY_PATH
  45.358 - * and DYLD_LIBRARY_PATH, and then finally fall back to looking into
  45.359 - * /usr/lib and /lib. Since both of the environments variables can contain a
  45.360 - * list of colon seperated paths, we simply concat them and the two other paths
  45.361 - * into one big string, which we then can easily parse.
  45.362 - * Splitting this string into the actual path list is done by getSearchPath()
  45.363 - */
  45.364 -static const char *searchList()
  45.365 -{
  45.366 -	size_t buf_size;
  45.367 -	static char *buf=NULL;
  45.368 -	const char *ldlp = safegetenv("LD_LIBRARY_PATH");
  45.369 -	const char *dyldlp = safegetenv("DYLD_LIBRARY_PATH");
  45.370 -	const char *stdpath = SDL_getenv("DYLD_FALLBACK_LIBRARY_PATH");
  45.371 -	if (!stdpath)
  45.372 -		stdpath = "/usr/local/lib:/lib:/usr/lib";
  45.373 -	if (!buf)
  45.374 -	{	
  45.375 -		buf_size = SDL_strlen(ldlp) + SDL_strlen(dyldlp) + SDL_strlen(stdpath) + 4;
  45.376 -		buf = SDL_malloc(buf_size);
  45.377 -		SDL_snprintf(buf, buf_size, "%s%s%s%s%s%c", dyldlp, (dyldlp[0] ? ":" : ""), ldlp, (ldlp[0] ? ":" : ""),
  45.378 -				 stdpath, '\0');
  45.379 -	}
  45.380 -	return buf;
  45.381 -}
  45.382 -
  45.383 -/* Returns the ith search path from the list as computed by searchList() */
  45.384 -static const char *getSearchPath(int i)
  45.385 -{
  45.386 -	static const char *list = 0;
  45.387 -	static char **path = (char **)0;
  45.388 -	static int end = 0;
  45.389 -	static int numsize = MAX_SEARCH_PATHS;
  45.390 -	static char **tmp;
  45.391 -	/* So we can call SDL_free() in the "destructor" we use i=-1 to return the alloc'd array */
  45.392 -	if (i == -1)
  45.393 -	{
  45.394 -		return (const char*)path;
  45.395 -	}
  45.396 -	if (!path)
  45.397 -	{
  45.398 -		path = (char **)SDL_calloc(MAX_SEARCH_PATHS, sizeof(char **));
  45.399 -	}
  45.400 -	if (!list && !end)
  45.401 -		list = searchList();
  45.402 -	if (i >= (numsize))
  45.403 -	{
  45.404 -		debug("Increasing size for long PATH");
  45.405 -		tmp = (char **)SDL_calloc((MAX_SEARCH_PATHS + numsize), sizeof(char **));
  45.406 -		if (tmp)
  45.407 -		{
  45.408 -			SDL_memcpy(tmp, path, sizeof(char **) * numsize);
  45.409 -			SDL_free(path);
  45.410 -			path = tmp;
  45.411 -			numsize += MAX_SEARCH_PATHS;
  45.412 -		}
  45.413 -		else
  45.414 -		{
  45.415 -			return 0;
  45.416 -		}
  45.417 -	}
  45.418 -
  45.419 -	while (!path[i] && !end)
  45.420 -	{
  45.421 -		path[i] = strsep((char **)&list, ":");
  45.422 -
  45.423 -		if (path[i][0] == 0)
  45.424 -			path[i] = 0;
  45.425 -		end = (list == 0);
  45.426 -	}
  45.427 -	return path[i];
  45.428 -}
  45.429 -
  45.430 -static const char *getFullPath(int i, const char *file)
  45.431 -{
  45.432 -	static char buf[PATH_MAX];
  45.433 -	const char *path = getSearchPath(i);
  45.434 -	if (path)
  45.435 -	{
  45.436 -		SDL_snprintf(buf, PATH_MAX, "%s/%s", path, file);
  45.437 -	}
  45.438 -	return path ? buf : 0;
  45.439 -}
  45.440 -
  45.441 -/* Given a file name, try to determine the full path for that file. Starts
  45.442 - * its search in the current directory, and then tries all paths in the 
  45.443 - * search list in the order they are specified there.
  45.444 - */
  45.445 -static const struct stat *findFile(const char *file, const char **fullPath)
  45.446 -{
  45.447 -	int i = 0;
  45.448 -	static struct stat sbuf;
  45.449 -	char *fileName;
  45.450 -	debug("finding file %s", file);
  45.451 -	*fullPath = file;
  45.452 -	if (0 == stat(file, &sbuf))
  45.453 -		return &sbuf;
  45.454 -	if (SDL_strchr(file, '/'))
  45.455 -		return 0;				/* If the path had a / we don't look in env var places */
  45.456 -	fileName = NULL;
  45.457 -	if (!fileName)
  45.458 -		fileName = (char *)file;
  45.459 -	while ((*fullPath = getFullPath(i++, fileName)))
  45.460 -	{
  45.461 -		if (0 == stat(*fullPath, &sbuf))
  45.462 -			return &sbuf;
  45.463 -	}
  45.464 -	;
  45.465 -	return 0;
  45.466 -}
  45.467 -
  45.468 -/* Determine whether a given dlstatus is valid or not */
  45.469 -static int isValidStatus(struct dlstatus *status)
  45.470 -{
  45.471 -	/* Walk the list to verify status is contained in it */
  45.472 -	struct dlstatus *dls = stqueue;
  45.473 -	while (dls && status != dls)
  45.474 -		dls = dls->next;
  45.475 -	if (dls == 0)
  45.476 -		error("invalid handle");
  45.477 -	else if ((dls->module == 0) || (dls->refs == 0))
  45.478 -		error("handle to closed library");
  45.479 -	else
  45.480 -		return TRUE;
  45.481 -	return FALSE;
  45.482 -}
  45.483 -
  45.484 -static inline int isFlagSet(int mode, int flag)
  45.485 -{
  45.486 -	return (mode & flag) == flag;
  45.487 -}
  45.488 -
  45.489 -static struct dlstatus *lookupStatus(const struct stat *sbuf)
  45.490 -{
  45.491 -	struct dlstatus *dls = stqueue;
  45.492 -	debug("looking for status");
  45.493 -	while (dls && ( /* isFlagSet(dls->mode, RTLD_UNSHARED) */ 0
  45.494 -				   || sbuf->st_dev != dls->device || sbuf->st_ino != dls->inode))
  45.495 -		dls = dls->next;
  45.496 -	return dls;
  45.497 -}
  45.498 -
  45.499 -static void insertStatus(struct dlstatus *dls, const struct stat *sbuf)
  45.500 -{
  45.501 -	debug("inserting status");
  45.502 -	dls->inode = sbuf->st_ino;
  45.503 -	dls->device = sbuf->st_dev;
  45.504 -	dls->refs = 0;
  45.505 -	dls->mode = 0;
  45.506 -	if ((dls->flags & DL_IN_LIST) == 0)
  45.507 -	{
  45.508 -		dls->next = stqueue;
  45.509 -		stqueue = dls;
  45.510 -		dls->flags |= DL_IN_LIST;
  45.511 -	}
  45.512 -}
  45.513 -
  45.514 -static struct dlstatus *allocStatus()
  45.515 -{
  45.516 -	struct dlstatus *dls;
  45.517 -#ifdef REUSE_STATUS
  45.518 -	dls = stqueue;
  45.519 -	while (dls && dls->module)
  45.520 -		dls = dls->next;
  45.521 -	if (!dls)
  45.522 -#endif
  45.523 -		dls = SDL_calloc(sizeof(*dls),1);
  45.524 -	return dls;
  45.525 -}
  45.526 -
  45.527 -static int promoteLocalToGlobal(struct dlstatus *dls)
  45.528 -{
  45.529 -	static int (*p) (NSModule module) = 0;
  45.530 -	debug("promoting");
  45.531 -	if (!p)
  45.532 -		_dyld_func_lookup("__dyld_NSMakePrivateModulePublic", (unsigned long *)&p);
  45.533 -	return (dls->module == MAGIC_DYLIB_MOD) || (p && p(dls->module));
  45.534 -}
  45.535 -
  45.536 -static void *reference(struct dlstatus *dls, int mode)
  45.537 -{
  45.538 -	if (dls)
  45.539 -	{
  45.540 -		if (dls->module == MAGIC_DYLIB_MOD && isFlagSet(mode, RTLD_LOCAL))
  45.541 -		{
  45.542 -			warning("trying to open a .dylib with RTLD_LOCAL");
  45.543 -			error("unable to open a .dylib with RTLD_LOCAL");
  45.544 -			return NULL;
  45.545 -		}
  45.546 -		if (isFlagSet(mode, RTLD_GLOBAL) &&
  45.547 -			!isFlagSet(dls->mode, RTLD_GLOBAL) && !promoteLocalToGlobal(dls))
  45.548 -		{
  45.549 -			error("unable to promote local module to global");
  45.550 -			return NULL;
  45.551 -		}
  45.552 -		dls->mode |= mode;
  45.553 -		dls->refs++;
  45.554 -	}
  45.555 -	else
  45.556 -		debug("reference called with NULL argument");
  45.557 -
  45.558 -	return dls;
  45.559 -}
  45.560 -
  45.561 -static const struct mach_header *my_find_image(const char *name)
  45.562 -{
  45.563 -	const struct mach_header *mh = 0;
  45.564 -	const char *id = NULL;
  45.565 -	int i = _dyld_image_count();
  45.566 -	int j;
  45.567 -	mh = (struct mach_header *)
  45.568 -		dyld_NSAddImage(name, NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED |
  45.569 -						NSADDIMAGE_OPTION_RETURN_ON_ERROR);
  45.570 -	if (!mh)
  45.571 -	{
  45.572 -		for (j = 0; j < i; j++)
  45.573 -		{
  45.574 -			id = _dyld_get_image_name(j);
  45.575 -			if (!SDL_strcmp(id, name))
  45.576 -			{
  45.577 -				mh = _dyld_get_image_header(j);
  45.578 -				break;
  45.579 -			}
  45.580 -		}
  45.581 -	}
  45.582 -	return mh;
  45.583 -}
  45.584 -
  45.585 -/*
  45.586 - * dyld adds libraries by first adding the directly dependant libraries in link order, and
  45.587 - * then adding the dependencies for those libraries, so we should do the same... but we don't
  45.588 - * bother adding the extra dependencies, if the symbols are neither in the loaded image nor
  45.589 - * any of it's direct dependencies, then it probably isn't there.
  45.590 - */
  45.591 -static NSSymbol *search_linked_libs(const struct mach_header * mh, const char *symbol)
  45.592 -{
  45.593 -	unsigned int n;
  45.594 -	struct load_command *lc = 0;
  45.595 -	struct mach_header *wh;
  45.596 -	NSSymbol *nssym = 0;
  45.597 -	if (dyld_NSAddImage && dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage)
  45.598 -	{
  45.599 -		lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
  45.600 -		for (n = 0; n < mh->ncmds; n++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
  45.601 -		{
  45.602 -			if ((LC_LOAD_DYLIB == lc->cmd) || (LC_LOAD_WEAK_DYLIB == lc->cmd))
  45.603 -			{
  45.604 -				if ((wh = (struct mach_header *)
  45.605 -					 my_find_image((char *)(((struct dylib_command *)lc)->dylib.name.offset +
  45.606 -											(char *)lc))))
  45.607 -				{
  45.608 -					if (dyld_NSIsSymbolNameDefinedInImage(wh, symbol))
  45.609 -					{
  45.610 -						nssym = dyld_NSLookupSymbolInImage(wh,
  45.611 -														   symbol,
  45.612 -														   NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
  45.613 -														   NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
  45.614 -						break;
  45.615 -					}
  45.616 -				}
  45.617 -			}
  45.618 -		}
  45.619 -		if ((!nssym) && NSIsSymbolNameDefined(symbol))
  45.620 -		{
  45.621 -			/* I've never seen this debug message...*/
  45.622 -			debug("Symbol \"%s\" is defined but was not found", symbol);
  45.623 -		}
  45.624 -	}
  45.625 -	return nssym;
  45.626 -}
  45.627 -
  45.628 -/* Up to the caller to SDL_free() returned string */
  45.629 -static inline char *dyld_error_str()
  45.630 -{
  45.631 -	NSLinkEditErrors dylder;
  45.632 -	int dylderno;
  45.633 -	const char *dylderrstr;
  45.634 -	const char *dyldfile;
  45.635 -	char* retStr = NULL;
  45.636 -	NSLinkEditError(&dylder, &dylderno, &dyldfile, &dylderrstr);
  45.637 -	if (dylderrstr && *dylderrstr)
  45.638 -	{
  45.639 -		retStr = SDL_strdup(dylderrstr);
  45.640 -	}
  45.641 -	return retStr;
  45.642 -}
  45.643 -
  45.644 -static void *dlsymIntern(struct dlstatus *dls, const char *symbol, int canSetError)
  45.645 -{
  45.646 -  NSSymbol *nssym = 0;
  45.647 -#ifdef __GCC__  
  45.648 -	void *caller = __builtin_return_address(1);	/* Be *very* careful about inlining */
  45.649 -#else
  45.650 -	void *caller = NULL;
  45.651 -#endif
  45.652 -	const struct mach_header *caller_mh = 0;
  45.653 -	char *savedErrorStr = NULL;
  45.654 -	resetdlerror();
  45.655 -#ifndef RTLD_SELF
  45.656 -#define	RTLD_SELF		((void *) -3)
  45.657 -#endif
  45.658 -	if (NULL == dls)
  45.659 -		dls = RTLD_SELF;
  45.660 -	if ((RTLD_NEXT == dls) || (RTLD_SELF == dls))
  45.661 -	{
  45.662 -		if (dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage && caller)
  45.663 -		  {
  45.664 -			caller_mh = image_for_address(caller);
  45.665 -			if (RTLD_SELF == dls)
  45.666 -			{
  45.667 -				/* FIXME: We should be using the NSModule api, if SELF is an MH_BUNDLE
  45.668 -				 * But it appears to work anyway, and looking at the code in dyld_libfuncs.c
  45.669 -				 * this is acceptable.
  45.670 -				 */
  45.671 -				if (dyld_NSIsSymbolNameDefinedInImage(caller_mh, symbol))
  45.672 -				{
  45.673 -					nssym = dyld_NSLookupSymbolInImage(caller_mh,
  45.674 -													   symbol,
  45.675 -													   NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
  45.676 -													   NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
  45.677 -				}
  45.678 -			}
  45.679 -			if (!nssym)
  45.680 -			{
  45.681 -				if (RTLD_SELF == dls)
  45.682 -					savedErrorStr = dyld_error_str();
  45.683 -				nssym = search_linked_libs(caller_mh, symbol);
  45.684 -			}
  45.685 -		}
  45.686 -		else
  45.687 -		{
  45.688 -			if (canSetError)
  45.689 -				error("RTLD_SELF and RTLD_NEXT are not supported");
  45.690 -			return NULL;
  45.691 -		}
  45.692 -	}
  45.693 -	if (!nssym)
  45.694 -	{
  45.695 -
  45.696 -		if (RTLD_DEFAULT == dls)
  45.697 -		{
  45.698 -			dls = &mainStatus;
  45.699 -		}
  45.700 -		if (!isValidStatus(dls))
  45.701 -			return NULL;
  45.702 -
  45.703 -		if (dls->module != MAGIC_DYLIB_MOD)
  45.704 -		{
  45.705 -			nssym = NSLookupSymbolInModule(dls->module, symbol);
  45.706 -			if (!nssym && NSIsSymbolNameDefined(symbol))
  45.707 -			{
  45.708 -				debug("Searching dependencies");
  45.709 -				savedErrorStr = dyld_error_str();
  45.710 -				nssym = search_linked_libs(get_mach_header_from_NSModule(dls->module), symbol);
  45.711 -			}
  45.712 -		}
  45.713 -		else if (dls->lib && dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage)
  45.714 -		{
  45.715 -			if (dyld_NSIsSymbolNameDefinedInImage(dls->lib, symbol))
  45.716 -			{
  45.717 -				nssym = dyld_NSLookupSymbolInImage(dls->lib,
  45.718 -												   symbol,
  45.719 -												   NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
  45.720 -												   NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
  45.721 -			}
  45.722 -			else if (NSIsSymbolNameDefined(symbol))
  45.723 -			{
  45.724 -				debug("Searching dependencies");
  45.725 -				savedErrorStr = dyld_error_str();
  45.726 -				nssym = search_linked_libs(dls->lib, symbol);
  45.727 -			}
  45.728 -		}
  45.729 -		else if (dls->module == MAGIC_DYLIB_MOD)
  45.730 -		{
  45.731 -			/* Global context, use NSLookupAndBindSymbol */
  45.732 -			if (NSIsSymbolNameDefined(symbol))
  45.733 -			{
  45.734 -				/* There doesn't seem to be a return on error option for this call???
  45.735 -				   this is potentially broken, if binding fails, it will improperly
  45.736 -				   exit the application. */
  45.737 -				nssym = NSLookupAndBindSymbol(symbol);
  45.738 -			}
  45.739 -			else
  45.740 -			{
  45.741 -				if (savedErrorStr)
  45.742 -					SDL_free(savedErrorStr);			
  45.743 -				savedErrorStr = SDL_malloc(256);
  45.744 -				SDL_snprintf(savedErrorStr, 256, "Symbol \"%s\" not in global context",symbol);	
  45.745 -			}
  45.746 -		}
  45.747 -	}
  45.748 -	/* Error reporting */
  45.749 -	if (!nssym)
  45.750 -	{
  45.751 -		if (!savedErrorStr || !SDL_strlen(savedErrorStr))
  45.752 -		{
  45.753 -			if (savedErrorStr)
  45.754 -				SDL_free(savedErrorStr);
  45.755 -			savedErrorStr = SDL_malloc(256);
  45.756 -			SDL_snprintf(savedErrorStr, 256,"Symbol \"%s\" not found",symbol);
  45.757 -		}
  45.758 -		if (canSetError)
  45.759 -		{
  45.760 -			error(savedErrorStr);
  45.761 -		}
  45.762 -		else
  45.763 -		{
  45.764 -			debug(savedErrorStr);
  45.765 -		}
  45.766 -		if (savedErrorStr)
  45.767 -			SDL_free(savedErrorStr);
  45.768 -		return NULL;
  45.769 -	}
  45.770 -	return NSAddressOfSymbol(nssym);
  45.771 -}
  45.772 -
  45.773 -static struct dlstatus *loadModule(const char *path, const struct stat *sbuf, int mode)
  45.774 -{
  45.775 -	NSObjectFileImage ofi = 0;
  45.776 -	NSObjectFileImageReturnCode ofirc;
  45.777 -	struct dlstatus *dls;
  45.778 -	NSLinkEditErrors ler;
  45.779 -	int lerno;
  45.780 -	const char *errstr;
  45.781 -	const char *file;
  45.782 -	void (*init) (void);
  45.783 -
  45.784 -	ofirc = NSCreateObjectFileImageFromFile(path, &ofi);
  45.785 -	switch (ofirc)
  45.786 -	{
  45.787 -		case NSObjectFileImageSuccess:
  45.788 -			break;
  45.789 -		case NSObjectFileImageInappropriateFile:
  45.790 -			if (dyld_NSAddImage && dyld_NSIsSymbolNameDefinedInImage && dyld_NSLookupSymbolInImage)
  45.791 -			{	
  45.792 -				if (isFlagSet(mode, RTLD_LOCAL))
  45.793 -				{
  45.794 -					warning("trying to open a .dylib with RTLD_LOCAL");
  45.795 -					error("unable to open this file with RTLD_LOCAL");
  45.796 -					return NULL;
  45.797 -				}
  45.798 -			}
  45.799 -			else
  45.800 -			{
  45.801 -				error("opening this file is unsupported on this system");
  45.802 -				return NULL;
  45.803 -			}
  45.804 -			break;
  45.805 -		case NSObjectFileImageFailure:
  45.806 -			error("object file setup failure");
  45.807 -			return NULL;
  45.808 -		case NSObjectFileImageArch:
  45.809 -			error("no object for this architecture");
  45.810 -			return NULL;
  45.811 -		case NSObjectFileImageFormat:
  45.812 -			error("bad object file format");
  45.813 -			return NULL;
  45.814 -		case NSObjectFileImageAccess:
  45.815 -			error("can't read object file");
  45.816 -			return NULL;
  45.817 -		default:
  45.818 -			error("unknown error from NSCreateObjectFileImageFromFile()");
  45.819 -			return NULL;
  45.820 -	}
  45.821 -	dls = lookupStatus(sbuf);
  45.822 -	if (!dls)
  45.823 -	{
  45.824 -		dls = allocStatus();
  45.825 -	}
  45.826 -	if (!dls)
  45.827 -	{
  45.828 -		error("unable to allocate memory");
  45.829 -		return NULL;
  45.830 -	}
  45.831 -	//	dls->lib = 0;
  45.832 -	if (ofirc == NSObjectFileImageInappropriateFile)
  45.833 -	{
  45.834 -		if ((dls->lib = dyld_NSAddImage(path, NSADDIMAGE_OPTION_RETURN_ON_ERROR)))
  45.835 -		{
  45.836 -			debug("Dynamic lib loaded at %ld", dls->lib);
  45.837 -			ofi = MAGIC_DYLIB_OFI;
  45.838 -			dls->module = MAGIC_DYLIB_MOD;
  45.839 -			ofirc = NSObjectFileImageSuccess;
  45.840 -			/* Although it is possible with a bit of work to modify this so it works and
  45.841 -			   functions with RTLD_NOW, I don't deem it necessary at the moment */
  45.842 -		}
  45.843 -		if (!(dls->module))
  45.844 -		{
  45.845 -			NSLinkEditError(&ler, &lerno, &file, &errstr);
  45.846 -			if (!errstr || (!SDL_strlen(errstr)))
  45.847 -				error("Can't open this file type");
  45.848 -			else
  45.849 -				error(errstr);
  45.850 -			if ((dls->flags & DL_IN_LIST) == 0)
  45.851 -			{
  45.852 -				SDL_free(dls);
  45.853 -			}
  45.854 -			return NULL;
  45.855 -		}
  45.856 -	}
  45.857 -	else
  45.858 -	{
  45.859 -		dls->module = NSLinkModule(ofi, path,
  45.860 -								   NSLINKMODULE_OPTION_RETURN_ON_ERROR |
  45.861 -								   NSLINKMODULE_OPTION_PRIVATE |
  45.862 -								   (isFlagSet(mode, RTLD_NOW) ? NSLINKMODULE_OPTION_BINDNOW : 0));
  45.863 -		NSDestroyObjectFileImage(ofi);
  45.864 -		if (dls->module)
  45.865 -		{
  45.866 -			dls->lib = get_mach_header_from_NSModule(dls->module);
  45.867 -		}
  45.868 -	}
  45.869 -	if (!dls->module)
  45.870 -	{
  45.871 -		NSLinkEditError(&ler, &lerno, &file, &errstr);
  45.872 -		if ((dls->flags & DL_IN_LIST) == 0)
  45.873 -		{
  45.874 -			SDL_free(dls);
  45.875 -		}
  45.876 -		error(errstr);
  45.877 -		return NULL;
  45.878 -	}
  45.879 -
  45.880 -	insertStatus(dls, sbuf);
  45.881 -	dls = reference(dls, mode);
  45.882 -	if ((init = dlsymIntern(dls, "__init", 0)))
  45.883 -	{
  45.884 -		debug("calling _init()");
  45.885 -		init();
  45.886 -	}
  45.887 -	return dls;
  45.888 -}
  45.889 -
  45.890 -inline static void dlcompat_init_check(void)
  45.891 -{
  45.892 -	static pthread_mutex_t l = PTHREAD_MUTEX_INITIALIZER;
  45.893 -	static int init_done = 0;
  45.894 -
  45.895 -	pthread_mutex_lock(&l);
  45.896 -	if (!init_done) {
  45.897 -		dlcompat_init_func();
  45.898 -		init_done = 1;
  45.899 -	}
  45.900 -	pthread_mutex_unlock(&l);
  45.901 -}
  45.902 -
  45.903 -static void dlcompat_init_func(void)
  45.904 -{
  45.905 -        _dyld_func_lookup("__dyld_NSAddImage", (unsigned long *)&dyld_NSAddImage);
  45.906 -	_dyld_func_lookup("__dyld_NSIsSymbolNameDefinedInImage",
  45.907 -			  (unsigned long *)&dyld_NSIsSymbolNameDefinedInImage);
  45.908 -	_dyld_func_lookup("__dyld_NSLookupSymbolInImage", (unsigned long *)&dyld_NSLookupSymbolInImage);
  45.909 -	if (pthread_mutex_init(&dlcompat_mutex, NULL))
  45.910 -	    exit(1);
  45.911 -	if (pthread_key_create(&dlerror_key, &dlerrorfree))
  45.912 -	    exit(1);
  45.913 -}
  45.914 -
  45.915 -static void resetdlerror()
  45.916 -{
  45.917 -	struct dlthread *tss;
  45.918 -	tss = pthread_getspecific(dlerror_key);
  45.919 -	tss->errset = 0;
  45.920 -}
  45.921 -
  45.922 -static void dlerrorfree(void *data)
  45.923 -{
  45.924 -	SDL_free(data);
  45.925 -}
  45.926 -
  45.927 -/* We kind of want a recursive lock here, but meet a little trouble
  45.928 - * because they are not available pre OS X 10.2, so we fake it
  45.929 - * using thread specific storage to keep a lock count
  45.930 - */ 
  45.931 -static inline void dolock(void)
  45.932 -{
  45.933 -	int err = 0;
  45.934 -	struct dlthread *tss;
  45.935 -	dlcompat_init_check();
  45.936 -	tss = pthread_getspecific(dlerror_key);
  45.937 -	if (!tss)
  45.938 -	{
  45.939 -		tss = SDL_malloc(sizeof(struct dlthread));
  45.940 -		tss->lockcnt = 0;
  45.941 -		tss->errset = 0;
  45.942 -		if (pthread_setspecific(dlerror_key, tss))
  45.943 -		{
  45.944 -			fprintf(stderr,"dlcompat: pthread_setspecific failed\n");
  45.945 -			exit(1);
  45.946 -		}
  45.947 -	}
  45.948 -	if (!tss->lockcnt)
  45.949 -		err = pthread_mutex_lock(&dlcompat_mutex);
  45.950 -	tss->lockcnt = tss->lockcnt +1;	
  45.951 -	if (err)
  45.952 -		exit(err);
  45.953 -}
  45.954 -
  45.955 -static inline void dounlock(void)
  45.956 -{
  45.957 -	int err = 0;
  45.958 -	struct dlthread *tss;
  45.959 -	tss = pthread_getspecific(dlerror_key);
  45.960 -	tss->lockcnt = tss->lockcnt -1;
  45.961 -	if (!tss->lockcnt)
  45.962 -		err = pthread_mutex_unlock(&dlcompat_mutex);
  45.963 -	if (err)
  45.964 -		exit(err);
  45.965 -}
  45.966 -
  45.967 -static void *SDL_OSX_dlopen(const char *path, int mode)
  45.968 -{
  45.969 -	const struct stat *sbuf;
  45.970 -	struct dlstatus *dls;
  45.971 -	const char *fullPath;
  45.972 -
  45.973 -	dolock();
  45.974 -	resetdlerror();
  45.975 -	if (!path)
  45.976 -	{
  45.977 -		dls = &mainStatus;
  45.978 -		goto dlopenok;
  45.979 -	}
  45.980 -	if (!(sbuf = findFile(path, &fullPath)))
  45.981 -	{
  45.982 -		error("file \"%s\" not found", path);
  45.983 -		goto dlopenerror;
  45.984 -	}
  45.985 -	/* Now checks that it hasn't been closed already */
  45.986 -	if ((dls = lookupStatus(sbuf)) && (dls->refs > 0))
  45.987 -	{
  45.988 -		/* debug("status found"); */
  45.989 -		dls = reference(dls, mode);
  45.990 -		goto dlopenok;
  45.991 -	}
  45.992 -#ifdef 	RTLD_NOLOAD
  45.993 -	if (isFlagSet(mode, RTLD_NOLOAD))
  45.994 -	{
  45.995 -		error("no existing handle and RTLD_NOLOAD specified");
  45.996 -		goto dlopenerror;
  45.997 -	}
  45.998 -#endif
  45.999 -	if (isFlagSet(mode, RTLD_LAZY) && isFlagSet(mode, RTLD_NOW))
 45.1000 -	{
 45.1001 -		error("how can I load something both RTLD_LAZY and RTLD_NOW?");
 45.1002 -		goto dlopenerror;
 45.1003 -	}
 45.1004 -	dls = loadModule(fullPath, sbuf, mode);
 45.1005 -	
 45.1006 -  dlopenok:
 45.1007 -	dounlock();
 45.1008 -	return (void *)dls;
 45.1009 -  dlopenerror:
 45.1010 -	dounlock();
 45.1011 -	return NULL;
 45.1012 -}
 45.1013 -
 45.1014 -#if !FINK_BUILD
 45.1015 -static void *SDL_OSX_dlsym(void * dl_restrict handle, const char * dl_restrict symbol)
 45.1016 -{
 45.1017 -	int sym_len = SDL_strlen(symbol);
 45.1018 -	void *value = NULL;
 45.1019 -	char *malloc_sym = NULL;
 45.1020 -	dolock();
 45.1021 -	malloc_sym = SDL_malloc(sym_len + 2);
 45.1022 -	if (malloc_sym)
 45.1023 -	{
 45.1024 -		SDL_snprintf(malloc_sym, sym_len+2, "_%s", symbol);
 45.1025 -		value = dlsymIntern(handle, malloc_sym, 1);
 45.1026 -		SDL_free(malloc_sym);
 45.1027 -	}
 45.1028 -	else
 45.1029 -	{
 45.1030 -		error("Unable to allocate memory");
 45.1031 -		goto dlsymerror;
 45.1032 -	}
 45.1033 -	dounlock();
 45.1034 -	return value;
 45.1035 -  dlsymerror:
 45.1036 -	dounlock();
 45.1037 -	return NULL;
 45.1038 -}
 45.1039 -#endif
 45.1040 -
 45.1041 -#if FINK_BUILD
 45.1042 -
 45.1043 -static void *dlsym_prepend_underscore(void *handle, const char *symbol)
 45.1044 -{
 45.1045 -	void *answer;
 45.1046 -	dolock();
 45.1047 -	answer = dlsym_prepend_underscore_intern(handle, symbol);
 45.1048 -	dounlock();
 45.1049 -	return answer;
 45.1050 -}
 45.1051 -
 45.1052 -static void *dlsym_prepend_underscore_intern(void *handle, const char *symbol)
 45.1053 -{
 45.1054 -/*
 45.1055 - *	A quick and easy way for porting packages which call dlsym(handle,"sym")
 45.1056 - *	If the porter adds -Ddlsym=dlsym_prepend_underscore to the CFLAGS then
 45.1057 - *	this function will be called, and will add the required underscore.
 45.1058 - *	
 45.1059 - *	Note that I haven't figured out yet which should be "standard", prepend
 45.1060 - *	the underscore always, or not at all. These global functions need to go away
 45.1061 - *	for opendarwin.
 45.1062 - */
 45.1063 -	int sym_len = SDL_strlen(symbol);
 45.1064 -	void *value = NULL;
 45.1065 -	char *malloc_sym = NULL;
 45.1066 -	malloc_sym = SDL_malloc(sym_len + 2);
 45.1067 -	if (malloc_sym)
 45.1068 -	{
 45.1069 -		SDL_snprintf(malloc_sym, sym_len+2, "_%s", symbol);
 45.1070 -		value = dlsymIntern(handle, malloc_sym, 1);
 45.1071 -		SDL_free(malloc_sym);
 45.1072 -	}
 45.1073 -	else
 45.1074 -	{
 45.1075 -		error("Unable to allocate memory");
 45.1076 -	}
 45.1077 -	return value;
 45.1078 -}
 45.1079 -
 45.1080 -static void *dlsym_auto_underscore(void *handle, const char *symbol)
 45.1081 -{
 45.1082 -	void *answer;
 45.1083 -	dolock();
 45.1084 -	answer = dlsym_auto_underscore_intern(handle, symbol);
 45.1085 -	dounlock();
 45.1086 -	return answer;
 45.1087 -
 45.1088 -}
 45.1089 -static void *dlsym_auto_underscore_intern(void *handle, const char *symbol)
 45.1090 -{
 45.1091 -	struct dlstatus *dls = handle;
 45.1092 -	void *addr = 0;
 45.1093 -	addr = dlsymIntern(dls, symbol, 0);
 45.1094 -	if (!addr)
 45.1095 -		addr = dlsym_prepend_underscore_intern(handle, symbol);
 45.1096 -	return addr;
 45.1097 -}
 45.1098 -
 45.1099 -
 45.1100 -static void *SDL_OSX_dlsym(void * dl_restrict handle, const char * dl_restrict symbol)
 45.1101 -{
 45.1102 -	struct dlstatus *dls = handle;
 45.1103 -	void *addr = 0;
 45.1104 -	dolock();
 45.1105 -	addr = dlsymIntern(dls, symbol, 1);
 45.1106 -	dounlock();
 45.1107 -	return addr;
 45.1108 -}
 45.1109 -#endif
 45.1110 -
 45.1111 -static int SDL_OSX_dlclose(void *handle)
 45.1112 -{
 45.1113 -	struct dlstatus *dls = handle;
 45.1114 -	dolock();
 45.1115 -	resetdlerror();
 45.1116 -	if (!isValidStatus(dls))
 45.1117 -	{
 45.1118 -		goto dlcloseerror;
 45.1119 -	}
 45.1120 -	if (dls->module == MAGIC_DYLIB_MOD)
 45.1121 -	{
 45.1122 -		const char *name;
 45.1123 -		if (!dls->lib)
 45.1124 -		{
 45.1125 -			name = "global context";
 45.1126 -		}
 45.1127 -		else
 45.1128 -		{
 45.1129 -			name = get_lib_name(dls->lib);
 45.1130 -		}
 45.1131 -		warning("trying to close a .dylib!");
 45.1132 -		error("Not closing \"%s\" - dynamic libraries cannot be closed", name);
 45.1133 -		goto dlcloseerror;
 45.1134 -	}
 45.1135 -	if (!dls->module)
 45.1136 -	{
 45.1137 -		error("module already closed");
 45.1138 -		goto dlcloseerror;
 45.1139 -	}
 45.1140 -	
 45.1141 -	if (dls->refs == 1)
 45.1142 -	{
 45.1143 -		unsigned long options = 0;
 45.1144 -		void (*fini) (void);
 45.1145 -		if ((fini = dlsymIntern(dls, "__fini", 0)))
 45.1146 -		{
 45.1147 -			debug("calling _fini()");
 45.1148 -			fini();
 45.1149 -		}
 45.1150 -		options |= NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES;
 45.1151 -#ifdef RTLD_NODELETE
 45.1152 -		if (isFlagSet(dls->mode, RTLD_NODELETE))
 45.1153 -			options |= NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED;
 45.1154 -#endif
 45.1155 -		if (!NSUnLinkModule(dls->module, options))
 45.1156 -		{
 45.1157 -			error("unable to unlink module");
 45.1158 -			goto dlcloseerror;
 45.1159 -		}
 45.1160 -		dls->refs--;
 45.1161 -		dls->module = 0;
 45.1162 -		/* Note: the dlstatus struct dls is neither removed from the list
 45.1163 -		 * nor is the memory it occupies freed. This shouldn't pose a 
 45.1164 -		 * problem in mostly all cases, though.
 45.1165 -		 */
 45.1166 -	}
 45.1167 -	dounlock();
 45.1168 -	return 0;
 45.1169 -  dlcloseerror:
 45.1170 -	dounlock();
 45.1171 -	return 1;
 45.1172 -}
 45.1173 -
 45.1174 -static const char *SDL_OSX_dlerror(void)
 45.1175 -{
 45.1176 -	struct dlthread  *tss;
 45.1177 -	const char * err_str = NULL;
 45.1178 -	dlcompat_init_check();
 45.1179 -	tss = pthread_getspecific(dlerror_key);
 45.1180 -	if (tss != NULL && tss->errset != 0) {
 45.1181 -		tss->errset = 0;	
 45.1182 -		err_str = tss->errstr;
 45.1183 -	}
 45.1184 -	return (err_str);
 45.1185 -}
 45.1186 -
 45.1187 -/* Given an address, return the mach_header for the image containing it
 45.1188 - * or zero if the given address is not contained in any loaded images.
 45.1189 - */
 45.1190 -static const struct mach_header *image_for_address(const void *address)
 45.1191 -{
 45.1192 -	unsigned long i;
 45.1193 -	unsigned long j;
 45.1194 -	unsigned long count = _dyld_image_count();
 45.1195 -	struct mach_header *mh = 0;
 45.1196 -	struct load_command *lc = 0;
 45.1197 -	unsigned long addr = NULL;
 45.1198 -	for (i = 0; i < count; i++)
 45.1199 -	{
 45.1200 -		addr = (unsigned long)address - _dyld_get_image_vmaddr_slide(i);
 45.1201 -		mh = _dyld_get_image_header(i);
 45.1202 -		if (mh)
 45.1203 -		{
 45.1204 -			lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
 45.1205 -			for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
 45.1206 -			{
 45.1207 -				if (LC_SEGMENT == lc->cmd &&
 45.1208 -					addr >= ((struct segment_command *)lc)->vmaddr &&
 45.1209 -					addr <
 45.1210 -					((struct segment_command *)lc)->vmaddr + ((struct segment_command *)lc)->vmsize)
 45.1211 -				{
 45.1212 -					goto image_found;
 45.1213 -				}
 45.1214 -			}
 45.1215 -		}
 45.1216 -		mh = 0;
 45.1217 -	}
 45.1218 -  image_found:
 45.1219 -	return mh;
 45.1220 -}
 45.1221 -
 45.1222 -static int SDL_OSX_dladdr(const void * dl_restrict p, SDL_OSX_Dl_info * dl_restrict info)
 45.1223 -{
 45.1224 -/*
 45.1225 -	FIXME: USe the routine image_for_address.
 45.1226 -*/
 45.1227 -	unsigned long i;
 45.1228 -	unsigned long j;
 45.1229 -	unsigned long count = _dyld_image_count();
 45.1230 -	struct mach_header *mh = 0;
 45.1231 -	struct load_command *lc = 0;
 45.1232 -	unsigned long addr = NULL;
 45.1233 -	unsigned long table_off = (unsigned long)0;
 45.1234 -	int found = 0;
 45.1235 -	if (!info)
 45.1236 -		return 0;
 45.1237 -	dolock();
 45.1238 -	resetdlerror();
 45.1239 -	info->dli_fname = 0;
 45.1240 -	info->dli_fbase = 0;
 45.1241 -	info->dli_sname = 0;
 45.1242 -	info->dli_saddr = 0;
 45.1243 -/* Some of this was swiped from code posted by Douglas Davidson <ddavidso AT apple DOT com>
 45.1244 - * to darwin-development AT lists DOT apple DOT com and slightly modified
 45.1245 - */
 45.1246 -	for (i = 0; i < count; i++)
 45.1247 -	{
 45.1248 -		addr = (unsigned long)p - _dyld_get_image_vmaddr_slide(i);
 45.1249 -		mh = _dyld_get_image_header(i);
 45.1250 -		if (mh)
 45.1251 -		{
 45.1252 -			lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
 45.1253 -			for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
 45.1254 -			{
 45.1255 -				if (LC_SEGMENT == lc->cmd &&
 45.1256 -					addr >= ((struct segment_command *)lc)->vmaddr &&
 45.1257 -					addr <
 45.1258 -					((struct segment_command *)lc)->vmaddr + ((struct segment_command *)lc)->vmsize)
 45.1259 -				{
 45.1260 -					info->dli_fname = _dyld_get_image_name(i);
 45.1261 -					info->dli_fbase = (void *)mh;
 45.1262 -					found = 1;
 45.1263 -					break;
 45.1264 -				}
 45.1265 -			}
 45.1266 -			if (found)
 45.1267 -				break;
 45.1268 -		}
 45.1269 -	}
 45.1270 -	if (!found)
 45.1271 -	{
 45.1272 -		dounlock();
 45.1273 -		return 0;
 45.1274 -	}
 45.1275 -	lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
 45.1276 -	for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
 45.1277 -	{
 45.1278 -		if (LC_SEGMENT == lc->cmd)
 45.1279 -		{
 45.1280 -			if (!SDL_strcmp(((struct segment_command *)lc)->segname, "__LINKEDIT"))
 45.1281 -				break;
 45.1282 -		}
 45.1283 -	}
 45.1284 -	table_off =
 45.1285 -		((unsigned long)((struct segment_command *)lc)->vmaddr) -
 45.1286 -		((unsigned long)((struct segment_command *)lc)->fileoff) + _dyld_get_image_vmaddr_slide(i);
 45.1287 -	debug("table off %x", table_off);
 45.1288 -
 45.1289 -	lc = (struct load_command *)((char *)mh + sizeof(struct mach_header));
 45.1290 -	for (j = 0; j < mh->ncmds; j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
 45.1291 -	{
 45.1292 -		if (LC_SYMTAB == lc->cmd)
 45.1293 -		{
 45.1294 -
 45.1295 -			struct nlist *symtable = (struct nlist *)(((struct symtab_command *)lc)->symoff + table_off);
 45.1296 -			unsigned long numsyms = ((struct symtab_command *)lc)->nsyms;
 45.1297 -			struct nlist *nearest = NULL;
 45.1298 -			unsigned long diff = 0xffffffff;
 45.1299 -			unsigned long strtable = (unsigned long)(((struct symtab_command *)lc)->stroff + table_off);
 45.1300 -			debug("symtable %x", symtable);
 45.1301 -			for (i = 0; i < numsyms; i++)
 45.1302 -			{
 45.1303 -				/* Ignore the following kinds of Symbols */
 45.1304 -				if ((!symtable->n_value)	/* Undefined */
 45.1305 -					|| (symtable->n_type >= N_PEXT)	/* Debug symbol */
 45.1306 -					|| (!(symtable->n_type & N_EXT))	/* Local Symbol */
 45.1307 -					)
 45.1308 -				{
 45.1309 -					symtable++;
 45.1310 -					continue;
 45.1311 -				}
 45.1312 -				if ((addr >= symtable->n_value) && (diff >= (symtable->n_value - addr)))
 45.1313 -				{
 45.1314 -					diff = (unsigned long)symtable->n_value - addr;
 45.1315 -					nearest = symtable;
 45.1316 -				}
 45.1317 -				symtable++;
 45.1318 -			}
 45.1319 -			if (nearest)
 45.1320 -			{
 45.1321 -				info->dli_saddr = nearest->n_value + ((void *)p - addr);
 45.1322 -				info->dli_sname = (char *)(strtable + nearest->n_un.n_strx);
 45.1323 -			}
 45.1324 -		}
 45.1325 -	}
 45.1326 -	dounlock();
 45.1327 -	return 1;
 45.1328 -}
 45.1329 -
 45.1330 -
 45.1331 -/*
 45.1332 - * Implement the dlfunc() interface, which behaves exactly the same as
 45.1333 - * dlsym() except that it returns a function pointer instead of a data
 45.1334 - * pointer.  This can be used by applications to avoid compiler warnings
 45.1335 - * about undefined behavior, and is intended as prior art for future
 45.1336 - * POSIX standardization.  This function requires that all pointer types
 45.1337 - * have the same representation, which is true on all platforms FreeBSD
 45.1338 - * runs on, but is not guaranteed by the C standard.
 45.1339 - */
 45.1340 -#if 0 
 45.1341 -static dlfunc_t SDL_OSX_dlfunc(void * dl_restrict handle, const char * dl_restrict symbol)
 45.1342 -{
 45.1343 -	union
 45.1344 -	{
 45.1345 -		void *d;
 45.1346 -		dlfunc_t f;
 45.1347 -	} rv;
 45.1348 -	int sym_len = SDL_strlen(symbol);
 45.1349 -	char *malloc_sym = NULL;
 45.1350 -	dolock();
 45.1351 -	malloc_sym = SDL_malloc(sym_len + 2);
 45.1352 -	if (malloc_sym)
 45.1353 -	{
 45.1354 -		SDL_snprintf(malloc_sym, sym_len+2, "_%s", symbol);
 45.1355 -		rv.d = dlsymIntern(handle, malloc_sym, 1);
 45.1356 -		SDL_free(malloc_sym);
 45.1357 -	}
 45.1358 -	else
 45.1359 -	{
 45.1360 -		error("Unable to allocate memory");
 45.1361 -		goto dlfuncerror;
 45.1362 -	}
 45.1363 -	dounlock();
 45.1364 -	return rv.f;
 45.1365 -  dlfuncerror:
 45.1366 -	dounlock();
 45.1367 -	return NULL;
 45.1368 -}
 45.1369 -#endif
 45.1370 -
 45.1371 -
 45.1372 -
 45.1373 -/* dlcompat ends, here's the SDL interface...  --ryan.  */
 45.1374 -
 45.1375 -
 45.1376 -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 45.1377 -/* System dependent library loading routines                           */
 45.1378 -
 45.1379 -#include "SDL_loadso.h"
 45.1380 -
 45.1381 -void *SDL_LoadObject(const char *sofile)
 45.1382 -{
 45.1383 -	void *handle = SDL_OSX_dlopen(sofile, RTLD_NOW);
 45.1384 -	const char *loaderror = SDL_OSX_dlerror();
 45.1385 -	if ( handle == NULL ) {
 45.1386 -		SDL_SetError("Failed loading %s: %s", sofile, loaderror);
 45.1387 -	}
 45.1388 -	return(handle);
 45.1389 -}
 45.1390 -
 45.1391 -void *SDL_LoadFunction(void *handle, const char *name)
 45.1392 -{
 45.1393 -	void *symbol = SDL_OSX_dlsym(handle, name);
 45.1394 -	if ( symbol == NULL ) {
 45.1395 -		SDL_SetError("Failed loading %s: %s", name, SDL_OSX_dlerror());
 45.1396 -	}
 45.1397 -	return(symbol);
 45.1398 -}
 45.1399 -
 45.1400 -void SDL_UnloadObject(void *handle)
 45.1401 -{
 45.1402 -	if ( handle != NULL ) {
 45.1403 -		SDL_OSX_dlclose(handle);
 45.1404 -	}
 45.1405 -}
 45.1406 -
 45.1407 -#endif /* SDL_LOADSO_DLCOMPAT */
    46.1 --- a/src/main/dummy/SDL_dummy_main.c	Mon May 01 06:58:33 2006 +0000
    46.2 +++ b/src/main/dummy/SDL_dummy_main.c	Wed May 17 08:18:28 2006 +0000
    46.3 @@ -9,5 +9,5 @@
    46.4  	return(SDL_main(argc, argv));
    46.5  }
    46.6  #else
    46.7 -/* Nothing to do on this platform */;
    46.8 +/* Nothing to do on this platform */
    46.9  #endif
    47.1 --- a/src/main/macosx/SDLMain.m	Mon May 01 06:58:33 2006 +0000
    47.2 +++ b/src/main/macosx/SDLMain.m	Wed May 17 08:18:28 2006 +0000
    47.3 @@ -252,19 +252,24 @@
    47.4   */
    47.5  - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
    47.6  {
    47.7 +    const char *temparg;
    47.8 +    size_t arglen;
    47.9 +    char *arg;
   47.10 +    char **newargv;
   47.11 +
   47.12      if (!gFinderLaunch)  /* MacOS is passing command line args. */
   47.13          return FALSE;
   47.14  
   47.15      if (gCalledAppMainline)  /* app has started, ignore this document. */
   47.16          return FALSE;
   47.17  
   47.18 -    const char *temparg = [filename UTF8String];
   47.19 -    size_t arglen = SDL_strlen(temparg) + 1;
   47.20 -    char *arg = (char *) SDL_malloc(arglen);
   47.21 +    temparg = [filename UTF8String];
   47.22 +    arglen = SDL_strlen(temparg) + 1;
   47.23 +    arg = (char *) SDL_malloc(arglen);
   47.24      if (arg == NULL)
   47.25          return FALSE;
   47.26  
   47.27 -    char **newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2));
   47.28 +    newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2));
   47.29      if (newargv == NULL)
   47.30      {
   47.31          SDL_free(arg);
   47.32 @@ -376,3 +381,4 @@
   47.33  #endif
   47.34      return 0;
   47.35  }
   47.36 +
    48.1 --- a/src/main/win32/SDL_win32_main.c	Mon May 01 06:58:33 2006 +0000
    48.2 +++ b/src/main/win32/SDL_win32_main.c	Wed May 17 08:18:28 2006 +0000
    48.3 @@ -121,8 +121,15 @@
    48.4  	return FALSE;
    48.5  }
    48.6  
    48.7 +/* SDL_Quit() shouldn't be used with atexit() directly because
    48.8 +   calling conventions may differ... */
    48.9 +static void cleanup(void)
   48.10 +{
   48.11 +	SDL_Quit();
   48.12 +}
   48.13 +
   48.14  /* Remove the output files if there was no output written */
   48.15 -static void __cdecl cleanup_output(void)
   48.16 +static void cleanup_output(void)
   48.17  {
   48.18  #ifndef NO_STDIO_REDIRECT
   48.19  	FILE *file;
   48.20 @@ -188,7 +195,7 @@
   48.21  	if ( bufp == NULL ) {
   48.22  		return OutOfMemory();
   48.23  	}
   48.24 -	SDL_strlcpy(bufp, appname, n);
   48.25 +	SDL_strlcpy(bufp, appname, n+1);
   48.26  	appname = bufp;
   48.27  
   48.28  	/* Load SDL dynamic link library */
   48.29 @@ -197,7 +204,7 @@
   48.30  		return(FALSE);
   48.31  	}
   48.32  	atexit(cleanup_output);
   48.33 -	atexit(SDL_Quit);
   48.34 +	atexit(cleanup);
   48.35  
   48.36  	/* Sam:
   48.37  	   We still need to pass in the application handle so that
    49.1 --- a/src/stdlib/SDL_string.c	Mon May 01 06:58:33 2006 +0000
    49.2 +++ b/src/stdlib/SDL_string.c	Wed May 17 08:18:28 2006 +0000
    49.3 @@ -985,10 +985,10 @@
    49.4  
    49.5      SDL_ltoa(value, num, radix);
    49.6      size = SDL_strlen(num);
    49.7 -    if ( size > maxlen ) {
    49.8 -        size = maxlen;
    49.9 +    if ( size >= maxlen ) {
   49.10 +        size = maxlen-1;
   49.11      }
   49.12 -    SDL_strlcpy(text, num, size);
   49.13 +    SDL_strlcpy(text, num, size+1);
   49.14  
   49.15      return size;
   49.16  }
   49.17 @@ -999,10 +999,10 @@
   49.18  
   49.19      SDL_ultoa(value, num, radix);
   49.20      size = SDL_strlen(num);
   49.21 -    if ( size > maxlen ) {
   49.22 -        size = maxlen;
   49.23 +    if ( size >= maxlen ) {
   49.24 +        size = maxlen-1;
   49.25      }
   49.26 -    SDL_strlcpy(text, num, size);
   49.27 +    SDL_strlcpy(text, num, size+1);
   49.28  
   49.29      return size;
   49.30  }
   49.31 @@ -1014,10 +1014,10 @@
   49.32  
   49.33      SDL_lltoa(value, num, radix);
   49.34      size = SDL_strlen(num);
   49.35 -    if ( size > maxlen ) {
   49.36 -        size = maxlen;
   49.37 +    if ( size >= maxlen ) {
   49.38 +        size = maxlen-1;
   49.39      }
   49.40 -    SDL_strlcpy(text, num, size);
   49.41 +    SDL_strlcpy(text, num, size+1);
   49.42  
   49.43      return size;
   49.44  }
   49.45 @@ -1028,10 +1028,10 @@
   49.46  
   49.47      SDL_ulltoa(value, num, radix);
   49.48      size = SDL_strlen(num);
   49.49 -    if ( size > maxlen ) {
   49.50 -        size = maxlen;
   49.51 +    if ( size >= maxlen ) {
   49.52 +        size = maxlen-1;
   49.53      }
   49.54 -    SDL_strlcpy(text, num, size);
   49.55 +    SDL_strlcpy(text, num, size+1);
   49.56  
   49.57      return size;
   49.58  }
   49.59 @@ -1101,6 +1101,9 @@
   49.60  
   49.61              ++fmt;
   49.62              /* FIXME: implement more of the format specifiers */
   49.63 +            while ( *fmt == '.' || (*fmt >= '0' && *fmt <= '9') ) {
   49.64 +                ++fmt;
   49.65 +            }
   49.66              while (!done) {
   49.67                  switch(*fmt) {
   49.68                      case '%':
    50.1 --- a/src/thread/SDL_thread.c	Mon May 01 06:58:33 2006 +0000
    50.2 +++ b/src/thread/SDL_thread.c	Wed May 17 08:18:28 2006 +0000
    50.3 @@ -168,7 +168,7 @@
    50.4  
    50.5  /* Arguments and callback to setup and run the user thread function */
    50.6  typedef struct {
    50.7 -	int (*func)(void *);
    50.8 +	int (SDLCALL *func)(void *);
    50.9  	void *data;
   50.10  	SDL_Thread *info;
   50.11  	SDL_sem *wait;
   50.12 @@ -177,7 +177,7 @@
   50.13  void SDL_RunThread(void *data)
   50.14  {
   50.15  	thread_args *args;
   50.16 -	int (*userfunc)(void *);
   50.17 +	int (SDLCALL *userfunc)(void *);
   50.18  	void *userdata;
   50.19  	int *statusloc;
   50.20  
   50.21 @@ -204,9 +204,9 @@
   50.22  
   50.23  #ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
   50.24  #undef SDL_CreateThread
   50.25 -DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (*fn)(void *), void *data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread)
   50.26 +DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (SDLCALL *fn)(void *), void *data, pfnSDL_CurrentBeginThread pfnBeginThread, pfnSDL_CurrentEndThread pfnEndThread)
   50.27  #else
   50.28 -DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (*fn)(void *), void *data)
   50.29 +DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (SDLCALL *fn)(void *), void *data)
   50.30  #endif
   50.31  {
   50.32  	SDL_Thread *thread;
    51.1 --- a/src/thread/pth/SDL_systhread.c	Mon May 01 06:58:33 2006 +0000
    51.2 +++ b/src/thread/pth/SDL_systhread.c	Wed May 17 08:18:28 2006 +0000
    51.3 @@ -27,12 +27,13 @@
    51.4   *	Patrice Mandin
    51.5   */
    51.6  
    51.7 -#include "SDL_thread.h"
    51.8 -#include "../SDL_systhread.h"
    51.9 -
   51.10  #include <pth.h>
   51.11  #include <signal.h>
   51.12  
   51.13 +#include "SDL_thread.h"
   51.14 +#include "../SDL_thread_c.h"
   51.15 +#include "../SDL_systhread.h"
   51.16 +
   51.17  /* List of signals to mask in the subthreads */
   51.18  static int sig_list[] = {
   51.19  	SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH,
    52.1 --- a/src/thread/win32/SDL_systhread.c	Mon May 01 06:58:33 2006 +0000
    52.2 +++ b/src/thread/win32/SDL_systhread.c	Wed May 17 08:18:28 2006 +0000
    52.3 @@ -41,6 +41,15 @@
    52.4          unsigned (__stdcall *func)(void *), void *arg, 
    52.5          unsigned, unsigned *threadID);
    52.6  typedef void (__cdecl *pfnSDL_CurrentEndThread)(unsigned code);
    52.7 +#elif defined(__WATCOMC__)
    52.8 +/* This is for Watcom targets except OS2 */
    52.9 +#if __WATCOMC__ < 1240
   52.10 +#define __watcall
   52.11 +#endif
   52.12 +typedef unsigned long (__watcall *pfnSDL_CurrentBeginThread) (void *, unsigned,
   52.13 +        unsigned (__stdcall *func)(void *), void *arg, 
   52.14 +        unsigned, unsigned *threadID);
   52.15 +typedef void (__watcall *pfnSDL_CurrentEndThread)(unsigned code);
   52.16  #else
   52.17  typedef uintptr_t (__cdecl *pfnSDL_CurrentBeginThread) (void *, unsigned,
   52.18          unsigned (__stdcall *func)(void *), void *arg, 
    53.1 --- a/src/timer/SDL_timer.c	Mon May 01 06:58:33 2006 +0000
    53.2 +++ b/src/timer/SDL_timer.c	Wed May 17 08:18:28 2006 +0000
    53.3 @@ -95,6 +95,7 @@
    53.4  	}
    53.5  	if ( SDL_timer_threaded ) {
    53.6  		SDL_DestroyMutex(SDL_timer_mutex);
    53.7 +		SDL_timer_mutex = NULL;
    53.8  	}
    53.9  	SDL_timer_started = 0;
   53.10  	SDL_timer_threaded = 0;
    54.1 --- a/src/timer/macos/FastTimes.c	Mon May 01 06:58:33 2006 +0000
    54.2 +++ b/src/timer/macos/FastTimes.c	Wed May 17 08:18:28 2006 +0000
    54.3 @@ -19,6 +19,11 @@
    54.4  
    54.5  #include "FastTimes.h"
    54.6  
    54.7 +#ifdef TARGET_CPU_PPC
    54.8 +#undef GENERATINGPOWERPC /* stop whining */
    54.9 +#define GENERATINGPOWERPC TARGET_CPU_PPC
   54.10 +#endif
   54.11 +
   54.12  /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */
   54.13  /* **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** */
   54.14  /*
    55.1 --- a/src/timer/macos/SDL_systimer.c	Mon May 01 06:58:33 2006 +0000
    55.2 +++ b/src/timer/macos/SDL_systimer.c	Wed May 17 08:18:28 2006 +0000
    55.3 @@ -36,6 +36,10 @@
    55.4  
    55.5  #include "FastTimes.h"
    55.6  
    55.7 +#if TARGET_API_MAC_CARBON
    55.8 +#define NewTimerProc NewTimerUPP
    55.9 +#endif
   55.10 +
   55.11  #define MS_PER_TICK	(1000.0/60.0)		/* MacOS tick = 1/60 second */
   55.12  
   55.13  
   55.14 @@ -67,7 +71,11 @@
   55.15  
   55.16          stop = SDL_GetTicks() + ms;
   55.17          do {
   55.18 +            #if TARGET_API_MAC_CARBON
   55.19 +                MPYield();
   55.20 +            #else
   55.21                  SystemTask();
   55.22 +            #endif
   55.23  
   55.24                  now = SDL_GetTicks();
   55.25  
    56.1 --- a/src/video/SDL_blit_A.c	Mon May 01 06:58:33 2006 +0000
    56.2 +++ b/src/video/SDL_blit_A.c	Wed May 17 08:18:28 2006 +0000
    56.3 @@ -637,6 +637,9 @@
    56.4  #endif /* GCC_ASMBLIT, MSVC_ASMBLIT */
    56.5  
    56.6  #if SDL_ALTIVEC_BLITTERS
    56.7 +#if __MWERKS__
    56.8 +#pragma altivec_model on
    56.9 +#endif
   56.10  #if HAVE_ALTIVEC_H
   56.11  #include <altivec.h>
   56.12  #endif
   56.13 @@ -1406,6 +1409,9 @@
   56.14          dstp += dstskip;
   56.15      }
   56.16  }
   56.17 +#if __MWERKS__
   56.18 +#pragma altivec_model off
   56.19 +#endif
   56.20  #endif /* SDL_ALTIVEC_BLITTERS */
   56.21  
   56.22  /* fast RGB888->(A)RGB888 blending with surface alpha=128 special case */
    57.1 --- a/src/video/SDL_blit_N.c	Mon May 01 06:58:33 2006 +0000
    57.2 +++ b/src/video/SDL_blit_N.c	Wed May 17 08:18:28 2006 +0000
    57.3 @@ -29,6 +29,9 @@
    57.4  /* Functions to blit from N-bit surfaces to other surfaces */
    57.5  
    57.6  #if SDL_ALTIVEC_BLITTERS
    57.7 +#if __MWERKS__
    57.8 +#pragma altivec_model on
    57.9 +#endif
   57.10  #ifdef HAVE_ALTIVEC_H
   57.11  #include <altivec.h>
   57.12  #endif
   57.13 @@ -830,6 +833,9 @@
   57.14      }
   57.15      return features;
   57.16  }
   57.17 +#if __MWERKS__
   57.18 +#pragma altivec_model off
   57.19 +#endif
   57.20  #else
   57.21  /* Feature 1 is has-MMX */
   57.22  #define GetBlitFeatures() ((Uint32)(SDL_HasMMX() ? 1 : 0))
    58.1 --- a/src/video/ataricommon/SDL_ikbdinterrupt_s.h	Mon May 01 06:58:33 2006 +0000
    58.2 +++ b/src/video/ataricommon/SDL_ikbdinterrupt_s.h	Wed May 17 08:18:28 2006 +0000
    58.3 @@ -44,14 +44,14 @@
    58.4  
    58.5  /* Variables */
    58.6  
    58.7 -extern Uint8  SDL_AtariIkbd_keyboard[128];	/* Keyboard table */
    58.8 -extern Uint16 SDL_AtariIkbd_mouseb;	/* Mouse on port 0, buttons */
    58.9 -extern Sint16 SDL_AtariIkbd_mousex;	/* Mouse X relative motion */
   58.10 -extern Sint16 SDL_AtariIkbd_mousey;	/* Mouse Y relative motion */
   58.11 -extern Uint16 SDL_AtariIkbd_joystick;	/* Joystick on port 1 */
   58.12 +extern volatile Uint8  SDL_AtariIkbd_keyboard[128];	/* Keyboard table */
   58.13 +extern volatile Uint16 SDL_AtariIkbd_mouseb;	/* Mouse on port 0, buttons */
   58.14 +extern volatile Sint16 SDL_AtariIkbd_mousex;	/* Mouse X relative motion */
   58.15 +extern volatile Sint16 SDL_AtariIkbd_mousey;	/* Mouse Y relative motion */
   58.16 +extern volatile Uint16 SDL_AtariIkbd_joystick;	/* Joystick on port 1 */
   58.17  
   58.18 -extern Uint16 SDL_AtariIkbd_enabled;	/* For joystick driver to know
   58.19 -											if this is usable */
   58.20 +/* For joystick driver to know if this is usable */
   58.21 +extern Uint16 SDL_AtariIkbd_enabled;
   58.22  										
   58.23  /* Functions */ 
   58.24  
    59.1 --- a/src/video/ataricommon/SDL_xbiosinterrupt_s.h	Mon May 01 06:58:33 2006 +0000
    59.2 +++ b/src/video/ataricommon/SDL_xbiosinterrupt_s.h	Wed May 17 08:18:28 2006 +0000
    59.3 @@ -36,10 +36,10 @@
    59.4  
    59.5  /* Variables */
    59.6  
    59.7 -extern Uint16 SDL_AtariXbios_mouseb;	/* buttons */
    59.8 -extern Sint16 SDL_AtariXbios_mousex;	/* X relative motion */
    59.9 -extern Sint16 SDL_AtariXbios_mousey;	/* Y relative motion */
   59.10 -extern Uint16 SDL_AtariXbios_joystick;	/* Joystick */
   59.11 +extern volatile Uint16 SDL_AtariXbios_mouseb;	/* buttons */
   59.12 +extern volatile Sint16 SDL_AtariXbios_mousex;	/* X relative motion */
   59.13 +extern volatile Sint16 SDL_AtariXbios_mousey;	/* Y relative motion */
   59.14 +extern volatile Uint16 SDL_AtariXbios_joystick;	/* Joystick */
   59.15  
   59.16  /* Functions */ 
   59.17  
    60.1 --- a/src/video/dga/SDL_dgavideo.c	Mon May 01 06:58:33 2006 +0000
    60.2 +++ b/src/video/dga/SDL_dgavideo.c	Wed May 17 08:18:28 2006 +0000
    60.3 @@ -41,6 +41,13 @@
    60.4  /* get function pointers... */
    60.5  #include "../x11/SDL_x11dyn.h"
    60.6  
    60.7 +/*#define DGA_DEBUG*/
    60.8 +
    60.9 +/* Heheh we're using X11 event code */
   60.10 +extern void X11_SaveScreenSaver(Display *display, int *saved_timeout, BOOL *dpms);
   60.11 +extern void X11_DisableScreenSaver(Display *display);
   60.12 +extern void X11_RestoreScreenSaver(Display *display, int saved_timeout, BOOL dpms);
   60.13 +
   60.14  /* Initialization/Query functions */
   60.15  static int DGA_VideoInit(_THIS, SDL_PixelFormat *vformat);
   60.16  static SDL_Rect **DGA_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
   60.17 @@ -169,7 +176,7 @@
   60.18  static int DGA_AddMode(_THIS, int bpp, int w, int h)
   60.19  {
   60.20  	SDL_Rect *mode;
   60.21 -	int i, index;
   60.22 +	int index;
   60.23  	int next_mode;
   60.24  
   60.25  	/* Check to see if we already have this mode */
   60.26 @@ -177,8 +184,8 @@
   60.27  		return(0);
   60.28  	}
   60.29  	index = ((bpp+7)/8)-1;
   60.30 -	for ( i=0; i<SDL_nummodes[index]; ++i ) {
   60.31 -		mode = SDL_modelist[index][i];
   60.32 +	if ( SDL_nummodes[index] > 0 ) {
   60.33 +		mode = SDL_modelist[index][SDL_nummodes[index]-1];
   60.34  		if ( (mode->w == w) && (mode->h == h) ) {
   60.35  			return(0);
   60.36  		}
   60.37 @@ -281,14 +288,21 @@
   60.38      const SDL_NAME(XDGAMode) *a = (const SDL_NAME(XDGAMode) *)va;
   60.39      const SDL_NAME(XDGAMode) *b = (const SDL_NAME(XDGAMode) *)vb;
   60.40  
   60.41 -    /* Prefer DirectColor visuals for otherwise equal modes */
   60.42      if ( (a->viewportWidth == b->viewportWidth) &&
   60.43           (b->viewportHeight == a->viewportHeight) ) {
   60.44 -        if ( a->visualClass == DirectColor )
   60.45 +        /* Prefer 32 bpp over 24 bpp, 16 bpp over 15 bpp */
   60.46 +        int a_bpp = a->depth == 24 ? a->bitsPerPixel : a->depth;
   60.47 +        int b_bpp = b->depth == 24 ? b->bitsPerPixel : b->depth;
   60.48 +        if ( a_bpp != b_bpp ) {
   60.49 +            return b_bpp - a_bpp;
   60.50 +        }
   60.51 +        /* Prefer DirectColor visuals, for gamma support */
   60.52 +        if ( a->visualClass == DirectColor && b->visualClass != DirectColor )
   60.53              return -1;
   60.54 -        if ( b->visualClass == DirectColor )
   60.55 +        if ( b->visualClass == DirectColor && a->visualClass != DirectColor )
   60.56              return 1;
   60.57 -        return 0;
   60.58 +        /* Maintain server refresh rate sorting */
   60.59 +        return a->num - b->num;
   60.60      } else if ( a->viewportWidth == b->viewportWidth ) {
   60.61          return b->viewportHeight - a->viewportHeight;
   60.62      } else {
   60.63 @@ -387,16 +401,21 @@
   60.64  		return(-1);
   60.65  	}
   60.66  
   60.67 +	/* Save DPMS and screensaver settings */
   60.68 +	X11_SaveScreenSaver(DGA_Display, &screensaver_timeout, &dpms_enabled);
   60.69 +	X11_DisableScreenSaver(DGA_Display);
   60.70 +
   60.71  	/* Query for the list of available video modes */
   60.72  	modes = SDL_NAME(XDGAQueryModes)(DGA_Display, DGA_Screen, &num_modes);
   60.73  	SDL_qsort(modes, num_modes, sizeof *modes, cmpmodes);
   60.74  	for ( i=0; i<num_modes; ++i ) {
   60.75 +		if ( ((modes[i].visualClass == PseudoColor) ||
   60.76 +		      (modes[i].visualClass == DirectColor) ||
   60.77 +		      (modes[i].visualClass == TrueColor)) && 
   60.78 +		     !(modes[i].flags & (XDGAInterlaced|XDGADoublescan)) ) {
   60.79  #ifdef DGA_DEBUG
   60.80 -		PrintMode(&modes[i]);
   60.81 +			PrintMode(&modes[i]);
   60.82  #endif
   60.83 -		if ( (modes[i].visualClass == PseudoColor) ||
   60.84 -		     (modes[i].visualClass == DirectColor) ||
   60.85 -		     (modes[i].visualClass == TrueColor) ) {
   60.86  			DGA_AddMode(this, modes[i].bitsPerPixel,
   60.87  			            modes[i].viewportWidth,
   60.88  			            modes[i].viewportHeight);
   60.89 @@ -452,7 +471,6 @@
   60.90  	for ( i=0; i<num_modes; ++i ) {
   60.91  		int depth;
   60.92  
   60.93 -		
   60.94  		depth = modes[i].depth;
   60.95  		if ( depth == 24 ) { /* Distinguish between 24 and 32 bpp */
   60.96  			depth = modes[i].bitsPerPixel;
   60.97 @@ -462,7 +480,8 @@
   60.98  		     (modes[i].viewportHeight == height) &&
   60.99  		     ((modes[i].visualClass == PseudoColor) ||
  60.100  		      (modes[i].visualClass == DirectColor) ||
  60.101 -		      (modes[i].visualClass == TrueColor)) ) {
  60.102 +		      (modes[i].visualClass == TrueColor)) &&
  60.103 +		     !(modes[i].flags & (XDGAInterlaced|XDGADoublescan)) ) {
  60.104  			break;
  60.105  		}
  60.106  	}
  60.107 @@ -470,6 +489,9 @@
  60.108  		SDL_SetError("No matching video mode found");
  60.109  		return(NULL);
  60.110  	}
  60.111 +#ifdef DGA_DEBUG
  60.112 +	PrintMode(&modes[i]);
  60.113 +#endif
  60.114  
  60.115  	/* Set the video mode */
  60.116  	mode = SDL_NAME(XDGASetMode)(DGA_Display, DGA_Screen, modes[i].num);
  60.117 @@ -749,6 +771,13 @@
  60.118  {
  60.119  	vidmem_bucket *bucket, *freeable;
  60.120  
  60.121 +	/* Wait for any pending operations involving this surface */
  60.122 +	if ( DGA_IsSurfaceBusy(surface) ) {
  60.123 +		LOCK_DISPLAY();
  60.124 +		DGA_WaitBusySurfaces(this);
  60.125 +		UNLOCK_DISPLAY();
  60.126 +	}
  60.127 +
  60.128  	/* Look for the bucket in the current list */
  60.129  	for ( bucket=&surfaces; bucket; bucket=bucket->next ) {
  60.130  		if ( bucket == (vidmem_bucket *)surface->hwdata ) {
  60.131 @@ -1032,7 +1061,7 @@
  60.132  		SDL_NAME(XDGACloseFramebuffer)(DGA_Display, DGA_Screen);
  60.133  		if ( this->screen ) {
  60.134  			/* Tell SDL not to free the pixels */
  60.135 -			this->screen->pixels = NULL;
  60.136 +			DGA_FreeHWSurface(this, this->screen);
  60.137  		}
  60.138  		SDL_NAME(XDGASetMode)(DGA_Display, DGA_Screen, 0);
  60.139  
  60.140 @@ -1048,7 +1077,6 @@
  60.141  		}
  60.142  #endif /* LOCK_DGA_DISPLAY */
  60.143  
  60.144 -
  60.145  		/* Clean up defined video modes */
  60.146  		for ( i=0; i<NUM_MODELISTS; ++i ) {
  60.147  			if ( SDL_modelist[i] != NULL ) {
  60.148 @@ -1063,6 +1091,9 @@
  60.149  		/* Clean up the memory bucket list */
  60.150  		DGA_FreeHWSurfaces(this);
  60.151  
  60.152 +		/* Restore DPMS and screensaver settings */
  60.153 +		X11_RestoreScreenSaver(DGA_Display, screensaver_timeout, dpms_enabled);
  60.154 +
  60.155  		/* Close up the display */
  60.156  		XCloseDisplay(DGA_Display);
  60.157  	}
    61.1 --- a/src/video/dga/SDL_dgavideo.h	Mon May 01 06:58:33 2006 +0000
    61.2 +++ b/src/video/dga/SDL_dgavideo.h	Wed May 17 08:18:28 2006 +0000
    61.3 @@ -25,11 +25,16 @@
    61.4  #define _SDL_dgavideo_h
    61.5  
    61.6  #include <X11/Xlib.h>
    61.7 +#include <X11/Xproto.h>
    61.8  
    61.9  #include "SDL_mouse.h"
   61.10  #include "SDL_mutex.h"
   61.11  #include "../SDL_sysvideo.h"
   61.12  
   61.13 +#if SDL_VIDEO_DRIVER_X11_DPMS
   61.14 +#include <X11/extensions/dpms.h>
   61.15 +#endif
   61.16 +
   61.17  /* Hidden "this" pointer for the video functions */
   61.18  #define _THIS	SDL_VideoDevice *this
   61.19  
   61.20 @@ -86,6 +91,10 @@
   61.21  #ifdef LOCK_DGA_DISPLAY
   61.22  	SDL_mutex *event_lock;
   61.23  #endif
   61.24 +
   61.25 +	/* Screensaver settings */
   61.26 +	int screensaver_timeout;
   61.27 +	BOOL dpms_enabled;
   61.28  };
   61.29  /* Old variable names */
   61.30  #define DGA_Display		(this->hidden->DGA_Display)
   61.31 @@ -107,5 +116,7 @@
   61.32  #define hw_lock			(this->hidden->hw_lock)
   61.33  #define DGA_event_base		(this->hidden->event_base)
   61.34  #define event_lock		(this->hidden->event_lock)
   61.35 +#define screensaver_timeout	(this->hidden->screensaver_timeout)
   61.36 +#define dpms_enabled		(this->hidden->dpms_enabled)
   61.37  
   61.38  #endif /* _SDL_dgavideo_h */
    62.1 --- a/src/video/directfb/SDL_DirectFB_events.c	Mon May 01 06:58:33 2006 +0000
    62.2 +++ b/src/video/directfb/SDL_DirectFB_events.c	Wed May 17 08:18:28 2006 +0000
    62.3 @@ -155,7 +155,7 @@
    62.4    keymap[DIKI_SHIFT_L - DIKI_UNKNOWN] = SDLK_LSHIFT;
    62.5    keymap[DIKI_SHIFT_R - DIKI_UNKNOWN] = SDLK_RSHIFT;
    62.6    keymap[DIKI_ALT_L - DIKI_UNKNOWN] = SDLK_LALT;
    62.7 -  keymap[DIKI_ALTGR - DIKI_UNKNOWN] = SDLK_RALT;
    62.8 +  keymap[DIKI_ALT_R - DIKI_UNKNOWN] = SDLK_RALT;
    62.9    keymap[DIKI_TAB - DIKI_UNKNOWN] = SDLK_TAB;
   62.10    keymap[DIKI_ENTER - DIKI_UNKNOWN] = SDLK_RETURN;
   62.11    keymap[DIKI_SPACE - DIKI_UNKNOWN] = SDLK_SPACE;
    63.1 --- a/src/video/directfb/SDL_DirectFB_video.c	Mon May 01 06:58:33 2006 +0000
    63.2 +++ b/src/video/directfb/SDL_DirectFB_video.c	Wed May 17 08:18:28 2006 +0000
    63.3 @@ -191,6 +191,9 @@
    63.4  
    63.5    HIDDEN->nummodes++;
    63.6  
    63.7 +  if (enumlist && enumlist->r.w == width && enumlist->r.h == height)
    63.8 +    return DFENUM_OK;
    63.9 +
   63.10    enumrect = SDL_calloc(1, sizeof(struct DirectFBEnumRect));
   63.11    if (!enumrect)
   63.12      {
    64.1 --- a/src/video/directfb/SDL_DirectFB_yuv.c	Mon May 01 06:58:33 2006 +0000
    64.2 +++ b/src/video/directfb/SDL_DirectFB_yuv.c	Wed May 17 08:18:28 2006 +0000
    64.3 @@ -200,7 +200,7 @@
    64.4  {
    64.5    DFBResult         ret;
    64.6    void             *data;
    64.7 -  unsigned int      pitch;
    64.8 +  int               pitch;
    64.9    IDirectFBSurface *surface = overlay->hwdata->surface;
   64.10  
   64.11    ret = surface->Lock (surface, DSLF_READ | DSLF_WRITE, &data, &pitch);
    65.1 --- a/src/video/fbcon/SDL_fb3dfx.c	Mon May 01 06:58:33 2006 +0000
    65.2 +++ b/src/video/fbcon/SDL_fb3dfx.c	Wed May 17 08:18:28 2006 +0000
    65.3 @@ -57,6 +57,9 @@
    65.4  	int dstX, dstY;
    65.5  
    65.6  	/* Don't blit to the display surface when switched away */
    65.7 +	if ( switched_away ) {
    65.8 +		return -2; /* no hardware access */
    65.9 +	}
   65.10  	if ( dst == this->screen ) {
   65.11  		SDL_mutexP(hw_lock);
   65.12  	}
   65.13 @@ -102,6 +105,9 @@
   65.14  	Uint32 use_colorkey;
   65.15  
   65.16  	/* Don't blit to the display surface when switched away */
   65.17 +	if ( switched_away ) {
   65.18 +		return -2; /* no hardware access */
   65.19 +	}
   65.20  	if ( dst == this->screen ) {
   65.21  		SDL_mutexP(hw_lock);
   65.22  	}
    66.1 --- a/src/video/fbcon/SDL_fbevents.c	Mon May 01 06:58:33 2006 +0000
    66.2 +++ b/src/video/fbcon/SDL_fbevents.c	Wed May 17 08:18:28 2006 +0000
    66.3 @@ -55,6 +55,8 @@
    66.4  #define GPM_NODE_FIFO	"/dev/gpmdata"
    66.5  #endif
    66.6  
    66.7 +/*#define DEBUG_KEYBOARD*/
    66.8 +/*#define DEBUG_MOUSE*/
    66.9  
   66.10  /* The translation tables from a console scancode to a SDL keysym */
   66.11  #define NUM_VGAKEYMAPS	(1<<KG_CAPSSHIFT)
   66.12 @@ -207,6 +209,8 @@
   66.13  			SDL_SetError("Unable to set keyboard in graphics mode");
   66.14  			return(-1);
   66.15  		}
   66.16 +		/* Prevent switching the virtual terminal */
   66.17 +		ioctl(keyboard_fd, VT_LOCKSWITCH, 1);
   66.18  	}
   66.19  	return(keyboard_fd);
   66.20  }
   66.21 @@ -220,6 +224,7 @@
   66.22  		saved_kbd_mode = -1;
   66.23  
   66.24  		/* Head back over to the original virtual terminal */
   66.25 +		ioctl(keyboard_fd, VT_UNLOCKSWITCH, 1);
   66.26  		if ( saved_vt > 0 ) {
   66.27  			ioctl(keyboard_fd, VT_ACTIVATE, saved_vt);
   66.28  		}
   66.29 @@ -280,8 +285,15 @@
   66.30  		}
   66.31   		if ( keyboard_fd < 0 ) {
   66.32  			/* Last resort, maybe our tty is a usable VT */
   66.33 -			current_vt = 0;
   66.34 +			struct vt_stat vtstate;
   66.35 +
   66.36  			keyboard_fd = open("/dev/tty", O_RDWR);
   66.37 +
   66.38 +			if ( ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0 ) {
   66.39 +				current_vt = vtstate.v_active;
   66.40 +			} else {
   66.41 +				current_vt = 0;
   66.42 +			}
   66.43   		}
   66.44  #ifdef DEBUG_KEYBOARD
   66.45  		fprintf(stderr, "Current VT: %d\n", current_vt);
   66.46 @@ -360,7 +372,7 @@
   66.47  }
   66.48  
   66.49  /* Returns true if /dev/gpmdata is being written to by gpm */
   66.50 -static int gpm_available(void)
   66.51 +static int gpm_available(char *proto, size_t protolen)
   66.52  {
   66.53  	int available;
   66.54  	DIR *proc;
   66.55 @@ -370,6 +382,9 @@
   66.56  	char args[PATH_MAX], *arg;
   66.57  
   66.58  	/* Don't bother looking if the fifo isn't there */
   66.59 +#ifdef DEBUG_MOUSE 
   66.60 +	fprintf(stderr,"testing gpm\n");
   66.61 +#endif
   66.62  	if ( access(GPM_NODE_FIFO, F_OK) < 0 ) {
   66.63  		return(0);
   66.64  	}
   66.65 @@ -377,17 +392,37 @@
   66.66  	available = 0;
   66.67  	proc = opendir("/proc");
   66.68  	if ( proc ) {
   66.69 -		while ( (pid=find_pid(proc, "gpm")) > 0 ) {
   66.70 +		char raw_proto[10] = { '\0' };
   66.71 +		char repeat_proto[10] = { '\0' };
   66.72 +		while ( !available && (pid=find_pid(proc, "gpm")) > 0 ) {
   66.73  			SDL_snprintf(path, SDL_arraysize(path), "/proc/%d/cmdline", pid);
   66.74  			cmdline = open(path, O_RDONLY, 0);
   66.75  			if ( cmdline >= 0 ) {
   66.76  				len = read(cmdline, args, sizeof(args));
   66.77  				arg = args;
   66.78  				while ( len > 0 ) {
   66.79 -					if ( SDL_strcmp(arg, "-R") == 0 ) {
   66.80 +					arglen = SDL_strlen(arg)+1;
   66.81 +#ifdef DEBUG_MOUSE 
   66.82 +				        fprintf(stderr,"gpm arg %s len %d\n",arg,arglen);
   66.83 +#endif
   66.84 +					if ( SDL_strcmp(arg, "-t") == 0) {
   66.85 +						/* protocol string, keep it for later */
   66.86 +						char *t, *s;
   66.87 +						t = arg + arglen;
   66.88 +						s = SDL_strchr(t, ' ');
   66.89 +						if (s) *s = 0;
   66.90 +						SDL_strlcpy(raw_proto, t, SDL_arraysize(raw_proto));
   66.91 +						if (s) *s = ' ';
   66.92 +					}
   66.93 +					if ( SDL_strncmp(arg, "-R", 2) == 0 ) {
   66.94 +						char *t, *s;
   66.95  						available = 1;
   66.96 +						t = arg + 2;
   66.97 +						s = SDL_strchr(t, ' ');
   66.98 +						if (s) *s = 0;
   66.99 +						SDL_strlcpy(repeat_proto, t, SDL_arraysize(repeat_proto));
  66.100 +						if (s) *s = ' ';
  66.101  					}
  66.102 -					arglen = SDL_strlen(arg)+1;
  66.103  					len -= arglen;
  66.104  					arg += arglen;
  66.105  				}
  66.106 @@ -395,6 +430,16 @@
  66.107  			}
  66.108  		}
  66.109  		closedir(proc);
  66.110 +
  66.111 +		if ( available ) {
  66.112 +			if ( SDL_strcmp(repeat_proto, "raw") == 0 ) {
  66.113 +				SDL_strlcpy(proto, raw_proto, protolen);
  66.114 +			} else if ( *repeat_proto ) {
  66.115 +				SDL_strlcpy(proto, repeat_proto, protolen);
  66.116 +			} else {
  66.117 +				SDL_strlcpy(proto, "msc", protolen);
  66.118 +			}
  66.119 +		}
  66.120  	}
  66.121  	return available;
  66.122  }
  66.123 @@ -414,7 +459,7 @@
  66.124  			{0xFF}
  66.125  	*/
  66.126  	Uint8 set_imps2[] = {0xf3, 200, 0xf3, 100, 0xf3, 80};
  66.127 -	Uint8 reset = 0xff;
  66.128 +	/*Uint8 reset = 0xff;*/
  66.129  	fd_set fdset;
  66.130  	struct timeval tv;
  66.131  	int retval = 0;
  66.132 @@ -552,14 +597,35 @@
  66.133  		};
  66.134  		/* First try to use GPM in repeater mode */
  66.135  		if ( mouse_fd < 0 ) {
  66.136 -			if ( gpm_available() ) {
  66.137 +			char proto[10];
  66.138 +			if ( gpm_available(proto, SDL_arraysize(proto)) ) {
  66.139  				mouse_fd = open(GPM_NODE_FIFO, O_RDONLY, 0);
  66.140  				if ( mouse_fd >= 0 ) {
  66.141 +					if ( SDL_strcmp(proto, "msc") == 0 ) {
  66.142 +						mouse_drv = MOUSE_MSC;
  66.143 +					} else if ( SDL_strcmp(proto, "ps2") == 0 ) {
  66.144 +						mouse_drv = MOUSE_PS2;
  66.145 +					} else if ( SDL_strcmp(proto, "imps2") == 0 ) {
  66.146 +						mouse_drv = MOUSE_IMPS2;
  66.147 +					} else if ( SDL_strcmp(proto, "ms") == 0 ||
  66.148 +					            SDL_strcmp(proto, "bare") == 0 ) {
  66.149 +						mouse_drv = MOUSE_MS;
  66.150 +					} else if ( SDL_strcmp(proto, "bm") == 0 ) {
  66.151 +						mouse_drv = MOUSE_BM;
  66.152 +					} else {
  66.153 +						/* Unknown protocol... */
  66.154  #ifdef DEBUG_MOUSE
  66.155 -fprintf(stderr, "Using GPM mouse\n");
  66.156 +						fprintf(stderr, "GPM mouse using unknown protocol = %s\n", proto);
  66.157  #endif
  66.158 -					mouse_drv = MOUSE_MSC;
  66.159 +						close(mouse_fd);
  66.160 +						mouse_fd = -1;
  66.161 +					}
  66.162  				}
  66.163 +#ifdef DEBUG_MOUSE
  66.164 +				if ( mouse_fd >= 0 ) {
  66.165 +					fprintf(stderr, "Using GPM mouse, protocol = %s\n", proto);
  66.166 +				}
  66.167 +#endif /* DEBUG_MOUSE */
  66.168  			}
  66.169  		}
  66.170  		/* Now try to use a modern PS/2 mouse */
  66.171 @@ -853,65 +919,65 @@
  66.172  	return;
  66.173  }
  66.174  
  66.175 -/* Handle switching to another VC, returns when our VC is back.
  66.176 -   This isn't necessarily the best solution.  For SDL 1.3 we need
  66.177 -   a way of notifying the application when we lose access to the
  66.178 -   video hardware and when we regain it.
  66.179 - */
  66.180 +/* Handle switching to another VC, returns when our VC is back */
  66.181 +static void switch_vt_prep(_THIS)
  66.182 +{
  66.183 +	SDL_Surface *screen = SDL_VideoSurface;
  66.184 +
  66.185 +	SDL_PrivateAppActive(0, (SDL_APPACTIVE|SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS));
  66.186 +
  66.187 +	/* Save the contents of the screen, and go to text mode */
  66.188 +	wait_idle(this);
  66.189 +	screen_arealen = ((screen->h + (2*this->offset_y)) * screen->pitch);
  66.190 +	screen_contents = (Uint8 *)SDL_malloc(screen_arealen);
  66.191 +	if ( screen_contents ) {
  66.192 +		SDL_memcpy(screen_contents, screen->pixels, screen_arealen);
  66.193 +	}
  66.194 +	FB_SavePaletteTo(this, 256, screen_palette);
  66.195 +	ioctl(console_fd, FBIOGET_VSCREENINFO, &screen_vinfo);
  66.196 +	ioctl(keyboard_fd, KDSETMODE, KD_TEXT);
  66.197 +	ioctl(keyboard_fd, VT_UNLOCKSWITCH, 1);
  66.198 +}
  66.199 +static void switch_vt_done(_THIS)
  66.200 +{
  66.201 +	SDL_Surface *screen = SDL_VideoSurface;
  66.202 +
  66.203 +	/* Restore graphics mode and the contents of the screen */
  66.204 +	ioctl(keyboard_fd, VT_LOCKSWITCH, 1);
  66.205 +	ioctl(keyboard_fd, KDSETMODE, KD_GRAPHICS);
  66.206 +	ioctl(console_fd, FBIOPUT_VSCREENINFO, &screen_vinfo);
  66.207 +	FB_RestorePaletteFrom(this, 256, screen_palette);
  66.208 +	if ( screen_contents ) {
  66.209 +		SDL_memcpy(screen->pixels, screen_contents, screen_arealen);
  66.210 +		SDL_free(screen_contents);
  66.211 +		screen_contents = NULL;
  66.212 +	}
  66.213 +
  66.214 +	/* Get updates to the shadow surface while switched away */
  66.215 +	if ( SDL_ShadowSurface ) {
  66.216 +		SDL_UpdateRect(SDL_ShadowSurface, 0, 0, 0, 0);
  66.217 +	}
  66.218 +
  66.219 +	SDL_PrivateAppActive(1, (SDL_APPACTIVE|SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS));
  66.220 +}
  66.221  static void switch_vt(_THIS, unsigned short which)
  66.222  {
  66.223 -	struct fb_var_screeninfo vinfo;
  66.224  	struct vt_stat vtstate;
  66.225 -	unsigned short v_active;
  66.226 -	__u16 saved_pal[3*256];
  66.227 -	SDL_Surface *screen;
  66.228 -	Uint32 screen_arealen;
  66.229 -	Uint8 *screen_contents = NULL;
  66.230  
  66.231  	/* Figure out whether or not we're switching to a new console */
  66.232  	if ( (ioctl(keyboard_fd, VT_GETSTATE, &vtstate) < 0) ||
  66.233  	     (which == vtstate.v_active) ) {
  66.234  		return;
  66.235  	}
  66.236 -	v_active = vtstate.v_active;
  66.237 -
  66.238 -	/* Save the contents of the screen, and go to text mode */
  66.239 -	SDL_mutexP(hw_lock);
  66.240 -	wait_idle(this);
  66.241 -	screen = SDL_VideoSurface;
  66.242 -	if ( !SDL_ShadowSurface ) {
  66.243 -		screen_arealen = (screen->h*screen->pitch);
  66.244 -		screen_contents = (Uint8 *)SDL_malloc(screen_arealen);
  66.245 -		if ( screen_contents ) {
  66.246 -			SDL_memcpy(screen_contents, (Uint8 *)screen->pixels + screen->offset, screen_arealen);
  66.247 -		}
  66.248 -	}
  66.249 -	FB_SavePaletteTo(this, 256, saved_pal);
  66.250 -	ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo);
  66.251 -	ioctl(keyboard_fd, KDSETMODE, KD_TEXT);
  66.252  
  66.253  	/* New console, switch to it */
  66.254 +	SDL_mutexP(hw_lock);
  66.255 +	switch_vt_prep(this);
  66.256  	if ( ioctl(keyboard_fd, VT_ACTIVATE, which) == 0 ) {
  66.257 -		/* Wait for our console to be activated again */
  66.258  		ioctl(keyboard_fd, VT_WAITACTIVE, which);
  66.259 -		while ( ioctl(keyboard_fd, VT_WAITACTIVE, v_active) < 0 ) {
  66.260 -			if ( (errno != EINTR) && (errno != EAGAIN) ) {
  66.261 -				/* Unknown VT error - cancel this */
  66.262 -				break;
  66.263 -			}
  66.264 -			SDL_Delay(500);
  66.265 -		}
  66.266 -	}
  66.267 -
  66.268 -	/* Restore graphics mode and the contents of the screen */
  66.269 -	ioctl(keyboard_fd, KDSETMODE, KD_GRAPHICS);
  66.270 -	ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo);
  66.271 -	FB_RestorePaletteFrom(this, 256, saved_pal);
  66.272 -	if ( screen_contents ) {
  66.273 -		SDL_memcpy((Uint8 *)screen->pixels + screen->offset, screen_contents, screen_arealen);
  66.274 -		SDL_free(screen_contents);
  66.275 +		switched_away = 1;
  66.276  	} else {
  66.277 -		SDL_UpdateRect(screen, 0, 0, 0, 0);
  66.278 +		switch_vt_done(this);
  66.279  	}
  66.280  	SDL_mutexV(hw_lock);
  66.281  }
  66.282 @@ -969,6 +1035,18 @@
  66.283  	static struct timeval zero;
  66.284  
  66.285  	do {
  66.286 +		if ( switched_away ) {
  66.287 +			struct vt_stat vtstate;
  66.288 +
  66.289 +			SDL_mutexP(hw_lock);
  66.290 +			if ( (ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0) &&
  66.291 +			     vtstate.v_active == current_vt ) {
  66.292 +				switched_away = 0;
  66.293 +				switch_vt_done(this);
  66.294 +			}
  66.295 +			SDL_mutexV(hw_lock);
  66.296 +		}
  66.297 +
  66.298  		posted = 0;
  66.299  
  66.300  		FD_ZERO(&fdset);
  66.301 @@ -1037,6 +1115,12 @@
  66.302  	  case SCANCODE_LEFTWIN:
  66.303  	    keymap[i] = SDLK_LSUPER;
  66.304  	    break;
  66.305 +	  case SCANCODE_LEFTALT:
  66.306 +	    keymap[i] = SDLK_LALT;
  66.307 +	    break;
  66.308 +	  case SCANCODE_RIGHTALT:
  66.309 +	    keymap[i] = SDLK_RALT;
  66.310 +	    break;
  66.311  	  case 127:
  66.312  	    keymap[i] = SDLK_MENU;
  66.313  	    break;
  66.314 @@ -1138,10 +1222,10 @@
  66.315  		if ( modstate & KMOD_CTRL ) {
  66.316  			map |= (1<<KG_CTRL);
  66.317  		}
  66.318 -		if ( modstate & KMOD_ALT ) {
  66.319 +		if ( modstate & KMOD_LALT ) {
  66.320  			map |= (1<<KG_ALT);
  66.321  		}
  66.322 -		if ( modstate & KMOD_MODE ) {
  66.323 +		if ( modstate & KMOD_RALT ) {
  66.324  			map |= (1<<KG_ALTGR);
  66.325  		}
  66.326  		if ( KTYP(vga_keymap[map][scancode]) == KT_LETTER ) {
    67.1 --- a/src/video/fbcon/SDL_fbmatrox.c	Mon May 01 06:58:33 2006 +0000
    67.2 +++ b/src/video/fbcon/SDL_fbmatrox.c	Wed May 17 08:18:28 2006 +0000
    67.3 @@ -70,6 +70,9 @@
    67.4  	Uint32 fillop;
    67.5  
    67.6  	/* Don't blit to the display surface when switched away */
    67.7 +	if ( switched_away ) {
    67.8 +		return -2; /* no hardware access */
    67.9 +	}
   67.10  	if ( dst == this->screen ) {
   67.11  		SDL_mutexP(hw_lock);
   67.12  	}
   67.13 @@ -132,6 +135,9 @@
   67.14  	}
   67.15  
   67.16  	/* Don't blit to the display surface when switched away */
   67.17 +	if ( switched_away ) {
   67.18 +		return -2; /* no hardware access */
   67.19 +	}
   67.20  	if ( dst == this->screen ) {
   67.21  		SDL_mutexP(hw_lock);
   67.22  	}
    68.1 --- a/src/video/fbcon/SDL_fbriva.c	Mon May 01 06:58:33 2006 +0000
    68.2 +++ b/src/video/fbcon/SDL_fbriva.c	Wed May 17 08:18:28 2006 +0000
    68.3 @@ -77,6 +77,9 @@
    68.4  	RivaBitmap *Bitmap = (RivaBitmap *)(mapped_io + BITMAP_OFFSET);
    68.5  
    68.6  	/* Don't blit to the display surface when switched away */
    68.7 +	if ( switched_away ) {
    68.8 +		return -2; /* no hardware access */
    68.9 +	}
   68.10  	if ( dst == this->screen ) {
   68.11  		SDL_mutexP(hw_lock);
   68.12  	}
   68.13 @@ -120,6 +123,9 @@
   68.14  	}
   68.15  
   68.16  	/* Don't blit to the display surface when switched away */
   68.17 +	if ( switched_away ) {
   68.18 +		return -2; /* no hardware access */
   68.19 +	}
   68.20  	if ( dst == this->screen ) {
   68.21  		SDL_mutexP(hw_lock);
   68.22  	}
    69.1 --- a/src/video/fbcon/SDL_fbvideo.c	Mon May 01 06:58:33 2006 +0000
    69.2 +++ b/src/video/fbcon/SDL_fbvideo.c	Wed May 17 08:18:28 2006 +0000
    69.3 @@ -149,11 +149,25 @@
    69.4                                    struct fb_var_screeninfo *vinfo);
    69.5  static void FB_RestorePalette(_THIS);
    69.6  
    69.7 +/* Small wrapper for mmap() so we can play nicely with no-mmu hosts
    69.8 + * (non-mmu hosts disallow the MAP_SHARED flag) */
    69.9 +
   69.10 +static void *do_mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)
   69.11 +{
   69.12 +	void *ret;
   69.13 +	ret = mmap(start, length, prot, flags, fd, offset);
   69.14 +	if ( ret == (char *)-1 && (flags & MAP_SHARED) ) {
   69.15 +		ret = mmap(start, length, prot,
   69.16 +		           (flags & ~MAP_SHARED) | MAP_PRIVATE, fd, offset);
   69.17 +	}
   69.18 +	return ret;
   69.19 +}
   69.20 +
   69.21  /* FB driver bootstrap functions */
   69.22  
   69.23  static int FB_Available(void)
   69.24  {
   69.25 -	int console;
   69.26 +	int console = -1;
   69.27  	/* Added check for /fb/0 (devfs) */
   69.28  	/* but - use environment variable first... if it fails, still check defaults */
   69.29  	int idx = 0;
   69.30 @@ -535,7 +549,7 @@
   69.31  	mapped_offset = (((long)finfo.smem_start) -
   69.32  	                (((long)finfo.smem_start)&~(PAGE_SIZE-1)));
   69.33  	mapped_memlen = finfo.smem_len+mapped_offset;
   69.34 -	mapped_mem = mmap(NULL, mapped_memlen,
   69.35 +	mapped_mem = do_mmap(NULL, mapped_memlen,
   69.36  	                  PROT_READ|PROT_WRITE, MAP_SHARED, console_fd, 0);
   69.37  	if ( mapped_mem == (char *)-1 ) {
   69.38  		SDL_SetError("Unable to memory map the video hardware");
   69.39 @@ -579,7 +593,7 @@
   69.40  	ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo);
   69.41  	if ( finfo.accel && finfo.mmio_len ) {
   69.42  		mapped_iolen = finfo.mmio_len;
   69.43 -		mapped_io = mmap(NULL, mapped_iolen, PROT_READ|PROT_WRITE,
   69.44 +		mapped_io = do_mmap(NULL, mapped_iolen, PROT_READ|PROT_WRITE,
   69.45  		                 MAP_SHARED, console_fd, mapped_memlen);
   69.46  		if ( mapped_io == (char *)-1 ) {
   69.47  			/* Hmm, failed to memory map I/O registers */
   69.48 @@ -1238,26 +1252,10 @@
   69.49  	surface->hwdata = NULL;
   69.50  }
   69.51  
   69.52 -/* Routine to check to see if the frame buffer virtual terminal */
   69.53 -/* is the current(active) one.  If it is not, result will cause */
   69.54 -/* Lock to fail.  (would have waited forever, since the fbevent */
   69.55 -/* keyboard handler maintains a lock when switched away from    */
   69.56 -/* current) */
   69.57 -static __inline__ int FB_IsFrameBufferActive(_THIS)
   69.58 -{
   69.59 -	struct vt_stat vtstate;
   69.60 -	if ( (ioctl(keyboard_fd, VT_GETSTATE, &vtstate) < 0) ||
   69.61 -	     (current_vt != vtstate.v_active) ) {
   69.62 -		return 0;
   69.63 -	}
   69.64 -	return 1;
   69.65 -}
   69.66 -
   69.67 -
   69.68  static int FB_LockHWSurface(_THIS, SDL_Surface *surface)
   69.69  {
   69.70 -	if ( !FB_IsFrameBufferActive(this) ) {
   69.71 -		return -1; /* fail locking. */
   69.72 +	if ( switched_away ) {
   69.73 +		return -2; /* no hardware access */
   69.74  	}
   69.75  	if ( surface == this->screen ) {
   69.76  		SDL_mutexP(hw_lock);
   69.77 @@ -1293,6 +1291,10 @@
   69.78  
   69.79  static int FB_FlipHWSurface(_THIS, SDL_Surface *surface)
   69.80  {
   69.81 +	if ( switched_away ) {
   69.82 +		return -2; /* no hardware access */
   69.83 +	}
   69.84 +
   69.85  	/* Wait for vertical retrace and then flip display */
   69.86  	cache_vinfo.yoffset = flip_page*surface->h;
   69.87  	if ( FB_IsSurfaceBusy(this->screen) ) {
   69.88 @@ -1333,6 +1335,10 @@
   69.89      Uint32 *src, *srcPtr;
   69.90      Uint8  *dst, *dstPtr;
   69.91  
   69.92 +    if ( switched_away ) {
   69.93 +        return; /* no hardware access */
   69.94 +    }
   69.95 +
   69.96      screen = this->screen;
   69.97      FBPitch = screen->w >> 3;
   69.98      SRCPitch = screen->pitch >> 2;
    70.1 --- a/src/video/fbcon/SDL_fbvideo.h	Mon May 01 06:58:33 2006 +0000
    70.2 +++ b/src/video/fbcon/SDL_fbvideo.h	Wed May 17 08:18:28 2006 +0000
    70.3 @@ -85,6 +85,11 @@
    70.4  	int surfaces_memleft;
    70.5  
    70.6  	SDL_mutex *hw_lock;
    70.7 +	int switched_away;
    70.8 +	struct fb_var_screeninfo screen_vinfo;
    70.9 +	Uint32 screen_arealen;
   70.10 +	Uint8 *screen_contents;
   70.11 +	__u16  screen_palette[3*256];
   70.12  
   70.13  	void (*wait_vbl)(_THIS);
   70.14  	void (*wait_idle)(_THIS);
   70.15 @@ -117,6 +122,11 @@
   70.16  #define surfaces_memtotal	(this->hidden->surfaces_memtotal)
   70.17  #define surfaces_memleft	(this->hidden->surfaces_memleft)
   70.18  #define hw_lock			(this->hidden->hw_lock)
   70.19 +#define switched_away		(this->hidden->switched_away)
   70.20 +#define screen_vinfo		(this->hidden->screen_vinfo)
   70.21 +#define screen_arealen		(this->hidden->screen_arealen)
   70.22 +#define screen_contents		(this->hidden->screen_contents)
   70.23 +#define screen_palette		(this->hidden->screen_palette)
   70.24  #define wait_vbl		(this->hidden->wait_vbl)
   70.25  #define wait_idle		(this->hidden->wait_idle)
   70.26  
    71.1 --- a/src/video/maccommon/SDL_macgl.c	Mon May 01 06:58:33 2006 +0000
    71.2 +++ b/src/video/maccommon/SDL_macgl.c	Wed May 17 08:18:28 2006 +0000
    71.3 @@ -168,7 +168,11 @@
    71.4  int Mac_GL_LoadLibrary(_THIS, const char *location)
    71.5  {
    71.6  	if (location == NULL)
    71.7 +#if __MACH__
    71.8 +		location = "/System/Library/Frameworks/OpenGL.framework/OpenGL";
    71.9 +#else
   71.10  		location = "OpenGLLibrary";
   71.11 +#endif
   71.12  
   71.13  	this->hidden->libraryHandle = SDL_LoadObject(location);
   71.14  
    72.1 --- a/src/video/maccommon/SDL_macgl_c.h	Mon May 01 06:58:33 2006 +0000
    72.2 +++ b/src/video/maccommon/SDL_macgl_c.h	Wed May 17 08:18:28 2006 +0000
    72.3 @@ -26,7 +26,7 @@
    72.4  
    72.5  #if SDL_VIDEO_OPENGL
    72.6  #include "SDL_opengl.h"
    72.7 -#ifdef MACOSX
    72.8 +#if __MACOSX__
    72.9  #include <AGL/agl.h>   /* AGL.framework */
   72.10  #else
   72.11  #include <agl.h>
    73.1 --- a/src/video/macdsp/SDL_dspvideo.c	Mon May 01 06:58:33 2006 +0000
    73.2 +++ b/src/video/macdsp/SDL_dspvideo.c	Wed May 17 08:18:28 2006 +0000
    73.3 @@ -682,7 +682,7 @@
    73.4    if (dialog == NULL)
    73.5  	 return (0);
    73.6    
    73.7 -#if TARGET_API_CARBON
    73.8 +#if TARGET_API_MAC_CARBON
    73.9    SetPort (GetDialogPort(dialog));
   73.10  #else
   73.11    SetPort ((WindowPtr) dialog);
    74.1 --- a/src/video/macrom/SDL_romvideo.c	Mon May 01 06:58:33 2006 +0000
    74.2 +++ b/src/video/macrom/SDL_romvideo.c	Wed May 17 08:18:28 2006 +0000
    74.3 @@ -35,6 +35,7 @@
    74.4  #include <Movies.h>
    74.5  #endif
    74.6  #else
    74.7 +#include <Quickdraw.h>
    74.8  #include <LowMem.h>
    74.9  #include <Gestalt.h>
   74.10  #include <Devices.h>
   74.11 @@ -637,12 +638,12 @@
   74.12  	SetPortWindowPort(SDL_Window);
   74.13  	thePort = GetWindowPort(SDL_Window);
   74.14  	memworld = (GWorldPtr)GetWRefCon(SDL_Window);
   74.15 -#if TARGET_API_MAC_CARBON
   74.16 +#if TARGET_API_MAC_CARBON && ACCESSOR_CALLS_ARE_FUNCTIONS
   74.17  	memBits = GetPortBitMapForCopyBits((CGrafPtr) memworld);
   74.18  #else
   74.19  	memBits = &((GrafPtr)memworld)->portBits;
   74.20  #endif
   74.21 -#if TARGET_API_MAC_CARBON
   74.22 +#if TARGET_API_MAC_CARBON && ACCESSOR_CALLS_ARE_FUNCTIONS
   74.23  	winBits = GetPortBitMapForCopyBits(thePort);
   74.24  #else
   74.25  	winBits = &SDL_Window->portBits;
    75.1 --- a/src/video/ps2gs/SDL_gsyuv.c	Mon May 01 06:58:33 2006 +0000
    75.2 +++ b/src/video/ps2gs/SDL_gsyuv.c	Wed May 17 08:18:28 2006 +0000
    75.3 @@ -325,7 +325,7 @@
    75.4  	int lum_pitch;
    75.5  	int crb_pitch;
    75.6  	Uint32 *lum_src, *Cr_src, *Cb_src;
    75.7 -	Uint32 *src, *dst;
    75.8 +	Uint32 *srcp, *dstp;
    75.9  	unsigned int x, y;
   75.10  	SDL_Surface *screen;
   75.11  
   75.12 @@ -345,7 +345,7 @@
   75.13  		SDL_SetError("Unsupported YUV format in blit (?)");
   75.14  		return(-1);
   75.15  	}
   75.16 -	dst = (Uint32 *)hwdata->ipu_imem;
   75.17 +	dstp = (Uint32 *)hwdata->ipu_imem;
   75.18  	lum_pitch = overlay->w/4;
   75.19  	crb_pitch = (overlay->w/2)/4;
   75.20  
   75.21 @@ -355,28 +355,28 @@
   75.22  		Cr_src = Cr;
   75.23  		Cb_src = Cb;
   75.24  		for ( w=overlay->w/16; w; --w ) {
   75.25 -			src = lum_src;
   75.26 +			srcp = lum_src;
   75.27  			for ( i=0; i<16; ++i ) {
   75.28 -				dst[0] = src[0];
   75.29 -				dst[1] = src[1];
   75.30 -				dst[2] = src[2];
   75.31 -				dst[3] = src[3];
   75.32 -				src += lum_pitch;
   75.33 -				dst += 4;
   75.34 +				dstp[0] = srcp[0];
   75.35 +				dstp[1] = srcp[1];
   75.36 +				dstp[2] = srcp[2];
   75.37 +				dstp[3] = srcp[3];
   75.38 +				srcp += lum_pitch;
   75.39 +				dstp += 4;
   75.40  			}
   75.41 -			src = Cb_src;
   75.42 +			srcp = Cb_src;
   75.43  			for ( i=0; i<8; ++i ) {
   75.44 -				dst[0] = src[0];
   75.45 -				dst[1] = src[1];
   75.46 -				src += crb_pitch;
   75.47 -				dst += 2;
   75.48 +				dstp[0] = srcp[0];
   75.49 +				dstp[1] = srcp[1];
   75.50 +				srcp += crb_pitch;
   75.51 +				dstp += 2;
   75.52  			}
   75.53 -			src = Cr_src;
   75.54 +			srcp = Cr_src;
   75.55  			for ( i=0; i<8; ++i ) {
   75.56 -				dst[0] = src[0];
   75.57 -				dst[1] = src[1];
   75.58 -				src += crb_pitch;
   75.59 -				dst += 2;
   75.60 +				dstp[0] = srcp[0];
   75.61 +				dstp[1] = srcp[1];
   75.62 +				srcp += crb_pitch;
   75.63 +				dstp += 2;
   75.64  			}
   75.65  			lum_src += 16 / 4;
   75.66  			Cb_src += 8 / 4;
    76.1 --- a/src/video/quartz/SDL_QuartzVideo.m	Mon May 01 06:58:33 2006 +0000
    76.2 +++ b/src/video/quartz/SDL_QuartzVideo.m	Wed May 17 08:18:28 2006 +0000
    76.3 @@ -117,14 +117,14 @@
    76.4      SDL_VideoDevice *device;
    76.5      SDL_PrivateVideoData *hidden;
    76.6  
    76.7 -    device = (SDL_VideoDevice*) malloc (sizeof (*device) );
    76.8 -    hidden = (SDL_PrivateVideoData*) malloc (sizeof (*hidden) );
    76.9 +    device = (SDL_VideoDevice*) SDL_malloc (sizeof (*device) );
   76.10 +    hidden = (SDL_PrivateVideoData*) SDL_malloc (sizeof (*hidden) );
   76.11  
   76.12      if (device == NULL || hidden == NULL)
   76.13          SDL_OutOfMemory ();
   76.14  
   76.15 -    memset (device, 0, sizeof (*device) );
   76.16 -    memset (hidden, 0, sizeof (*hidden) );
   76.17 +    SDL_memset (device, 0, sizeof (*device) );
   76.18 +    SDL_memset (hidden, 0, sizeof (*hidden) );
   76.19  
   76.20      device->hidden = hidden;
   76.21  
   76.22 @@ -178,8 +178,8 @@
   76.23  
   76.24  static void QZ_DeleteDevice (SDL_VideoDevice *device) {
   76.25  
   76.26 -    free (device->hidden);
   76.27 -    free (device);
   76.28 +    SDL_free (device->hidden);
   76.29 +    SDL_free (device);
   76.30  }
   76.31  
   76.32  static int QZ_VideoInit (_THIS, SDL_PixelFormat *video_format) {
   76.33 @@ -242,9 +242,9 @@
   76.34          int i;
   76.35  
   76.36          for (i = 0; client_mode_list[i] != NULL; i++)
   76.37 -            free (client_mode_list[i]);
   76.38 +            SDL_free (client_mode_list[i]);
   76.39  
   76.40 -        free (client_mode_list);
   76.41 +        SDL_free (client_mode_list);
   76.42          client_mode_list = NULL;
   76.43      }
   76.44  
   76.45 @@ -297,12 +297,12 @@
   76.46  
   76.47                  if (client_mode_list == NULL)
   76.48                      client_mode_list = (SDL_Rect**) 
   76.49 -                        malloc (sizeof(*client_mode_list) * (list_size+1) );
   76.50 +                        SDL_malloc (sizeof(*client_mode_list) * (list_size+1) );
   76.51                  else
   76.52                      client_mode_list = (SDL_Rect**) 
   76.53 -                        realloc (client_mode_list, sizeof(*client_mode_list) * (list_size+1));
   76.54 +                        SDL_realloc (client_mode_list, sizeof(*client_mode_list) * (list_size+1));
   76.55  
   76.56 -                rect = (SDL_Rect*) malloc (sizeof(**client_mode_list));
   76.57 +                rect = (SDL_Rect*) SDL_malloc (sizeof(**client_mode_list));
   76.58  
   76.59                  if (client_mode_list == NULL || rect == NULL) {
   76.60                      SDL_OutOfMemory ();
   76.61 @@ -372,7 +372,7 @@
   76.62              SDL_WaitThread (thread, NULL);
   76.63              SDL_DestroySemaphore (sem1);
   76.64              SDL_DestroySemaphore (sem2);
   76.65 -            free (sw_buffers[0]);
   76.66 +            SDL_free (sw_buffers[0]);
   76.67          }
   76.68          
   76.69          /* 
   76.70 @@ -493,7 +493,7 @@
   76.71          this->UnlockHWSurface = QZ_UnlockDoubleBuffer;
   76.72          this->FlipHWSurface = QZ_FlipDoubleBuffer;
   76.73  
   76.74 -        current->pixels = malloc (current->pitch * current->h * 2);
   76.75 +        current->pixels = SDL_malloc (current->pitch * current->h * 2);
   76.76          if (current->pixels == NULL) {
   76.77              SDL_OutOfMemory ();
   76.78              goto ERR_DOUBLEBUF;
   76.79 @@ -984,7 +984,7 @@
   76.80          
   76.81          while ( h-- ) {
   76.82          
   76.83 -            memcpy (dst, src, len);
   76.84 +            SDL_memcpy (dst, src, len);
   76.85              src += skip;
   76.86              dst += skip;
   76.87          }
   76.88 @@ -1211,7 +1211,7 @@
   76.89                              dockIconCacheMiss) {
   76.90  
   76.91                              numCachedDockIcons = i - firstDockIcon;
   76.92 -                            memcpy (dockIcons, &(windows[firstDockIcon]),
   76.93 +                            SDL_memcpy (dockIcons, &(windows[firstDockIcon]),
   76.94                                      numCachedDockIcons * sizeof(*windows));
   76.95                          }
   76.96  
    77.1 --- a/src/video/quartz/SDL_QuartzWM.m	Mon May 01 06:58:33 2006 +0000
    77.2 +++ b/src/video/quartz/SDL_QuartzWM.m	Wed May 17 08:18:28 2006 +0000
    77.3 @@ -41,12 +41,12 @@
    77.4      int row, bytes;
    77.5          
    77.6      /* Allocate the cursor memory */
    77.7 -    cursor = (WMcursor *)malloc(sizeof(WMcursor));
    77.8 +    cursor = (WMcursor *)SDL_malloc(sizeof(WMcursor));
    77.9      if ( cursor == NULL ) {
   77.10          SDL_OutOfMemory();
   77.11          return(NULL);
   77.12      }
   77.13 -    memset(cursor, 0, sizeof(*cursor));
   77.14 +    SDL_memset(cursor, 0, sizeof(*cursor));
   77.15      
   77.16      if (w > 16)
   77.17          w = 16;
   77.18 @@ -57,11 +57,11 @@
   77.19      bytes = (w+7)/8;
   77.20  
   77.21      for ( row=0; row<h; ++row ) {
   77.22 -        memcpy(&cursor->curs.data[row], data, bytes);
   77.23 +        SDL_memcpy(&cursor->curs.data[row], data, bytes);
   77.24          data += bytes;
   77.25      }
   77.26      for ( row=0; row<h; ++row ) {
   77.27 -        memcpy(&cursor->curs.mask[row], mask, bytes);
   77.28 +        SDL_memcpy(&cursor->curs.mask[row], mask, bytes);
   77.29          mask += bytes;
   77.30      }
   77.31      cursor->curs.hotSpot.h = hot_x;
   77.32 @@ -262,68 +262,67 @@
   77.33      NSBitmapImageRep *imgrep;
   77.34      NSImage *img;
   77.35      SDL_Surface *mergedSurface;
   77.36 -    int i,j;
   77.37      NSAutoreleasePool *pool;
   77.38 -    SDL_Rect rrect;
   77.39 -    NSSize imgSize = {icon->w, icon->h};
   77.40 +    Uint8 *pixels;
   77.41 +    SDL_bool iconSrcAlpha;
   77.42 +    Uint8 iconAlphaValue;
   77.43 +    int i, j, maskPitch, index;
   77.44      
   77.45      pool = [ [ NSAutoreleasePool alloc ] init ];
   77.46 -    SDL_GetClipRect(icon, &rrect);
   77.47      
   77.48 -    /* create a big endian RGBA surface */
   77.49 -    mergedSurface = SDL_CreateRGBSurface(SDL_SWSURFACE|SDL_SRCALPHA, 
   77.50 -                    icon->w, icon->h, 32, 0xff<<24, 0xff<<16, 0xff<<8, 0xff<<0);
   77.51 -    if (mergedSurface==NULL) {
   77.52 -        NSLog(@"Error creating surface for merge");
   77.53 -        goto freePool;
   77.54 -    }
   77.55 +    imgrep = [ [ [ NSBitmapImageRep alloc ] initWithBitmapDataPlanes: NULL pixelsWide: icon->w pixelsHigh: icon->h bitsPerSample: 8 samplesPerPixel: 4 hasAlpha: YES isPlanar: NO colorSpaceName: NSDeviceRGBColorSpace bytesPerRow: 4*icon->w bitsPerPixel: 32 ] autorelease ];
   77.56 +    if (imgrep == nil) goto freePool;
   77.57 +    pixels = [ imgrep bitmapData ];
   77.58 +    SDL_memset(pixels, 0, 4*icon->w*icon->h); /* make the background, which will survive in colorkeyed areas, completely transparent */
   77.59      
   77.60 -    if (mergedSurface->pitch != 
   77.61 -        mergedSurface->format->BytesPerPixel * mergedSurface->w) {
   77.62 -        SDL_SetError ("merged surface has wrong format");
   77.63 -        SDL_FreeSurface (mergedSurface);
   77.64 -        goto freePool;
   77.65 -    }
   77.66 +#if SDL_BYTEORDER == SDL_BIG_ENDIAN
   77.67 +#define BYTEORDER_DEPENDENT_RGBA_MASKS 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF
   77.68 +#else
   77.69 +#define BYTEORDER_DEPENDENT_RGBA_MASKS 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000
   77.70 +#endif
   77.71 +    mergedSurface = SDL_CreateRGBSurfaceFrom(pixels, icon->w, icon->h, 32, 4*icon->w, BYTEORDER_DEPENDENT_RGBA_MASKS);
   77.72 +    if (mergedSurface == NULL) goto freePool;
   77.73      
   77.74 -    if (SDL_BlitSurface(icon,&rrect,mergedSurface,&rrect)) {
   77.75 -        NSLog(@"Error blitting to mergedSurface");
   77.76 -        goto freePool;
   77.77 -    }
   77.78 +    /* blit, with temporarily cleared SRCALPHA flag because we want to copy, not alpha-blend */
   77.79 +    iconSrcAlpha = ((icon->flags & SDL_SRCALPHA) != 0);
   77.80 +    iconAlphaValue = icon->format->alpha;
   77.81 +    SDL_SetAlpha(icon, 0, 255);
   77.82 +    SDL_BlitSurface(icon, NULL, mergedSurface, NULL);
   77.83 +    if (iconSrcAlpha) SDL_SetAlpha(icon, SDL_SRCALPHA, iconAlphaValue);
   77.84      
   77.85 -    if (mask) {
   77.86 -
   77.87 -        Uint32 *pixels = mergedSurface->pixels;
   77.88 -        for (i = 0; i < mergedSurface->h; i++) {
   77.89 -            for (j = 0; j < mergedSurface->w; j++) {
   77.90 -                
   77.91 -                int index = i * mergedSurface->w + j;
   77.92 -                int mindex = index >> 3;
   77.93 -                int bindex = 7 - (index & 0x7);
   77.94 -                
   77.95 -                if (mask[mindex] & (1 << bindex))
   77.96 -                    pixels[index] |= 0x000000FF;
   77.97 -                else
   77.98 -                    pixels[index] &= 0xFFFFFF00;
   77.99 +    SDL_FreeSurface(mergedSurface);
  77.100 +    
  77.101 +    /* apply mask, source alpha, and premultiply color values by alpha */
  77.102 +    maskPitch = (icon->w+7)/8;
  77.103 +    for (i = 0; i < icon->h; i++) {
  77.104 +        for (j = 0; j < icon->w; j++) {
  77.105 +            index = i*4*icon->w + j*4;
  77.106 +            if (!(mask[i*maskPitch + j/8] & (128 >> j%8))) {
  77.107 +                pixels[index + 3] = 0;
  77.108 +            }
  77.109 +            else {
  77.110 +                if (iconSrcAlpha) {
  77.111 +                    if (icon->format->Amask == 0) pixels[index + 3] = icon->format->alpha;
  77.112 +                }
  77.113 +                else {
  77.114 +                    pixels[index + 3] = 255;
  77.115 +                }
  77.116 +            }
  77.117 +            if (pixels[index + 3] < 255) {
  77.118 +                pixels[index + 0] = (Uint16)pixels[index + 0]*pixels[index + 3]/255;
  77.119 +                pixels[index + 1] = (Uint16)pixels[index + 1]*pixels[index + 3]/255;
  77.120 +                pixels[index + 2] = (Uint16)pixels[index + 2]*pixels[index + 3]/255;
  77.121              }
  77.122          }
  77.123      }
  77.124      
  77.125 -    imgrep = [ [ NSBitmapImageRep alloc] 
  77.126 -                    initWithBitmapDataPlanes:(unsigned char **)&mergedSurface->pixels 
  77.127 -                        pixelsWide:icon->w pixelsHigh:icon->h bitsPerSample:8 samplesPerPixel:4 
  77.128 -                        hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace 
  77.129 -                        bytesPerRow:icon->w<<2 bitsPerPixel:32 ];
  77.130 -    
  77.131 -    img = [ [ NSImage alloc ] initWithSize:imgSize ];
  77.132 -    
  77.133 +    img = [ [ [ NSImage alloc ] initWithSize: NSMakeSize(icon->w, icon->h) ] autorelease ];
  77.134 +    if (img == nil) goto freePool;
  77.135      [ img addRepresentation: imgrep ];
  77.136      [ NSApp setApplicationIconImage:img ];
  77.137      
  77.138 -    [ img release ];
  77.139 -    [ imgrep release ];
  77.140 -    SDL_FreeSurface(mergedSurface);
  77.141  freePool:
  77.142 -    [pool release];
  77.143 +    [ pool release ];
  77.144  }
  77.145  
  77.146  int  QZ_IconifyWindow (_THIS) { 
    78.1 --- a/src/video/quartz/SDL_QuartzYUV.m	Mon May 01 06:58:33 2006 +0000
    78.2 +++ b/src/video/quartz/SDL_QuartzYUV.m	Wed May 17 08:18:28 2006 +0000
    78.3 @@ -91,16 +91,16 @@
    78.4      CDSequenceEnd (yuv_seq);
    78.5      ExitMovies();
    78.6  
    78.7 -    free (overlay->hwfuncs);
    78.8 -    free (overlay->pitches);
    78.9 -    free (overlay->pixels);
   78.10 +    SDL_free (overlay->hwfuncs);
   78.11 +    SDL_free (overlay->pitches);
   78.12 +    SDL_free (overlay->pixels);
   78.13  
   78.14      if (SDL_VideoSurface->flags & SDL_FULLSCREEN) {
   78.15          [ qz_window close ];
   78.16          qz_window = nil;
   78.17      }
   78.18  
   78.19 -    free (yuv_matrix);
   78.20 +    SDL_free (yuv_matrix);
   78.21      DisposeHandle ((Handle)yuv_idh);
   78.22  }
   78.23  
   78.24 @@ -134,7 +134,7 @@
   78.25          return NULL;
   78.26      }
   78.27  
   78.28 -    yuv_matrix = (MatrixRecordPtr) malloc (sizeof(MatrixRecord));
   78.29 +    yuv_matrix = (MatrixRecordPtr) SDL_malloc (sizeof(MatrixRecord));
   78.30      if (yuv_matrix == NULL) {
   78.31          SDL_OutOfMemory();
   78.32          return NULL;
   78.33 @@ -234,7 +234,7 @@
   78.34          return NULL;
   78.35      }
   78.36      
   78.37 -    overlay = (SDL_Overlay*) malloc (sizeof(*overlay));
   78.38 +    overlay = (SDL_Overlay*) SDL_malloc (sizeof(*overlay));
   78.39      if (overlay == NULL) {
   78.40          SDL_OutOfMemory();
   78.41          return NULL;
   78.42 @@ -267,15 +267,15 @@
   78.43              return NULL;
   78.44          }
   78.45  
   78.46 -        pixels = (Uint8**) malloc (sizeof(*pixels) * 3);
   78.47 -        pitches = (Uint16*) malloc (sizeof(*pitches) * 3);
   78.48 +        pixels = (Uint8**) SDL_malloc (sizeof(*pixels) * 3);
   78.49 +        pitches = (Uint16*) SDL_malloc (sizeof(*pitches) * 3);
   78.50          if (pixels == NULL || pitches == NULL) {
   78.51              SDL_OutOfMemory();
   78.52              return NULL;
   78.53          }
   78.54  
   78.55          yuv_pixmap = (PlanarPixmapInfoYUV420*)
   78.56 -            malloc (sizeof(PlanarPixmapInfoYUV420) +
   78.57 +            SDL_malloc (sizeof(PlanarPixmapInfoYUV420) +
   78.58                      (width * height * 2));
   78.59          if (yuv_pixmap == NULL) {
   78.60              SDL_OutOfMemory ();
   78.61 @@ -310,7 +310,7 @@
   78.62          overlay->pitches = pitches;
   78.63      }
   78.64  
   78.65 -    overlay->hwfuncs = malloc (sizeof(*overlay->hwfuncs));
   78.66 +    overlay->hwfuncs = SDL_malloc (sizeof(*overlay->hwfuncs));
   78.67      if (overlay->hwfuncs == NULL) {
   78.68          SDL_OutOfMemory();
   78.69          return NULL;
    79.1 --- a/src/video/wincommon/SDL_wingl.c	Mon May 01 06:58:33 2006 +0000
    79.2 +++ b/src/video/wincommon/SDL_wingl.c	Wed May 17 08:18:28 2006 +0000
    79.3 @@ -177,6 +177,7 @@
    79.4  	int iAttribs[64];
    79.5  	int *iAttr;
    79.6  	float fAttribs[1] = { 0 };
    79.7 +	const GLubyte *(WINAPI *glGetStringFunc)(GLenum);
    79.8  	const char *wglext;
    79.9  
   79.10  	/* load the gl driver from a default path */
   79.11 @@ -338,8 +339,14 @@
   79.12  	 * somewhat a documented and reliable hack - it was originally
   79.13  	 * as a feature added by mistake, but since so many people rely
   79.14  	 * on it, it will not be removed.  strstr should be safe here.*/
   79.15 -	wglext = (const char *)this->glGetString(GL_EXTENSIONS);
   79.16 -	if ( !SDL_strstr(wglext, "WGL_EXT_swap_control") ) {
   79.17 +	glGetStringFunc = WIN_GL_GetProcAddress(this, "glGetString");
   79.18 +	if ( glGetStringFunc ) {
   79.19 +		wglext = (const char *)glGetStringFunc(GL_EXTENSIONS);
   79.20 +	} else {
   79.21 +		/* Uh oh, something is seriously wrong here... */
   79.22 +		wglext = NULL;
   79.23 +	}
   79.24 +	if ( !wglext || !SDL_strstr(wglext, "WGL_EXT_swap_control") ) {
   79.25  		this->gl_data->wglSwapIntervalEXT = NULL;
   79.26  		this->gl_data->wglGetSwapIntervalEXT = NULL;
   79.27  	}
    80.1 --- a/src/video/windib/SDL_dibvideo.c	Mon May 01 06:58:33 2006 +0000
    80.2 +++ b/src/video/windib/SDL_dibvideo.c	Wed May 17 08:18:28 2006 +0000
    80.3 @@ -348,7 +348,6 @@
    80.4  #endif
    80.5  	}
    80.6  	/* Sort the mode lists */
    80.7 -	if( i > 1 )
    80.8  	for ( i=0; i<NUM_MODELISTS; ++i ) {
    80.9  		if ( SDL_nummodes[i] > 0 ) {
   80.10  			SDL_qsort(SDL_modelist[i], SDL_nummodes[i], sizeof *SDL_modelist[i], cmpmodes);
   80.11 @@ -361,7 +360,7 @@
   80.12  	// because SDL surface conversion is much faster than the WinCE one.
   80.13  	// Although it should be tested on devices with graphics accelerator.
   80.14  
   80.15 -    DIB_AddMode(this, vformat->BitsPerPixel,
   80.16 +	DIB_AddMode(this, vformat->BitsPerPixel,
   80.17  			GetDeviceCaps(GetDC(NULL), HORZRES), 
   80.18  			GetDeviceCaps(GetDC(NULL), VERTRES));
   80.19  
    81.1 --- a/src/video/windx5/SDL_dx5video.c	Mon May 01 06:58:33 2006 +0000
    81.2 +++ b/src/video/windx5/SDL_dx5video.c	Wed May 17 08:18:28 2006 +0000
    81.3 @@ -636,6 +636,16 @@
    81.4  	DX5_Available, DX5_CreateDevice
    81.5  };
    81.6  
    81.7 +static int cmpmodes(const void *va, const void *vb)
    81.8 +{
    81.9 +    SDL_Rect *a = *(SDL_Rect **)va;
   81.10 +    SDL_Rect *b = *(SDL_Rect **)vb;
   81.11 +    if ( a->w == b->w )
   81.12 +        return b->h - a->h;
   81.13 +    else
   81.14 +        return b->w - a->w;
   81.15 +}
   81.16 +
   81.17  static HRESULT WINAPI EnumModes2(DDSURFACEDESC *desc, VOID *udata)
   81.18  {
   81.19  	SDL_VideoDevice *this = (SDL_VideoDevice *)udata;
   81.20 @@ -955,6 +965,10 @@
   81.21  			SDL_modelist[i][j] = &rect->r;
   81.22  		}
   81.23  		SDL_modelist[i][j] = NULL;
   81.24 +
   81.25 +		if ( SDL_nummodes[i] > 0 ) {
   81.26 +			SDL_qsort(SDL_modelist[i], SDL_nummodes[i], sizeof *SDL_modelist[i], cmpmodes);
   81.27 +		}
   81.28  	}
   81.29  	
   81.30  	/* Fill in some window manager capabilities */
    82.1 --- a/src/video/x11/SDL_x11dyn.c	Mon May 01 06:58:33 2006 +0000
    82.2 +++ b/src/video/x11/SDL_x11dyn.c	Wed May 17 08:18:28 2006 +0000
    82.3 @@ -61,30 +61,27 @@
    82.4      { NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR },
    82.5  };
    82.6  
    82.7 -static void *X11_GetSym(const char *fnname, int *rc)
    82.8 +static void X11_GetSym(const char *fnname, int *rc, void **fn)
    82.9  {
   82.10  	int i;
   82.11 -	void *fn = NULL;
   82.12  	for (i = 0; i < SDL_TABLESIZE(x11libs); i++) {
   82.13  		if (x11libs[i].lib != NULL)
   82.14  		{
   82.15 -			fn = SDL_LoadFunction(x11libs[i].lib, fnname);
   82.16 -			if (fn != NULL)
   82.17 +			*fn = SDL_LoadFunction(x11libs[i].lib, fnname);
   82.18 +			if (*fn != NULL)
   82.19  				break;
   82.20  		}
   82.21  	}
   82.22  
   82.23  	#if DEBUG_DYNAMIC_X11
   82.24 -	if (fn != NULL)
   82.25 -		printf("X11: Found '%s' in %s (%p)\n", fnname, x11libs[i].libname, fn);
   82.26 +	if (*fn != NULL)
   82.27 +		printf("X11: Found '%s' in %s (%p)\n", fnname, x11libs[i].libname, *fn);
   82.28  	else
   82.29  		printf("X11: Symbol '%s' NOT FOUND!\n", fnname);
   82.30  	#endif
   82.31  
   82.32 -	if (fn == NULL)
   82.33 +	if (*fn == NULL)
   82.34  		*rc = 0;  /* kill this module. */
   82.35 -
   82.36 -	return fn;
   82.37  }
   82.38  
   82.39  
   82.40 @@ -159,13 +156,13 @@
   82.41  			}
   82.42  		}
   82.43  		#define SDL_X11_MODULE(modname) thismod = &SDL_X11_HAVE_##modname;
   82.44 -		#define SDL_X11_SYM(a,fn,x,y,z) p##fn = X11_GetSym(#fn,thismod);
   82.45 +		#define SDL_X11_SYM(a,fn,x,y,z) X11_GetSym(#fn,thismod,(void**)&p##fn);
   82.46  		#include "SDL_x11sym.h"
   82.47  		#undef SDL_X11_MODULE
   82.48  		#undef SDL_X11_SYM
   82.49  
   82.50  		#ifdef X_HAVE_UTF8_STRING
   82.51 -		pXCreateIC = X11_GetSym("XCreateIC",&SDL_X11_HAVE_UTF8);
   82.52 +		X11_GetSym("XCreateIC",&SDL_X11_HAVE_UTF8,(void **)&pXCreateIC);
   82.53  		#endif
   82.54  
   82.55  		if (!SDL_X11_HAVE_BASEXLIB) {  /* some required symbol didn't load. */
    83.1 --- a/src/video/x11/SDL_x11events.c	Mon May 01 06:58:33 2006 +0000
    83.2 +++ b/src/video/x11/SDL_x11events.c	Wed May 17 08:18:28 2006 +0000
    83.3 @@ -291,11 +291,10 @@
    83.4  		     (xevent.xcrossing.mode != NotifyUngrab) ) {
    83.5  			if ( this->input_grab == SDL_GRAB_OFF ) {
    83.6  				posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
    83.7 -			} else {
    83.8 -				posted = SDL_PrivateMouseMotion(0, 0,
    83.9 -						xevent.xcrossing.x,
   83.10 -						xevent.xcrossing.y);
   83.11  			}
   83.12 +			posted = SDL_PrivateMouseMotion(0, 0,
   83.13 +					xevent.xcrossing.x,
   83.14 +					xevent.xcrossing.y);
   83.15  		}
   83.16  	    }
   83.17  	    break;
   83.18 @@ -1118,3 +1117,57 @@
   83.19  	X11_InitKeymap();
   83.20  }
   83.21  
   83.22 +void X11_SaveScreenSaver(Display *display, int *saved_timeout, BOOL *dpms)
   83.23 +{
   83.24 +	int timeout, interval, prefer_blank, allow_exp;
   83.25 +	XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp);
   83.26 +	*saved_timeout = timeout;
   83.27 +
   83.28 +#if SDL_VIDEO_DRIVER_X11_DPMS
   83.29 +	if ( SDL_X11_HAVE_DPMS ) {
   83.30 +		int dummy;
   83.31 +	  	if ( DPMSQueryExtension(display, &dummy, &dummy) ) {
   83.32 +			CARD16 state;
   83.33 +			DPMSInfo(display, &state, dpms);
   83.34 +		}
   83.35 +	}
   83.36 +#else
   83.37 +	*dpms = 0;
   83.38 +#endif /* SDL_VIDEO_DRIVER_X11_DPMS */
   83.39 +}
   83.40 +
   83.41 +void X11_DisableScreenSaver(Display *display)
   83.42 +{
   83.43 +	int timeout, interval, prefer_blank, allow_exp;
   83.44 +	XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp);
   83.45 +	timeout = 0;
   83.46 +	XSetScreenSaver(display, timeout, interval, prefer_blank, allow_exp);
   83.47 +
   83.48 +#if SDL_VIDEO_DRIVER_X11_DPMS
   83.49 +	if ( SDL_X11_HAVE_DPMS ) {
   83.50 +		int dummy;
   83.51 +	  	if ( DPMSQueryExtension(display, &dummy, &dummy) ) {
   83.52 +			DPMSDisable(display);
   83.53 +		}
   83.54 +	}
   83.55 +#endif /* SDL_VIDEO_DRIVER_X11_DPMS */
   83.56 +}
   83.57 +
   83.58 +void X11_RestoreScreenSaver(Display *display, int saved_timeout, BOOL dpms)
   83.59 +{
   83.60 +	int timeout, interval, prefer_blank, allow_exp;
   83.61 +	XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp);
   83.62 +	timeout = saved_timeout;
   83.63 +	XSetScreenSaver(display, timeout, interval, prefer_blank, allow_exp);
   83.64 +
   83.65 +#if SDL_VIDEO_DRIVER_X11_DPMS
   83.66 +	if ( SDL_X11_HAVE_DPMS ) {
   83.67 +		int dummy;
   83.68 +	  	if ( DPMSQueryExtension(display, &dummy, &dummy) ) {
   83.69 +			if ( dpms ) {
   83.70 +				DPMSEnable(display);
   83.71 +			}
   83.72 +		}
   83.73 +	}
   83.74 +#endif /* SDL_VIDEO_DRIVER_X11_DPMS */
   83.75 +}
    84.1 --- a/src/video/x11/SDL_x11events_c.h	Mon May 01 06:58:33 2006 +0000
    84.2 +++ b/src/video/x11/SDL_x11events_c.h	Wed May 17 08:18:28 2006 +0000
    84.3 @@ -28,3 +28,6 @@
    84.4  extern void X11_PumpEvents(_THIS);
    84.5  extern void X11_SetKeyboardState(Display *display, const char *key_vec);
    84.6  
    84.7 +extern void X11_SaveScreenSaver(Display *display, int *saved_timeout, BOOL *dpms);
    84.8 +extern void X11_DisableScreenSaver(Display *display);
    84.9 +extern void X11_RestoreScreenSaver(Display *display, int saved_timeout, BOOL dpms);
    85.1 --- a/src/video/x11/SDL_x11gl.c	Mon May 01 06:58:33 2006 +0000
    85.2 +++ b/src/video/x11/SDL_x11gl.c	Wed May 17 08:18:28 2006 +0000
    85.3 @@ -46,6 +46,7 @@
    85.4  #ifndef GLX_EXT_visual_rating
    85.5  #define GLX_EXT_visual_rating
    85.6  #define GLX_VISUAL_CAVEAT_EXT              0x20
    85.7 +#define GLX_NONE_EXT                       0x8000
    85.8  #define GLX_SLOW_VISUAL_EXT                0x8001
    85.9  #define GLX_NON_CONFORMANT_VISUAL_EXT      0x800D
   85.10  #endif
   85.11 @@ -182,7 +183,7 @@
   85.12  	if( this->gl_config.accelerated >= 0 &&
   85.13  	    glXExtensionSupported(this, "GLX_EXT_visual_rating") ) {
   85.14  		attribs[i++] = GLX_VISUAL_CAVEAT_EXT;
   85.15 -		attribs[i++] = this->gl_config.accelerated ? GLX_NONE : GLX_DONT_CARE;
   85.16 +		attribs[i++] = GLX_NONE_EXT;
   85.17  	}
   85.18  
   85.19  #ifdef GLX_DIRECT_COLOR /* Try for a DirectColor visual for gamma support */
    86.1 --- a/src/video/x11/SDL_x11modes.c	Mon May 01 06:58:33 2006 +0000
    86.2 +++ b/src/video/x11/SDL_x11modes.c	Wed May 17 08:18:28 2006 +0000
    86.3 @@ -33,12 +33,22 @@
    86.4  #include "SDL_x11modes_c.h"
    86.5  #include "SDL_x11image_c.h"
    86.6  
    86.7 -#if SDL_VIDEO_DRIVER_X11_XINERAMA
    86.8 -#include "../Xext/extensions/Xinerama.h"
    86.9 -#endif 
   86.10 +/*#define X11MODES_DEBUG*/
   86.11  
   86.12  #define MAX(a, b)        (a > b ? a : b)
   86.13  
   86.14 +#if SDL_VIDEO_DRIVER_X11_XRANDR
   86.15 +static int cmpmodelist(const void *va, const void *vb)
   86.16 +{
   86.17 +    const SDL_Rect *a = *(const SDL_Rect **)va;
   86.18 +    const SDL_Rect *b = *(const SDL_Rect **)vb;
   86.19 +    if ( a->w == b->w )
   86.20 +        return b->h - a->h;
   86.21 +    else
   86.22 +        return b->w - a->w;
   86.23 +}
   86.24 +#endif
   86.25 +
   86.26  #if SDL_VIDEO_DRIVER_X11_VIDMODE
   86.27  Bool SDL_NAME(XF86VidModeGetModeInfo)(Display *dpy, int scr, SDL_NAME(XF86VidModeModeInfo) *info)
   86.28  {
   86.29 @@ -86,18 +96,6 @@
   86.30  }
   86.31  #endif
   86.32  
   86.33 -#if SDL_VIDEO_DRIVER_X11_XRANDR
   86.34 -static int cmpmodelist(const void *va, const void *vb)
   86.35 -{
   86.36 -    const SDL_Rect *a = *(const SDL_Rect **)va;
   86.37 -    const SDL_Rect *b = *(const SDL_Rect **)vb;
   86.38 -    if ( a->w == b->w )
   86.39 -        return b->h - a->h;
   86.40 -    else
   86.41 -        return b->w - a->w;
   86.42 -}
   86.43 -#endif
   86.44 -
   86.45  static void get_real_resolution(_THIS, int* w, int* h);
   86.46  
   86.47  static void set_best_resolution(_THIS, int width, int height)
   86.48 @@ -107,45 +105,37 @@
   86.49          SDL_NAME(XF86VidModeModeLine) mode;
   86.50          SDL_NAME(XF86VidModeModeInfo) **modes;
   86.51          int i;
   86.52 -        int best_width = 0, best_height = 0;
   86.53          int nmodes;
   86.54 +        int best = -1;
   86.55  
   86.56          if ( SDL_NAME(XF86VidModeGetModeLine)(SDL_Display, SDL_Screen, &i, &mode) &&
   86.57 -             SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display,SDL_Screen,&nmodes,&modes)){
   86.58 -#ifdef XFREE86_DEBUG
   86.59 -            printf("Available modes (unsorted):\n");
   86.60 -            for ( i = 0; i < nmodes; ++i ) {
   86.61 -                printf("Mode %d: %d x %d @ %d\n", i,
   86.62 -                        modes[i]->hdisplay, modes[i]->vdisplay,
   86.63 -                        1000 * modes[i]->dotclock / (modes[i]->htotal *
   86.64 -                        modes[i]->vtotal) );
   86.65 -            }
   86.66 -#endif
   86.67 +             SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display,SDL_Screen,&nmodes,&modes) ) {
   86.68              for ( i = 0; i < nmodes ; i++ ) {
   86.69                  if ( (modes[i]->hdisplay == width) &&
   86.70 -                     (modes[i]->vdisplay == height) )
   86.71 -                    goto match;
   86.72 -            }
   86.73 -            qsort(modes, nmodes, sizeof *modes, cmpmodes);
   86.74 -            for ( i = nmodes-1; i > 0 ; i-- ) {
   86.75 -		if ( ! best_width ) {
   86.76 -                    if ( (modes[i]->hdisplay >= width) &&
   86.77 -                         (modes[i]->vdisplay >= height) ) {
   86.78 -                        best_width = modes[i]->hdisplay;
   86.79 -                        best_height = modes[i]->vdisplay;
   86.80 -                    }
   86.81 -                } else {
   86.82 -                    if ( (modes[i]->hdisplay != best_width) ||
   86.83 -                         (modes[i]->vdisplay != best_height) ) {
   86.84 -                        i++;
   86.85 -                        break;
   86.86 +                     (modes[i]->vdisplay == height) ) {
   86.87 +                    best = i;
   86.88 +                    break;
   86.89 +                }
   86.90 +                if ( modes[i]->hdisplay >= width &&
   86.91 +                     modes[i]->vdisplay >= height ) {
   86.92 +                    if ( best < 0 ||
   86.93 +                         (modes[i]->hdisplay < modes[best]->hdisplay &&
   86.94 +                          modes[i]->vdisplay <= modes[best]->vdisplay) ||
   86.95 +                         (modes[i]->vdisplay < modes[best]->vdisplay &&
   86.96 +                          modes[i]->hdisplay <= modes[best]->hdisplay) ) {
   86.97 +                        best = i;
   86.98                      }
   86.99                  }
  86.100              }
  86.101 -       match:
  86.102 -            if ( (modes[i]->hdisplay != mode.hdisplay) ||
  86.103 -                 (modes[i]->vdisplay != mode.vdisplay) ) {
  86.104 -                SDL_NAME(XF86VidModeSwitchToMode)(SDL_Display, SDL_Screen, modes[i]);
  86.105 +            if ( best >= 0 &&
  86.106 +                 ((modes[best]->hdisplay != mode.hdisplay) ||
  86.107 +                  (modes[best]->vdisplay != mode.vdisplay)) ) {
  86.108 +#ifdef X11MODES_DEBUG
  86.109 +                printf("Best Mode %d: %d x %d @ %d\n", best,
  86.110 +                        modes[best]->hdisplay, modes[best]->vdisplay,
  86.111 +                        (modes[best]->htotal && modes[best]->vtotal) ? (1000 * modes[best]->dotclock / (modes[best]->htotal * modes[best]->vtotal)) : 0 );
  86.112 +#endif
  86.113 +                SDL_NAME(XF86VidModeSwitchToMode)(SDL_Display, SDL_Screen, modes[best]);
  86.114              }
  86.115              XFree(modes);
  86.116          }
  86.117 @@ -154,13 +144,13 @@
  86.118  
  86.119                                  /* XiG */
  86.120  #if SDL_VIDEO_DRIVER_X11_XME
  86.121 -#ifdef XIG_DEBUG
  86.122 -    fprintf(stderr, "XME: set_best_resolution(): w = %d, h = %d\n",
  86.123 -            width, height);
  86.124 -#endif
  86.125 -    if ( SDL_modelist ) {
  86.126 +    if ( use_xme && SDL_modelist ) {
  86.127          int i;
  86.128  
  86.129 +#ifdef X11MODES_DEBUG
  86.130 +        fprintf(stderr, "XME: set_best_resolution(): w = %d, h = %d\n",
  86.131 +                width, height);
  86.132 +#endif
  86.133          for ( i=0; SDL_modelist[i]; ++i ) {
  86.134              if ( (SDL_modelist[i]->w >= width) &&
  86.135                   (SDL_modelist[i]->h >= height) ) {
  86.136 @@ -175,11 +165,11 @@
  86.137              get_real_resolution(this, &w, &h);
  86.138  
  86.139              if ( (SDL_modelist[i]->w != w) || (SDL_modelist[i]->h != h) ) {
  86.140 -# ifdef XIG_DEBUG
  86.141 +#ifdef X11MODES_DEBUG
  86.142                  fprintf(stderr, "XME: set_best_resolution: "
  86.143                          "XiGMiscChangeResolution: %d %d\n",
  86.144 -                        SDL_modelist[s]->w, SDL_modelist[s]->h);
  86.145 -# endif
  86.146 +                        SDL_modelist[i]->w, SDL_modelist[i]->h);
  86.147 +#endif
  86.148                  XiGMiscChangeResolution(SDL_Display, 
  86.149                                          SDL_Screen,
  86.150                                          0, /* view */
  86.151 @@ -193,58 +183,73 @@
  86.152  #endif /* SDL_VIDEO_DRIVER_X11_XME */
  86.153  
  86.154  #if SDL_VIDEO_DRIVER_X11_XRANDR
  86.155 -    if ( use_xrandr ) {
  86.156 -#ifdef XRANDR_DEBUG
  86.157 +    if ( use_xrandr && SDL_modelist ) {
  86.158 +#ifdef X11MODES_DEBUG
  86.159          fprintf(stderr, "XRANDR: set_best_resolution(): w = %d, h = %d\n",
  86.160                  width, height);
  86.161  #endif
  86.162 -        if ( SDL_modelist ) {
  86.163 -            int i, nsizes;
  86.164 -            XRRScreenSize *sizes;
  86.165 +        int i, nsizes;
  86.166 +        XRRScreenSize *sizes;
  86.167  
  86.168 -            /* find the smallest resolution that is at least as big as the user requested */
  86.169 -            sizes = XRRConfigSizes(screen_config, &nsizes);
  86.170 -            for ( i = (nsizes-1); i >= 0; i-- ) {
  86.171 -                if ( (SDL_modelist[i]->w >= width) &&
  86.172 -                     (SDL_modelist[i]->h >= height) ) {
  86.173 -                    break;
  86.174 -                }
  86.175 +        /* find the smallest resolution that is at least as big as the user requested */
  86.176 +        sizes = XRRConfigSizes(screen_config, &nsizes);
  86.177 +        for ( i = (nsizes-1); i >= 0; i-- ) {
  86.178 +            if ( (SDL_modelist[i]->w >= width) &&
  86.179 +                 (SDL_modelist[i]->h >= height) ) {
  86.180 +                break;
  86.181              }
  86.182 +        }
  86.183  
  86.184 -            if ( i >= 0 && SDL_modelist[i] ) { /* found one, lets try it */
  86.185 -                int w, h;
  86.186 +        if ( i >= 0 && SDL_modelist[i] ) { /* found one, lets try it */
  86.187 +            int w, h;
  86.188  
  86.189 -                /* check current mode so we can avoid uneccessary mode changes */
  86.190 -                get_real_resolution(this, &w, &h);
  86.191 +            /* check current mode so we can avoid uneccessary mode changes */
  86.192 +            get_real_resolution(this, &w, &h);
  86.193  
  86.194 -                if ( (SDL_modelist[i]->w != w) || (SDL_modelist[i]->h != h) ) {
  86.195 -                    int size_id;
  86.196 +            if ( (SDL_modelist[i]->w != w) || (SDL_modelist[i]->h != h) ) {
  86.197 +                int size_id;
  86.198  
  86.199 -#ifdef XRANDR_DEBUG
  86.200 -                    fprintf(stderr, "XRANDR: set_best_resolution: "
  86.201 -                            "XXRSetScreenConfig: %d %d\n",
  86.202 -                            SDL_modelist[i]->w, SDL_modelist[i]->h);
  86.203 +#ifdef X11MODES_DEBUG
  86.204 +                fprintf(stderr, "XRANDR: set_best_resolution: "
  86.205 +                        "XXRSetScreenConfig: %d %d\n",
  86.206 +                        SDL_modelist[i]->w, SDL_modelist[i]->h);
  86.207  #endif
  86.208  
  86.209 -                    /* find the matching size entry index */
  86.210 -                    for ( size_id = 0; size_id < nsizes; ++size_id ) {
  86.211 -                        if ( (sizes[size_id].width == SDL_modelist[i]->w) &&
  86.212 -                             (sizes[size_id].height == SDL_modelist[i]->h) )
  86.213 -                            break;
  86.214 -                    }
  86.215 +                /* find the matching size entry index */
  86.216 +                for ( size_id = 0; size_id < nsizes; ++size_id ) {
  86.217 +                    if ( (sizes[size_id].width == SDL_modelist[i]->w) &&
  86.218 +                         (sizes[size_id].height == SDL_modelist[i]->h) )
  86.219 +                        break;
  86.220 +                }
  86.221  
  86.222 -                    XRRSetScreenConfig(SDL_Display, screen_config, SDL_Root,
  86.223 -                                       size_id, saved_rotation, CurrentTime);
  86.224 -                }
  86.225 +                XRRSetScreenConfig(SDL_Display, screen_config, SDL_Root,
  86.226 +                                   size_id, saved_rotation, CurrentTime);
  86.227              }
  86.228          }
  86.229      }
  86.230  #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
  86.231 -
  86.232  }
  86.233  
  86.234  static void get_real_resolution(_THIS, int* w, int* h)
  86.235  {
  86.236 +#if SDL_VIDEO_DRIVER_X11_XME
  86.237 +    if ( use_xme ) {
  86.238 +        int ractive;
  86.239 +        XiGMiscResolutionInfo *modelist;
  86.240 +
  86.241 +        XiGMiscQueryResolutions(SDL_Display, SDL_Screen,
  86.242 +                                0, /* view */
  86.243 +                                &ractive, &modelist);
  86.244 +        *w = modelist[ractive].width;
  86.245 +        *h = modelist[ractive].height;
  86.246 +#ifdef X11MODES_DEBUG
  86.247 +        fprintf(stderr, "XME: get_real_resolution: w = %d h = %d\n", *w, *h);
  86.248 +#endif
  86.249 +        XFree(modelist);
  86.250 +        return;
  86.251 +    }
  86.252 +#endif /* SDL_VIDEO_DRIVER_X11_XME */
  86.253 +
  86.254  #if SDL_VIDEO_DRIVER_X11_VIDMODE
  86.255      if ( use_vidmode ) {
  86.256          SDL_NAME(XF86VidModeModeLine) mode;
  86.257 @@ -258,24 +263,6 @@
  86.258      }
  86.259  #endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
  86.260  
  86.261 -#if SDL_VIDEO_DRIVER_X11_XME
  86.262 -    if ( use_xme ) {
  86.263 -        int ractive;
  86.264 -        XiGMiscResolutionInfo *modelist;
  86.265 -
  86.266 -        XiGMiscQueryResolutions(SDL_Display, SDL_Screen,
  86.267 -                                0, /* view */
  86.268 -                                &ractive, &modelist);
  86.269 -        *w = modelist[ractive].width;
  86.270 -        *h = modelist[ractive].height;
  86.271 -#ifdef XIG_DEBUG
  86.272 -        fprintf(stderr, "XME: get_real_resolution: w = %d h = %d\n", *w, *h);
  86.273 -#endif
  86.274 -        XFree(modelist);
  86.275 -        return;
  86.276 -    }
  86.277 -#endif /* SDL_VIDEO_DRIVER_X11_XME */
  86.278 -
  86.279  #if SDL_VIDEO_DRIVER_X11_XRANDR
  86.280      if ( use_xrandr ) {
  86.281          int nsizes;
  86.282 @@ -291,7 +278,7 @@
  86.283                  *w = sizes[cur_size].width;
  86.284                  *h = sizes[cur_size].height;
  86.285              }
  86.286 -#ifdef XRANDR_DEBUG
  86.287 +#ifdef X11MODES_DEBUG
  86.288              fprintf(stderr, "XRANDR: get_real_resolution: w = %d h = %d\n", *w, *h);
  86.289  #endif
  86.290              return;
  86.291 @@ -299,6 +286,14 @@
  86.292      }
  86.293  #endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
  86.294  
  86.295 +#if SDL_VIDEO_DRIVER_X11_XINERAMA
  86.296 +    if ( use_xinerama ) {
  86.297 +        *w = xinerama_info.width;
  86.298 +        *h = xinerama_info.height;
  86.299 +        return;
  86.300 +    }
  86.301 +#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
  86.302 +
  86.303      *w = DisplayWidth(SDL_Display, SDL_Screen);
  86.304      *h = DisplayHeight(SDL_Display, SDL_Screen);
  86.305  }
  86.306 @@ -360,10 +355,136 @@
  86.307  /* Global for the error handler */
  86.308  int vm_event, vm_error = -1;
  86.309  
  86.310 +#if SDL_VIDEO_DRIVER_X11_XINERAMA
  86.311 +static int CheckXinerama(_THIS, int *major, int *minor)
  86.312 +{
  86.313 +    const char *env;
  86.314 +
  86.315 +    /* Default the extension not available */
  86.316 +    *major = *minor = 0;
  86.317 +
  86.318 +    /* Allow environment override */
  86.319 +    env = getenv("SDL_VIDEO_X11_XINERAMA");
  86.320 +    if ( env && !SDL_atoi(env) ) {
  86.321 +        return 0;
  86.322 +    }
  86.323 +
  86.324 +    /* Query the extension version */
  86.325 +    if ( !SDL_NAME(XineramaQueryExtension)(SDL_Display, major, minor) ||
  86.326 +         !SDL_NAME(XineramaIsActive)(SDL_Display) ) {
  86.327 +        return 0;
  86.328 +    }
  86.329 +    return 1;
  86.330 +}
  86.331 +#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
  86.332 +
  86.333 +#if SDL_VIDEO_DRIVER_X11_XRANDR
  86.334 +static int CheckXRandR(_THIS, int *major, int *minor)
  86.335 +{
  86.336 +    const char *env;
  86.337 +
  86.338 +    /* Default the extension not available */
  86.339 +    *major = *minor = 0;
  86.340 +
  86.341 +    /* Allow environment override */
  86.342 +    env = getenv("SDL_VIDEO_X11_XRANDR");
  86.343 +    if ( env && !SDL_atoi(env) ) {
  86.344 +        return 0;
  86.345 +    }
  86.346 +
  86.347 +    /* This defaults off now, due to KDE window maximize problems */
  86.348 +    if ( !env ) {
  86.349 +        return 0;
  86.350 +    }
  86.351 +
  86.352 +    if ( !SDL_X11_HAVE_XRANDR ) {
  86.353 +        return 0;
  86.354 +    }
  86.355 +
  86.356 +    /* Query the extension version */
  86.357 +    if ( !XRRQueryVersion(SDL_Display, major, minor) ) {
  86.358 +        return 0;
  86.359 +    }
  86.360 +    return 1;
  86.361 +}
  86.362 +#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
  86.363 +
  86.364 +#if SDL_VIDEO_DRIVER_X11_VIDMODE
  86.365 +static int CheckVidMode(_THIS, int *major, int *minor)
  86.366 +{
  86.367 +    const char *env;
  86.368 +
  86.369 +    /* Default the extension not available */
  86.370 +    *major = *minor = 0;
  86.371 +
  86.372 +    /* Allow environment override */
  86.373 +    env = getenv("SDL_VIDEO_X11_VIDMODE");
  86.374 +    if ( env && !SDL_atoi(env) ) {
  86.375 +        return 0;
  86.376 +    }
  86.377 +    
  86.378 +    /* Metro-X 4.3.0 and earlier has a broken implementation of
  86.379 +       XF86VidModeGetAllModeLines() - it hangs the client.
  86.380 +     */
  86.381 +    if ( SDL_strcmp(ServerVendor(SDL_Display), "Metro Link Incorporated") == 0 ) {
  86.382 +        FILE *metro_fp;
  86.383 +
  86.384 +        metro_fp = fopen("/usr/X11R6/lib/X11/Metro/.version", "r");
  86.385 +        if ( metro_fp != NULL ) {
  86.386 +            int major, minor, patch, version;
  86.387 +            major = 0; minor = 0; patch = 0;
  86.388 +            fscanf(metro_fp, "%d.%d.%d", &major, &minor, &patch);
  86.389 +            fclose(metro_fp);
  86.390 +            version = major*100+minor*10+patch;
  86.391 +            if ( version < 431 ) {
  86.392 +                return 0;
  86.393 +            }
  86.394 +        }
  86.395 +    }
  86.396 +
  86.397 +    /* Query the extension version */
  86.398 +    vm_error = -1;
  86.399 +    if ( !SDL_NAME(XF86VidModeQueryExtension)(SDL_Display, &vm_event, &vm_error) ||
  86.400 +         !SDL_NAME(XF86VidModeQueryVersion)(SDL_Display, major, minor) ) {
  86.401 +        return 0;
  86.402 +    }
  86.403 +    return 1;
  86.404 +}
  86.405 +#endif /* SDL_VIDEO_DRIVER_X11_VIDMODE */
  86.406 +
  86.407 +#if SDL_VIDEO_DRIVER_X11_XME
  86.408 +static int CheckXME(_THIS, int *major, int *minor)
  86.409 +{
  86.410 +    const char *env;
  86.411 +
  86.412 +    /* Default the extension not available */
  86.413 +    *major = *minor = 0;
  86.414 +
  86.415 +    /* Allow environment override */
  86.416 +    env = getenv("SDL_VIDEO_X11_VIDMODE");
  86.417 +    if ( env && !SDL_atoi(env) ) {
  86.418 +        return 0;
  86.419 +    }
  86.420 +    
  86.421 +    /* Query the extension version */
  86.422 +    if ( !XiGMiscQueryVersion(SDL_Display, major, minor) ) {
  86.423 +        return 0;
  86.424 +    }
  86.425 +    return 1;
  86.426 +}
  86.427 +#endif /* SDL_VIDEO_DRIVER_X11_XME */
  86.428 +
  86.429  int X11_GetVideoModes(_THIS)
  86.430  {
  86.431 +#if SDL_VIDEO_DRIVER_X11_XINERAMA
  86.432 +    int xinerama_major, xinerama_minor;
  86.433 +#endif
  86.434 +#if SDL_VIDEO_DRIVER_X11_XRANDR
  86.435 +    int xrandr_major, xrandr_minor;
  86.436 +    int nsizes;
  86.437 +    XRRScreenSize *sizes;