Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 4, 2011, 2:47:44 AM (13 years ago)
Author:
rgrieder
Message:

Merged unity_build branch back to trunk.

Features:

  • Implemented fully automatic build units to speed up compilation if requested
  • Added DOUT macro for quick debug output
  • Activated text colouring in the POSIX IOConsole
  • DeclareToluaInterface is not necessary anymore

Improvements:

  • Output levels now change appropriately when switch back and forth from dev mode
  • Log level for the file output is now also correct during startup
  • Removed some header file dependencies in core and tools to speed up compilation

no more file for command line options

  • Improved util::tribool by adapting some concepts from boost::tribool

Regressions:

  • It is not possible anymore to specify command line arguments in an extra file because we've got config values for that purpose.
Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/CommandLineParser.cc

    r7401 r8729  
    4141namespace orxonox
    4242{
    43     SetCommandLineOnlyArgument(optionsFile, "start.ini").shortcut("o");
    44 
    4543    /**
    4644    @brief
     
    5048        so that you can have simple command line switches.
    5149    */
    52     void CommandLineArgument::parse(const std::string& value, bool bParsingFile)
    53     {
    54         if (bParsingFile && this->bCommandLineOnly_)
    55             ThrowException(Argument, "Command line argument '" + getName() + "' is not allowed in files.");
     50    void CommandLineArgument::parse(const std::string& value)
     51    {
    5652        if (value_.getType() == MT_Type::Bool)
    5753        {
     
    116112    }
    117113
    118     /**
    119     @brief
    120         Reads the command line parses the values of each argument.
    121         It is then stored in the corresponding CommandLineArgument.
     114    /** Parses the command line string for arguments and stores these.
    122115    @note
    123116        The reason that you have to provide the string to be parsed as
    124         space separted list is because of argc and argv. If you only have
     117        space separated list is because of argc and argv. If you only have
    125118        a whole string, simply use getAllStrings() of SubString.
    126     @param arguments
    127         Vector of space separated strings.
    128     @param bParsingFile
    129         Parsing a file or the command line itself
    130     */
    131     void CommandLineParser::_parse(const std::vector<std::string>& arguments, bool bParsingFile)
    132     {
     119    @param cmdLine
     120        Command line string WITHOUT the execution path.
     121    */
     122    void CommandLineParser::_parse(const std::string& cmdLine)
     123    {
     124        std::vector<std::string> arguments;
     125        SubString tokens(cmdLine, " ", " ", false, '\\', true, '"', true, '\0', '\0', false);
     126        for (unsigned i = 0; i < tokens.size(); ++i)
     127            arguments.push_back(tokens[i]);
     128
    133129        try
    134130        {
     
    177173                            if (!name.empty())
    178174                            {
    179                                 checkFullArgument(name, value, bParsingFile);
     175                                checkFullArgument(name, value);
    180176                                name.clear();
    181177                                assert(shortcut.empty());
     
    183179                            else if (!shortcut.empty())
    184180                            {
    185                                 checkShortcut(shortcut, value, bParsingFile);
     181                                checkShortcut(shortcut, value);
    186182                                shortcut.clear();
    187183                                assert(name.empty());
     
    222218            if (!name.empty())
    223219            {
    224                 checkFullArgument(name, value, bParsingFile);
     220                checkFullArgument(name, value);
    225221                assert(shortcut.empty());
    226222            }
    227223            else if (!shortcut.empty())
    228224            {
    229                 checkShortcut(shortcut, value, bParsingFile);
     225                checkShortcut(shortcut, value);
    230226                assert(name.empty());
    231227            }
     
    233229        catch (const ArgumentException& ex)
    234230        {
    235             COUT(0) << "Could not parse command line (including additional files): " << ex.what() << std::endl;
     231            COUT(0) << "Could not parse command line: " << ex.what() << std::endl;
    236232            COUT(0) << CommandLineParser::getUsageInformation() << std::endl;
    237233            throw GeneralException("");
     
    249245        Parsing a file or the command line itself
    250246    */
    251     void CommandLineParser::checkFullArgument(const std::string& name, const std::string& value, bool bParsingFile)
     247    void CommandLineParser::checkFullArgument(const std::string& name, const std::string& value)
    252248    {
    253249        std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgs_.find(name);
     
    255251            ThrowException(Argument, "Command line argument '" + name + "' does not exist.");
    256252
    257         it->second->parse(value, bParsingFile);
     253        it->second->parse(value);
    258254    }
    259255
     
    268264        Parsing a file or the command line itself
    269265    */
    270     void CommandLineParser::checkShortcut(const std::string& shortcut, const std::string& value, bool bParsingFile)
     266    void CommandLineParser::checkShortcut(const std::string& shortcut, const std::string& value)
    271267    {
    272268        std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgsShortcut_.find(shortcut);
     
    274270            ThrowException(Argument, "Command line shortcut '" + shortcut + "' does not exist.");
    275271
    276         it->second->parse(value, bParsingFile);
     272        it->second->parse(value);
    277273    }
    278274
     
    342338        }
    343339    }
    344 
    345     /**
    346     @brief
    347         Parses only the command line for CommandLineArguments.
    348     */
    349     void CommandLineParser::_parseCommandLine(const std::string& cmdLine)
    350     {
    351         std::vector<std::string> args;
    352         SubString tokens(cmdLine, " ", " ", false, '\\', true, '"', true, '\0', '\0', false);
    353         for (unsigned i = 0; i < tokens.size(); ++i)
    354             args.push_back(tokens[i]);
    355         this->_parse(args, false);
    356     }
    357 
    358     /**
    359     @brief
    360         Parses start.ini (or the file specified with --optionsFile) for CommandLineArguments.
    361     */
    362     void CommandLineParser::_parseFile()
    363     {
    364         const std::string& filename = CommandLineParser::getValue("optionsFile").getString();
    365 
    366         // look for additional arguments in given file or start.ini as default
    367         // They will not overwrite the arguments given directly
    368         std::ifstream file;
    369         file.open((PathConfig::getConfigPathString() + filename).c_str());
    370         std::vector<std::string> args;
    371         if (file)
    372         {
    373             while (!file.eof())
    374             {
    375                 std::string line;
    376                 std::getline(file, line);
    377                 line = removeTrailingWhitespaces(line);
    378                 //if (!(line[0] == '#' || line[0] == '%'))
    379                 //{
    380                 SubString tokens(line, " ", " ", false, '\\', true, '"', true, '\0', '\0', false, '#');
    381                 for (unsigned i = 0; i < tokens.size(); ++i)
    382                     if (tokens[i][0] != '#')
    383                         args.push_back(tokens[i]);
    384                 //args.insert(args.end(), tokens.getAllStrings().begin(), tokens.getAllStrings().end());
    385                 //}
    386             }
    387             file.close();
    388         }
    389 
    390         _parse(args, true);
    391     }
    392340}
Note: See TracChangeset for help on using the changeset viewer.