(svn r27834) -Change: Parse extmidi command string for parameters to pass on.

This commit is contained in:
peter1138 2017-03-29 17:36:46 +00:00
parent 4f3c7e74e7
commit 5bcc54e021
2 changed files with 30 additions and 8 deletions

View File

@ -12,6 +12,7 @@
#include "../stdafx.h" #include "../stdafx.h"
#include "../debug.h" #include "../debug.h"
#include "../string_func.h" #include "../string_func.h"
#include "../core/alloc_func.hpp"
#include "../sound/sound_driver.hpp" #include "../sound/sound_driver.hpp"
#include "../video/video_driver.hpp" #include "../video/video_driver.hpp"
#include "../gfx_func.h" #include "../gfx_func.h"
@ -42,9 +43,33 @@ const char *MusicDriver_ExtMidi::Start(const char * const * parm)
} }
const char *command = GetDriverParam(parm, "cmd"); const char *command = GetDriverParam(parm, "cmd");
#ifndef MIDI_ARG
if (StrEmpty(command)) command = EXTERNAL_PLAYER; 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->song[0] = '\0';
this->pid = -1; this->pid = -1;
return NULL; return NULL;
@ -52,7 +77,8 @@ const char *MusicDriver_ExtMidi::Start(const char * const * parm)
void MusicDriver_ExtMidi::Stop() void MusicDriver_ExtMidi::Stop()
{ {
free(command); free(params[0]);
free(params);
this->song[0] = '\0'; this->song[0] = '\0';
this->DoStop(); this->DoStop();
} }
@ -91,11 +117,7 @@ void MusicDriver_ExtMidi::DoPlay()
close(0); close(0);
int d = open("/dev/null", O_RDONLY); int d = open("/dev/null", O_RDONLY);
if (d != -1 && dup2(d, 1) != -1 && dup2(d, 2) != -1) { if (d != -1 && dup2(d, 1) != -1 && dup2(d, 2) != -1) {
#if defined(MIDI_ARG) execvp(this->params[0], this->params);
execlp(this->command, "extmidi", MIDI_ARG, this->song, (char*)0);
#else
execlp(this->command, "extmidi", this->song, (char*)0);
#endif
} }
_exit(1); _exit(1);
} }

View File

@ -16,7 +16,7 @@
class MusicDriver_ExtMidi : public MusicDriver { class MusicDriver_ExtMidi : public MusicDriver {
private: private:
char *command; char **params;
char song[MAX_PATH]; char song[MAX_PATH];
pid_t pid; pid_t pid;