Fix code style, and make some minor changes

Assume timidity is in the user's PATH if not the specified location
Also, get the error message for the execvp failure if it does fail
This commit is contained in:
Kevin Caccamo 2017-07-30 22:27:02 -04:00 committed by Rachael Alexanderson
parent 233fce7ef6
commit 18e76c978c

View file

@ -529,20 +529,27 @@ bool TimidityPPMIDIDevice::LaunchTimidity ()
int spaceIdx = 0; int spaceIdx = 0;
int spaceInExePathCount = -1; int spaceInExePathCount = -1;
FString TimidityExe; FString TimidityExe;
do { do
{
spaceIdx = CommandLine.IndexOf(' ', spaceIdx); spaceIdx = CommandLine.IndexOf(' ', spaceIdx);
spaceInExePathCount += 1; spaceInExePathCount += 1;
TimidityExe = CommandLine.Left(spaceIdx); TimidityExe = CommandLine.Left(spaceIdx);
glob(TimidityExe.GetChars(), 0, NULL, &glb); glob(TimidityExe.GetChars(), 0, NULL, &glb);
} while (spaceIdx != -1 && glb.gl_pathc == 0); } while (spaceIdx != -1 && glb.gl_pathc == 0);
if (spaceIdx == -1) return false; if (spaceIdx == -1)
{
TimidityExe = FString("timidity"); // Maybe it's in your PATH?
}
globfree(&glb); globfree(&glb);
int strCount = 1; int strCount = 1;
for (spaceIdx = 0; spaceIdx < CommandLine.Len(); spaceIdx++) { for (spaceIdx = 0; spaceIdx < CommandLine.Len(); spaceIdx++)
if (CommandLine[spaceIdx] == ' ') { {
if (CommandLine[spaceIdx] == ' ')
{
++strCount; ++strCount;
if (CommandLine[spaceIdx+1] == ' ') { if (CommandLine[spaceIdx+1] == ' ')
{
--strCount; --strCount;
} }
} }
@ -558,11 +565,14 @@ bool TimidityPPMIDIDevice::LaunchTimidity ()
strcpy(TimidityArgs[0], TimidityExe.GetChars()); strcpy(TimidityArgs[0], TimidityExe.GetChars());
int argLen; int argLen;
while (curSpace != -1) { while (curSpace != -1)
{
curSpace = CommandLine.IndexOf(' ', spaceIdx); curSpace = CommandLine.IndexOf(' ', spaceIdx);
if (curSpace != spaceIdx) { if (curSpace != spaceIdx)
{
argLen = curSpace - spaceIdx + 1; argLen = curSpace - spaceIdx + 1;
if (argLen < 0) { if (argLen < 0)
{
argLen = CommandLine.Len() - curSpace; argLen = CommandLine.Len() - curSpace;
} }
TimidityArgs[i] = new char[argLen]; TimidityArgs[i] = new char[argLen];
@ -573,7 +583,8 @@ bool TimidityPPMIDIDevice::LaunchTimidity ()
} }
DPrintf(DMSG_NOTIFY, "Timidity EXE: \x1cG%s\n", TimidityExe.GetChars()); DPrintf(DMSG_NOTIFY, "Timidity EXE: \x1cG%s\n", TimidityExe.GetChars());
for (i = 0; i < strCount; i++) { for (i = 0; i < strCount; i++)
{
DPrintf(DMSG_NOTIFY, "arg %d: \x1cG%s\n", i, TimidityArgs[i]); DPrintf(DMSG_NOTIFY, "arg %d: \x1cG%s\n", i, TimidityArgs[i]);
} }
@ -588,7 +599,7 @@ bool TimidityPPMIDIDevice::LaunchTimidity ()
close (WavePipe[1]); close (WavePipe[1]);
execvp (TimidityExe.GetChars(), TimidityArgs); execvp (TimidityExe.GetChars(), TimidityArgs);
fprintf(stderr,"execvp failed\n"); fprintf(stderr,"execvp failed: %s\n", strerror(errno));
_exit (0); // if execvp succeeds, we never get here _exit (0); // if execvp succeeds, we never get here
} }
else if (forkres < 0) else if (forkres < 0)