Build optstring on the fly

Instead of having to maintain two lists of options, just generate
one from the other.
This commit is contained in:
Simon Ser 2021-09-01 15:14:08 +02:00
parent 13f792ab15
commit 5904078b2c

View file

@ -24,7 +24,7 @@
#include "pipewire.hpp" #include "pipewire.hpp"
#endif #endif
const char *gamescope_optstring = "R:T:C:w:h:W:H:m:r:o:NFSvVecsdLinbfxO:"; const char *gamescope_optstring = nullptr;
const struct option *gamescope_options = (struct option[]){ const struct option *gamescope_options = (struct option[]){
{ "nested-width", required_argument, nullptr, 'w' }, { "nested-width", required_argument, nullptr, 'w' },
@ -95,8 +95,26 @@ int BIsNested()
static int initOutput(void); static int initOutput(void);
static void steamCompMgrThreadRun(int argc, char **argv); static void steamCompMgrThreadRun(int argc, char **argv);
static std::string build_optstring(const struct option *options) {
std::string optstring;
for (size_t i = 0; options[i].name != nullptr; i++) {
if (!options[i].val)
continue;
char str[] = { (char) options[i].val, '\0' };
optstring.append(str);
if (options[i].has_arg)
optstring.append(":");
}
return optstring;
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
static std::string optstring = build_optstring(gamescope_options);
gamescope_optstring = optstring.c_str();
int o; int o;
bool bSleepAtStartup = false; bool bSleepAtStartup = false;
int opt_index = -1; int opt_index = -1;