- Timestamp:
- Aug 15, 2005, 12:10:07 AM (19 years ago)
- Location:
- orxonox/trunk/src/lib
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/gui/gui_exec.cc
r5016 r5021 202 202 void GuiExec::writeToFile(Widget* widget) 203 203 { 204 this->CONFIG_FILE = fopen(this->confFile, "w"); 205 if(this->CONFIG_FILE) 206 this->writeFileText(widget, 0); 207 fclose(this->CONFIG_FILE); 204 IniParser iniParser; 205 this->writeFileText(widget, &iniParser, 0); 206 char* fileName = ResourceManager::homeDirCheck(confFile); 207 iniParser.writeFile(fileName); 208 delete fileName; 208 209 } 209 210 … … 211 212 * Actually writes into the configuration file to the disk. 212 213 * @param widget from which Widget on should be saved. 214 * @param parser the IniParser to write to. 213 215 * @param depth initially "0", and grows higher, while new Groups are bundeled. 214 216 */ 215 void GuiExec::writeFileText(Widget* widget, int depth)216 { 217 int counter = 0;218 while(counter < depth &&((widget->optionType > GUI_NOTHING219 &&(static_cast<Option*>(widget)->isSaveable()))220 ||(widget->optionType < GUI_NOTHING221 && static_cast<Packer*>(widget)->getGroupName())))222 {223 fprintf(this->CONFIG_FILE, " ", depth);224 counter++;225 }217 void GuiExec::writeFileText(Widget* widget, IniParser* parser, int depth) 218 { 219 // int counter = 0; 220 // while(counter < depth &&((widget->optionType > GUI_NOTHING 221 // &&(static_cast<Option*>(widget)->isSaveable())) 222 // ||(widget->optionType < GUI_NOTHING 223 // && static_cast<Packer*>(widget)->getGroupName()))) 224 // { 225 // fprintf(this->CONFIG_FILE, " ", depth); 226 // counter++; 227 // } 226 228 227 229 // check if it is a Packer, and if it is, check if it has a name and if there is something in it. … … 230 232 if(static_cast<Packer*>(widget)->getGroupName()) 231 233 { 232 fprintf(CONFIG_FILE, "[%s]\n", static_cast<Packer*>(widget)->getGroupName()); 233 this->writeFileText(static_cast<Packer*>(widget)->down, depth+1); 234 fprintf(CONFIG_FILE, "\n"); 234 parser->addSection(static_cast<Packer*>(widget)->getGroupName()); 235 this->writeFileText(static_cast<Packer*>(widget)->down, parser, depth+1); 235 236 } 236 237 else 237 238 { 238 this->writeFileText(static_cast<Packer*>(widget)->down, depth);239 this->writeFileText(static_cast<Packer*>(widget)->down, parser, depth); 239 240 } 240 241 } … … 242 243 if(widget->optionType > GUI_NOTHING) 243 244 if (static_cast<Option*>(widget)->isSaveable()) 244 fprintf(CONFIG_FILE, "%s = %s\n",static_cast<Option*>(widget)->title, static_cast<Option*>(widget)->save());245 parser->addVar(static_cast<Option*>(widget)->title, static_cast<Option*>(widget)->save()); 245 246 246 247 if(widget->next != NULL) 247 this->writeFileText(widget->next, depth);248 this->writeFileText(widget->next, parser, depth); 248 249 } 249 250 -
orxonox/trunk/src/lib/gui/gui_exec.h
r5015 r5021 14 14 class CheckButton; 15 15 using namespace std; 16 class IniParser; 16 17 17 18 //! Class that creates the execute-Options. … … 41 42 int shouldsave(); 42 43 void writeToFile(Widget* widget); 43 void writeFileText(Widget* widget, int depth);44 void writeFileText(Widget* widget, IniParser* parser, int depth); 44 45 void readFromFile(Widget* widget); 45 46 static void readFileText(Widget* widget, void* varInfo); -
orxonox/trunk/src/lib/util/ini_parser.cc
r5020 r5021 116 116 char lineBuffer[PARSELINELENGHT]; 117 117 char buffer[PARSELINELENGHT]; 118 const char* lineBegin; 118 119 char* ptr; 119 120 … … 122 123 // get next line 123 124 fgets (lineBuffer, PARSELINELENGHT, stream); 125 lineBegin = lineBuffer; 124 126 // remove newline char, and \0-terminate 125 127 if( (ptr = strchr( lineBuffer, '\n')) != NULL) 126 128 *ptr = 0; 129 // cut up to the beginning of the line. 130 while((*lineBegin == ' ' || *lineBegin == '\t') && lineBegin < lineBuffer + strlen(lineBuffer)) 131 ++lineBegin; 132 if (strlen(lineBegin) <= 1 || *lineBegin == '#' || *lineBegin == ';') 133 continue;//printf("empty Line\n"); 127 134 // check for section identifyer 128 if (strlen(lineBuffer) <= 1) 129 ;//printf("empty Line\n"); 130 else if( sscanf (lineBuffer, "[%s", buffer) == 1) 135 else if( sscanf (lineBegin, "[%s", buffer) == 1) 131 136 { 132 137 if( (ptr = strchr( buffer, ']')) != NULL) … … 137 142 } 138 143 // check for Entry identifier (Entry = Value) 139 else if( (ptr = strchr( lineB uffer, '=')) != NULL)144 else if( (ptr = strchr( lineBegin, '=')) != NULL) 140 145 { 141 146 if (currentSection == NULL) 142 147 { 143 PRINTF(2)("Not in a Section yet for %s\n", lineB uffer);148 PRINTF(2)("Not in a Section yet for %s\n", lineBegin); 144 149 continue; 145 150 } 146 if( ptr == lineB uffer)151 if( ptr == lineBegin) 147 152 continue; 148 153 char* valueBegin = ptr+1; 149 while ((*valueBegin == ' ' || *valueBegin == '\t') && valueBegin <= lineB uffer + strlen(lineBuffer))154 while ((*valueBegin == ' ' || *valueBegin == '\t') && valueBegin <= lineBegin + strlen(lineBegin)) 150 155 ++valueBegin; 151 char* nameBegin = lineBuffer;152 while ((*nameBegin == ' ' || *nameBegin == '\t') && nameBegin < ptr)153 ++nameBegin;154 156 char* nameEnd = ptr-1; 155 while ((*nameEnd == ' ' || *nameEnd == '\t' ) && nameEnd >= nameBegin)157 while ((*nameEnd == ' ' || *nameEnd == '\t' ) && nameEnd >= lineBegin) 156 158 --nameEnd; 157 159 nameEnd[1] = '\0'; 158 160 159 this->addVar( nameBegin, valueBegin);161 this->addVar(lineBegin, valueBegin); 160 162 } 161 163 } … … 173 175 { 174 176 FILE* stream; //!< The stream we use to read the file. 175 if (sections != NULL)176 deleteSections();177 177 if( fileName == NULL) 178 178 return false; … … 191 191 while (sectionEnum) 192 192 { 193 fprintf(stream, " [%s]\n", sectionEnum->name);193 fprintf(stream, "\n [%s]\n", sectionEnum->name); 194 194 195 195 tIterator<IniEntry>* entryIt = sectionEnum->entries->getIterator(); … … 197 197 while (entryEnum) 198 198 { 199 fprintf(stream, " %s = %s\n", entryEnum->name, entryEnum->value);199 fprintf(stream, " %s = %s\n", entryEnum->name, entryEnum->value); 200 200 201 201 entryEnum = entryIt->nextElement(); … … 213 213 } 214 214 215 /** 216 * adds a section to the list of Sections, 217 * if no Section list is availiable, it will create it 218 * @param sectionName the Name of the section to add 219 * @return true on success... there is only success or segfault :) 220 */ 215 221 bool IniParser::addSection(const char* sectionName) 216 222 { … … 224 230 this->currentSection = newSection; 225 231 this->sections->add(newSection); 232 PRINTF(0)("Added Section %s\n", sectionName); 233 return true; 226 234 } 227 235
Note: See TracChangeset
for help on using the changeset viewer.