src/driver.cpp
author Darkvater
Sun, 18 Feb 2007 22:50:51 +0000
changeset 6400 7b98825c5cb0
parent 6360 37f43b7ce27b
child 6268 4b5241e5dd10
permissions -rw-r--r--
(svn r8807) -Feature: Add support for loading (some of) the TTDP extra chunks mainly list of GRFIDs and TTDP version the game was saved with.
GRFID list is read and active GRFs are loaded with the game if present in the data/ directory.
TTDP versioning information only works for newer versions, old versions will only give rough information but it's not worth the effort to precisely figure out what bit means what where and when.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2171
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2171
diff changeset
     2
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
     3
#include "stdafx.h"
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
     4
#include "openttd.h"
2210
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
     5
#include "debug.h"
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
     6
#include "driver.h"
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
     7
#include "functions.h"
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
     8
#include "hal.h"
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
     9
#include "string.h"
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    10
2210
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    11
#include "music/bemidi.h"
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    12
#include "music/dmusic.h"
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    13
#include "music/extmidi.h"
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    14
#include "music/null_m.h"
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    15
#include "music/os2_m.h"
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    16
#include "music/win32_m.h"
2496
ad131afbc8cb (svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents: 2458
diff changeset
    17
#include "music/qtmidi.h"
6360
37f43b7ce27b (svn r8757) -Add: added libtimidity music driver (it is a nice small library simular to timidity via extmidi)
truelight
parents: 6007
diff changeset
    18
#include "music/libtimidity.h"
2210
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    19
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    20
#include "sound/null_s.h"
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    21
#include "sound/sdl_s.h"
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2500
diff changeset
    22
#include "sound/cocoa_s.h"
2210
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    23
#include "sound/win32_s.h"
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    24
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    25
#include "video/dedicated_v.h"
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    26
#include "video/null_v.h"
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    27
#include "video/sdl_v.h"
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2500
diff changeset
    28
#include "video/cocoa_v.h"
2210
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    29
#include "video/win32_v.h"
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    30
2219
a62bfd598c83 (svn r2737) static, const and don't make variables public nobody else needs to know about
tron
parents: 2210
diff changeset
    31
typedef struct DriverDesc {
a62bfd598c83 (svn r2737) static, const and don't make variables public nobody else needs to know about
tron
parents: 2210
diff changeset
    32
	const char* name;
a62bfd598c83 (svn r2737) static, const and don't make variables public nobody else needs to know about
tron
parents: 2210
diff changeset
    33
	const char* longname;
2224
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    34
	const HalCommonDriver* drv;
2219
a62bfd598c83 (svn r2737) static, const and don't make variables public nobody else needs to know about
tron
parents: 2210
diff changeset
    35
} DriverDesc;
a62bfd598c83 (svn r2737) static, const and don't make variables public nobody else needs to know about
tron
parents: 2210
diff changeset
    36
a62bfd598c83 (svn r2737) static, const and don't make variables public nobody else needs to know about
tron
parents: 2210
diff changeset
    37
typedef struct DriverClass {
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    38
	const DriverDesc *descs;
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    39
	const char *name;
2224
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    40
	const HalCommonDriver** drv;
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    41
} DriverClass;
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    42
2222
d227c0207a02 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    43
2902
2800aa0bd3ce (svn r3457) -Fix: killed some warnings about strict-alias in an ugly way (but it works ;))
truelight
parents: 2832
diff changeset
    44
#define M(x, y, z) { x, y, (const HalCommonDriver *)(void *)z }
2222
d227c0207a02 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    45
static const DriverDesc _music_driver_descs[] = {
d227c0207a02 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    46
#ifdef __BEOS__
2224
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    47
	M("bemidi",  "BeOS MIDI Driver",        &_bemidi_music_driver),
2222
d227c0207a02 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    48
#endif
5305
e07957fe871e (svn r7461) -Fix: [FS#262] Add support for building with GCC on OS/2 (psmedley)
Darkvater
parents: 5170
diff changeset
    49
#if defined(__OS2__) && !defined(__INNOTEK_LIBC__)
2224
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    50
	M("os2",     "OS/2 Music Driver",       &_os2_music_driver),
2222
d227c0207a02 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    51
#endif
d227c0207a02 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    52
#ifdef WIN32_ENABLE_DIRECTMUSIC_SUPPORT
2224
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    53
	M("dmusic",  "DirectMusic MIDI Driver", &_dmusic_midi_driver),
2222
d227c0207a02 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    54
#endif
6007
4544ad85ea3f (svn r8307) [WinCE] -Fix: for now disable sound and music. That will be done later.
truelight
parents: 5835
diff changeset
    55
#if defined(WIN32) && !defined(WINCE)
2224
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    56
	M("win32",   "Win32 MIDI Driver",       &_win32_music_driver),
2222
d227c0207a02 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    57
#endif
2500
e2b13f720a94 (svn r3026) -Fix: [OSX] fixed bug that prevented dedicated servers from compiling (introduced in r3022)
bjarni
parents: 2496
diff changeset
    58
#if defined(__APPLE__) && !defined(DEDICATED)
2496
ad131afbc8cb (svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents: 2458
diff changeset
    59
	M("qt",      "QuickTime MIDI Driver",   &_qtime_music_driver),
ad131afbc8cb (svn r3022) -feature: [OSX] OSX now uses quicktime to play midi files
bjarni
parents: 2458
diff changeset
    60
#endif
2222
d227c0207a02 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    61
#ifdef UNIX
6360
37f43b7ce27b (svn r8757) -Add: added libtimidity music driver (it is a nice small library simular to timidity via extmidi)
truelight
parents: 6007
diff changeset
    62
#if defined(LIBTIMIDITY)
37f43b7ce27b (svn r8757) -Add: added libtimidity music driver (it is a nice small library simular to timidity via extmidi)
truelight
parents: 6007
diff changeset
    63
	M("libtimidity", "LibTimidity MIDI Driver", &_libtimidity_music_driver),
37f43b7ce27b (svn r8757) -Add: added libtimidity music driver (it is a nice small library simular to timidity via extmidi)
truelight
parents: 6007
diff changeset
    64
#endif /* LIBTIMIDITY */
37f43b7ce27b (svn r8757) -Add: added libtimidity music driver (it is a nice small library simular to timidity via extmidi)
truelight
parents: 6007
diff changeset
    65
#if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(PSP)
2224
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    66
	M("extmidi", "External MIDI Driver",    &_extmidi_music_driver),
2222
d227c0207a02 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    67
#endif
d227c0207a02 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    68
#endif
2224
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    69
	M("null",    "Null Music Driver",       &_null_music_driver),
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    70
	M(NULL, NULL, NULL)
2222
d227c0207a02 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    71
};
d227c0207a02 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    72
d227c0207a02 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    73
static const DriverDesc _sound_driver_descs[] = {
6007
4544ad85ea3f (svn r8307) [WinCE] -Fix: for now disable sound and music. That will be done later.
truelight
parents: 5835
diff changeset
    74
#if defined(WIN32) && !defined(WINCE)
2224
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    75
	M("win32", "Win32 WaveOut Driver", &_win32_sound_driver),
2222
d227c0207a02 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    76
#endif
d227c0207a02 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    77
#ifdef WITH_SDL
2224
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    78
	M("sdl",   "SDL Sound Driver",     &_sdl_sound_driver),
2222
d227c0207a02 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    79
#endif
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2500
diff changeset
    80
#ifdef WITH_COCOA
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2500
diff changeset
    81
	M("cocoa", "Cocoa Sound Driver",   &_cocoa_sound_driver),
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2500
diff changeset
    82
#endif
2224
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    83
	M("null",  "Null Sound Driver",    &_null_sound_driver),
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    84
	M(NULL, NULL, NULL)
2222
d227c0207a02 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    85
};
d227c0207a02 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    86
d227c0207a02 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    87
static const DriverDesc _video_driver_descs[] = {
d227c0207a02 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    88
#ifdef WIN32
2224
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    89
	M("win32",      "Win32 GDI Video Driver", &_win32_video_driver),
2222
d227c0207a02 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    90
#endif
d227c0207a02 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    91
#ifdef WITH_SDL
2224
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    92
	M("sdl",        "SDL Video Driver",       &_sdl_video_driver),
2222
d227c0207a02 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    93
#endif
2736
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2500
diff changeset
    94
#ifdef WITH_COCOA
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2500
diff changeset
    95
	M("cocoa",      "Cocoa Video Driver",       &_cocoa_video_driver),
1ea068235989 (svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
bjarni
parents: 2500
diff changeset
    96
#endif
2224
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    97
	M("null",       "Null Video Driver",      &_null_video_driver),
2222
d227c0207a02 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    98
#ifdef ENABLE_NETWORK
2224
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    99
	M("dedicated",  "Dedicated Video Driver", &_dedicated_video_driver),
2222
d227c0207a02 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
   100
#endif
2224
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   101
	M(NULL, NULL, NULL)
2222
d227c0207a02 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
   102
};
2224
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   103
#undef M
2222
d227c0207a02 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
   104
2219
a62bfd598c83 (svn r2737) static, const and don't make variables public nobody else needs to know about
tron
parents: 2210
diff changeset
   105
2902
2800aa0bd3ce (svn r3457) -Fix: killed some warnings about strict-alias in an ugly way (but it works ;))
truelight
parents: 2832
diff changeset
   106
#define M(x, y, z) { x, y, (const HalCommonDriver **)(void *)z }
2219
a62bfd598c83 (svn r2737) static, const and don't make variables public nobody else needs to know about
tron
parents: 2210
diff changeset
   107
static const DriverClass _driver_classes[] = {
2224
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   108
	M(_video_driver_descs, "video", &_video_driver),
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   109
	M(_sound_driver_descs, "sound", &_sound_driver),
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   110
	M(_music_driver_descs, "music", &_music_driver)
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   111
};
2224
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   112
#undef M
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   113
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   114
static const DriverDesc* GetDriverByName(const DriverDesc* dd, const char* name)
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   115
{
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   116
	for (; dd->name != NULL; dd++) {
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   117
		if (strcmp(dd->name, name) == 0) return dd;
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   118
	}
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   119
	return NULL;
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   120
}
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   121
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   122
void LoadDriver(int driver, const char *name)
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   123
{
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   124
	const DriverClass *dc = &_driver_classes[driver];
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   125
	const DriverDesc *dd;
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   126
	const char *err;
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   127
2210
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   128
	if (*name == '\0') {
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   129
		for (dd = dc->descs; dd->name != NULL; dd++) {
2224
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   130
			err = dd->drv->start(NULL);
2210
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   131
			if (err == NULL) break;
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5305
diff changeset
   132
			DEBUG(driver, 1, "Probing %s driver '%s' failed with error: %s",
2210
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   133
				dc->name, dd->name, err
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   134
			);
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   135
		}
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5305
diff changeset
   136
		if (dd->name == NULL) error("Couldn't find any suitable %s driver", dc->name);
2210
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   137
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5305
diff changeset
   138
		DEBUG(driver, 1, "Successfully probed %s driver '%s'", dc->name, dd->name);
2210
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   139
2224
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   140
		*dc->drv = dd->drv;
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   141
	} else {
2224
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   142
		char* parm;
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   143
		char buffer[256];
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   144
		const char* parms[32];
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   145
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   146
		// Extract the driver name and put parameter list in parm
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   147
		ttd_strlcpy(buffer, name, sizeof(buffer));
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   148
		parm = strchr(buffer, ':');
2224
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   149
		parms[0] = NULL;
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   150
		if (parm != NULL) {
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   151
			uint np = 0;
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   152
			// Tokenize the parm.
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   153
			do {
2224
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   154
				*parm++ = '\0';
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   155
				if (np < lengthof(parms) - 1)
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   156
					parms[np++] = parm;
2224
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   157
				while (*parm != '\0' && *parm != ',')
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   158
					parm++;
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   159
			} while (*parm == ',');
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   160
			parms[np] = NULL;
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   161
		}
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   162
		dd = GetDriverByName(dc->descs, buffer);
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   163
		if (dd == NULL)
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   164
			error("No such %s driver: %s\n", dc->name, buffer);
2210
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   165
2224
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   166
		if (*dc->drv != NULL) (*dc->drv)->stop();
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   167
		*dc->drv = NULL;
2210
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   168
2224
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   169
		err = dd->drv->start(parms);
2210
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   170
		if (err != NULL) {
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   171
			error("Unable to load driver %s(%s). The error was: %s\n",
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   172
				dd->name, dd->longname, err
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   173
			);
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
   174
		}
2224
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   175
		*dc->drv = dd->drv;
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   176
	}
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   177
}
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   178
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   179
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   180
static const char* GetDriverParam(const char* const* parm, const char* name)
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   181
{
2458
c95808cd2ac9 (svn r2984) Use adequate types, this should aid portability a bit
tron
parents: 2303
diff changeset
   182
	size_t len;
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   183
2224
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   184
	if (parm == NULL) return NULL;
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   185
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
   186
	len = strlen(name);
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   187
	for (; *parm != NULL; parm++) {
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   188
		const char* p = *parm;
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   189
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   190
		if (strncmp(p, name, len) == 0) {
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   191
			if (p[len] == '=')  return p + len + 1;
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   192
			if (p[len] == '\0') return p + len;
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   193
		}
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   194
	}
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   195
	return NULL;
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   196
}
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   197
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   198
bool GetDriverParamBool(const char* const* parm, const char* name)
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   199
{
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   200
	return GetDriverParam(parm, name) != NULL;
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   201
}
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   202
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   203
int GetDriverParamInt(const char* const* parm, const char* name, int def)
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   204
{
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   205
	const char* p = GetDriverParam(parm, name);
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   206
	return p != NULL ? atoi(p) : def;
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   207
}
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   208
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   209
5170
56c12a62af49 (svn r7280) -Codechange: Replace some sprintf() functions with the safer snprintf() functions
Darkvater
parents: 2902
diff changeset
   210
char *GetDriverList(char* p, const char *last)
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   211
{
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   212
	const DriverClass* dc;
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   213
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   214
	for (dc = _driver_classes; dc != endof(_driver_classes); dc++) {
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   215
		const DriverDesc* dd;
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   216
5170
56c12a62af49 (svn r7280) -Codechange: Replace some sprintf() functions with the safer snprintf() functions
Darkvater
parents: 2902
diff changeset
   217
		p += snprintf(p, last - p, "List of %s drivers:\n", dc->name);
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   218
		for (dd = dc->descs; dd->name != NULL; dd++) {
5170
56c12a62af49 (svn r7280) -Codechange: Replace some sprintf() functions with the safer snprintf() functions
Darkvater
parents: 2902
diff changeset
   219
			p += snprintf(p, last - p, "%10s: %s\n", dd->name, dd->longname);
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   220
		}
5170
56c12a62af49 (svn r7280) -Codechange: Replace some sprintf() functions with the safer snprintf() functions
Darkvater
parents: 2902
diff changeset
   221
		p = strecpy(p, "\n", last);
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   222
	}
2831
510c08cd43d2 (svn r3379) -Fix: protect showhelp against any possible overflow
truelight
parents: 2736
diff changeset
   223
2832
acf08469a0c6 (svn r3380) -Fix: removed 'size' from r3379, because it was pretty silly
truelight
parents: 2831
diff changeset
   224
	return p;
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   225
}