Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7251 in orxonox.OLD


Ignore:
Timestamp:
Mar 27, 2006, 8:01:11 PM (18 years ago)
Author:
rennerc
Message:

you can register commandline args now

Location:
branches/preferences/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/preferences/src/lib/parser/preferences/cmd_line_prefs_reader.cc

    r7250 r7251  
    2121
    2222using namespace std;
     23
     24RegistredArgs CmdLinePrefsReader::regArgs;
    2325
    2426/**
     
    6466      cbd->iniEntries.back().key = key;
    6567      cbd->iniEntries.back().value = argArgs[0].getString();
    66       break;
     68      return true;
    6769    }
    6870    case ID_HELP:
    6971      cbd->parser->showHelp();
    70       break;
    71     default:
    72       assert(false);
     72      return true;
     73  }
     74 
     75  if ( entry.id >= ID_LAST && entry.id - ID_LAST < regArgs.size() )
     76  {
     77    if ( regArgs[entry.id - ID_LAST].value == "%arg%" )
     78    {
     79      assert( argArgs.size() == 1 );
     80     
     81      cbd->iniEntries.push_back( IniEntry() );
     82      cbd->iniEntries.back().section = regArgs[entry.id - ID_LAST].section;
     83      cbd->iniEntries.back().key = regArgs[entry.id - ID_LAST].key;
     84      cbd->iniEntries.back().value = argArgs[0].getString();
     85    }
     86    else
     87    {
     88      cbd->iniEntries.push_back( IniEntry() );
     89      cbd->iniEntries.back().section = regArgs[entry.id - ID_LAST].section;
     90      cbd->iniEntries.back().key = regArgs[entry.id - ID_LAST].key;
     91      cbd->iniEntries.back().value = regArgs[entry.id - ID_LAST].value;
     92    }
     93  }
     94  else
     95  {
     96    assert(false);
    7397  }
    7498 
     
    81105  CmdLineParser parser;
    82106 
    83   parser.add( ID_HELP, "help", 'h', 0, "", "Show this help");
    84   parser.add( 99, "port", 'p', 0, "", "dont know");
     107  parser.add( ID_HELP, "help", 'h', 0, "", "Shows this help");
     108 
     109  for ( int i = 0; i<regArgs.size(); i++ )
     110  {
     111    if ( regArgs[i].value == "%arg%" )
     112    {
     113      parser.add( ID_LAST + i, regArgs[i].longOption, regArgs[i].shortOption, 1, regArgs[i].argName, regArgs[i].help );
     114    }
     115    else
     116    {
     117      parser.add( ID_LAST + i, regArgs[i].longOption, regArgs[i].shortOption, 0, "", regArgs[i].help );
     118    }
     119  }
    85120 
    86121  parser.add( ID_SET_INI, "set-%", '\0', 1, "value", "Override a configuration element." );
     
    90125  cbd.parser = &parser;
    91126 
    92   parser.parse( &callBack, &cbd, argc, argv );
     127  if ( parser.parse( &callBack, &cbd, argc, argv ) )
     128  {
     129    std::list<IniEntry>::const_iterator it;
     130    for ( it = cbd.iniEntries.begin(); it != cbd.iniEntries.end(); it++ )
     131    {
     132      Preferences::getInstance()->setString( it->section, it->key, it->value, true);
     133    }
     134  }
     135  else
     136  {
     137    exit(EXIT_FAILURE);
     138  }
     139 
     140  return true;
     141}
     142
     143bool CmdLinePrefsReader::registerArgument( const char shortOption, const std::string & longOption, const std::string & section, const std::string & key, const std::string & help, const std::string & argName, const std::string & value )
     144{
     145  RegistredArgument arg;
     146 
     147  arg.longOption = longOption;
     148  arg.shortOption = shortOption;
     149  arg.value = value;
     150  arg.help = help;
     151  arg.argName = argName;
     152  arg.section = section;
     153  arg.key = key;
     154 
     155  regArgs.push_back( arg );
    93156}
    94157
  • branches/preferences/src/lib/parser/preferences/cmd_line_prefs_reader.h

    r7250 r7251  
    2525};
    2626
     27struct RegistredArgument
     28{
     29  char shortOption;
     30  std::string longOption;
     31  std::string value;
     32  std::string help;
     33  std::string argName;
     34  std::string section;
     35  std::string key;
     36};
     37
     38typedef std::vector<RegistredArgument> RegistredArgs;
     39
    2740enum
    2841{
    2942  ID_SET_INI = 1,
    30   ID_HELP
     43  ID_HELP,
     44  ID_LAST
    3145};
     46
     47#define REGISTER_ARG_FLAG(shortOption,longOption,section,key,description,value) bool _ARGVAR_##shortOption##_##longOption = CmdLinePrefsReader::registerArgument(#shortOption[0],#longOption,section,key,description,"",value)
     48
     49#define REGISTER_ARG_ARG(shortOption,longOption,section,key,description,argname) bool _ARGVAR_##shortOption##_##longOption = CmdLinePrefsReader::registerArgument(#shortOption[0],#longOption,section,key,description,argname)
    3250
    3351//! A class for reading commandline arguments into Preferences
     
    4159    bool parse(int argc, char** argv);
    4260   
     61    static bool registerArgument( const char shortOption, const std::string & longOption, const std::string & section, const std::string & key, const std::string & help,  const std::string & argName = "", const std::string & value = "%arg%" );
     62   
     63    static bool asdf;
     64   
    4365  private:
    4466    static bool callBack( ArgTableEntry entry, void* data, const std::string & arg, const std::vector<MultiType> & argArgs );
     67   
     68    static RegistredArgs regArgs;
    4569
    4670};
  • branches/preferences/src/orxonox.cc

    r7248 r7251  
    6767
    6868SHELL_COMMAND(restart, Orxonox, restart);
     69
     70REGISTER_ARG_FLAG( s, server, "game", "isServer", "Start Orxonox as Game Server", "1" );
     71REGISTER_ARG_ARG( p, port, "game", "port", "Port to use", "port" );
    6972
    7073/**
     
    405408  prefs.parse(argc, argv);
    406409 
    407   //Preferences::getInstance()->debug();
    408  
    409410  int i;
    410411  for(i = 1; i < argc; ++i)
Note: See TracChangeset for help on using the changeset viewer.