Use getopt_long for processing command line arguments to Non-DAW and Non-Mixer.

This commit is contained in:
Jonathan Moore Liles 2012-02-28 22:12:07 -08:00
parent 3a5c330e34
commit 46eb00f8d6
4 changed files with 112 additions and 105 deletions

View File

@ -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,72 +204,69 @@ 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;
int i = 1;
for ( ; i < argc; ++i, --r )
{ {
if ( !strcmp( argv[i], "--instance" ) ) { "instance", required_argument, 0, 'i' },
{ { "osc-port", required_argument, 0, 'p' },
if ( r > 1 ) { 0, 0, 0, 0 }
{ };
MESSAGE( "Using instance name \"%s\"", argv[i+1] );
instance_name = strdup( argv[i+1] ); int option_index = 0;
--r; int c = 0;
++i;
}
else while ( ( c = getopt_long_only( argc, argv, "", long_options, &option_index ) ) != -1 )
{ {
FATAL( "Missing instance name" ); switch ( c )
} {
} case 'p':
else if ( !strcmp( argv[i], "--osc-port" ) ) DMESSAGE( "Using OSC port %s", optarg );
{ osc_port = optarg;
if ( r > 1 ) break;
{ case 'i':
MESSAGE( "Using OSC port \"%s\"", argv[i+1] ); DMESSAGE( "Using OSC port %s", optarg );
osc_port = argv[i+1]; free( instance_name );
--r; instance_name = strdup( optarg );
++i; instance_override = true;
} break;
else case '?':
{ printf( "Usage: %s [--osc-port portnum]\n\n", argv[0] );
FATAL( "Missing OSC port" ); exit(0);
}
}
else if ( !strncmp( argv[i], "--", 2 ) )
{
WARNING( "Unrecognized option: %s", argv[i] );
}
else
break; break;
} }
}
mixer->init_osc( osc_port ); mixer->init_osc( osc_port );
char *nsm_url = getenv( "NSM_URL" ); char *nsm_url = getenv( "NSM_URL" );
if ( nsm_url ) if ( nsm_url )
{
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." );
nsm->announce( APP_NAME, ":switch:dirty:", argv[0] );
// poll so we can keep OSC handlers running in the GUI thread and avoid extra sync if ( optind < argc )
Fl::add_timeout( NSM_CHECK_INTERVAL, check_nsm, NULL ); WARNING( "Loading files from the command-line is incompatible with session management, ignoring." );
}
nsm->announce( APP_NAME, ":switch:dirty:", argv[0] );
// poll so we can keep OSC handlers running in the GUI thread and avoid extra sync
Fl::add_timeout( NSM_CHECK_INTERVAL, check_nsm, NULL );
} }
else }
else
{
if ( optind < argc )
{ {
if ( r >= 1 ) MESSAGE( "Loading \"%s\"", argv[optind] );
{
MESSAGE( "Loading \"%s\"", argv[i] );
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" );
}
} }
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -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,67 +194,74 @@ main ( int argc, char **argv )
const char *osc_port = NULL; const char *osc_port = NULL;
static struct option long_options[] =
{
{ "instance", required_argument, 0, 'i' },
{ "osc-port", required_argument, 0, 'p' },
{ 0, 0, 0, 0 }
};
int option_index = 0;
int c = 0;
while ( ( c = getopt_long_only( argc, argv, "", long_options, &option_index ) ) != -1 )
{ {
int r = argc - 1; switch ( c )
int i = 1; {
for ( ; i < argc; ++i, --r ) 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;
}
}
if ( !strcmp( argv[i], "--osc-port" ) ) MESSAGE( "Starting GUI" );
{
if ( r > 1 )
{
MESSAGE( "Using OSC port \"%s\"", argv[i+1] );
osc_port = argv[i+1];
--r;
++i;
}
else
{
FATAL( "Missing OSC port" );
}
}
tle->run();
MESSAGE( "Starting GUI" ); timeline->init_osc( osc_port );
tle->run();
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" ); if ( nsm_url )
{
if ( nsm_url ) 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." );
nsm->announce( APP_NAME, ":progress:switch:", argv[0] );
/* poll so we can keep OSC handlers running in the GUI thread and avoid extra sync */ if ( optind < argc )
Fl::add_timeout( NSM_CHECK_INTERVAL, check_nsm, NULL ); WARNING( "Loading files from the command-line is incompatible with session management, ignoring." );
}
nsm->announce( APP_NAME, ":progress:switch:", argv[0] );
/* poll so we can keep OSC handlers running in the GUI thread and avoid extra sync */
Fl::add_timeout( NSM_CHECK_INTERVAL, check_nsm, NULL );
} }
else }
else
{
if ( optind < argc )
{ {
if ( r >= 1 ) MESSAGE( "Loading \"%s\"", argv[optind] );
{
MESSAGE( "Loading \"%s\"", argv[i] );
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 );