Changeset 5945 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Dec 6, 2005, 11:39:05 PM (19 years ago)
- Location:
- trunk/src/lib
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/gui/gtk_gui/gui_keys.cc
r5766 r5945 119 119 pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_LEFT, "LEFT")); 120 120 pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_RIGHT, "RIGHT")); 121 pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_FIRE, " MOUSE_LEFT"));121 pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_FIRE, "BUTTON_LEFT")); 122 122 pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_NEXT_WEAPON, "m")); 123 123 pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_PREV_WEAPON, "n")); -
trunk/src/lib/parser/ini_parser/ini_parser.cc
r5944 r5945 43 43 { 44 44 this->fileName = NULL; 45 45 this->comment = NULL; 46 46 47 47 if (fileName != NULL) … … 117 117 { 118 118 FILE* stream; //< The stream we use to read the file. 119 int lineCount = 0; //< The Count of lines. 120 119 121 120 122 if (this->fileName != NULL) … … 142 144 while( fgets (lineBuffer, PARSELINELENGHT, stream)) 143 145 { 146 // if (lineCount == 0) 147 144 148 lineBegin = lineBuffer; 145 149 // remove newline char, and \0-terminate … … 183 187 184 188 this->addVar(lineBegin, valueBegin); 189 190 lineCount++; 185 191 } 186 192 } … … 203 209 { 204 210 FILE* stream; //!< The stream we use to read the file. 205 if( fileName == NULL )211 if( fileName == NULL && (fileName = this->fileName) == NULL ) 206 212 return false; 207 213 … … 224 230 } 225 231 fclose(stream); 232 } 233 234 void IniParser::setFileComment(const char* fileComment) 235 { 236 226 237 } 227 238 … … 267 278 268 279 280 void IniParser::setSectionComment(const char* comment, const char* sectionName) 281 { 282 283 } 284 285 286 const char* IniParser::getSectionComment(const char* sectionName) const 287 { 288 289 } 290 291 269 292 /** 270 293 * @brief moves to the first section … … 296 319 else 297 320 return NULL; 298 }299 300 301 /**302 * @brief moves to the first Variable of the current Section303 */304 void IniParser::firstVar()305 {306 if (!this->sections.empty() &&307 this->currentSection != this->sections.end())308 this->currentEntry = (*this->currentSection).entries.begin();309 }310 311 312 /**313 * @brief gets the next VarName = VarValue pair from the parsing stream314 * @return true on success, false otherwise (in the latter case name and value will be NULL)315 */316 bool IniParser::nextVar()317 {318 if ( this->sections.empty()319 || this->currentSection == this->sections.end()320 || this->currentEntry == (*this->currentSection).entries.end())321 return false;322 323 this->currentEntry++;324 325 if (this->currentEntry == (*this->currentSection).entries.end())326 return false;327 else328 return true;329 321 } 330 322 … … 351 343 else 352 344 section = this->currentSection; 345 353 346 if (section == this->sections.end()) 354 347 return false; … … 367 360 strcpy((*section).entries.back().value, value); 368 361 PRINTF(5)("Added Entry %s with Value '%s' to Section %s\n", 369 370 371 362 (*section).entries.back().name, 363 (*section).entries.back().value, 364 (*section).name); 372 365 return true; 373 366 } … … 387 380 const char* IniParser::getVar(const char* entryName, const char* sectionName, const char* defaultValue) const 388 381 { 389 if (fileName != NULL) 390 { 391 std::list<IniSection>::const_iterator section; 392 if (sectionName != NULL) 393 { 394 for (section = this->sections.begin(); section != this->sections.end(); section++) 395 { 396 if (!strcmp((*section).name, sectionName)) 397 { 398 break; 399 } 400 } 401 } 402 else 403 section = this->currentSection; 404 405 if (section == this->sections.end()) 406 { 407 PRINTF(2)("Section %s that should be containing %s not found.\n", sectionName, entryName); 408 return (defaultValue); 409 } 382 if (this->fileName != NULL) 383 { 384 std::list<IniSection>::const_iterator section = this->getSectionIT(sectionName); 385 386 if (section == this->sections.end()) 387 { 388 PRINTF(2)("Section %s that should be containing %s not found.\n", sectionName, entryName); 389 return (defaultValue); 390 } 410 391 411 392 std::list<IniEntry>::const_iterator entry; 412 393 for (entry = (*section).entries.begin(); entry != (*section).entries.end(); entry++) 413 394 if (!strcmp((*entry).name, entryName)) 414 395 return (*entry).value; 415 396 PRINTF(2)("Entry '%s' in section '%s' not found.\n", entryName, sectionName); 416 397 … … 422 403 423 404 } 405 406 407 const char* IniParser::setEntryComment(const char* comment, const char* entryName, const char* sectionName) 408 { 409 410 411 } 412 413 414 const char* IniParser::getEntryComment(const char* entryName, const char* sectionName) const 415 { 416 417 418 } 419 420 421 /** 422 * @brief moves to the first Variable of the current Section 423 */ 424 void IniParser::firstVar() 425 { 426 if (!this->sections.empty() && 427 this->currentSection != this->sections.end()) 428 this->currentEntry = (*this->currentSection).entries.begin(); 429 } 430 431 432 /** 433 * @brief gets the next VarName = VarValue pair from the parsing stream 434 * @return true on success, false otherwise (in the latter case name and value will be NULL) 435 */ 436 bool IniParser::nextVar() 437 { 438 if ( this->sections.empty() 439 || this->currentSection == this->sections.end() 440 || this->currentEntry == (*this->currentSection).entries.end()) 441 return false; 442 443 this->currentEntry++; 444 445 if (this->currentEntry == (*this->currentSection).entries.end()) 446 return false; 447 else 448 return true; 449 } 450 424 451 425 452 … … 464 491 465 492 493 std::list<IniParser::IniSection>::const_iterator IniParser::getSectionIT(const char* sectionName) const 494 { 495 std::list<IniSection>::const_iterator section; 496 if (sectionName != NULL) 497 { 498 for (section = this->sections.begin(); section != this->sections.end(); section++) 499 { 500 if (!strcmp((*section).name, sectionName)) 501 { 502 break; 503 } 504 } 505 } 506 else 507 section = this->currentSection; 508 509 return section; 510 } 511 512 513 std::list<IniParser::IniEntry>::const_iterator IniParser::getEntryIT(const char* entryName, const char* sectionName) const 514 { 515 if (entryName == NULL) 516 return this->currentEntry; 517 518 } 519 520 521 466 522 /** 467 523 * @brief output the whole tree in a nice and easy way. -
trunk/src/lib/parser/ini_parser/ini_parser.h
r5944 r5945 27 27 struct IniEntry 28 28 { 29 char* name; //!< name of a given Entry 30 char* value; //!< value of a given Entry 29 char* comment; //!< A Comment that is appendet to the Top of this Entry. 30 char* name; //!< name of a given Entry 31 char* value; //!< value of a given Entry 31 32 }; 33 32 34 //! a struct for Sections in the Parser's file 33 35 struct IniSection 34 36 { 35 char* name; //!< name of a given section 36 std::list<IniEntry> entries; //!< a list of entries for this section 37 char* comment; //!< A Comment that is appendet to the Top of this Section. 38 char* name; //!< name of a given section 39 std::list<IniEntry> entries; //!< a list of entries for this section 37 40 }; 38 41 //////////////////////////////////// … … 42 45 ~IniParser (); 43 46 47 /** @returns true if the file is opened, false otherwise*/ 48 bool isOpen() const { return (this->fileName != NULL)? true : false; }; 49 /** @returns the fileName we have opened. */ 50 const char* getFileName() const { return this->fileName; }; 51 44 52 bool readFile(const char* fileName); 45 53 bool writeFile(const char* fileName) const; 46 54 55 void setFileComment(const char* fileComment); 56 const char* getFileComment() const { return this->comment; }; 57 47 58 bool addSection(const char* sectionName); 48 59 bool getSection(const char* sectionName); 60 void setSectionComment(const char* comment, const char* sectionName); 61 const char* getSectionComment(const char* sectionNane) const; 49 62 50 /** @returns true if the file is opened, false otherwise*/ 51 bool isOpen() const { return (this->fileName != NULL)? true : false; }; 52 63 // iterate through sections with these Functions 53 64 void firstSection(); 54 65 const char* nextSection(); 55 66 56 /** @returns the fileName we have opened. */57 const char* getFileName() const { return this->fileName; };58 67 59 68 bool addVar(const char* entryName, const char* value, const char* sectionName = NULL); 60 69 const char* getVar(const char* entryName, const char* sectionName, const char* defaultValue = "") const; 70 const char* setEntryComment(const char* comment, const char* entryName, const char* sectionName); 71 const char* getEntryComment(const char* entryName, const char* sectionName) const; 61 72 73 // iterate Through Variables with these Functions. 62 74 void firstVar(); 63 75 bool nextVar(); 64 76 77 78 // retrieving functions when iterating. 65 79 const char* getCurrentSection() const; 66 80 const char* getCurrentName() const; 67 81 const char* getCurrentValue() const; 68 82 83 84 // maintenance. 69 85 void debug() const; 70 86 … … 74 90 void setFileName(const char* fileName); 75 91 92 std::list<IniSection>::const_iterator getSectionIT(const char* sectionName) const; 93 std::list<IniEntry>::const_iterator getEntryIT(const char* entryName, const char* sectionName = NULL) const; 94 76 95 private: 77 96 char* fileName; //!< The name of the File that was parsed. 97 char* comment; //!< A Comment for the header of this File. 78 98 std::list<IniSection> sections; //!< a list of all stored Sections of the Parser 79 99 std::list<IniSection>::iterator currentSection; //!< the current selected Section 80 100 std::list<IniEntry>::iterator currentEntry; //!< the current selected entry (in currentSection) 101 102 std::list<char*> commentList; //!< A list of Comments. (this is for temporary saving of Comments, that are inserted in front of Sections/Entries.) 81 103 }; 82 104
Note: See TracChangeset
for help on using the changeset viewer.