Use getopt_long for processing command line arguments to Non-DAW and Non-Mixer.
This commit is contained in:
parent
3a5c330e34
commit
46eb00f8d6
|
@ -23,6 +23,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
|
||||||
#include <FL/Fl.H>
|
#include <FL/Fl.H>
|
||||||
#include <FL/Fl_Double_Window.H>
|
#include <FL/Fl_Double_Window.H>
|
||||||
|
@ -203,46 +204,38 @@ main ( int argc, char **argv )
|
||||||
nsm = new NSM_Client;
|
nsm = new NSM_Client;
|
||||||
|
|
||||||
instance_name = strdup( APP_NAME );
|
instance_name = strdup( APP_NAME );
|
||||||
|
bool instance_override = false;
|
||||||
|
|
||||||
|
static struct option long_options[] =
|
||||||
{
|
{
|
||||||
int r = argc - 1;
|
{ "instance", required_argument, 0, 'i' },
|
||||||
int i = 1;
|
{ "osc-port", required_argument, 0, 'p' },
|
||||||
for ( ; i < argc; ++i, --r )
|
{ 0, 0, 0, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
int option_index = 0;
|
||||||
|
int c = 0;
|
||||||
|
|
||||||
|
|
||||||
|
while ( ( c = getopt_long_only( argc, argv, "", long_options, &option_index ) ) != -1 )
|
||||||
{
|
{
|
||||||
if ( !strcmp( argv[i], "--instance" ) )
|
switch ( c )
|
||||||
{
|
{
|
||||||
if ( r > 1 )
|
case 'p':
|
||||||
{
|
DMESSAGE( "Using OSC port %s", optarg );
|
||||||
MESSAGE( "Using instance name \"%s\"", argv[i+1] );
|
osc_port = optarg;
|
||||||
instance_name = strdup( argv[i+1] );
|
|
||||||
--r;
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
FATAL( "Missing instance name" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ( !strcmp( argv[i], "--osc-port" ) )
|
|
||||||
{
|
|
||||||
if ( r > 1 )
|
|
||||||
{
|
|
||||||
MESSAGE( "Using OSC port \"%s\"", argv[i+1] );
|
|
||||||
osc_port = argv[i+1];
|
|
||||||
--r;
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
FATAL( "Missing OSC port" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ( !strncmp( argv[i], "--", 2 ) )
|
|
||||||
{
|
|
||||||
WARNING( "Unrecognized option: %s", argv[i] );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
break;
|
break;
|
||||||
|
case 'i':
|
||||||
|
DMESSAGE( "Using OSC port %s", optarg );
|
||||||
|
free( instance_name );
|
||||||
|
instance_name = strdup( optarg );
|
||||||
|
instance_override = true;
|
||||||
|
break;
|
||||||
|
case '?':
|
||||||
|
printf( "Usage: %s [--osc-port portnum]\n\n", argv[0] );
|
||||||
|
exit(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mixer->init_osc( osc_port );
|
mixer->init_osc( osc_port );
|
||||||
|
@ -253,6 +246,12 @@ main ( int argc, char **argv )
|
||||||
{
|
{
|
||||||
if ( ! nsm->init( nsm_url ) )
|
if ( ! nsm->init( nsm_url ) )
|
||||||
{
|
{
|
||||||
|
if ( instance_override )
|
||||||
|
WARNING( "--instance option is not available when running under session management, ignoring." );
|
||||||
|
|
||||||
|
if ( optind < argc )
|
||||||
|
WARNING( "Loading files from the command-line is incompatible with session management, ignoring." );
|
||||||
|
|
||||||
nsm->announce( APP_NAME, ":switch:dirty:", argv[0] );
|
nsm->announce( APP_NAME, ":switch:dirty:", argv[0] );
|
||||||
|
|
||||||
// poll so we can keep OSC handlers running in the GUI thread and avoid extra sync
|
// poll so we can keep OSC handlers running in the GUI thread and avoid extra sync
|
||||||
|
@ -261,17 +260,16 @@ main ( int argc, char **argv )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( r >= 1 )
|
if ( optind < argc )
|
||||||
{
|
{
|
||||||
MESSAGE( "Loading \"%s\"", argv[i] );
|
MESSAGE( "Loading \"%s\"", argv[optind] );
|
||||||
|
|
||||||
if ( ! mixer->command_load( argv[i] ) )
|
if ( ! mixer->command_load( argv[optind] ) )
|
||||||
{
|
{
|
||||||
fl_alert( "Error opening project specified on commandline" );
|
fl_alert( "Error opening project specified on commandline" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Fl::add_check( check_sigterm );
|
Fl::add_check( check_sigterm );
|
||||||
|
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 7.9 KiB |
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
|
@ -26,6 +26,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
|
||||||
/* for registrations */
|
/* for registrations */
|
||||||
#include "Audio_Region.H"
|
#include "Audio_Region.H"
|
||||||
|
@ -183,6 +184,7 @@ main ( int argc, char **argv )
|
||||||
tle = new TLE;
|
tle = new TLE;
|
||||||
|
|
||||||
instance_name = strdup( APP_NAME );
|
instance_name = strdup( APP_NAME );
|
||||||
|
bool instance_override = false;
|
||||||
|
|
||||||
/* we don't really need a pointer for this */
|
/* we don't really need a pointer for this */
|
||||||
// will be created on project new/open
|
// will be created on project new/open
|
||||||
|
@ -192,39 +194,47 @@ main ( int argc, char **argv )
|
||||||
|
|
||||||
const char *osc_port = NULL;
|
const char *osc_port = NULL;
|
||||||
|
|
||||||
|
static struct option long_options[] =
|
||||||
{
|
{
|
||||||
int r = argc - 1;
|
{ "instance", required_argument, 0, 'i' },
|
||||||
int i = 1;
|
{ "osc-port", required_argument, 0, 'p' },
|
||||||
for ( ; i < argc; ++i, --r )
|
{ 0, 0, 0, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
if ( !strcmp( argv[i], "--osc-port" ) )
|
int option_index = 0;
|
||||||
{
|
int c = 0;
|
||||||
if ( r > 1 )
|
|
||||||
{
|
|
||||||
MESSAGE( "Using OSC port \"%s\"", argv[i+1] );
|
|
||||||
osc_port = argv[i+1];
|
|
||||||
--r;
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
FATAL( "Missing OSC port" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
while ( ( c = getopt_long_only( argc, argv, "", long_options, &option_index ) ) != -1 )
|
||||||
|
{
|
||||||
|
switch ( c )
|
||||||
|
{
|
||||||
|
case 'p':
|
||||||
|
DMESSAGE( "Using OSC port %s", optarg );
|
||||||
|
osc_port = optarg;
|
||||||
|
break;
|
||||||
|
case 'i':
|
||||||
|
DMESSAGE( "Using OSC port %s", optarg );
|
||||||
|
free( instance_name );
|
||||||
|
instance_name = strdup( optarg );
|
||||||
|
instance_override = true;
|
||||||
|
break;
|
||||||
|
case '?':
|
||||||
|
printf( "Usage: %s [--osc-port portnum]\n\n", argv[0] );
|
||||||
|
exit(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MESSAGE( "Starting GUI" );
|
MESSAGE( "Starting GUI" );
|
||||||
|
|
||||||
tle->run();
|
tle->run();
|
||||||
|
|
||||||
|
|
||||||
timeline->init_osc( osc_port );
|
timeline->init_osc( osc_port );
|
||||||
|
|
||||||
#ifdef HAVE_XPM
|
#ifdef HAVE_XPM
|
||||||
tle->main_window->icon((char *)p);
|
tle->main_window->icon((char *)p);
|
||||||
#endif
|
#endif
|
||||||
tle->main_window->show( argc, argv );
|
tle->main_window->show( 0, NULL );
|
||||||
|
|
||||||
|
|
||||||
char *nsm_url = getenv( "NSM_URL" );
|
char *nsm_url = getenv( "NSM_URL" );
|
||||||
|
|
||||||
|
@ -232,6 +242,12 @@ main ( int argc, char **argv )
|
||||||
{
|
{
|
||||||
if ( ! nsm->init( nsm_url ) )
|
if ( ! nsm->init( nsm_url ) )
|
||||||
{
|
{
|
||||||
|
if ( instance_override )
|
||||||
|
WARNING( "--instance option is not available when running under session management, ignoring." );
|
||||||
|
|
||||||
|
if ( optind < argc )
|
||||||
|
WARNING( "Loading files from the command-line is incompatible with session management, ignoring." );
|
||||||
|
|
||||||
nsm->announce( APP_NAME, ":progress:switch:", argv[0] );
|
nsm->announce( APP_NAME, ":progress:switch:", argv[0] );
|
||||||
|
|
||||||
/* poll so we can keep OSC handlers running in the GUI thread and avoid extra sync */
|
/* poll so we can keep OSC handlers running in the GUI thread and avoid extra sync */
|
||||||
|
@ -240,21 +256,14 @@ main ( int argc, char **argv )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( r >= 1 )
|
if ( optind < argc )
|
||||||
{
|
{
|
||||||
MESSAGE( "Loading \"%s\"", argv[i] );
|
MESSAGE( "Loading \"%s\"", argv[optind] );
|
||||||
|
|
||||||
tle->open( argv[i] );
|
tle->open( argv[optind] );
|
||||||
|
|
||||||
/* ) */
|
|
||||||
/* { */
|
|
||||||
/* fl_alert( "Error opening project specified on commandline" ); */
|
|
||||||
/* } */
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Fl::add_check( check_sigterm );
|
Fl::add_check( check_sigterm );
|
||||||
|
|
||||||
Fl::run();
|
Fl::run();
|
||||||
|
|
Loading…
Reference in New Issue