mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-09 19:10:38 +00:00
(svn r27834) -Change: Parse extmidi command string for parameters to pass on.
This commit is contained in:
parent
4f3c7e74e7
commit
5bcc54e021
@ -12,6 +12,7 @@
|
||||
#include "../stdafx.h"
|
||||
#include "../debug.h"
|
||||
#include "../string_func.h"
|
||||
#include "../core/alloc_func.hpp"
|
||||
#include "../sound/sound_driver.hpp"
|
||||
#include "../video/video_driver.hpp"
|
||||
#include "../gfx_func.h"
|
||||
@ -42,9 +43,33 @@ const char *MusicDriver_ExtMidi::Start(const char * const * parm)
|
||||
}
|
||||
|
||||
const char *command = GetDriverParam(parm, "cmd");
|
||||
#ifndef MIDI_ARG
|
||||
if (StrEmpty(command)) command = EXTERNAL_PLAYER;
|
||||
#else
|
||||
if (StrEmpty(command)) command = EXTERNAL_PLAYER " " MIDI_ARG;
|
||||
#endif
|
||||
|
||||
/* Count number of arguments, but include 3 extra slots: 1st for command, 2nd for song title, and 3rd for terminating NULL. */
|
||||
uint num_args = 3;
|
||||
for (const char *t = command; *t != '\0'; t++) if (*t == ' ') num_args++;
|
||||
|
||||
this->params = CallocT<char *>(num_args);
|
||||
this->params[0] = stredup(command);
|
||||
|
||||
/* Replace space with \0 and add next arg to params */
|
||||
uint p = 1;
|
||||
while (true) {
|
||||
this->params[p] = strchr(this->params[p - 1], ' ');
|
||||
if (this->params[p] == NULL) break;
|
||||
|
||||
this->params[p][0] = '\0';
|
||||
this->params[p]++;
|
||||
p++;
|
||||
}
|
||||
|
||||
/* Last parameter is the song file. */
|
||||
this->params[p] = this->song;
|
||||
|
||||
this->command = stredup(command);
|
||||
this->song[0] = '\0';
|
||||
this->pid = -1;
|
||||
return NULL;
|
||||
@ -52,7 +77,8 @@ const char *MusicDriver_ExtMidi::Start(const char * const * parm)
|
||||
|
||||
void MusicDriver_ExtMidi::Stop()
|
||||
{
|
||||
free(command);
|
||||
free(params[0]);
|
||||
free(params);
|
||||
this->song[0] = '\0';
|
||||
this->DoStop();
|
||||
}
|
||||
@ -91,11 +117,7 @@ void MusicDriver_ExtMidi::DoPlay()
|
||||
close(0);
|
||||
int d = open("/dev/null", O_RDONLY);
|
||||
if (d != -1 && dup2(d, 1) != -1 && dup2(d, 2) != -1) {
|
||||
#if defined(MIDI_ARG)
|
||||
execlp(this->command, "extmidi", MIDI_ARG, this->song, (char*)0);
|
||||
#else
|
||||
execlp(this->command, "extmidi", this->song, (char*)0);
|
||||
#endif
|
||||
execvp(this->params[0], this->params);
|
||||
}
|
||||
_exit(1);
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
class MusicDriver_ExtMidi : public MusicDriver {
|
||||
private:
|
||||
char *command;
|
||||
char **params;
|
||||
char song[MAX_PATH];
|
||||
pid_t pid;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user