From 18e76c978c7058656b7cf873389466580a324ae1 Mon Sep 17 00:00:00 2001 From: Kevin Caccamo Date: Sun, 30 Jul 2017 22:27:02 -0400 Subject: [PATCH] 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 --- .../music_timiditypp_mididevice.cpp | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/sound/mididevices/music_timiditypp_mididevice.cpp b/src/sound/mididevices/music_timiditypp_mididevice.cpp index 0628ea140..a2da274e3 100644 --- a/src/sound/mididevices/music_timiditypp_mididevice.cpp +++ b/src/sound/mididevices/music_timiditypp_mididevice.cpp @@ -529,20 +529,27 @@ bool TimidityPPMIDIDevice::LaunchTimidity () int spaceIdx = 0; int spaceInExePathCount = -1; FString TimidityExe; - do { + 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; + if (spaceIdx == -1) + { + TimidityExe = FString("timidity"); // Maybe it's in your PATH? + } globfree(&glb); int strCount = 1; - for (spaceIdx = 0; spaceIdx < CommandLine.Len(); spaceIdx++) { - if (CommandLine[spaceIdx] == ' ') { + for (spaceIdx = 0; spaceIdx < CommandLine.Len(); spaceIdx++) + { + if (CommandLine[spaceIdx] == ' ') + { ++strCount; - if (CommandLine[spaceIdx+1] == ' ') { + if (CommandLine[spaceIdx+1] == ' ') + { --strCount; } } @@ -558,11 +565,14 @@ bool TimidityPPMIDIDevice::LaunchTimidity () strcpy(TimidityArgs[0], TimidityExe.GetChars()); int argLen; - while (curSpace != -1) { + while (curSpace != -1) + { curSpace = CommandLine.IndexOf(' ', spaceIdx); - if (curSpace != spaceIdx) { + if (curSpace != spaceIdx) + { argLen = curSpace - spaceIdx + 1; - if (argLen < 0) { + if (argLen < 0) + { argLen = CommandLine.Len() - curSpace; } TimidityArgs[i] = new char[argLen]; @@ -573,7 +583,8 @@ bool TimidityPPMIDIDevice::LaunchTimidity () } 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]); } @@ -588,7 +599,7 @@ bool TimidityPPMIDIDevice::LaunchTimidity () close (WavePipe[1]); 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 } else if (forkres < 0)