Changeset 5021 in orxonox.OLD for orxonox/trunk/src/lib/util/ini_parser.cc
- Timestamp:
- Aug 15, 2005, 12:10:07 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.