Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 31, 2008, 8:39:13 PM (17 years ago)
Author:
rgrieder
Message:

Added support to specify the command line arguments in start.ini (uses the same formatting). '#' is the comment character.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gui/src/core/RootGameState.cc

    r1689 r1690  
    2929#include "RootGameState.h"
    3030
     31#include "util/String.h"
     32#include "util/SubString.h"
    3133#include "Clock.h"
    3234#include "Debug.h"
     
    129131    void RootGameState::start(int argc, char** argv)
    130132    {
    131         parseCommandLine(argc, argv);
     133        parseArguments(argc, argv);
    132134
    133135        this->activate();
     
    152154    }
    153155
    154     void RootGameState::parseCommandLine(int argc, char** argv)
    155     {
     156    /**
     157    @brief
     158        Parses both command line and start.ini for CommandLineArguments.
     159    */
     160    void RootGameState::parseArguments(int argc, char** argv)
     161    {
     162        // parse command line first
    156163        std::vector<std::string> args;
    157164        for (int i = 1; i < argc; ++i)
     
    167174            COUT(0) << "Usage:" << std::endl << "orxonox " << CommandLine::getUsageInformation() << std::endl;
    168175        }
     176
     177        // look for additional arguments in start.ini
     178        std::ifstream file;
     179        file.open("start.ini");
     180        args.clear();
     181        if (file)
     182        {
     183            while (!file.eof())
     184            {
     185                std::string line;
     186                std::getline(file, line);
     187                line = removeTrailingWhitespaces(line);
     188                //if (!(line[0] == '#' || line[0] == '%'))
     189                //{
     190                SubString tokens(line, " ", " ", false, 92, false, 34, false, 40, 41, false, '#');
     191                for (unsigned i = 0; i < tokens.size(); ++i)
     192                    if (tokens[i][0] != '#')
     193                        args.push_back(tokens[i]);
     194                //args.insert(args.end(), tokens.getAllStrings().begin(), tokens.getAllStrings().end());
     195                //}
     196            }
     197            file.close();
     198        }
     199
     200        try
     201        {
     202            orxonox::CommandLine::parse(args);
     203        }
     204        catch (orxonox::ArgumentException& ex)
     205        {
     206            COUT(1) << "An Exception occured while parsing start.ini" << std::endl;
     207            COUT(1) << ex.what() << std::endl;
     208            COUT(0) << "Usage:" << std::endl << "orxonox " << CommandLine::getUsageInformation() << std::endl;
     209        }
    169210    }
    170211}
Note: See TracChangeset for help on using the changeset viewer.