tPlugins are now selectable at runtime with the -u, --plugin command line optio… | |
git clone git://src.adamsgaard.dk/vaccinewars | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 064d97cc35949782635605a9d9caf3b648ed8f52 | |
parent 4a84c637bacdf71335f0040279538efc8a403ad8 | |
Author: Ben Webb <[email protected]> | |
Date: Tue, 14 May 2002 13:03:43 +0000 | |
Plugins are now selectable at runtime with the -u, --plugin | |
command line option. | |
Diffstat: | |
M src/curses_client/curses_client.c | 2 +- | |
M src/dopewars.c | 22 ++++++++++------------ | |
M src/dopewars.h | 3 ++- | |
M src/gui_client/gtk_client.c | 2 +- | |
M src/sound.c | 81 ++++++++++++++++++++++-------… | |
M src/sound.h | 2 +- | |
6 files changed, 73 insertions(+), 39 deletions(-) | |
--- | |
diff --git a/src/curses_client/curses_client.c b/src/curses_client/curses_clien… | |
t@@ -2410,7 +2410,7 @@ void CursesLoop(void) | |
LogMask() | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_WARNING, | |
LogMessage, NULL); | |
- SoundOpen(NULL); | |
+ SoundOpen(WantedPlugin); | |
display_intro(); | |
diff --git a/src/dopewars.c b/src/dopewars.c | |
t@@ -78,7 +78,7 @@ gboolean Network, Client, Server, NotifyMetaServer, AIPlayer; | |
unsigned Port = 7902; | |
gboolean Sanitized, ConfigVerbose, DrugValue; | |
gchar *HiScoreFile = NULL, *ServerName = NULL, *ConvertFile = NULL; | |
-gchar *ServerMOTD = NULL; | |
+gchar *ServerMOTD = NULL, *WantedPlugin = NULL; | |
gboolean WantHelp, WantVersion, WantAntique, WantColour, WantNetwork; | |
gboolean WantConvert, WantAdmin; | |
t@@ -2515,8 +2515,7 @@ void SetupParameters(void) | |
static void PluginHelp(void) | |
{ | |
- GSList *listpt = NULL; | |
- const gchar *plugname; | |
+ gchar *plugins; | |
#ifdef HAVE_GETOPT_LONG | |
g_print(_(" -u, --plugin=FILE use sound plugin \"FILE\"\n" | |
" ")); | |
t@@ -2524,14 +2523,9 @@ static void PluginHelp(void) | |
g_print(_(" -u file use sound plugin \"file\"\n" | |
" ")); | |
#endif | |
- g_print("(\"none\""); | |
- do { | |
- plugname = GetPluginName(&listpt); | |
- if (plugname) { | |
- g_print(", \"%s\"", plugname); | |
- } | |
- } while(plugname); | |
- g_print(_(" available)\n")); | |
+ plugins = GetPluginList(); | |
+ g_print(_("(%s available)\n"), plugins); | |
+ g_free(plugins); | |
} | |
void HandleHelpTexts(void) | |
t@@ -2616,7 +2610,7 @@ Report bugs to the author at [email protected]\… | |
void HandleCmdLine(int argc, char *argv[]) | |
{ | |
int c; | |
- static const gchar *options = "anbchvf:o:sSp:g:r:wtC:l:NA"; | |
+ static const gchar *options = "anbchvf:o:sSp:g:r:wtC:l:NAu:"; | |
#ifdef HAVE_GETOPT_LONG | |
static const struct option long_options[] = { | |
t@@ -2637,6 +2631,7 @@ void HandleCmdLine(int argc, char *argv[]) | |
{"convert", required_argument, NULL, 'C'}, | |
{"logfile", required_argument, NULL, 'l'}, | |
{"admin", no_argument, NULL, 'A'}, | |
+ {"plugin", required_argument, NULL, 'u'}, | |
{"help", no_argument, NULL, 'h'}, | |
{"version", no_argument, NULL, 'v'}, | |
{0, 0, 0, 0} | |
t@@ -2697,6 +2692,9 @@ void HandleCmdLine(int argc, char *argv[]) | |
case 'l': | |
AssignName(&Log.File, optarg); | |
break; | |
+ case 'u': | |
+ AssignName(&WantedPlugin, optarg); | |
+ break; | |
case 'w': | |
WantedClient = CLIENT_WINDOW; | |
break; | |
diff --git a/src/dopewars.h b/src/dopewars.h | |
t@@ -167,7 +167,8 @@ extern unsigned Port; | |
extern gboolean Sanitized, ConfigVerbose, DrugValue; | |
extern int NumLocation, NumGun, NumCop, NumDrug, NumSubway, NumPlaying, | |
NumStoppedTo; | |
-extern gchar *HiScoreFile, *ServerName, *ConvertFile, *ServerMOTD; | |
+extern gchar *HiScoreFile, *ServerName, *ConvertFile, *ServerMOTD, | |
+ *WantedPlugin; | |
extern gboolean WantHelp, WantVersion, WantAntique, WantColour, | |
WantNetwork, WantConvert, WantAdmin; | |
#ifdef CYGWIN | |
diff --git a/src/gui_client/gtk_client.c b/src/gui_client/gtk_client.c | |
t@@ -2220,7 +2220,7 @@ gboolean GtkLoop(int *argc, char **argv[], gboolean Retu… | |
if (!CheckHighScoreFileConfig()) | |
return TRUE; | |
- SoundOpen(NULL); | |
+ SoundOpen(WantedPlugin); | |
/* Create the main player */ | |
ClientData.Play = g_new(Player, 1); | |
diff --git a/src/sound.c b/src/sound.c | |
t@@ -37,37 +37,42 @@ | |
#include "plugins/sound_winmm.h" | |
#endif | |
+#include "nls.h" | |
#include "sound.h" | |
+#define NOPLUGIN "none" | |
+ | |
static SoundDriver *driver = NULL; | |
static GSList *driverlist = NULL; | |
typedef SoundDriver *(*InitFunc)(void); | |
-static gboolean module_open = FALSE; | |
-const gchar *GetPluginName(GSList **listpt) | |
+gchar *GetPluginList(void) | |
{ | |
- if (!*listpt) { | |
- *listpt = driverlist; | |
- } else { | |
- *listpt = g_slist_next(*listpt); | |
- } | |
- if (*listpt) { | |
- SoundDriver *drivpt = (SoundDriver *)(*listpt)->data; | |
+ GSList *listpt; | |
+ GString *plugins; | |
+ gchar *retstr; | |
+ | |
+ plugins = g_string_new("\""NOPLUGIN"\""); | |
+ for (listpt = driverlist; listpt; listpt = g_slist_next(listpt)) { | |
+ SoundDriver *drivpt = (SoundDriver *)listpt->data; | |
- if (drivpt) { | |
- return drivpt->name; | |
+ if (drivpt && drivpt->name) { | |
+ g_string_sprintfa(plugins, ", \"%s\"", drivpt->name); | |
} | |
} | |
- return NULL; | |
+ retstr = plugins->str; | |
+ g_string_free(plugins, FALSE); | |
+ return retstr; | |
} | |
static void AddPlugin(InitFunc ifunc, void *module) | |
{ | |
- driver = (*ifunc)(); | |
- if (driver) { | |
- g_print("%s sound plugin init OK\n", driver->name); | |
- driver->module = module; | |
- driverlist = g_slist_append(driverlist, driver); | |
+ SoundDriver *newdriver = (*ifunc)(); | |
+ | |
+ if (newdriver) { | |
+ g_print("%s sound plugin init OK\n", newdriver->name); | |
+ newdriver->module = module; | |
+ driverlist = g_slist_append(driverlist, newdriver); | |
} | |
} | |
t@@ -148,14 +153,44 @@ void SoundInit(void) | |
AddPlugin(sound_winmm_init, NULL); | |
#endif | |
#endif | |
- module_open = FALSE; | |
+ driver = NULL; | |
+} | |
+ | |
+static SoundDriver *GetPlugin(gchar *drivername) | |
+{ | |
+ GSList *listpt; | |
+ | |
+ for (listpt = driverlist; listpt; listpt = g_slist_next(listpt)) { | |
+ SoundDriver *drivpt = (SoundDriver *)listpt->data; | |
+ | |
+ if (drivpt && drivpt->name | |
+ && (!drivername || strcmp(drivpt->name, drivername) == 0)) { | |
+ return drivpt; | |
+ } | |
+ } | |
+ return NULL; | |
} | |
void SoundOpen(gchar *drivername) | |
{ | |
- if (driver && driver->open && !module_open) { | |
- driver->open(); | |
- module_open = TRUE; | |
+ if (!drivername || strcmp(drivername, NOPLUGIN) != 0) { | |
+ driver = GetPlugin(drivername); | |
+ if (driver) { | |
+ if (driver->open) { | |
+ g_print("Using plugin %s\n", driver->name); | |
+ driver->open(); | |
+ } | |
+ } else if (drivername) { | |
+ gchar *plugins, *err; | |
+ | |
+ plugins = GetPluginList(); | |
+ err = g_strdup_printf(_("Invalid plugin \"%s\" selected.\n" | |
+ "(%s available; now using \"%s\".)"), | |
+ drivername, plugins, NOPLUGIN); | |
+ g_log(NULL, G_LOG_LEVEL_CRITICAL, err); | |
+ g_free(plugins); | |
+ g_free(err); | |
+ } | |
} | |
} | |
t@@ -166,9 +201,9 @@ void SoundClose(void) | |
SoundDriver *listdriv; | |
#endif | |
- if (driver && driver->close && module_open) { | |
+ if (driver && driver->close) { | |
driver->close(); | |
- module_open = FALSE; | |
+ driver = NULL; | |
} | |
#ifdef PLUGINS | |
for (listpt = driverlist; listpt; listpt = g_slist_next(listpt)) { | |
diff --git a/src/sound.h b/src/sound.h | |
t@@ -37,7 +37,7 @@ struct _SoundDriver { | |
}; | |
typedef struct _SoundDriver SoundDriver; | |
-const gchar *GetPluginName(GSList **listpt); | |
+gchar *GetPluginList(void); | |
void SoundInit(void); | |
void SoundOpen(gchar *drivername); | |
void SoundClose(void); |