116 printf(
"error: could not open config file '%s'\n",
m_pchFileName);
121 fseek(pCfgFile , 0 , SEEK_END);
129 printf(
"error: out of memory\n");
167 bool bResult =
false;
173 szReturnString = szString;
180 bool bResult =
false;
185 if(bResult) nReturnInt = atoi(szInteger);
192 bool bResult =
false;
196 if (bResult) fReturnFloat = (float)atof(szFloat);
203 bool bResult =
false;
207 if(bResult) dReturnDouble = atof(szDouble);
215 char szTrue[] =
"true";
217 bool bResult =
false;
224 if(strcmp(szBool,szOn) == 0 ||
225 strcmp(szBool,szTrue) == 0)
242 int cnBufferPosition = 0;
243 char* pchCurrentName = NULL;
244 char* pchCurrentValue = NULL;
256 fError = !
ExtractName(pchBuffer,cnBufferPosition, pchCurrentName);
259 printf(
"error: could not extract variable name in line %d\n",
GetLineNumber(pchBuffer, cnBufferPosition));
267 fError = !
ExtractValue(pchBuffer,cnBufferPosition, pchCurrentValue);
270 printf(
"error: could not extract value of variable '%s' in line %d\n", pchCurrentName,
GetLineNumber(pchBuffer,cnBufferPosition));
284 switch(pchBuffer[cnBufferPosition])
287 while(cnBufferPosition <
m_nFileLength && pchBuffer[cnBufferPosition] !=
'\n')
292 while (cnBufferPosition <
m_nFileLength && pchBuffer[cnBufferPosition] !=
'\n')
293 printf(
"%c", pchBuffer[cnBufferPosition++]);
307 ( pchBuffer[cnBufferPosition] ==
' ' ||
308 pchBuffer[cnBufferPosition] ==
'\t' ||
309 pchBuffer[cnBufferPosition] ==
'\r' ||
310 pchBuffer[cnBufferPosition] ==
'\n' ||
311 pchBuffer[cnBufferPosition] ==
'\x27' 321 int nNameStart = cnBufferPosition;
324 ( pchBuffer[cnBufferPosition] !=
' ' &&
325 pchBuffer[cnBufferPosition] !=
'\t' &&
326 pchBuffer[cnBufferPosition] !=
'\r' &&
327 pchBuffer[cnBufferPosition] !=
'\n' &&
328 pchBuffer[cnBufferPosition] !=
'\x27' 333 int nNameEnd = cnBufferPosition;
336 pchResultName =
new char[nNameEnd - nNameStart + 1];
337 strncpy(pchResultName, pchBuffer + nNameStart, nNameEnd - nNameStart);
338 pchResultName[nNameEnd - nNameStart] =
'\0';
345 int nValueStart = cnBufferPosition;
346 bool fStringMode =
false;
349 ( (pchBuffer[cnBufferPosition] !=
' ' || fStringMode) &&
350 (pchBuffer[cnBufferPosition] !=
'\t' || fStringMode) &&
351 pchBuffer[cnBufferPosition] !=
'\r' &&
352 pchBuffer[cnBufferPosition] !=
'\n' &&
353 pchBuffer[cnBufferPosition] !=
'\x27' &&
354 !(pchBuffer[cnBufferPosition] ==
'\"' && fStringMode)
358 if (pchBuffer[cnBufferPosition] ==
'\"')
364 int nValueEnd = cnBufferPosition;
375 pchResultValue =
new char[nValueEnd - nValueStart + 1 - nAdjust];
376 strncpy(pchResultValue, pchBuffer + nValueStart + nAdjust, nValueEnd - nValueStart - nAdjust);
377 pchResultValue[nValueEnd - nValueStart - nAdjust] =
'\0';
384 if (pchCurrentName[0] ==
'\0' || pchCurrentValue[0] ==
'\0')
386 delete [] pchCurrentName;
387 delete [] pchCurrentValue;
409 pVariable->
szName = pchCurrentName;
410 pVariable->
szValue = pchCurrentValue;
421 for (
int pos = 0 ; pos < cnBufferPosition ; pos++)
423 if (pchBuffer[pos] ==
'\r')
428 else if (pchBuffer[pos] ==
'\n')
void SetFileName(const char *szFileName)
TVariableMap ** m_ppVariables
bool ParseBuffer(char *pchBuffer)
void AddVariable(char *pchCurrentName, char *pchCurrentValue)
int GetLineNumber(char *pchBuffer, int cnBufferPosition)
bool GetVarByName(char *szName, char *&szReturnString)
Determine if variable with Name exists.
bool ExtractValue(char *pchBuffer, int &cnBufferPosition, char *&pchResultValue)
bool GetFloat(char *szName, float &fReturnFloat)
Get float from configutation file.
bool ExtractName(char *pchBuffer, int &cnBufferPosition, char *&pchResultName)
bool CheckControlCharacter(char *pchBuffer, int &cnBufferPosition)
struct CConfiguration::VarMap TVariableMap
bool GetBool(char *szName, bool &bReturnBool)
Get bool from configutation file.
bool SeekNextContent(char *pchBuffer, int &cnBufferPosition)
bool GetDouble(char *szName, double &dReturnDouble)
Get double from configutation file.
virtual ~CConfiguration()
Destructor.
bool GetString(char *szName, char *&szReturnString)
Get string from configutation file.
CConfiguration()
Construct a new Configuration object.
bool GetInt(char *szName, int &nReturnInt)
Get integer from configutation file.