summaryrefslogtreecommitdiff
path: root/src/setup
diff options
context:
space:
mode:
authorSimon Howard2009-11-21 16:36:46 +0000
committerSimon Howard2009-11-21 16:36:46 +0000
commitafa0c4c7979c1508605d0e79487f299cd03adda6 (patch)
tree7df1745badf169e4490e3a56a89a28ac37977c14 /src/setup
parent095bc1110b3c11fbf2e17bfd51bf78909fe34662 (diff)
parent2c6e7b2f10c32ca0406ca6753e7701d83e6dea8f (diff)
downloadchocolate-doom-afa0c4c7979c1508605d0e79487f299cd03adda6.tar.gz
chocolate-doom-afa0c4c7979c1508605d0e79487f299cd03adda6.tar.bz2
chocolate-doom-afa0c4c7979c1508605d0e79487f299cd03adda6.zip
Merge from trunk.
Subversion-branch: /branches/raven-branch Subversion-revision: 1737
Diffstat (limited to 'src/setup')
-rw-r--r--src/setup/Makefile.am1
-rw-r--r--src/setup/execute.c123
-rw-r--r--src/setup/joystick.c2
-rw-r--r--src/setup/mainmenu.c9
-rw-r--r--src/setup/multiplayer.c2
-rw-r--r--src/setup/sound.c29
6 files changed, 101 insertions, 65 deletions
diff --git a/src/setup/Makefile.am b/src/setup/Makefile.am
index 737dd278..58561b62 100644
--- a/src/setup/Makefile.am
+++ b/src/setup/Makefile.am
@@ -2,6 +2,7 @@
gamesdir = $(prefix)/games
AM_CFLAGS = @SDL_CFLAGS@ \
+ @SDLMIXER_CFLAGS@ \
-I$(top_builddir)/textscreen -I.. \
-DINSTALL_DIR="\"$(gamesdir)\""
diff --git a/src/setup/execute.c b/src/setup/execute.c
index 18a07156..be7214f5 100644
--- a/src/setup/execute.c
+++ b/src/setup/execute.c
@@ -159,81 +159,69 @@ static unsigned int WaitForProcessExit(HANDLE subprocess)
}
}
-static wchar_t *GetFullExePath(const char *program)
+static void ConcatWCString(wchar_t *buf, const char *value)
+{
+ MultiByteToWideChar(CP_OEMCP, 0,
+ value, strlen(value) + 1,
+ buf + wcslen(buf), strlen(value) + 1);
+}
+
+// Build the command line string, a wide character string of the form:
+//
+// "program" "arg"
+
+static wchar_t *BuildCommandLine(const char *program, const char *arg)
{
wchar_t *result;
- unsigned int path_len;
char *sep;
- // Find the full path to the EXE to execute, by taking the path
- // to this program and concatenating the EXE name:
+ result = calloc(strlen(myargv[0]) + strlen(program) + strlen(arg) + 6,
+ sizeof(wchar_t));
+
+ wcscpy(result, L"\"");
sep = strrchr(myargv[0], DIR_SEPARATOR);
- if (sep == NULL)
- {
- path_len = 0;
- result = calloc(strlen(program) + 1, sizeof(wchar_t));
- }
- else
+ if (sep != NULL)
{
- path_len = sep - myargv[0] + 1;
-
- result = calloc(path_len + strlen(program) + 1,
- sizeof(wchar_t));
- MultiByteToWideChar(CP_OEMCP, 0,
- myargv[0], path_len,
- result, path_len);
- }
-
- MultiByteToWideChar(CP_OEMCP, 0,
- program, strlen(program) + 1,
- result + path_len, strlen(program) + 1);
-
- return result;
-}
+ ConcatWCString(result, myargv[0]);
-// Convert command line argument to wchar_t string and add surrounding
-// "" quotes:
+ // Cut off the string after the last directory separator,
+ // before appending the actual program.
-static wchar_t *GetPaddedWideArg(const char *arg)
-{
- wchar_t *result;
- unsigned int len = strlen(arg);
+ result[sep - myargv[0] + 2] = '\0';
+
+ }
- // Convert the command line arg to a wide char string:
+ ConcatWCString(result, program);
- result = calloc(len + 3, sizeof(wchar_t));
- MultiByteToWideChar(CP_OEMCP, 0,
- arg, len + 1,
- result + 1, len + 1);
+ wcscat(result, L"\" \"");
- // Surrounding quotes:
+ ConcatWCString(result, arg);
- result[0] = '"';
- result[len + 1] = '"';
- result[len + 2] = 0;
+ wcscat(result, L"\"");
return result;
}
static int ExecuteCommand(const char *program, const char *arg)
{
+ STARTUPINFOW startup_info;
PROCESS_INFORMATION proc_info;
- wchar_t *exe_path;
- wchar_t *warg;
+ wchar_t *command;
int result = 0;
- exe_path = GetFullExePath(program);
- warg = GetPaddedWideArg(arg);
+ command = BuildCommandLine(program, arg);
// Invoke the program:
memset(&proc_info, 0, sizeof(proc_info));
+ memset(&startup_info, 0, sizeof(startup_info));
+ startup_info.cb = sizeof(startup_info);
- if (!CreateProcessW(exe_path, warg,
- NULL, NULL, FALSE, 0, NULL, NULL, NULL,
- &proc_info))
+ if (!CreateProcessW(NULL, command,
+ NULL, NULL, FALSE, 0, NULL, NULL,
+ &startup_info, &proc_info))
{
result = -1;
}
@@ -247,19 +235,48 @@ static int ExecuteCommand(const char *program, const char *arg)
CloseHandle(proc_info.hThread);
}
- free(exe_path);
- free(warg);
+ free(command);
return result;
}
#else
+// Given the specified program name, get the full path to the program,
+// assuming that it is in the same directory as this program is.
+
+static char *GetFullExePath(const char *program)
+{
+ char *result;
+ char *sep;
+ unsigned int path_len;
+
+ sep = strrchr(myargv[0], DIR_SEPARATOR);
+
+ if (sep == NULL)
+ {
+ result = strdup(program);
+ }
+ else
+ {
+ path_len = sep - myargv[0] + 1;
+
+ result = malloc(strlen(program) + path_len + 1);
+
+ strncpy(result, myargv[0], path_len);
+ result[path_len] = '\0';
+
+ strcat(result, program);
+ }
+
+ return result;
+}
+
static int ExecuteCommand(const char *program, const char *arg)
{
pid_t childpid;
int result;
- const char *argv[] = { program, arg, NULL };
+ const char *argv[3];
childpid = fork();
@@ -267,7 +284,11 @@ static int ExecuteCommand(const char *program, const char *arg)
{
// This is the child. Execute the command.
- execv(argv[0], (char **) argv);
+ argv[0] = GetFullExePath(program);
+ argv[1] = arg;
+ argv[2] = NULL;
+
+ execvp(argv[0], (char **) argv);
exit(-1);
}
diff --git a/src/setup/joystick.c b/src/setup/joystick.c
index 3d2b713b..0094dd81 100644
--- a/src/setup/joystick.c
+++ b/src/setup/joystick.c
@@ -38,7 +38,7 @@ typedef enum
CALIBRATE_UP,
} calibration_stage_t;
-// SDL joystick successfully initialised?
+// SDL joystick successfully initialized?
static int joystick_initted = 0;
diff --git a/src/setup/mainmenu.c b/src/setup/mainmenu.c
index 3b79bc94..46e4b4e6 100644
--- a/src/setup/mainmenu.c
+++ b/src/setup/mainmenu.c
@@ -19,6 +19,7 @@
// 02111-1307, USA.
//
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -175,6 +176,10 @@ void MainMenu(void)
TXT_SetWindowAction(window, TXT_HORIZ_LEFT, quit_action);
}
+//
+// Initialize all configuration variables, load config file, etc
+//
+
static void InitConfig(void)
{
InitBindings();
@@ -228,7 +233,7 @@ static void SetIcon(void)
}
//
-// Initialise and run the textscreen GUI.
+// Initialize and run the textscreen GUI.
//
static void RunGUI(void)
@@ -237,7 +242,7 @@ static void RunGUI(void)
if (!TXT_Init())
{
- fprintf(stderr, "Failed to initialise GUI\n");
+ fprintf(stderr, "Failed to initialize GUI\n");
exit(-1);
}
diff --git a/src/setup/multiplayer.c b/src/setup/multiplayer.c
index 131ec068..f3b3221d 100644
--- a/src/setup/multiplayer.c
+++ b/src/setup/multiplayer.c
@@ -783,7 +783,7 @@ void SetChatMacroDefaults(void)
HUSTR_CHATMACRO0,
};
- // If the chat macros have not been set, initialise with defaults.
+ // If the chat macros have not been set, initialize with defaults.
for (i=0; i<10; ++i)
{
diff --git a/src/setup/sound.c b/src/setup/sound.c
index 0361ac62..97037ee9 100644
--- a/src/setup/sound.c
+++ b/src/setup/sound.c
@@ -23,6 +23,8 @@
#include <stdlib.h>
+#include "SDL_mixer.h"
+
#include "textscreen.h"
#include "m_config.h"
@@ -60,19 +62,10 @@ static char *musicmode_strings[] =
"CD audio"
};
-// Disable MIDI music on OSX: there are problems with the native
-// MIDI code in SDL_mixer.
-
-#ifdef __MACOSX__
-#define DEFAULT_MUSIC_DEVICE SNDDEVICE_NONE
-#else
-#define DEFAULT_MUSIC_DEVICE SNDDEVICE_SB
-#endif
-
// Config file variables:
int snd_sfxdevice = SNDDEVICE_SB;
-int snd_musicdevice = DEFAULT_MUSIC_DEVICE;
+int snd_musicdevice = SNDDEVICE_SB;
int snd_samplerate = 22050;
static int numChannels = 8;
@@ -237,5 +230,21 @@ void BindSoundVariables(void)
M_BindVariable("snd_sbirq", &snd_sbirq);
M_BindVariable("snd_sbdma", &snd_sbdma);
M_BindVariable("snd_mport", &snd_mport);
+
+ // Before SDL_mixer version 1.2.11, MIDI music caused the game
+ // to crash when it looped. If this is an old SDL_mixer version,
+ // disable MIDI.
+
+#ifdef __MACOSX__
+ {
+ const SDL_version *v = Mix_Linked_Version();
+
+ if (SDL_VERSIONNUM(v->major, v->minor, v->patch)
+ < SDL_VERSIONNUM(1, 2, 11))
+ {
+ snd_musicdevice = SNDDEVICE_NONE;
+ }
+ }
+#endif
}