Changeset 4597 in orxonox.OLD for orxonox/trunk/src/lib/util
- Timestamp:
- Jun 11, 2005, 12:55:48 AM (20 years ago)
- Location:
- orxonox/trunk/src/lib/util
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/util/ini_parser.cc
r4381 r4597 1 /* 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 … … 28 28 IniParser::IniParser (const char* filename) 29 29 { 30 this->setClassID(CL_INI_PARSER, "IniParser"); 31 30 32 stream = NULL; 31 33 bInSection = false; … … 50 52 char* tmpName = ResourceManager::homeDirCheck(filename); 51 53 if( filename == NULL) return -1; 52 if( stream != NULL) 54 if( stream != NULL) fclose (stream); 53 55 if( (stream = fopen (tmpName, "r")) == NULL) 54 56 { … … 71 73 bInSection = false; 72 74 if( stream == NULL) return -1; 73 75 74 76 char linebuffer[PARSELINELENGHT]; 75 77 char secbuffer[PARSELINELENGHT]; 76 78 char* ptr; 77 79 78 80 rewind (stream); 79 81 while( !feof( stream)) … … 85 87 // check for section identifyer 86 88 if( sscanf (linebuffer, "[%s", secbuffer) == 1) 87 88 89 90 91 92 93 94 95 96 97 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 } 98 100 } 99 101 return -1; … … 114 116 } 115 117 if( !bInSection) return -1; 116 118 117 119 char linebuffer[PARSELINELENGHT]; 118 120 char* ptr; 119 121 120 122 while( !feof( stream)) 121 123 { … … 125 127 if( (ptr = strchr( linebuffer, '\n')) != NULL) *ptr = 0; 126 128 if( linebuffer[0] == '[') 127 128 129 130 129 { 130 bInSection = false; 131 return -1; 132 } 131 133 sscanf(linebuffer, "%s = %s", name, value); 132 134 return 0; 133 135 /* 134 135 136 137 138 139 140 141 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 } 142 144 */ 143 145 } 144 return -1; 146 return -1; 145 147 } 146 148 … … 151 153 \param defvalue: what should be returned in case the entry cannot be found 152 154 \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 153 155 154 156 The returned pointer points to an internal buffer, so do not free it on your own. Do not give a NULL pointer to defvalue, this will certainly 155 157 lead to unwanted behaviour. … … 159 161 strcpy (internbuf, defvalue); 160 162 if( getSection (section) == -1) return internbuf; 161 163 162 164 char namebuf[PARSELINELENGHT]; 163 165 char valuebuf[PARSELINELENGHT]; 164 166 165 167 while( nextVar (namebuf, valuebuf) != -1) 166 168 { 167 169 if( !strcmp (name, namebuf)) 168 169 170 171 170 { 171 strcpy (internbuf, valuebuf); 172 return internbuf; 173 } 172 174 } 173 175 return internbuf; -
orxonox/trunk/src/lib/util/ini_parser.h
r4482 r4597 2 2 \file ini_parser.h 3 3 \brief A small ini file parser 4 4 5 5 Can be used to find a defined [Section] in an ini file and get the VarName=Value entries 6 6 */ … … 12 12 #include <string.h> 13 13 #include <stdlib.h> 14 #include "base_object.h" 14 15 15 16 #define PARSELINELENGHT 512 //!< how many chars to read at once … … 17 18 //! ini-file parser 18 19 /** 19 20 This class can be used to load an initializer file and parse it's contents for variablename=value pairs. 20 21 */ 21 class IniParser { 22 class IniParser : public BaseObject 23 { 22 24 public: 23 25 IniParser (const char* filename); 24 26 ~IniParser (); 25 27 26 28 char* getVar(const char* name, char* section, char* defvalue); 27 29 int openFile(const char* name); … … 33 35 bool bInSection; //!< if the requested parameter is in the section. 34 36 char internbuf[PARSELINELENGHT]; //!< a buffer 35 37 36 38 37 39 }; -
orxonox/trunk/src/lib/util/substring.cc
r4220 r4597 1 /* 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 … … 11 11 ### File Specific: 12 12 main-programmer: Christian Meyer 13 co-programmer: ... 13 co-programmer: Benjamin Grauer 14 15 2005-06-10: some naming conventions 14 16 */ 15 17 … … 28 30 { 29 31 n = 0; 30 32 31 33 assert( string != NULL); 32 34 33 35 for( int i = 0; i < strlen(string); i++) if( string[i] == ',') n++; 34 36 35 37 n += 1; 36 38 37 39 strings = new char*[n]; 38 40 39 41 assert (strings != NULL); 40 42 41 43 int i = 0; 42 44 int l = 0; 43 45 44 46 const char* offset = string; 45 47 char* end = strchr( string, ','); … … 57 59 end = strchr( offset, ','); 58 60 } 59 61 60 62 strings[i] = new char[l + 1]; 61 63 l = strlen( offset); … … 73 75 delete strings[i]; 74 76 } 75 77 76 78 delete strings; 77 79 } -
orxonox/trunk/src/lib/util/substring.h
r4482 r4597 1 /*! 1 /*! 2 2 \file substring.h 3 3 \brief a small class to get the parts of a string separated by commas … … 13 13 SubString(const char* string); 14 14 ~SubString(); 15 15 16 16 int getCount(); 17 17 const char* getString( int i); 18 18 19 19 private: 20 20 char** strings; //!< strings produced from a single string splitted in multiple strings
Note: See TracChangeset
for help on using the changeset viewer.