[vlmc-devel] main: Make sure read all the options even with the --no-gui option
Yikai Lu
git at videolan.org
Sat Jun 10 04:23:21 CEST 2017
vlmc | branch: master | Yikai Lu <luyikei.qmltu at gmail.com> | Sat Jun 10 10:48:27 2017 +0900| [c81cf2aac0b81d12038e1640d065befc33374a41] | committer: Yikai Lu
main: Make sure read all the options even with the --no-gui option
> https://code.videolan.org/videolan/vlmc/commit/c81cf2aac0b81d12038e1640d065befc33374a41
---
src/Main/main.cpp | 34 ++++++++++++++++++++++------------
src/Main/vlmc.cpp | 13 +++++++++++--
2 files changed, 33 insertions(+), 14 deletions(-)
diff --git a/src/Main/main.cpp b/src/Main/main.cpp
index f6389c70..8e0c4afb 100644
--- a/src/Main/main.cpp
+++ b/src/Main/main.cpp
@@ -196,8 +196,24 @@ VLMCCoremain( int argc, char **argv )
Backend::IBackend* backend;
VLMCmainCommon( app, &backend );
+ const QString* projectFile = nullptr;
+ const QString* outputFile = nullptr;
+ QStringList&& args = app.arguments();
+
+ // We don't check the first argument, possibly "./vlmc"
+ args.pop_front();
+
+ for ( const auto& arg : args )
+ {
+ // Make sure it's not an option
+ if ( projectFile == nullptr && arg.at( 0 ) != '-' )
+ projectFile = &arg;
+ else if ( outputFile == nullptr && arg.at( 0 ) != '-' )
+ outputFile = &arg;
+ }
+
/* Load a project file */
- if ( app.arguments().count() < 3 )
+ if ( projectFile == nullptr || outputFile == nullptr )
{
vlmcCritical() << "Usage: ./vlmc "
#ifdef HAVE_GUI
@@ -208,13 +224,13 @@ VLMCCoremain( int argc, char **argv )
}
- ConsoleRenderer renderer( app.arguments()[2] );
+ ConsoleRenderer renderer( *outputFile );
Project *p = Core::instance()->project();
QCoreApplication::connect( p, &Project::projectLoaded, &renderer, &ConsoleRenderer::startRender );
QCoreApplication::connect( &renderer, &ConsoleRenderer::finished, &app, &QCoreApplication::quit, Qt::QueuedConnection );
Core::instance()->settings()->load();
- p->load( app.arguments()[1] );
+ p->load( *projectFile );
auto res = app.exec();
Core::instance()->settings()->save();
@@ -222,18 +238,12 @@ VLMCCoremain( int argc, char **argv )
}
int
-VLMCmain( int argc, char **argv )
+VLMCmain( int argc, char **argv, bool gui )
{
#ifdef HAVE_GUI
- if ( argc < 2 || strcmp( argv[1], "--no-gui" ) != 0 )
- {
+ if ( gui == true )
return VLMCGuimain( argc, argv );
- }
- // Remove --no-gui from argv
- std::swap( argv[0], argv[1] );
- return VLMCCoremain( argc - 1, argv + 1 );
-#else
- return VLMCCoremain( argc, argv );
#endif
+ return VLMCCoremain( argc, argv );
}
diff --git a/src/Main/vlmc.cpp b/src/Main/vlmc.cpp
index 847a6b76..cd629516 100644
--- a/src/Main/vlmc.cpp
+++ b/src/Main/vlmc.cpp
@@ -37,7 +37,7 @@
#include <unistd.h>
-int VLMCmain( int , char** );
+int VLMCmain( int , char**, bool );
#if defined(WITH_CRASHHANDLER) && defined(Q_OS_UNIX)
@@ -100,6 +100,11 @@ usage( QString const& appName )
int
main( int argc, char **argv )
{
+#ifdef HAVE_GUI
+ bool gui = true;
+#else
+ bool gui = false;
+#endif
/* Check for command arguments */
for( int i = 1; i < argc; i++ )
{
@@ -115,6 +120,10 @@ main( int argc, char **argv )
::version();
return 2;
}
+#ifdef HAVE_GUI
+ else if( arg == "--no-gui" )
+ gui = false;
+#endif
}
#ifdef WITH_CRASHHANDLER
@@ -155,5 +164,5 @@ main( int argc, char **argv )
}
#endif
- return VLMCmain( argc, argv );
+ return VLMCmain( argc, argv, gui );
}
More information about the Vlmc-devel
mailing list