int main(int argc, char *argv[]) {
  QCoreApplication app (argc, argv);
 
  CmdLineParser cmd (app.arguments());
  CmdLineParser::Result res = cmd.parse();
  if (res == CmdLineParser::Help)
      return 0;
  else if (res == CmdLineParser::Error)
      return -1;


  QString filename = cmd.file();
  if (!QFile::exists ( filename )) {
    qCritical ("The file you specified doesn't exist!");
    exit (1);
  }
  
  Parser parser;
  bool ok;

  QFile file (filename);
  QVariant data = parser.parse (&file, &ok);
  if (!ok) {
    qCritical("%s:%i - Error: %s", filename.toLatin1().data(), parser.errorLine(), qPrintable(parser.errorString()));
    exit (1);
  }
  else {
    qDebug() << "json object successfully converted to:";
    qDebug() << data;
  }

  if (cmd.serialize()) {
    // serializer tests
    qDebug() << "Serialization output";
    QJson::Serializer serializer;
    serializer.setIndentMode(cmd.indentationMode());
    QByteArray b = serializer.serialize(data);
    qDebug() << b;
  }

  qDebug() << "JOB DONE, BYE";
  return 0;
}
AMCrashMonitorSupport::AMCrashMonitorSupport()
{
	errorFile_ = 0;

	QCoreApplication *app = QApplication::instance();

	QStringList applicationArguments = app->arguments();

	QString applicationPath = applicationArguments.at(0);
	QFileInfo applicationPathInfo(applicationPath);

	if(applicationPathInfo.isSymLink())
		pathToCrashReporter_ = applicationPathInfo.symLinkTarget().section('/', 0, -2);
	else
		pathToCrashReporter_ = applicationPathInfo.absoluteDir().path();

	pathToCrashReportFiles_ = "/home/acquaman/AcquamanApplicationCrashReports";

	if(applicationArguments.contains("--enableCrashMonitor")){
		signal(SIGSEGV, handle_signal_sigsev);
		signal(SIGABRT, handle_signal_sigabrt);
	}
}
Example #3
0
int main (int argc, char *argv[])
{
  QCoreApplication app (argc, argv);

  bool generate_dot = false;
  bool generate_report = false;
  bool no_lines = false;
  bool debug_info = true;
  bool troll_copyright = false;
  QString file_name = 0;

  QStringList args = app.arguments ();
  args.removeFirst ();

  foreach (QString arg, args)
    {
      if (arg == QLatin1String ("-h") || arg == QLatin1String ("--help"))
        help_me ();

      else if (arg == QLatin1String ("-v") || arg == QLatin1String ("--verbose"))
        generate_report = true;

      else if (arg == QLatin1String ("--dot"))
        generate_dot = true;

      else if (arg == QLatin1String ("--no-lines"))
        no_lines = true;

      else if (arg == QLatin1String ("--no-debug"))
        debug_info = false;

      else if (arg == QLatin1String ("--troll"))
        troll_copyright = true;

      else if (file_name.isEmpty ())
	file_name = arg;

      else
        qerr << "*** Warning. Ignore argument `" << arg << "'" << endl;
    }

  if (file_name.isEmpty ())
    {
      help_me ();
      exit (EXIT_SUCCESS);
    }

  Grammar grammar;
  Recognizer p (&grammar, no_lines);

  if (! p.parse (file_name))
    exit (EXIT_FAILURE);

  if (grammar.rules.isEmpty ())
    {
      qerr << "*** Fatal. No rules!" << endl;
      exit (EXIT_FAILURE);
    }

  else if (grammar.start == grammar.names.end ())
    {
      qerr << "*** Fatal. No start symbol!" << endl;
      exit (EXIT_FAILURE);
    }

  grammar.buildExtendedGrammar ();
  grammar.buildRuleMap ();

  Automaton aut (&grammar);
  aut.build ();

  CppGenerator gen (p, grammar, aut, generate_report);
  gen.setDebugInfo (debug_info);
  gen.setTrollCopyright (troll_copyright);
  gen ();

  if (generate_dot)
    {
      DotGraph genDotFile (qout);
      genDotFile (&aut);
    }

  else if (generate_report)
    {
      ParseTable genParseTable (qout);
      genParseTable(&aut);
    }

  return EXIT_SUCCESS;
}
int main(int argc, char *argv[]) {
  QCoreApplication app (argc, argv);

#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
  QTextCodec *codec = QTextCodec::codecForName("UTF-8");
  QTextCodec::setCodecForCStrings(codec);
#endif

  QTime time;
  int   duration;

 
  CmdLineParser cmd (app.arguments());
  CmdLineParser::Result res = cmd.parse();
  if (res == CmdLineParser::Help)
      return 0;
  else if (res == CmdLineParser::Error)
      return -1;

  QString filename = cmd.file();
  if (!QFile::exists ( filename )) {
    qCritical ("The file you specified doesn't exist!");
    exit (1);
  }

  Parser parser;
  bool ok;

  QFile file (filename);
  time.start();
  QVariant data = parser.parse (&file, &ok);
  duration = time.elapsed();
  if (!ok) {
    qCritical("%s:%i - Error: %s", filename.toLatin1().data(), parser.errorLine(), qPrintable(parser.errorString()));
    exit (1);
  }
  else {
    qDebug() << "Parsing of" << filename << "took" << duration << "ms";
    if (!cmd.quiet())
      qDebug() << data;
  }

  if (cmd.serialize()) {
    // serializer tests
    qDebug() << "Serializing... ";
    QJson::Serializer serializer;
    serializer.setIndentMode(cmd.indentationMode());
    time.start();
    QByteArray b = serializer.serialize(data, &ok);
    if (!ok) {
      qCritical() << "Serialization failed:" << serializer.errorMessage();
      exit(1);
    } else {
      duration = time.elapsed();
      qDebug() << "Serialization took:" << duration << "ms";
      if (!cmd.quiet())
       qDebug() << b;
    }
  }

  qDebug() << "JOB DONE, BYE";
  return 0;
}
Example #5
0
int main(int pArgC, char *pArgV[])
{
    // Initialise Qt's message pattern

    OpenCOR::initQtMessagePattern();

    // Initialise the plugins path

    OpenCOR::initPluginsPath(pArgV[0]);

    // Create our application

    QCoreApplication *cliApp = new QCoreApplication(pArgC, pArgV);

    // Some general initialisations

    OpenCOR::initApplication();

    // Try to run OpenCOR as a CLI application

    int res;

    if (!OpenCOR::cliApplication(&res)) {
        // OpenCOR isn't meant to be run as a CLI application, so start its GUI
        // version instead

        static const QString DotExe = ".exe";

        if (cliApp->applicationFilePath().right(DotExe.size()) == DotExe) {
            // This is a safeguard from accidentally running a non-renamed (to
            // '.com') CLI version of OpenCOR

            error("the CLI version of "+qAppName()+" has the wrong extension ('.exe' instead of '.com').");

            res = -1;
        } else {
            QString guiAppFilePath = cliApp->applicationDirPath()+QDir::separator()+qAppName()+DotExe;

            if (!QFile::exists(guiAppFilePath)) {
                // We can't find the GUI version of OpenCOR, so...

                error("the GUI version of "+qAppName()+" cannot be found.");

                res = -1;
            } else {
                // We found the GUI version of OpenCOR, so run it with our
                // arguments, minus the first one since it corresponds to the
                // full path to our executable, which we are not interested in

                QStringList appArguments = cliApp->arguments();

                appArguments.removeFirst();

                QProcess().startDetached(guiAppFilePath, appArguments, QProcess().workingDirectory());

                res = 0;
            }
        }
    }

    // Release some memory

    delete cliApp;

    // We are done, so...

    return res;
}
Example #6
0
bool
parseCommandLine( QCoreApplication& app, QCommandLineParser& parser, CliOptions& options, qint32& profileId,
                  QString& errmsg )
{
    parser.setApplicationDescription( "RedTimer Command Line Interface" );

    // Commands
    QMap<QString,QString> commands;
    commands.insert( "create", "Create a new issue" );
    commands.insert( "issue",  "Get the current issue ID" );
    commands.insert( "start",  "Start issue tracking" );
    commands.insert( "stop",   "Stop issue tracking" );

    QStringList descr;
    QMapIterator<QString, QString> cmd( commands );
    while( cmd.hasNext() )
    {
        cmd.next();

        QString data;
        QTextStream out( &data );
        out.setFieldAlignment( QTextStream::AlignLeft );
        out << qSetFieldWidth(10) << cmd.key() << cmd.value();
        descr.push_back( data );
    }

    parser.addPositionalArgument( "command", descr.join("\n"), "create|issue|start|stop" );

    // Program parameters
    parser.addOption( {"profile-id", "Redmine instance to send the command to", "ID"} );

    // Command parameters
    parser.addOption( {"assignee-id",        "Redmine assignee ID",      "ID"} );
    parser.addOption( {"issue-id",           "Redmine issue ID",         "ID"} );
    parser.addOption( {"parent-id",          "Redmine parent issue ID",  "ID"} );
    parser.addOption( {"project-id",         "Redmine project ID",       "ID"} );
    parser.addOption( {"tracker-id",         "Redmine tracker ID",       "ID"} );
    parser.addOption( {"version-id",         "Redmine version ID",       "ID"} );
    parser.addOption( {"external-id",        "External issue ID",        "text"} );
    parser.addOption( {"external-parent-id", "External parent issue ID", "text"} );
    parser.addOption( {"subject",            "Issue subject",            "text"} );
    parser.addOption( {"description",        "Issue description",        "text"} );

    // General parameters
    parser.addHelpOption();
    parser.addVersionOption();

    // Process command line options
    if( !parser.parse(app.arguments()) )
    {
        errmsg = parser.errorText();
        return false;
    }

    if( parser.isSet("help") )
        return false;


    // Get the command

    const QStringList positionalArguments = parser.positionalArguments();

    if( positionalArguments.isEmpty() )
    {
        errmsg = "No command specified.";
        return false;
    }

    if( positionalArguments.size() > 1 )
    {
        errmsg = "Several commands specified.";
        return false;
    }

    options.command = positionalArguments.first();

    if( commands.find(options.command) == commands.end() )
    {
        errmsg = QString("Command '%1' not found.").arg(options.command);
        return false;
    }

    auto getNumericId = [&]( const QString& option, qint32& id )
    {
        if( !parser.isSet(option) )
            return true;

        QString idString = parser.value( option );
        bool ok;
        id = idString.toInt( &ok );

        if( !ok )
        {
            errmsg = QString("Option '--%1' expects a numeric ID.").arg(option);
            return false;
        }

        return true;
    };

    auto getString = [&]( const QString& option, QString& str, bool allowWhitespaces )
    {
        if( !parser.isSet(option) )
            return true;

        str = parser.value( option );

        if( !allowWhitespaces && str.contains( QRegularExpression("\\W")) )
        {
            errmsg = QString("Option '--%1' must not contain whitespaces.").arg(option);
            return false;
        }

        return true;
    };

    if( !getNumericId("profile-id", profileId) )
        return false;

    if( !getNumericId("assignee-id", options.assigneeId) )
        return false;

    if( !getNumericId("issue-id", options.issueId) )
        return false;

    if( !getNumericId("parent-id", options.parentId) )
        return false;

    if( !getNumericId("project-id", options.projectId) )
        return false;

    if( !getNumericId("tracker-id", options.trackerId) )
        return false;

    if( !getNumericId("version-id", options.versionId) )
        return false;

    if( !getString("external-id", options.externalId, false) )
        return false;

    if( !getString("external-parent-id", options.externalParentId, false) )
        return false;

    if( !getString("description", options.description, true) )
        return false;

    if( !getString("subject", options.subject, true) )
        return false;

    auto isValid = [&]( const QString option, bool allowed )
    {
        if( allowed && !parser.isSet(option) )
        {
            errmsg = QString("Option '--%1' required by command '%2'.").arg(option).arg(options.command);
            return false;
        }
        else if( !allowed && parser.isSet(option) )
        {
            errmsg = QString("Option '--%1' not allowed for command '%2'.").arg(option).arg(options.command);
            return false;
        }

        return true;
    };

    // Required: issue-id
    if( options.command == "start" )
    {
        // Required
        if( !isValid("issue-id", true) )
            return false;

        // Not allowed
        if( !isValid("assignee-id", false) )
            return false;
        if( !isValid("parent-id", false) )
            return false;
        if( !isValid("project-id", false) )
            return false;
        if( !isValid("tracker-id", false) )
            return false;
        if( !isValid("version-id", false) )
            return false;
        if( !isValid("external-id", false) )
            return false;
        if( !isValid("external-parent-id", false) )
            return false;
        if( !isValid("subject", false) )
            return false;
        if( !isValid("description", false) )
            return false;
    }
    else if( options.command == "create" )
    {
        // Required
        if( !isValid("project-id", true) )
            return false;
        if( !isValid("subject", true) )
            return false;

        // Not allowed
        if( !isValid("issue-id", false) )
            return false;

        // Exclusive
        if( parser.isSet("parent-id") && parser.isSet("external-parent-id") )
        {
            errmsg = "Options '--parent-id' and '--external-parent-id' may not be combined.";
            return false;
        }
    }
    else
    {
        // Not allowed
        if( !isValid("assignee-id", false) )
            return false;
        if( !isValid("issue-id", false) )
            return false;
        if( !isValid("parent-id", false) )
            return false;
        if( !isValid("project-id", false) )
            return false;
        if( !isValid("tracker-id", false) )
            return false;
        if( !isValid("version-id", false) )
            return false;
        if( !isValid("external-id", false) )
            return false;
        if( !isValid("external-parent-id", false) )
            return false;
        if( !isValid("subject", false) )
            return false;
        if( !isValid("description", false) )
            return false;
    }

    return true;
}
Example #7
0
File: main.cpp Project: iTALC/italc
int main( int argc, char **argv )
{
	QCoreApplication* app = nullptr;

#ifdef ITALC_BUILD_LINUX
	// do not create graphical application if DISPLAY is not available
	if( QProcessEnvironment::systemEnvironment().contains( "DISPLAY" ) == false )
	{
		app = new QCoreApplication( argc, argv );
	}
	else
	{
		app = new QApplication( argc, argv );
	}
#else
	app = new QApplication( argc, argv );
#endif

	if( app->arguments().count() < 2 )
	{
		qCritical( "ERROR: not enough arguments - please specify a command" );

		return -1;
	}

	if( app->arguments().last() == "-v" || app->arguments().last() == "--version" )
	{
		printf( "%s\n", ITALC_VERSION );
		return 0;
	}

	ItalcCore* core = new ItalcCore( app, "Control" );

	QMap<CommandLinePluginInterface *, QObject *> commandLinePluginInterfaces;

	for( auto pluginObject : core->pluginManager().pluginObjects() )
	{
		auto commandLinePluginInterface = qobject_cast<CommandLinePluginInterface *>( pluginObject );
		if( commandLinePluginInterface )
		{
			commandLinePluginInterfaces[commandLinePluginInterface] = pluginObject;
		}
	}

	QString command = app->arguments()[1];

	for( auto commandLinePluginInterface : commandLinePluginInterfaces.keys() )
	{
		if( commandLinePluginInterface->commandName() == command )
		{
			CommandLinePluginInterface::RunResult runResult = CommandLinePluginInterface::Unknown;

			if( app->arguments().count() > 2 )
			{
				QString subCommand = app->arguments()[2];

				if( commandLinePluginInterface->subCommands().contains( subCommand ) &&
						QMetaObject::invokeMethod( commandLinePluginInterfaces[commandLinePluginInterface],
												   QString( "handle_%1" ).arg( subCommand ).toLatin1().constData(),
												   Qt::DirectConnection,
												   Q_RETURN_ARG(CommandLinePluginInterface::RunResult, runResult),
												   Q_ARG( QStringList, app->arguments().mid( 3 ) ) ) )
				{
					// runResult contains result
				}
				else
				{
					runResult = commandLinePluginInterface->runCommand( app->arguments().mid( 2 ) );
				}
			}
			else
			{
				runResult = CommandLinePluginInterface::NotEnoughArguments;
			}

			delete core;

			switch( runResult )
			{
			case CommandLinePluginInterface::Successful:
				qInfo( "[OK]" );
				return 0;
			case CommandLinePluginInterface::Failed:
				qInfo( "[FAIL]" );
				return -1;
			case CommandLinePluginInterface::InvalidCommand:
				if( app->arguments().contains( "help" ) == false )
				{
					qCritical( "Invalid subcommand!" );
				}
				qCritical( "Available subcommands:" );
				for( auto subCommand : commandLinePluginInterface->subCommands() )
				{
					qCritical( "    %s - %s", subCommand.toUtf8().constData(),
							   commandLinePluginInterface->subCommandHelp( subCommand ).toUtf8().constData() );
				}
				return -1;
			case CommandLinePluginInterface::InvalidArguments:
				qCritical( "Invalid arguments specified" );
				return -1;
			case CommandLinePluginInterface::NotEnoughArguments:
				qCritical( "Not enough arguments given - use \"%s help\" for more information",
						   command.toUtf8().constData() );
				return -1;
			case CommandLinePluginInterface::NoResult:
				return 0;
			default:
				qCritical( "Unknown result!" );
				return -1;
			}
		}
	}

	delete core;

	if( command == "help" )
	{
		qCritical( "Available commands:" );
	}
	else
	{
		qCritical( "command not found - available commands are:" );
	}

	for( auto commandLinePluginInterface : commandLinePluginInterfaces.keys() )
	{
		qCritical( "    %s - %s",
				   commandLinePluginInterface->commandName().toUtf8().constData(),
				   commandLinePluginInterface->commandHelp().toUtf8().constData() );
	}

	delete app;

	return -1;
}
int main ( int argc, char **argv )
{
  QCoreApplication app ( argc, argv );

  QHash<int, QImage> imagesToUse;
  QList<QImage> images;
  const QSize size16 ( 16,16 );
  const QSize size32 ( 32,32 );
  const QSize size48 ( 48,48 );
  if ( argc < 3 )
    usage ( "To few arguments" );

  QString rcFileName;
  QString icoFileName;
  int hotspotx = 0;
  int hotspoty = 0;
  int framerate = 3;
  for ( int i = 1; i < argc; i++ ) {
    const QString arg = app.arguments() [i];
    if ( arg == QLatin1String ( "--rcfile" ) ) {
      if ( i + 1 < argc ) {
        rcFileName = app.arguments() [i+1];
        i++;
        continue;
      } else {
        usage ( "option '--rcfile' without filename" );
      }
    } else if (arg == "--hotspotx") {
       if ( i + 1 < argc ) {
        hotspotx = app.arguments()[i+1].toInt();
        i++;
        continue;
       } else {
        usage ( "option '--hotspotx' without value" );
       }
    } else if (arg == "--hotspoty") {
       if ( i + 1 < argc ) {
        hotspoty = app.arguments()[i+1].toInt();
        i++;
        continue;
    } else {
        usage ( "option '--hotspoty' without value" );
       }
    } else if (arg == "--framerate") {
       if ( i + 1 < argc ) {
        framerate = app.arguments()[i+1].toInt();
        i++;
        continue;
    } else {
        usage ( "option '--framerate' without value" );
       }
    }

    if ( icoFileName.isEmpty() ) {
      icoFileName = arg;
      continue;
    }
    QImage img;
    img.load ( arg );
    if ( img.isNull() ) {
      warning ( QString ( "Can not load image %1" ).arg ( arg ) );
      continue;
    }

    if (icoFileName.endsWith(".ico", Qt::CaseInsensitive)) {
        images += img;
        if ( img.size() == size16 ) {
        if ( imagesToUse.contains ( 16 ) ) {
            warning ( QString ( "Already have an Image with 16x16 - overwriting with %1" ).arg ( arg ) );
        }
        imagesToUse.insert ( 16, img );
        continue;
        }
        if ( img.size() == size32 ) {
        if ( imagesToUse.contains ( 32 ) ) {
            warning ( QString ( "Already have an Image with 32x32 - overwriting with %1" ).arg ( arg ) );
        }
        imagesToUse.insert ( 32, img );
        continue;
        }
        if ( img.size() == size48 ) {
        if ( imagesToUse.contains ( 48 ) ) {
            warning ( QString ( "Already have an Image with 48x48- overwriting with %1" ).arg ( arg ) );
        }
        imagesToUse.insert ( 48, img );
        continue;
        }
    } else {
        if (img.size() != QSize(32, 32)) {
            img = scaleImage(img);
        }

        images += img;
    }
  }
  if ( images.count() == 0 )
    usage ( "No valid images found!" );
  if (icoFileName.endsWith(".ico", Qt::CaseInsensitive)) {
    qSort ( images.begin(), images.end(), sortQImageForSize );
    // 48x48 available -> if not create one
    if ( !imagesToUse.contains ( 48 ) ) {
        QImage img;
        Q_FOREACH ( const QImage &i, images ) {
        if ( img.width() >= 32 && img.height() >= 32 ) {
            img = i;
        }
        }
        if ( img.isNull() ) {
        // none found -> use the last (==biggest) available
        img = images.last();
        }
        imagesToUse.insert ( 48, img.scaled ( 48, 48, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) );
    }