- Timestamp:
- Aug 14, 2005, 5:25:53 PM (19 years ago)
- Location:
- orxonox/trunk/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/event/key_mapper.cc
r5014 r5015 128 128 int* index; 129 129 130 while(iniParser->nextVar()) 130 iniParser->getFirstVar(); 131 while(iniParser->getCurrentName()) 131 132 { 132 133 PRINTF(3)("Keys: Parsing %s, %s now.\n", iniParser->getCurrentName(), iniParser->getCurrentValue()); 133 134 index = nameToIndex (iniParser->getCurrentValue()); 134 135 this->mapKeys(iniParser->getCurrentName(), index[1]); 136 iniParser->nextVar(); 135 137 } 136 138 … … 143 145 } 144 146 145 while( iniParser->nextVar()) 147 iniParser->getFirstVar(); 148 while(iniParser->getCurrentName()) 146 149 { 147 150 PRINTF(3)("MISC: Parsing %s, %s now.\n", iniParser->getCurrentName(), iniParser->getCurrentValue()); 148 151 index = nameToIndex (iniParser->getCurrentValue()); 149 152 this->mapKeys(iniParser->getCurrentName(), index[1]); 153 iniParser->nextVar(); 150 154 } 151 155 } -
orxonox/trunk/src/lib/gui/gui_exec.cc
r5014 r5015 265 265 void GuiExec::readFromFile(Widget* widget) 266 266 { 267 IniParser iniParser(this->confFile); 267 268 char* fileName = ResourceManager::homeDirCheck(confFile); 269 IniParser iniParser(fileName); 270 delete fileName; 268 271 if (!iniParser.isOpen()) 269 272 return; 270 273 271 // const char* name; 272 // while (name = iniParser.nextSection()) 273 // printf("%s\n", name); 274 iniParser.getFirstSection(); 275 Widget* groupWidget = widget; 276 const char* groupName; 277 const char* widgetName; 278 VarInfo varInfo; 279 while (groupName = iniParser.getCurrentSection()) 280 { 281 if((groupWidget = locateGroup(widget, groupName, 1))==NULL) 282 { 283 PRINTF(2)("!!There is no group called %s in this GUI.\n First best Widget will get the Infos assigned.\n Config-File will be updated in next Save\n", groupName); 284 groupWidget = widget; 285 continue; 286 } 287 else 288 PRINT(0)("Group %s located.\n", static_cast<Packer*>(groupWidget)->groupName); 289 290 iniParser.getFirstVar(); 291 while(iniParser.getCurrentName()) 292 { 293 varInfo.variableName = iniParser.getCurrentName(); 294 varInfo.variableValue = iniParser.getCurrentValue(); 295 groupWidget->walkThrough(this->readFileText, &varInfo, 0); 296 iniParser.nextVar(); 297 } 298 299 iniParser.nextSection(); 300 } 301 widget->walkThrough(widget->setOptions, 0); 302 274 303 // 275 304 // … … 342 371 @todo do this in gui-gtk. 343 372 */ 344 Widget* GuiExec::locateGroup(Widget* widget, c har* groupName, int depth)373 Widget* GuiExec::locateGroup(Widget* widget, const char* groupName, int depth) 345 374 { 346 375 Widget* tmp; 347 348 // removes the trailing and ending [ ].349 if(!strncmp(groupName, "[", 1))350 {351 groupName = groupName+1;352 groupName[strlen(groupName)-1] = '\0';353 }354 376 355 377 if(widget->optionType < GUI_NOTHING) -
orxonox/trunk/src/lib/gui/gui_exec.h
r4746 r5015 28 28 struct VarInfo 29 29 { 30 c har* variableName;//!< The Name of this variable;31 c har* variableValue;//!< The Value this variable gets.30 const char* variableName; //!< The Name of this variable; 31 const char* variableValue; //!< The Value this variable gets. 32 32 }; 33 33 … … 35 35 GuiExec(); 36 36 ~GuiExec(); 37 37 38 38 void setConfDir(const char* confDir); 39 39 void setConfFile(const char* confFile); … … 44 44 void readFromFile(Widget* widget); 45 45 static void readFileText(Widget* widget, void* varInfo); 46 Widget* locateGroup(Widget* widget, c har* groupName, int depth);46 Widget* locateGroup(Widget* widget, const char* groupName, int depth); 47 47 48 48 #ifdef HAVE_GTK2 … … 55 55 }; 56 56 57 //! A simple hashtable 57 //! A simple hashtable 58 58 struct HashTable 59 59 { -
orxonox/trunk/src/lib/gui/gui_gtk.cc
r4836 r5015 1 /* 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 … … 16 16 You should have received a copy of the GNU General Public License 17 17 along with this program; if not, write to the Free Software Foundation, 18 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 19 20 20 … … 82 82 PRINT(0)(" #############################\n"); 83 83 Window::mainWindow->walkThrough(Widget::listOptionsAndGroups, 1); 84 84 85 85 PRINT(0)("\nDo you want change any of the above values now? [Yn] "); 86 86 scanf("%s", ans); 87 87 if (ans[0] =='n' || ans[0]=='N') 88 89 88 break; 89 90 90 PRINT(0)("\n Listing all groups\n"); 91 91 PRINT(0)(" #################\n"); 92 92 int groupCount = 0; 93 93 Window::mainWindow->walkThrough(Widget::listGroups, &groupCount, 1); 94 94 95 95 PRINT(0)("\nIn which Group? [1-%d] ", groupCount); 96 96 Packer* group; 97 97 while(true) 98 99 100 101 102 103 104 105 106 107 108 98 { 99 scanf("%s", ans); 100 int ansIp = atoi(ans); 101 if (ansIp <= groupCount) 102 { 103 group = static_cast<Packer*>(Window::mainWindow->findGroupByNumber(&ansIp, 1)); 104 break; 105 } 106 else 107 PRINT(0)("\nChoose a smaller Number please: [1-%d] ", groupCount); 108 } 109 109 PRINT(0)("\n\nGroup: [%s]\n\n", group->groupName); 110 110 int optionCount = 0; … … 113 113 Option* option; 114 114 while(true) 115 116 117 118 119 120 121 122 123 124 125 115 { 116 scanf("%s", ans); 117 int ansIp = atoi(ans); 118 if (ansIp <= groupCount) 119 { 120 option = static_cast<Option*>(group->findOptionByNumber(&ansIp, 0)); 121 break; 122 } 123 else 124 PRINT(0)("\nChoose a smaler Number please: [1-%d] ", optionCount); 125 } 126 126 PRINT(0)("\n\n:: %s ::\n", option->title); 127 127 option->changeOption(); 128 128 129 129 // here follows the rest.... this will be nasty. 130 130 //! @todo finish it. … … 132 132 } 133 133 #endif /* HAVE_GTK2 */ 134 134 135 135 } 136 136 … … 162 162 delete []this->title; 163 163 } 164 164 165 165 PRINTF(5)("deleting the Widget part.\n"); 166 166 … … 232 232 Widget* tmp = static_cast<Packer*>(this)->down->findWidgetByName(name, depth+1); 233 233 if (tmp) 234 235 } 236 234 return tmp; 235 } 236 237 237 if (depth>0 && this->next) 238 238 return this->next->findWidgetByName(name, depth); … … 243 243 /** 244 244 * Moves through all the Widgets downwards from this and executes the function on them. 245 * @param function must be of type void and takes a Widget* as an Input. 245 * @param function must be of type void and takes a Widget* as an Input. 246 246 * @param depth the current depth. if > 0 then the next Widget will also be walked through. 247 247 */ … … 252 252 { 253 253 static_cast<Packer*>(this)->down->walkThrough(function, depth+1); 254 } 254 } 255 255 256 256 if (this->next && depth != 0) … … 275 275 } 276 276 277 /** 277 /** 278 278 * This is for listing the options of "widget" 279 279 * @param widget specifies the widget that should be listed … … 289 289 } 290 290 291 /** 291 /** 292 292 * This is for listing the options of "widget" 293 293 * @param widget specifies the widget that should be listed … … 299 299 } 300 300 301 /** 301 /** 302 302 * This is for listing the options of "widget" 303 303 * @param widget specifies the widget that should be listed … … 306 306 void Widget::listOptions(Widget* widget, void* data) 307 307 { 308 308 309 309 if (widget->optionType > GUI_NOTHING) 310 310 { … … 312 312 *count = *count +1; 313 313 PRINT(0)(" %d:%s is %s\n", *count, 314 315 316 } 317 } 318 319 /** 314 static_cast<Option*>(widget)->title, 315 static_cast<Option*>(widget)->save()); 316 } 317 } 318 319 /** 320 320 * This is for listing the options of "widget" 321 321 * @param widget specifies the widget that should be listed … … 330 330 Option* option = (Option*)widget; 331 331 if (option->flagName || option->flagNameShort) 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 } 357 } 358 359 /** 332 { 333 PRINT(0)(" "); 334 if (option->flagNameShort) 335 { 336 PRINT(0)("-%s", option->flagNameShort); 337 helpLen += strlen(option->flagNameShort)+1; 338 } 339 if (option->flagName) 340 { 341 if (helpLen > 0) 342 { 343 PRINT(0)("|"); 344 helpLen++; 345 } 346 PRINT(0)("--%s:", option->flagName); 347 helpLen += strlen(option->flagName)+2; 348 } 349 while ((helpLen ++) < 29) 350 PRINT(0)(" "); 351 if (option->shortDescription) 352 PRINT(0)("%s\n", option->shortDescription); 353 else 354 PRINT(0)("\n"); 355 } 356 } 357 } 358 359 /** 360 360 * Finds an Option by a given number(the n'th option found away from this Widget) 361 361 * @param number The Count of options to wait(by reference) 362 362 * @param depth The depth of the sarch. if 0 it will not search next pointer 363 363 364 364 @todo should return Option* would be much sexier. 365 365 */ … … 370 370 --*number; 371 371 if (*number <= 0) 372 373 374 372 { 373 return this; 374 } 375 375 } 376 376 if (this->optionType < GUI_NOTHING && static_cast<Packer*>(this)->down) … … 378 378 Widget* tmp = static_cast<Packer*>(this)->down->findOptionByNumber(number, depth+1); 379 379 if (tmp) 380 380 return tmp; 381 381 } 382 382 if (depth>0 && this->next) … … 386 386 } 387 387 388 /** 388 /** 389 389 * This is for listing the groups of "widget" 390 390 * @param widget specifies the widget that should be listed … … 396 396 } 397 397 398 /** 398 /** 399 399 * This is for listing the Groups of "widget". It also displays the n'th number found. 400 400 * @param widget specifies the widget that should be listed … … 408 408 } 409 409 410 /** 410 /** 411 411 * Finds a Group by a given number(the n'th Group found away from this Widget) 412 412 * @param number The Count of options to wait(by reference) … … 419 419 --*number; 420 420 if (*number <= 0) 421 422 423 421 { 422 return this; 423 } 424 424 } 425 425 if (this->optionType < GUI_NOTHING && static_cast<Packer*>(this)->down) … … 427 427 Widget* tmp = static_cast<Packer*>(this)->down->findGroupByNumber(number, depth+1); 428 428 if (tmp) 429 429 return tmp; 430 430 } 431 431 if (depth>0 && this->next) … … 462 462 { 463 463 if (widget->optionType > GUI_NOTHING) 464 { 464 { 465 465 Option* option =(Option*)widget; 466 466 char* name =(char*)flagName; … … 469 469 // check if long flag matches 470 470 if ((option->flagName && strlen(name) > 2 && 471 472 473 474 475 476 477 478 479 471 !strncmp(name+2, option->flagName, strlen(option->flagName)) && 472 (name[strlen(option->flagName)+2] == '\0' || name[strlen(option->flagName)+2] == '=') )) 473 { 474 found = true; 475 if (name[strlen(option->flagName)+2] == '=') 476 { 477 value = name+strlen(option->flagName)+3; 478 } 479 } 480 480 // check if short flag matches 481 481 else if (option->flagNameShort && strlen(name)>1 && 482 483 484 485 486 487 488 489 } 490 482 !strncmp(name+1, option->flagNameShort, strlen(option->flagNameShort)) && 483 (name[strlen(option->flagNameShort)+1] == '\0' || name[strlen(option->flagNameShort)+1] == '=')) 484 { 485 found = true; 486 if (name[strlen(option->flagNameShort)+1] == '=') 487 { 488 value = name+strlen(option->flagNameShort)+2; 489 } 490 } 491 491 492 492 if (found) 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 } 508 } 509 510 #ifdef HAVE_GTK2 511 /** 493 { 494 PRINT(4)("found matching Flag %s\n", name); 495 if (value) 496 { 497 PRINT(4)("with Value %s\n", value); 498 option->value = atoi(value); 499 } 500 else 501 { 502 option->value = !option->defaultValue; 503 } 504 option->redraw(); 505 } 506 507 } 508 } 509 510 #ifdef HAVE_GTK2 511 /** 512 512 * Connect any signal to any given Sub-widget 513 513 */ … … 581 581 */ 582 582 Packer::~Packer() 583 { 583 { 584 584 PRINTF(5)("deleting the Packer part.\n"); 585 585 if (this->groupName) 586 586 delete []this->groupName; 587 587 588 588 //deleting recursively. 589 589 if (this->down) … … 620 620 */ 621 621 Container::~Container() 622 { 622 { 623 623 PRINTF(5)("deleting the Container part.\n"); 624 624 } … … 663 663 * The main Window of Th Gui 664 664 */ 665 Window* Window::mainWindow = NULL; 665 Window* Window::mainWindow = NULL; 666 666 667 667 /** … … 683 683 #if !defined(__WIN32__) 684 684 // gtk_window_set_decorated(GTK_WINDOW(widget), FALSE); 685 #endif 685 #endif 686 686 gtk_container_set_border_width(GTK_CONTAINER(widget), 3); 687 687 #endif /* HAVE_GTK2 */ … … 715 715 Widget* tmpWindow = mainWindow; 716 716 while(tmpWindow->next) 717 717 tmpWindow = tmpWindow->next; 718 718 tmpWindow->next = windowToAdd; 719 719 windowToAdd->isOpen = false; … … 904 904 } 905 905 906 /** 906 /** 907 907 * Fills a box with a given Widget. 908 908 * @param lowerWidget the next Widget that should be appendet to this Box … … 922 922 tmp = this->down; 923 923 while(tmp->next != NULL) 924 924 tmp = tmp->next; 925 925 tmp->next = lowerWidget; 926 926 } … … 939 939 this->flagName = NULL; 940 940 this->flagNameShort = NULL; 941 941 942 942 this->shortDescription = NULL; 943 943 this->longDescription = NULL; … … 951 951 */ 952 952 Option::~Option() 953 { 953 { 954 954 PRINTF(5)("deleting the Option Part.\n"); 955 955 if (this->flagName) … … 995 995 } 996 996 997 /** 997 /** 998 998 * see Option::setFlagName(char* flagname, int defaultvalue) 999 999 * @param flagname the Name that will be displayed in the output … … 1062 1062 * @param loadString the string from which to load the data from 1063 1063 */ 1064 void Option::load(c har* loadString)1064 void Option::load(const char* loadString) 1065 1065 { 1066 1066 this->value = atoi(loadString); 1067 PRINT(5)("Loading %s: %s %d\n", this->title, loadString, value); 1067 PRINT(5)("Loading %s: %s %d\n", this->title, loadString, value); 1068 1068 this->redraw(); 1069 1069 } … … 1078 1078 1079 1079 #ifdef HAVE_GTK2 1080 /** 1080 /** 1081 1081 * Signal OptionChange writes the Value from the Option to its Object-Database. 1082 1082 * @param widget The widget(Option) that has a changed Value … … 1156 1156 ///////////////// 1157 1157 /** 1158 * Creates a new CheckButton with an ame 1158 * Creates a new CheckButton with an ame 1159 1159 * @param buttonName The name the CheckButton should display. 1160 1160 */ … … 1182 1182 if (this->title) 1183 1183 PRINTF(5)("deleting the CheckButton: %s\n", this->title); 1184 else 1184 else 1185 1185 PRINTF(5)("deleting the CheckButton.\n"); 1186 1186 } … … 1334 1334 return value; 1335 1335 } 1336 void Slider::load(c har* loadString)1336 void Slider::load(const char* loadString) 1337 1337 { 1338 1338 this->fValue = atof(loadString); 1339 PRINT(5)("Loading %s: %s %f\n", this->title, loadString, fValue); 1339 PRINT(5)("Loading %s: %s %f\n", this->title, loadString, fValue); 1340 1340 this->redraw(); 1341 1341 } … … 1355 1355 } 1356 1356 1357 /** 1357 /** 1358 1358 * Creates a Menu-Item-list out of multiple input. 1359 1359 !! Consider, that the last input argument has to be "lastItem" for this to work!! … … 1389 1389 //! @todo destroy menu 1390 1390 /* 1391 1392 1393 1391 #ifdef HAVE_GTK2 1392 gtk_widget_destroy(this->currItem->item); 1393 #endif /* HAVE_GTK2 */ 1394 1394 MenuItem* tmpItem = this->currItem; 1395 1395 this->currItem = this->currItem->next; … … 1432 1432 return tmpName; 1433 1433 } 1434 else 1434 else 1435 1435 return NULL; 1436 1436 } … … 1440 1440 * @param loadString the string from which to load the data from 1441 1441 */ 1442 void Menu::load(c har* loadString)1442 void Menu::load(const char* loadString) 1443 1443 { 1444 1444 MenuItem* tmpItem = firstItem; … … 1447 1447 { 1448 1448 if (!strcmp(loadString, tmpItem->name)) 1449 1449 {foundItem = true; break;} 1450 1450 tmpItem = tmpItem->next; 1451 1451 } … … 1457 1457 PRINTF(2)("%s has not been found in the Itemlist of %s\n", loadString, this->title); 1458 1458 } 1459 PRINTF(5)( "Loading %s: setting to %d\n", this->title, this->value); 1459 PRINTF(5)( "Loading %s: setting to %d\n", this->title, this->value); 1460 1460 this->redraw(); 1461 1461 } … … 1601 1601 * @param loadString the string from which to load the data from 1602 1602 */ 1603 void OptionLabel::load(c har* loadString)1604 { 1605 PRINTF(5)("Loading %s: setting to %s\n", this->title, loadString); 1603 void OptionLabel::load(const char* loadString) 1604 { 1605 PRINTF(5)("Loading %s: setting to %s\n", this->title, loadString); 1606 1606 this->setValue(loadString); 1607 1607 } … … 1617 1617 { 1618 1618 this->optionType = GUI_NOTHING; 1619 1619 1620 1620 #ifdef HAVE_GTK2 1621 1621 this->widget = gtk_label_new(""); 1622 1622 gtk_label_set_line_wrap(GTK_LABEL(this->widget), TRUE); 1623 1623 #endif /* HAVE_GTK2 */ 1624 1624 1625 1625 if (text) 1626 1626 this->setTitle(text); … … 1658 1658 } 1659 1659 1660 /** 1660 /** 1661 1661 * appends some Text to a Label 1662 1662 * @param textToAppend The text that will be appended to this Label … … 1667 1667 { 1668 1668 char* tmpTitle = new char[strlen(this->title)+strlen(textToAppend)+1]; 1669 strcpy(tmpTitle, title); 1669 strcpy(tmpTitle, title); 1670 1670 strcat(tmpTitle, textToAppend); 1671 1671 delete []this->title; … … 1674 1674 else 1675 1675 this->title = new char[strlen(textToAppend)]; 1676 1676 1677 1677 #ifdef HAVE_GTK2 1678 1678 gtk_label_set_text(GTK_LABEL(this->widget), title); … … 1680 1680 } 1681 1681 1682 /** 1682 /** 1683 1683 * Appends some integer to the Label 1684 1684 * @param intToAppend The Int that will be added. 1685 1685 1686 1686 it does this by just converting the int into a char* and send it to appendText 1687 1687 */ … … 1805 1805 } 1806 1806 1807 /** 1807 /** 1808 1808 * Initializes a new Image 1809 1809 * @param name the name to set to the Image … … 1919 1919 #ifdef HAVE_GTK2 1920 1920 if(this->okFunc((const char*)gtk_file_selection_get_filename(GTK_FILE_SELECTION(this->widget)), this->okObject)) 1921 1921 this->close(); 1922 1922 #endif /* HAVE_GTK2 */ 1923 1923 } -
orxonox/trunk/src/lib/gui/gui_gtk.h
r4836 r5015 6 6 #define _GUI_GTK_H 7 7 8 #if HAVE_CONFIG_H 9 #include <config.h> 8 #if HAVE_CONFIG_H 9 #include <config.h> 10 10 #endif 11 11 … … 34 34 // enumerator for different GuiOption-Types 35 35 enum GUI_OPTION {GUI_BOX = -2, 36 37 38 39 40 41 42 36 GUI_CONTAINER = -1, 37 GUI_NOTHING = 0, 38 GUI_BOOL = 1, 39 GUI_INT = 2, 40 GUI_FLOAT = 3, 41 GUI_CHAR = 4, 42 GUI_CHAR_ARRAY = 5}; 43 43 44 44 extern char* executable; … … 77 77 static void redrawOptions(Widget* widget); 78 78 static void flagCheck(Widget* widget, void* flagName); 79 79 80 80 #ifdef HAVE_GTK2 81 81 // Connection - Functions … … 140 140 int borderwidth; //!< The width of The Container Boarder. 141 141 int policy; //!< The Update Policy of a Container. 142 142 143 143 public: 144 144 Container(); … … 164 164 Window(const char* windowName = NULL); 165 165 virtual ~Window(); 166 166 167 167 virtual void setTitle(const char* title); 168 168 void showall(); … … 216 216 Box(char boxtype = 'h'); 217 217 virtual ~Box(); 218 218 219 219 virtual void fill(Widget* lowerWidget); 220 220 }; … … 228 228 protected: 229 229 bool saveable; //!< Options can be Saved. 230 230 231 231 public: 232 232 Option(); … … 243 243 void saveability(bool isSaveable = true); 244 244 virtual char* save(); 245 virtual void load(c har* loadString);245 virtual void load(const char* loadString); 246 246 247 247 bool isSaveable(); … … 254 254 virtual void changeOption() = 0; //!< What to do, if an Option is Changed. eacht option decides for itself. 255 255 #ifdef HAVE_GTK2 256 // Signals 256 // Signals 257 257 static gint OptionChange(GtkWidget* widget, Widget* option); //!< Signal for Options that change. 258 258 #endif /* HAVE_GTK2 */ … … 263 263 * Buttons are mainly there for executing some action like Starting the Programm, or Quiting it. 264 264 */ 265 class Button : public Option 265 class Button : public Option 266 266 { 267 267 public: … … 310 310 311 311 virtual char* save(); 312 virtual void load(c har* loadString);312 virtual void load(const char* loadString); 313 313 }; 314 314 … … 334 334 MenuItem* firstItem; //!< Pointer to the first Item. 335 335 MenuItem* currItem; //!< Pointer to the current Item. 336 336 337 337 public: 338 338 Menu(const char* menuName); … … 342 342 343 343 virtual char* save(); 344 virtual void load(c har* loadString);345 344 virtual void load(const char* loadString); 345 346 346 void addItem(char* itemName); 347 347 virtual void redraw(); … … 355 355 OptionLabel(const char* label, const char* value); 356 356 virtual ~OptionLabel(); 357 357 358 358 void setValue(const char* newValue); 359 359 360 360 virtual char* save(); 361 virtual void load(c har* loadString);361 virtual void load(const char* loadString); 362 362 363 363 virtual void redraw(); … … 373 373 EntryField(const char* name = NULL); 374 374 virtual ~EntryField(); 375 375 376 376 void setValue(const char* newValue); 377 377 virtual char* save(); 378 virtual void load(c har* loadString);379 378 virtual void load(const char* loadString); 379 380 380 virtual void redraw(); 381 381 virtual void changeOption(); … … 388 388 Label(const char* text = NULL); 389 389 virtual ~Label(); 390 390 391 391 virtual void setTitle(const char* text); 392 392 void ereaseText(); … … 415 415 }; 416 416 417 //! Image is the keeper of one Image 418 /** 417 //! Image is the keeper of one Image 418 /** 419 419 * Images are mighty cool. 420 420 * Images can help you lighten up the Programming process, and will give everyone a better impression of the Software. -
orxonox/trunk/src/lib/util/ini_parser.cc
r5014 r5015 23 23 #include "list.h" 24 24 #include "stdlibincl.h" 25 26 #include "resource_manager.h"27 25 #include "debug.h" 28 26 … … 53 51 } 54 52 53 /** 54 * removes all the sections. This is like delete, but even cooler :) 55 */ 55 56 void IniParser::deleteSections() 56 57 { … … 80 81 } 81 82 delete this->sections; 83 this->currentEntry = NULL; 84 this->currentSection = NULL; 82 85 this->sections = NULL; 83 86 } … … 88 91 * @return true on success false otherwise; 89 92 */ 90 bool IniParser::openFile(const char* file name)93 bool IniParser::openFile(const char* fileName) 91 94 { 92 95 FILE* stream; //!< The stream we use to read the file. 93 96 94 95 if( filename == NULL)96 return false;97 char* tmpName = ResourceManager::homeDirCheck(filename);98 97 99 98 if (sections != NULL) 100 99 deleteSections(); 101 102 if( (stream = fopen (tmpName, "r")) == NULL) 103 { 104 PRINTF(1)("IniParser could not open %s\n", filename); 105 delete tmpName; 100 if( fileName == NULL) 101 return false; 102 103 if( (stream = fopen (fileName, "r")) == NULL) 104 { 105 PRINTF(1)("IniParser could not open %s\n", fileName); 106 106 return false; 107 107 } … … 189 189 { 190 190 this->currentSection = sectionEnum; 191 this->currentEntry = NULL; 191 192 delete sectionIt; 192 193 return true; … … 200 201 201 202 /** 203 * moves to the first section 204 */ 205 void IniParser::getFirstSection() 206 { 207 if (this->sections) 208 this->currentSection = this->sections->firstElement(); 209 else 210 this->currentSection = NULL; 211 this->currentEntry = NULL; 212 } 213 214 /** 202 215 * searches the next section 203 216 * @returns the name of the section if found, NULL otherwise … … 210 223 { 211 224 if (this->sections) 212 this->currentSection = sections->nextElement(this->currentSection); 213 } 225 { 226 if (this->currentSection == this->sections->lastElement()) 227 this->currentSection = NULL; 228 else 229 this->currentSection = this->sections->nextElement(this->currentSection); 230 } 231 } 232 214 233 if (this->currentSection != NULL) 215 234 return this->currentSection->name; … … 219 238 220 239 /** 240 * moves to the first Variable of the current Section 241 */ 242 void IniParser::getFirstVar() 243 { 244 if (this->currentSection) 245 this->currentEntry = this->currentSection->entries->firstElement(); 246 else 247 this->currentEntry = NULL; 248 } 249 250 /** 221 251 * gets the next VarName=VarValue pair from the parsing stream 222 * @param name: a pointer to the Name of the next Var223 * @param value: a pointer to the Value of the next Var224 252 * @return true on success, false otherwise (in the latter case name and value will be NULL) 225 253 */ 226 254 bool IniParser::nextVar() 227 255 { 228 if (this->currentSection == NULL )229 return false;230 if(this->currentEntry == this->currentSection->entries->lastElement())256 if (this->currentSection == NULL 257 || this->currentEntry == NULL 258 || this->currentEntry == this->currentSection->entries->lastElement()) 231 259 { 232 260 this->currentEntry = NULL; 233 261 return false; 234 262 } 235 if (this->currentEntry == NULL) 236 this->currentEntry = this->currentSection->entries->firstElement(); 237 else 238 this->currentEntry = this->currentSection->entries->nextElement(this->currentEntry); 263 this->currentEntry = this->currentSection->entries->nextElement(this->currentEntry); 239 264 240 265 if (this->currentEntry == NULL) -
orxonox/trunk/src/lib/util/ini_parser.h
r5014 r5015 43 43 bool openFile(const char* name); 44 44 45 bool getSection( const char* sectionName); 45 bool getSection(const char* sectionName); 46 47 void getFirstSection(); 46 48 const char* nextSection(); 47 49 50 /** @returns true if the file is opened, false otherwise*/ 48 51 bool isOpen() const { return (sections != NULL)?true:false; }; 49 52 50 53 const char* getVar(const char* entryName, const char* sectionName, const char* defaultValue = "") const; 54 55 void getFirstVar(); 51 56 bool nextVar(); 52 57 53 const char* getCurrentName() const { return (currentEntry!=NULL)?currentEntry->name:NULL; }; 54 const char* getCurrentValue() const { return (currentEntry!=NULL)?currentEntry->value:NULL; }; 58 /** @returns the name of the Current selected Section */ 59 const char* getCurrentSection() const { return (this->currentSection!=NULL)?this->currentSection->name:NULL; }; 60 /** @returns the current entries Name, or NULL if we havn't selected a Entry */ 61 const char* getCurrentName() const { return (this->currentEntry!=NULL)?this->currentEntry->name:NULL; }; 62 /** @returns the current entries Value, or NULL if we havn't selected a Entry */ 63 const char* getCurrentValue() const { return (this->currentEntry!=NULL)?this->currentEntry->value:NULL; }; 55 64 56 65 void debug() const; -
orxonox/trunk/src/orxonox.cc
r5014 r5015 124 124 const char* Orxonox::getConfigFile () 125 125 { 126 this->configFileName = new char[strlen(DEFAULT_CONFIG_FILE)]; 127 strcpy (this->configFileName, DEFAULT_CONFIG_FILE); 126 this->configFileName = ResourceManager::homeDirCheck(DEFAULT_CONFIG_FILE); 128 127 this->iniParser = new IniParser(this->configFileName); 129 128 }
Note: See TracChangeset
for help on using the changeset viewer.