- Timestamp:
- Aug 14, 2005, 4:29:29 PM (19 years ago)
- Location:
- orxonox/trunk/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/event/key_mapper.cc
r4866 r5014 121 121 void KeyMapper::loadKeyBindings(IniParser* iniParser) 122 122 { 123 if( iniParser->getSection (CONFIG_SECTION_PLAYER "1") == -1)123 if( !iniParser->getSection (CONFIG_SECTION_PLAYER "1")) 124 124 { 125 125 PRINTF(1)("Could not find key bindings " CONFIG_SECTION_PLAYER"1\n"); 126 126 return; 127 127 } 128 // allocate empty lookup table129 130 char namebuf[256];131 char valuebuf[256];132 memset (namebuf, 0, 256);133 memset (valuebuf, 0, 256);134 128 int* index; 135 129 136 while( iniParser->nextVar (namebuf, valuebuf) != -1) 137 { 138 PRINTF(3)("Keys: Parsing %s, %s now.\n", namebuf, valuebuf); 139 index = nameToIndex (valuebuf); 140 this->mapKeys(namebuf, index[1]); 141 142 /* 143 switch( index[0]) 144 { 145 case 0: 146 this->mapKeys(namebuf, index[1]); 147 break; 148 case 1: 149 this->mapKeys(namebuf, index[1]); 150 break; 151 default: 152 break; 153 } 154 */ 155 memset (namebuf, 0, 256); 156 memset (valuebuf, 0, 256); 130 while(iniParser->nextVar()) 131 { 132 PRINTF(3)("Keys: Parsing %s, %s now.\n", iniParser->getCurrentName(), iniParser->getCurrentValue()); 133 index = nameToIndex (iniParser->getCurrentValue()); 134 this->mapKeys(iniParser->getCurrentName(), index[1]); 157 135 } 158 136 159 137 160 138 // PARSE MISC SECTION 161 if( iniParser->getSection (CONFIG_SECTION_MISC_KEYS) == -1)162 { 163 PRINTF(1)("Could not find key bindings \n");139 if( !iniParser->getSection (CONFIG_SECTION_MISC_KEYS)) 140 { 141 PRINTF(1)("Could not find key bindings" CONFIG_SECTION_MISC_KEYS "\n"); 164 142 return; 165 143 } 166 144 167 while( iniParser->nextVar (namebuf, valuebuf) != -1) 168 { 169 PRINTF(3)("MISC: Parsing %s, %s now.\n", namebuf, valuebuf); 170 index = nameToIndex (valuebuf); 171 this->mapKeys(namebuf, index[1]); 172 /* 173 switch( index[0]) 174 { 175 case 0: 176 this->mapKeys(namebuf, index[1]); 177 break; 178 case 1: 179 this->mapKeys(namebuf, index[1]); 180 break; 181 default: 182 break; 183 } 184 */ 185 memset (namebuf, 0, 256); 186 memset (valuebuf, 0, 256); 145 while( iniParser->nextVar()) 146 { 147 PRINTF(3)("MISC: Parsing %s, %s now.\n", iniParser->getCurrentName(), iniParser->getCurrentValue()); 148 index = nameToIndex (iniParser->getCurrentValue()); 149 this->mapKeys(iniParser->getCurrentName(), index[1]); 187 150 } 188 151 } … … 192 155 * @param the name of the button 193 156 */ 194 int* KeyMapper::nameToIndex (c har* name)157 int* KeyMapper::nameToIndex (const char* name) 195 158 { 196 159 coord[0] = -1; … … 216 179 * @param id of the key 217 180 */ 218 void KeyMapper::mapKeys(c har* name, int keyID)181 void KeyMapper::mapKeys(const char* name, int keyID) 219 182 { 220 183 for(int i = 0; map[i].pValue != NULL; ++i ) -
orxonox/trunk/src/lib/event/key_mapper.h
r4866 r5014 35 35 36 36 private: 37 int* nameToIndex (c har* name);38 void mapKeys(c har* name, int keyID);37 int* nameToIndex (const char* name); 38 void mapKeys(const char* name, int keyID); 39 39 40 40 public: -
orxonox/trunk/src/lib/graphics/importer/objModel.cc
r4836 r5014 1 /* 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 … … 64 64 { 65 65 PRINTF(4)("preparing to read in file: %s\n", fileName); 66 // splitting the 66 // splitting the 67 67 char* split = NULL; 68 68 … … 103 103 // line termiated with \0 not \n 104 104 if (buffer[strlen(buffer)-1] == '\n') 105 105 buffer[strlen(buffer)-1] = '\0'; 106 106 107 107 // case vertice 108 108 if (!strncmp(buffer, "v ", 2)) 109 110 111 109 { 110 this->addVertex(buffer+2); 111 } 112 112 113 113 // case face 114 114 else if (!strncmp(buffer, "f ", 2)) 115 116 117 118 115 { 116 this->addFace (buffer+2); 117 } 118 119 119 else if (!strncmp(buffer, "mtllib ", 7)) 120 121 122 120 { 121 this->readMtlLib (buffer+7); 122 } 123 123 124 124 else if (!strncmp(buffer, "usemtl ", 7)) 125 126 127 125 { 126 this->setMaterial (buffer+7); 127 } 128 128 129 129 // case VertexNormal 130 130 else if (!strncmp(buffer, "vn ", 3)) 131 132 133 134 131 { 132 this->addVertexNormal(buffer+3); 133 } 134 135 135 // case VertexTextureCoordinate 136 136 else if (!strncmp(buffer, "vt ", 3)) 137 138 139 137 { 138 this->addVertexTexture(buffer+3); 139 } 140 140 // case group 141 141 else if (!strncmp(buffer, "g ", 2)) 142 143 144 142 { 143 this->addGroup (buffer+2); 144 } 145 145 else if (!strncmp(buffer, "s ", 2)) //! @todo smoothing groups have to be implemented 146 147 148 146 { 147 PRINTF(2)("smoothing groups not supportet yet. line: %s\n", buffer); 148 } 149 149 } 150 150 fclose (stream); … … 152 152 } 153 153 154 /** 154 /** 155 155 * Function to read in a mtl File. 156 156 * @param mtlFile The .mtl file to read … … 183 183 // line termiated with \0 not \n 184 184 if (buffer[strlen(buffer)-1] == '\n') 185 185 buffer[strlen(buffer)-1] = '\0'; 186 186 187 187 // create new Material 188 188 if (!strncmp(buffer, "newmtl ", 7)) 189 190 191 189 { 190 tmpMat = this->addMaterial(buffer+7);//tmpMat->addMaterial(buffer+7); 191 } 192 192 // setting a illumMode 193 193 else if (!strncmp(buffer, "illum ", 6)) 194 195 196 197 198 194 { 195 if (likely(tmpMat != NULL)) 196 tmpMat->setIllum(buffer+6); 197 198 } 199 199 // setting Diffuse Color 200 200 else if (!strncmp(buffer, "Kd ", 3)) 201 202 203 204 201 { 202 if (likely(tmpMat != NULL)) 203 tmpMat->setDiffuse(buffer+3); 204 } 205 205 // setting Ambient Color 206 206 else if (!strncmp(buffer, "Ka ", 3)) 207 208 209 210 207 { 208 if (likely(tmpMat != NULL)) 209 tmpMat->setAmbient(buffer+3); 210 } 211 211 // setting Specular Color 212 212 else if (!strncmp(buffer, "Ks ", 3)) 213 214 215 216 213 { 214 if (likely(tmpMat != NULL)) 215 tmpMat->setSpecular(buffer+3); 216 } 217 217 // setting The Specular Shininess 218 218 else if (!strncmp(buffer, "Ns ", 3)) 219 220 221 222 219 { 220 if (likely(tmpMat != NULL)) 221 tmpMat->setShininess(buffer+3); 222 } 223 223 // setting up transparency 224 224 else if (!strncmp(buffer, "d ", 2)) 225 226 227 228 225 { 226 if (likely(tmpMat != NULL)) 227 tmpMat->setTransparency(buffer+2); 228 } 229 229 else if (!strncmp(buffer, "Tf ", 3)) 230 231 232 233 234 230 { 231 if (likely(tmpMat != NULL)) 232 tmpMat->setTransparency(buffer+3); 233 } 234 235 235 else if (!strncmp(buffer, "map_Kd ", 7)) 236 237 238 239 236 { 237 if (likely(tmpMat != NULL)) 238 tmpMat->setDiffuseMap(buffer+7); 239 } 240 240 else if (!strncmp(buffer, "map_Ka ", 7)) 241 242 243 244 241 { 242 if (likely(tmpMat != NULL)) 243 tmpMat->setAmbientMap(buffer+7); 244 } 245 245 else if (!strncmp(buffer, "map_Ks ", 7)) 246 247 248 249 246 { 247 if (likely(tmpMat != NULL)) 248 tmpMat->setSpecularMap(buffer+7); 249 } 250 250 else if (!strncmp(buffer, "bump ", 5)) 251 252 253 254 255 251 { 252 if (likely(tmpMat != NULL)) 253 tmpMat->setBump(buffer+7); 254 } 255 256 256 257 257 } -
orxonox/trunk/src/lib/gui/gui_exec.cc
r4836 r5014 27 27 28 28 #include "resource_manager.h" 29 #include "ini_parser.h" 29 30 30 31 #include <string.h> … … 32 33 #include <sys/stat.h> 33 34 #include <sys/types.h> 35 34 36 35 37 #ifdef __WIN32__ … … 263 265 void GuiExec::readFromFile(Widget* widget) 264 266 { 265 this->CONFIG_FILE = fopen(this->confFile, "r"); 266 VarInfo varInfo; 267 if(this->CONFIG_FILE) 268 { 269 Widget* groupWidget = widget; 270 char Buffer[256] = ""; 271 char Variable[256]= ""; 272 char* Value; 273 while(fscanf(this->CONFIG_FILE, "%s", Buffer) != EOF) 274 { 275 // group-search // 276 if(!strncmp(Buffer, "[", 1)) 277 { 278 if((groupWidget = locateGroup(widget, Buffer, 1))==NULL) 279 { 280 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", Buffer); 281 groupWidget = widget; 282 } 283 else 284 PRINT(5)("Group %s located.\n", static_cast<Packer*>(groupWidget)->groupName); 285 } 286 // option-setting // 287 if(!strcmp(Buffer, "=")) 288 { 289 char* under2space; 290 while(under2space = strchr(Variable, '_')) 291 { 292 sprintf(under2space, " %s", under2space+1); 293 } 294 295 fscanf(this->CONFIG_FILE, "%s", Buffer); 296 varInfo.variableName = Variable; 297 varInfo.variableValue = Buffer; 298 groupWidget->walkThrough(this->readFileText, &varInfo, 0); 299 sprintf(Variable, ""); 300 } 301 sprintf(Variable, "%s", Buffer); 302 } 303 widget->walkThrough(widget->setOptions, 0); 304 } 305 fclose(this->CONFIG_FILE); 267 IniParser iniParser(this->confFile); 268 if (!iniParser.isOpen()) 269 return; 270 271 // const char* name; 272 // while (name = iniParser.nextSection()) 273 // printf("%s\n", name); 274 // 275 // 276 // this->CONFIG_FILE = fopen(this->confFile, "r"); 277 // VarInfo varInfo; 278 // if(this->CONFIG_FILE) 279 // { 280 // Widget* groupWidget = widget; 281 // char Buffer[256] = ""; 282 // char Variable[256]= ""; 283 // char* Value; 284 // while(fscanf(this->CONFIG_FILE, "%s", Buffer) != EOF) 285 // { 286 // // group-search // 287 // if(!strncmp(Buffer, "[", 1)) 288 // { 289 // if((groupWidget = locateGroup(widget, Buffer, 1))==NULL) 290 // { 291 // 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", Buffer); 292 // groupWidget = widget; 293 // } 294 // else 295 // PRINT(5)("Group %s located.\n", static_cast<Packer*>(groupWidget)->groupName); 296 // } 297 // // option-setting // 298 // if(!strcmp(Buffer, "=")) 299 // { 300 // char* under2space; 301 // while(under2space = strchr(Variable, '_')) 302 // { 303 // sprintf(under2space, " %s", under2space+1); 304 // } 305 // 306 // fscanf(this->CONFIG_FILE, "%s", Buffer); 307 // varInfo.variableName = Variable; 308 // varInfo.variableValue = Buffer; 309 // groupWidget->walkThrough(this->readFileText, &varInfo, 0); 310 // sprintf(Variable, ""); 311 // } 312 // sprintf(Variable, "%s", Buffer); 313 // } 314 // widget->walkThrough(widget->setOptions, 0); 315 // } 316 // fclose(this->CONFIG_FILE); 306 317 } 307 318 -
orxonox/trunk/src/lib/util/ini_parser.cc
r4836 r5014 10 10 11 11 ### File Specific: 12 main-programmer: Christian Meyer 13 co-programmer: ... 12 main-programmer: Benjamin Grauer 13 co-programmer: Christian Meyer 14 15 2005-08-14: complete reimplementation: 16 now the File is parsed at the initialisation, 17 and informations is gathered there. 14 18 */ 15 19 16 20 17 21 #include "ini_parser.h" 22 23 #include "list.h" 24 #include "stdlibincl.h" 18 25 19 26 #include "resource_manager.h" … … 26 33 * @param filename: the path and name of the file to parse 27 34 */ 28 IniParser::IniParser (const char* file name)35 IniParser::IniParser (const char* fileName) 29 36 { 30 37 this->setClassID(CL_INI_PARSER, "IniParser"); 31 32 stream = NULL; 33 bInSection = false; 34 this->openFile(filename); 38 this->setName(fileName); 39 40 this->currentEntry = NULL; 41 this->currentSection = NULL; 42 this->sections = NULL; 43 if (fileName != NULL) 44 this->openFile(fileName); 35 45 } 36 46 … … 40 50 IniParser::~IniParser () 41 51 { 42 if( stream != NULL) fclose (stream); 43 } 44 45 /** 46 * opens another file to parse 52 deleteSections(); 53 } 54 55 void IniParser::deleteSections() 56 { 57 if (this->sections) 58 { 59 tIterator<IniSection>* sectionIt = this->sections->getIterator(); 60 IniSection* sectionEnum = sectionIt->nextElement(); 61 while (sectionEnum) 62 { 63 tIterator<IniEntry>* entryIt = sectionEnum->entries->getIterator(); 64 IniEntry* entryEnum = entryIt->nextElement(); 65 while (entryEnum) 66 { 67 delete []entryEnum->name; 68 delete []entryEnum->value; 69 delete entryEnum; 70 entryEnum = entryIt->nextElement(); 71 } 72 delete entryIt; 73 74 delete []sectionEnum->name; 75 delete sectionEnum->entries; 76 delete sectionEnum; 77 sectionEnum = sectionIt->nextElement(); 78 } 79 delete sectionIt; 80 } 81 delete this->sections; 82 this->sections = NULL; 83 } 84 85 /** 86 * opens another file to parse 47 87 * @param filename: path and name of the new file to parse 48 * @return zero on success or -1 if an error occured; 49 */ 50 int IniParser::openFile(const char* filename) 51 { 88 * @return true on success false otherwise; 89 */ 90 bool IniParser::openFile(const char* filename) 91 { 92 FILE* stream; //!< The stream we use to read the file. 93 94 95 if( filename == NULL) 96 return false; 52 97 char* tmpName = ResourceManager::homeDirCheck(filename); 53 if( filename == NULL) return -1; 54 if( stream != NULL) fclose (stream); 98 99 if (sections != NULL) 100 deleteSections(); 101 55 102 if( (stream = fopen (tmpName, "r")) == NULL) 56 { 57 PRINTF(1)("IniParser could not open %s\n", filename); 58 delete tmpName; 59 return -1; 60 } 61 bInSection = false; 62 delete tmpName; 63 return 0; 103 { 104 PRINTF(1)("IniParser could not open %s\n", filename); 105 delete tmpName; 106 return false; 107 } 108 else 109 { 110 this->currentEntry = NULL; 111 this->currentSection = NULL; 112 this->sections = new tList<IniSection>; 113 114 ///////////////////////////// 115 // READING IN THE INI-FILE // 116 ///////////////////////////// 117 char lineBuffer[PARSELINELENGHT]; 118 char buffer[PARSELINELENGHT]; 119 char* ptr; 120 121 rewind (stream); 122 while( !feof( stream)) 123 { 124 // get next line 125 fgets (lineBuffer, PARSELINELENGHT, stream); 126 // remove newline char, and \0-terminate 127 if( (ptr = strchr( lineBuffer, '\n')) != NULL) 128 *ptr = 0; 129 // check for section identifyer 130 if( sscanf (lineBuffer, "[%s", buffer) == 1) 131 { 132 if( (ptr = strchr( buffer, ']')) != NULL) 133 { 134 *ptr = 0; 135 IniSection* newSection = new IniSection; 136 newSection->name = new char[strlen(buffer)+1]; 137 strcpy(newSection->name, buffer); 138 newSection->entries = new tList<IniEntry>; 139 this->sections->add(newSection); 140 this->currentSection = newSection; 141 } 142 } 143 else if( (ptr = strchr( lineBuffer, '=')) != NULL) 144 { 145 if (currentSection == NULL) 146 { 147 PRINTF(2)("Not in a Section yet for %s\n", lineBuffer); 148 continue; 149 } 150 if( ptr == lineBuffer) 151 continue; 152 IniEntry* newEntry = new IniEntry; 153 154 char* valueBegin = ptr+1; 155 while ((*valueBegin == ' ' || *valueBegin == '\t') && valueBegin <= lineBuffer + strlen(lineBuffer)) 156 ++valueBegin; 157 newEntry->value = new char[strlen(valueBegin)+1]; 158 strcpy(newEntry->value, valueBegin); 159 char* nameEnd = ptr-1, *nameBegin = lineBuffer; 160 while ((*nameBegin == ' ' || *nameBegin == '\t') && nameBegin < ptr) 161 ++nameBegin; 162 while ((*nameEnd == ' ' || *nameEnd == '\t' ) && nameEnd >= nameBegin) 163 --nameEnd; 164 nameEnd[1] = '\0'; 165 newEntry->name = new char[strlen (nameBegin)]; 166 strcpy(newEntry->name, nameBegin); 167 168 this->currentSection->entries->add(newEntry); 169 } 170 171 } 172 } 173 fclose(stream); 174 return true; 64 175 } 65 176 66 177 /** 67 178 * set the parsing cursor to the specified section 68 * @param section: the name of the section to set the cursor to 69 * @return zero on success or -1 if the section could not be found 70 */ 71 int IniParser::getSection( const char* section) 72 { 73 bInSection = false; 74 if( stream == NULL) return -1; 75 76 char linebuffer[PARSELINELENGHT]; 77 char secbuffer[PARSELINELENGHT]; 78 char* ptr; 79 80 rewind (stream); 81 while( !feof( stream)) 82 { 83 // get next line 84 fgets (linebuffer, PARSELINELENGHT, stream); 85 // remove newline char 86 if( (ptr = strchr( linebuffer, '\n')) != NULL) *ptr = 0; 87 // check for section identifyer 88 if( sscanf (linebuffer, "[%s", secbuffer) == 1) 89 { 90 if( (ptr = strchr( secbuffer, ']')) != NULL) 91 { 92 *ptr = 0; 93 if( !strcmp( secbuffer, section)) 94 { 95 bInSection = true; 96 return 0; 97 } 98 } 99 } 100 } 101 return -1; 179 * @param sectionName: the name of the section to set the cursor to 180 * @return true on success or false if the section could not be found 181 */ 182 bool IniParser::getSection( const char* sectionName) 183 { 184 tIterator<IniSection>* sectionIt = this->sections->getIterator(); 185 IniSection* sectionEnum = sectionIt->nextElement(); 186 while (sectionEnum) 187 { 188 if (!strcmp(sectionEnum->name, sectionName)) 189 { 190 this->currentSection = sectionEnum; 191 delete sectionIt; 192 return true; 193 } 194 195 sectionEnum = sectionIt->nextElement(); 196 } 197 delete sectionIt; 198 return false; 199 } 200 201 /** 202 * searches the next section 203 * @returns the name of the section if found, NULL otherwise 204 */ 205 const char* IniParser::nextSection() 206 { 207 if (this->currentSection == NULL) 208 return NULL; 209 else 210 { 211 if (this->sections) 212 this->currentSection = sections->nextElement(this->currentSection); 213 } 214 if (this->currentSection != NULL) 215 return this->currentSection->name; 216 else 217 return NULL; 102 218 } 103 219 104 220 /** 105 221 * gets the next VarName=VarValue pair from the parsing stream 106 * @param name: a pointer to a buffer to store the name of the entry 107 * @param value: a pointer to a buffer to store the value of the entry 108 * @return zero if the buffers have been filled with data or -1 if there are no entries left in the current section 109 */ 110 int IniParser::nextVar( const char* name, const char* value) 111 { 112 if( stream == NULL) 113 { 114 bInSection = false; 115 return -1; 116 } 117 if( !bInSection) return -1; 118 119 char linebuffer[PARSELINELENGHT]; 120 char* ptr; 121 122 while( !feof( stream)) 123 { 124 // get next line 125 fgets (linebuffer, PARSELINELENGHT, stream); 126 // remove newline char 127 if( (ptr = strchr( linebuffer, '\n')) != NULL) *ptr = 0; 128 if( linebuffer[0] == '[') 129 { 130 bInSection = false; 131 return -1; 132 } 133 sscanf(linebuffer, "%s = %s", name, value); 134 return 0; 135 /* 136 if( (ptr = strchr( tmpBuffer, '=')) != NULL) 137 { 138 if( ptr == linebuffer) continue; 139 strcpy (value, &ptr[1]); 140 strncpy (name, linebuffer, strlen (linebuffer) - strlen (value) - 1); 141 printf ("%s, %s\n", value, name); 142 return 0; 143 } 144 */ 145 } 146 return -1; 222 * @param name: a pointer to the Name of the next Var 223 * @param value: a pointer to the Value of the next Var 224 * @return true on success, false otherwise (in the latter case name and value will be NULL) 225 */ 226 bool IniParser::nextVar() 227 { 228 if (this->currentSection == NULL) 229 return false; 230 if(this->currentEntry == this->currentSection->entries->lastElement()) 231 { 232 this->currentEntry = NULL; 233 return false; 234 } 235 if (this->currentEntry == NULL) 236 this->currentEntry = this->currentSection->entries->firstElement(); 237 else 238 this->currentEntry = this->currentSection->entries->nextElement(this->currentEntry); 239 240 if (this->currentEntry == NULL) 241 return false; 242 else 243 return true; 147 244 } 148 245 149 246 /** 150 247 * directly acesses an entry in a section 151 * @param name: the name of the entry to find152 * @param section : the section where the entry is to be found153 * @param def value: what should be returned in case the entry cannot be found248 * @param entryName: the name of the entry to find 249 * @param sectionName: the section where the entry is to be found 250 * @param defaultValue: what should be returned in case the entry cannot be found 154 251 * @return a pointer to a buffer conatining the value of the specified entry. This buffer will contain the data specified in defvalue in case the entry wasn't found 155 252 … … 157 254 lead to unwanted behaviour. 158 255 */ 159 const char* IniParser::getVar(const char* name, const char* section, const char* defvalue = "") 160 { 161 strcpy (internbuf, defvalue); 162 if( getSection (section) == -1) return internbuf; 163 164 char namebuf[PARSELINELENGHT]; 165 char valuebuf[PARSELINELENGHT]; 166 167 while( nextVar (namebuf, valuebuf) != -1) 168 { 169 if( !strcmp (name, namebuf)) 256 const char* IniParser::getVar(const char* entryName, const char* sectionName, const char* defaultValue) const 257 { 258 if (this->sections) 259 { 260 tIterator<IniSection>* sectionIt = this->sections->getIterator(); 261 IniSection* sectionEnum = sectionIt->nextElement(); 262 while (sectionEnum) 263 { 264 if (!strcmp(sectionEnum->name, sectionName)) 265 { 266 tIterator<IniEntry>* entryIt = sectionEnum->entries->getIterator(); 267 IniEntry* entryEnum = entryIt->nextElement(); 268 while (entryEnum) 170 269 { 171 strcpy (internbuf, valuebuf); 172 return internbuf; 270 if (!strcmp(entryEnum->name, entryName)) 271 { 272 delete entryIt; 273 delete sectionIt; 274 return entryEnum->value; 275 } 276 entryEnum = entryIt->nextElement(); 173 277 } 174 } 175 return internbuf; 176 } 278 delete entryIt; 279 PRINTF(2)("Entry %s in section %s not found.\n", entryName, sectionName); 280 break; 281 } 282 sectionEnum = sectionIt->nextElement(); 283 } 284 delete sectionIt; 285 PRINTF(2)("Section %s that should be containing %s not found.\n", sectionName, entryName); 286 } 287 else 288 PRINTF(1)("%s not opened\n", this->getName()); 289 290 return defaultValue; 291 292 } 293 294 void IniParser::debug() const 295 { 296 PRINTF(0)("Iniparser %s - debug\n", this->getName()); 297 if (this->sections) 298 { 299 tIterator<IniSection>* sectionIt = this->sections->getIterator(); 300 IniSection* sectionEnum = sectionIt->nextElement(); 301 while (sectionEnum) 302 { 303 PRINTF(0)(" [%s]\n", sectionEnum->name); 304 305 tIterator<IniEntry>* entryIt = sectionEnum->entries->getIterator(); 306 IniEntry* entryEnum = entryIt->nextElement(); 307 while (entryEnum) 308 { 309 PRINTF(0)(" :%s: -> '%s'\n", entryEnum->name, entryEnum->value); 310 311 entryEnum = entryIt->nextElement(); 312 } 313 delete entryIt; 314 315 sectionEnum = sectionIt->nextElement(); 316 } 317 delete sectionIt; 318 } 319 else 320 PRINTF(1)("%s not opened\n", this->getName()); 321 } -
orxonox/trunk/src/lib/util/ini_parser.h
r4836 r5014 1 1 /*! 2 \file ini_parser.h3 *A small ini file parser4 5 Can be used to find a defined [Section] in an ini file and get the VarName=Value entries6 */2 * @file ini_parser.h 3 * A small ini file parser 4 * 5 * Can be used to find a defined [Section] in an ini file and get the VarName = Value entries 6 */ 7 7 8 8 #ifndef _INI_PARSER_H 9 9 #define _INI_PARSER_H 10 10 11 #include <stdio.h> 12 #include <string.h> 13 #include <stdlib.h> 11 #define PARSELINELENGHT 512 //!< how many chars to read at once 12 14 13 #include "base_object.h" 15 14 16 #define PARSELINELENGHT 512 //!< how many chars to read at once 15 // FORWARD DEFINITION // 16 template<class T> class tList; 17 17 18 18 //! ini-file parser 19 19 /** 20 21 */20 * This class can be used to load an initializer file and parse it's contents for variablename=value pairs. 21 */ 22 22 class IniParser : public BaseObject 23 23 { 24 public: 25 IniParser (const char* filename); 26 ~IniParser (); 24 private: 25 //////////////////////////////////// 26 struct IniEntry 27 { 28 char* name; 29 char* value; 30 }; 27 31 28 const char* getVar(const char* name, const char* section, const char* defvalue); 29 int openFile(const char* name); 30 int getSection( const char* section); 31 int nextVar( const char* name, const char* value); 32 struct IniSection 33 { 34 char* name; 35 tList<IniEntry>* entries; 36 }; 37 //////////////////////////////////// 32 38 33 private: 34 FILE* stream; //!< A FileStream to be loaded 35 bool bInSection; //!< if the requested parameter is in the section. 36 char internbuf[PARSELINELENGHT]; //!< a buffer 39 public: 40 IniParser (const char* filename = NULL); 41 ~IniParser (); 37 42 43 bool openFile(const char* name); 38 44 45 bool getSection( const char* sectionName); 46 const char* nextSection(); 47 48 bool isOpen() const { return (sections != NULL)?true:false; }; 49 50 const char* getVar(const char* entryName, const char* sectionName, const char* defaultValue = "") const; 51 bool nextVar(); 52 53 const char* getCurrentName() const { return (currentEntry!=NULL)?currentEntry->name:NULL; }; 54 const char* getCurrentValue() const { return (currentEntry!=NULL)?currentEntry->value:NULL; }; 55 56 void debug() const; 57 58 private: 59 void deleteSections(); 60 61 private: 62 tList<IniSection>* sections; 63 IniSection* currentSection; 64 IniEntry* currentEntry; 39 65 }; 40 66 -
orxonox/trunk/src/orxonox.cc
r4985 r5014 219 219 PRINT(3)("initializing ResourceManager\n"); 220 220 221 // create parser222 if ( this->iniParser->getSection (CONFIG_SECTION_DATA) == -1)221 const char* dataPath; 222 if ((dataPath = this->iniParser->getVar(CONFIG_NAME_DATADIR, CONFIG_SECTION_DATA))!= NULL) 223 223 { 224 PRINTF(1)("Could not find Section %s in %s\n", CONFIG_SECTION_DATA, DEFAULT_CONFIG_FILE); 225 return -1; 226 } 227 char namebuf[256]; 228 char valuebuf[256]; 229 memset (namebuf, 0, 256); 230 memset (valuebuf, 0, 256); 231 232 while( this->iniParser->nextVar (namebuf, valuebuf) != -1) 233 { 234 if (!strcmp(namebuf, CONFIG_NAME_DATADIR)) 224 if (!ResourceManager::getInstance()->setDataDir(dataPath)) 235 225 { 236 // printf("Not yet implemented\n"); 237 if (!ResourceManager::getInstance()->setDataDir(valuebuf)) 238 { 239 PRINTF(1)("Data Could not be located\n"); 240 exit(-1); 241 } 226 PRINTF(1)("Data Could not be located\n"); 227 exit(-1); 242 228 } 243 244 memset (namebuf, 0, 256);245 memset (valuebuf, 0, 256);246 229 } 247 230 -
orxonox/trunk/src/util/track/track_manager.h
r4836 r5014 1 1 /*! 2 \file track_manager.h3 4 5 6 7 2 * @file track_manager.h 3 * manages all tracks defined in the world and the path the player takes 4 * 5 * it is a container for all tracks and all track-nodes. it manages the movement of 6 * the track helper-parent (that drives the player). it is responsable for calculating 7 * smooth curves etc. 8 8 */ 9 9
Note: See TracChangeset
for help on using the changeset viewer.