mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-01-31 05:40:44 +00:00
Initial attempt to make timidity work on Linux again
Add code to find the timidity executable, and split the command line into separate arguments by spaces.
For some reason, this doesn't work, although reverting 64e96c5f
makes timidity work again.
This commit is contained in:
parent
49b77f3a17
commit
233fce7ef6
1 changed files with 59 additions and 18 deletions
|
@ -525,15 +525,56 @@ bool TimidityPPMIDIDevice::LaunchTimidity ()
|
|||
int forkres;
|
||||
glob_t glb;
|
||||
|
||||
switch (glob (CommandLine.GetChars(), 0, NULL, &glb))
|
||||
{
|
||||
case 0: // all good
|
||||
break;
|
||||
// Get timidity executable path
|
||||
int spaceIdx = 0;
|
||||
int spaceInExePathCount = -1;
|
||||
FString TimidityExe;
|
||||
do {
|
||||
spaceIdx = CommandLine.IndexOf(' ', spaceIdx);
|
||||
spaceInExePathCount += 1;
|
||||
TimidityExe = CommandLine.Left(spaceIdx);
|
||||
glob(TimidityExe.GetChars(), 0, NULL, &glb);
|
||||
} while (spaceIdx != -1 && glb.gl_pathc == 0);
|
||||
if (spaceIdx == -1) return false;
|
||||
globfree(&glb);
|
||||
|
||||
case GLOB_NOSPACE:
|
||||
globfree (&glb);
|
||||
default:
|
||||
return false;
|
||||
int strCount = 1;
|
||||
for (spaceIdx = 0; spaceIdx < CommandLine.Len(); spaceIdx++) {
|
||||
if (CommandLine[spaceIdx] == ' ') {
|
||||
++strCount;
|
||||
if (CommandLine[spaceIdx+1] == ' ') {
|
||||
--strCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
strCount -= spaceInExePathCount;
|
||||
|
||||
char** TimidityArgs = new char*[strCount];
|
||||
|
||||
spaceIdx = CommandLine.IndexOf(' ');
|
||||
int curSpace = spaceIdx, i = 1;
|
||||
|
||||
TimidityArgs[0] = new char[TimidityExe.Len() + 1];
|
||||
strcpy(TimidityArgs[0], TimidityExe.GetChars());
|
||||
|
||||
int argLen;
|
||||
while (curSpace != -1) {
|
||||
curSpace = CommandLine.IndexOf(' ', spaceIdx);
|
||||
if (curSpace != spaceIdx) {
|
||||
argLen = curSpace - spaceIdx + 1;
|
||||
if (argLen < 0) {
|
||||
argLen = CommandLine.Len() - curSpace;
|
||||
}
|
||||
TimidityArgs[i] = new char[argLen];
|
||||
strcpy(TimidityArgs[i], CommandLine.Mid(spaceIdx, curSpace - spaceIdx).GetChars());
|
||||
i += 1;
|
||||
}
|
||||
spaceIdx = curSpace + 1;
|
||||
}
|
||||
|
||||
DPrintf(DMSG_NOTIFY, "Timidity EXE: \x1cG%s\n", TimidityExe.GetChars());
|
||||
for (i = 0; i < strCount; i++) {
|
||||
DPrintf(DMSG_NOTIFY, "arg %d: \x1cG%s\n", i, TimidityArgs[i]);
|
||||
}
|
||||
|
||||
forkres = fork ();
|
||||
|
@ -546,7 +587,7 @@ bool TimidityPPMIDIDevice::LaunchTimidity ()
|
|||
// freopen ("/dev/null", "w", stderr);
|
||||
close (WavePipe[1]);
|
||||
|
||||
execvp (glb.gl_pathv[0], glb.gl_pathv);
|
||||
execvp (TimidityExe.GetChars(), TimidityArgs);
|
||||
fprintf(stderr,"execvp failed\n");
|
||||
_exit (0); // if execvp succeeds, we never get here
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue