Simplify g_nSubCommandArg logic
getopt() will eat the "--" separator if there's one. Rely on the value of optind after the getopt() loop finishes to figure out whether a command has been specified.
This commit is contained in:
parent
4cc32ca8a6
commit
a22e9d3c0d
3 changed files with 10 additions and 19 deletions
15
src/main.cpp
15
src/main.cpp
|
@ -43,8 +43,6 @@ bool g_bNiceCap = false;
|
|||
int g_nOldNice = 0;
|
||||
int g_nNewNice = 0;
|
||||
|
||||
uint32_t g_nSubCommandArg = 0;
|
||||
|
||||
pthread_t g_mainThread;
|
||||
|
||||
int BIsNested()
|
||||
|
@ -54,17 +52,6 @@ int BIsNested()
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// Grab the starting position of a potential command that follows "--" in argv
|
||||
// Do it before getopt can reorder anything, for use later
|
||||
for ( int i = 0; i < argc; i++ )
|
||||
{
|
||||
if ( strcmp( "--", argv[ i ] ) == 0 && i + 1 < argc )
|
||||
{
|
||||
g_nSubCommandArg = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int o;
|
||||
ac = argc;
|
||||
av = argv;
|
||||
|
@ -195,7 +182,7 @@ int main(int argc, char **argv)
|
|||
|
||||
// If DRM format modifiers aren't supported, prevent our clients from using
|
||||
// DCC, as this can cause tiling artifacts.
|
||||
if ( g_nSubCommandArg != 0 && !g_vulkanSupportsModifiers )
|
||||
if ( !g_vulkanSupportsModifiers )
|
||||
{
|
||||
const char *pchR600Debug = getenv( "R600_DEBUG" );
|
||||
|
||||
|
|
|
@ -27,8 +27,6 @@ extern bool g_bBorderlessOutputWindow;
|
|||
|
||||
extern bool g_bTakeScreenshot;
|
||||
|
||||
extern uint32_t g_nSubCommandArg;
|
||||
|
||||
extern bool g_bNiceCap;
|
||||
extern int g_nOldNice;
|
||||
extern int g_nNewNice;
|
||||
|
|
|
@ -3243,7 +3243,7 @@ steamcompmgr_main (int argc, char **argv)
|
|||
int o;
|
||||
int readyPipeFD = -1;
|
||||
|
||||
// :/
|
||||
// Reset getopt() state
|
||||
optind = 1;
|
||||
|
||||
while ((o = getopt (argc, argv, GAMESCOPE_OPTIONS)) != -1)
|
||||
|
@ -3292,6 +3292,12 @@ steamcompmgr_main (int argc, char **argv)
|
|||
}
|
||||
}
|
||||
|
||||
int subCommandArg = -1;
|
||||
if ( optind < argc )
|
||||
{
|
||||
subCommandArg = optind;
|
||||
}
|
||||
|
||||
if ( pipe2( g_nudgePipe, O_CLOEXEC | O_NONBLOCK ) != 0 )
|
||||
{
|
||||
perror( "steamcompmgr: pipe failed" );
|
||||
|
@ -3461,9 +3467,9 @@ steamcompmgr_main (int argc, char **argv)
|
|||
readyPipeFD = -1;
|
||||
}
|
||||
|
||||
if ( g_nSubCommandArg != 0 )
|
||||
if ( subCommandArg >= 0 )
|
||||
{
|
||||
spawn_client( &argv[ g_nSubCommandArg ] );
|
||||
spawn_client( &argv[ subCommandArg ] );
|
||||
}
|
||||
|
||||
std::thread imageWaitThread( imageWaitThreadMain );
|
||||
|
|
Loading…
Reference in a new issue