Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7243 in orxonox.OLD


Ignore:
Timestamp:
Mar 24, 2006, 4:28:02 PM (18 years ago)
Author:
rennerc
Message:
 
Location:
branches/preferences/src
Files:
7 edited

Legend:

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

    r7241 r7243  
    5757 
    5858  for ( int i = 1; i<argc; i++ )
    59     args.push_back( argv[i] );
     59  {
     60    std::string s = argv[i];
     61   
     62    if ( s.find( "=" ) == std::string::npos )
     63    {
     64      args.push_back(s);
     65    }
     66    else
     67    {
     68      std::string op = s;
     69      std::string ar = s;
     70      op.erase( op.find("=") );
     71      ar.erase( 0, ar.find("=")+1);
     72     
     73      PRINTF(0)("'%s' '%s'\n", op.c_str(), ar.c_str());
     74      args.push_back( op );
     75      args.push_back( ar );
     76    }
     77  }
    6078 
    6179  int i = 0;
     
    7694        if ( it->numArgs + i >= args.size() )
    7795        {
    78           PRINTF(1)( "%s needs %d arguments!", args[i].c_str(), it->numArgs );
     96          PRINTF(1)( "%s needs %d arguments!\n", args[i].c_str(), it->numArgs );
     97          return false;
    7998        }
    8099       
    81         std::vector<std::string> argArgs;
     100        std::vector<MultiType> argArgs;
    82101       
    83         for ( int j = 0; j < it->numArgs; j++ )
     102        for ( int j = 1; j <= it->numArgs; j++ )
    84103          argArgs.push_back( args[i+j] );
    85104       
     
    87106          return false;
    88107       
    89         i += it->numArgs;
     108        i += it->numArgs + 1;
    90109       
    91110        if ( finish )
     
    121140      arg.erase( 0, 2 );
    122141     
    123       if ( arg.find('%') != std::string::npos )
     142      if ( entry.longOption.find('%') != std::string::npos )
    124143      {
    125144        //TODO implement bether match algo
    126         assert( arg.find('%') == arg.length()-1 );
    127         arg.erase( arg.length()-1, 1 );
    128         return entry.longOption.find( arg ) == 0;
     145        assert( entry.longOption.find('%') == entry.longOption.length()-1 );
     146        std::string lo = entry.longOption;
     147        lo.erase( lo.length()-1, 1 );
     148        PRINTF(0)("%s %s\n", arg.c_str(), lo.c_str());
     149        return arg.find( lo ) == 0;
    129150      }
    130151      else
    131152      {
    132         return entry.longOption == arg;
     153        return arg.find( entry.longOption ) != std::string::npos;
    133154      }
    134155    }
     
    140161        return false;
    141162      }
    142       finish = false;
     163      finish = arg.length()==2;
    143164      return arg.find(entry.shortOption) != std::string::npos;
    144165    }
  • branches/preferences/src/lib/parser/cmdline_parser/cmdline_parser.h

    r7241 r7243  
    1212
    1313#include "src/defs/debug.h"
     14#include "src/lib/util/multi_type.h"
    1415
    1516
     
    2425typedef std::list<ArgTableEntry> ArgTable;
    2526
    26 typedef bool (ArgParserCallback)( ArgTableEntry, void*, const std::string &, const std::vector<std::string> & );
     27typedef bool (*ArgParserCallback)( ArgTableEntry, void*, const std::string &, const std::vector<MultiType> & );
    2728
    2829
  • branches/preferences/src/lib/parser/preferences/cmd_line_prefs_reader.cc

    r7241 r7243  
    1818#include "cmd_line_prefs_reader.h"
    1919
     20#include "preferences.h"
     21
    2022using namespace std;
    2123
     
    3638}
    3739
    38 bool CmdLinePrefsReader::callBack( ArgTableEntry entry, void * data, const std::string & arg, const std::vector< std::string > & argArgs )
     40bool CmdLinePrefsReader::callBack( ArgTableEntry entry, void * data, const std::string & arg, const std::vector<MultiType> & argArgs )
    3941{
     42  switch ( entry.id )
     43  {
     44    case ID_SET_INI:
     45    {
     46      std::string section = arg;
     47      section.erase( 0, entry.longOption.length()+1 );
     48      std::string key = section;
     49      section.erase( section.find(".") );
     50      key.erase( 0, key.find(".")+1 );
     51      //PRINTF(0)("SECTION '%s', KEY '%s'\n", section.c_str(), key.c_str());
     52     
     53      if ( key == "" || section == "" || argArgs.size() != 1 )
     54      {
     55        PRINTF(1)("usage: --set-section.key=value\n");
     56        return false;
     57      }
     58     
     59      Preferences::getInstance()->setMultiType( section, key, argArgs[0], true );
     60      break;
     61    }
     62    default:
     63      assert(false);
     64  }
     65 
     66  return true;
    4067}
    4168
     
    4370{
    4471  CmdLineParser parser;
     72 
     73  parser.add( ID_SET_INI, "set-%", '\0', 1 );
     74 
     75  parser.parse( &callBack, NULL, argc, argv );
    4576}
    4677
  • branches/preferences/src/lib/parser/preferences/cmd_line_prefs_reader.h

    r7241 r7243  
    1212#include "src/lib/parser/cmdline_parser/cmdline_parser.h"
    1313
     14enum
     15{
     16  ID_SET_INI = 1
     17};
     18
    1419//! A class for reading commandline arguments into Preferences
    1520class CmdLinePrefsReader
     
    2328   
    2429  private:
    25     static bool callBack( ArgTableEntry entry, void* data, const std::string & arg, const std::vector<std::string> & argArgs );
     30    static bool callBack( ArgTableEntry entry, void* data, const std::string & arg, const std::vector<MultiType> & argArgs );
    2631
    2732};
  • branches/preferences/src/lib/util/preferences.cc

    r7234 r7243  
    157157 * @param value value
    158158 */
    159 void Preferences::setMultiType(const char* section, const char* name, MultiType& value, bool dontSetModified)
     159void Preferences::setMultiType(const char* section, const char* name, const MultiType& value, bool dontSetModified)
    160160{
    161161  std::list<prefSection>::iterator it = data.begin();
  • branches/preferences/src/lib/util/preferences.h

    r7236 r7243  
    4141   void setInt(const std::string& section, const std::string& name, int value, bool dontSetModified = false);
    4242   void setFloat(const std::string& section, const std::string& name, float value, bool dontSetModified = false);
    43    void setMultiType(const std::string& section, const std::string& name, MultiType& value, bool dontSetModified = false);
     43   void setMultiType(const std::string& section, const std::string& name, const MultiType& value, bool dontSetModified = false);
    4444
    4545   const std::string getString(const std::string& section, const std::string& name, const std::string& defaultValue);
  • branches/preferences/src/orxonox.cc

    r7241 r7243  
    406406  prefs.parse(argc, argv);
    407407
     408 // assert(false);
     409 
    408410  int i;
    409411  for(i = 1; i < argc; ++i)
Note: See TracChangeset for help on using the changeset viewer.