Merge pull request #389 from CarterLi/command

RFC: an attempt to add a new module which can run custom shell scripts
This commit is contained in:
Carter Li
2023-01-15 00:08:04 +08:00
committed by GitHub
7 changed files with 114 additions and 2 deletions
+20
View File
@@ -350,6 +350,18 @@ static void defaultConfig(FFinstance* instance)
ffStrbufInitA(&instance->config.playerName, 0);
instance->config.percentType = 1;
ffStrbufInitS(&instance->config.commandShell,
#ifdef _WIN32
"cmd"
#elif defined(__FreeBSD__)
"csh"
#else
"bash"
#endif
);
ffListInit(&instance->config.commandKeys, sizeof(FFstrbuf));
ffListInit(&instance->config.commandTexts, sizeof(FFstrbuf));
}
void ffInitInstance(FFinstance* instance)
@@ -564,6 +576,14 @@ static void destroyConfig(FFinstance* instance)
ffStrbufDestroy(&instance->config.weatherOutputFormat);
ffStrbufDestroy(&instance->config.osFile);
ffStrbufDestroy(&instance->config.playerName);
ffStrbufDestroy(&instance->config.commandShell);
FF_LIST_FOR_EACH(FFstrbuf, item, instance->config.commandKeys)
ffStrbufDestroy(item);
ffListDestroy(&instance->config.commandKeys);
FF_LIST_FOR_EACH(FFstrbuf, item, instance->config.commandTexts)
ffStrbufDestroy(item);
ffListDestroy(&instance->config.commandTexts);
}
static void destroyState(FFinstance* instance)
+2 -2
View File
@@ -31,8 +31,8 @@ const char* ffProcessAppendStdOut(FFstrbuf* buffer, char* const argv[])
//Parent
close(pipes[1]);
waitpid(childPid, NULL, 0);
ffAppendFDBuffer(pipes[0], buffer);
bool ok = ffAppendFDBuffer(pipes[0], buffer);
close(pipes[0]);
return NULL;
return ok ? NULL : "ffAppendFDBuffer() failed";
}