57 std::cout <<
"Creating new INI-File " <<
m_fileName.c_str() << std::endl;
62 std::cout <<
"INI-File not found " <<
m_fileName.c_str() << std::endl;
73 std::string StrWithDelimeters =
'"' + *pStrToWrite +
'"';
74 return WriteKeyValue(pSect, pKey, StrWithDelimeters.c_str(), bWarnIfNotfound);
83 int bFoundSect,bFoundKey;
95 if ((lS * lK) == 0)
return -1;
102 std::cout <<
"INI-File not found " <<
m_fileName.c_str() << std::endl;
105 if ((ftemp = tmpfile()) == NULL)
107 std::cout <<
"tmpfile() did not work!" << std::endl;
120 if (!
FindKey(szKey,
false)) bFoundKey = 1;
123 if (feof(
f)) bEoff = 1;
129 int res = fscanf(
f,
"%c",&c);
130 fprintf(ftemp,
"%c",c);
139 fprintf(ftemp,
"\n\n[%s]\n",szSect);
141 if (bFoundSect && (!bFoundKey) && (bEoff))
149 fprintf(ftemp,
"%s=",szKey);
152 fprintf(ftemp,
"%s",szValue);
155 if (!(bEoff || feof(
f)))
156 { fprintf(ftemp,
"\n");
159 int res = fscanf(
f,
"%c",&c);
162 fprintf(ftemp,
"%c",c);
174 std::cout <<
"INI-File is write protected " <<
m_fileName.c_str() << std::endl;
178 std::cout <<
"INI-File not found " <<
m_fileName.c_str() << std::endl;
181 fseek(ftemp,0,SEEK_SET);
184 int res = fscanf(ftemp,
"%c",&c);
203 snprintf(buff, 10,
"%d", nValue);
208 int Length,
int decimals,
bool bWarnIfNotfound)
211 sprintf(buff,
"%g", Value);
216 bool bWarnIfNotfound)
221 if (
GetKeyValue(pSect, pKey, pBuf, 20, bWarnIfNotfound) == -1)
225 while( *pChar ==
' ' ) pChar++;
227 if( strncmp(pChar,
"true", 4) == 0 )
232 if( strncmp(pChar,
"false", 5) == 0 )
242 bool bWarnIfNotfound)
245 if (
GetKeyValue(szSect,szKey,buf,9, bWarnIfNotfound)!=-1)
250 for (
int i=0; i<=6; i++)
255 if ((buf[0]==
'0') && (buf[1] ==
'x'))
259 for (
int z=0; z<=7; z++)
262 if ((buf[z+2]<0x30) || (buf[z+2]>0x3A))
269 for (
int i=0; i<=(iNumLength); i++)
272 *pValue += (buf[i+2]-0x30) * (
int)pow((
double)16, (iNumLength-i));
286 bool bWarnIfNotfound)
289 if (
GetKeyValue(szSect,szKey,buf,9, bWarnIfNotfound)!=-1)
298 bool bWarnIfNotfound)
301 if (
GetKeyValue(szSect, szKey, buf, 50, bWarnIfNotfound) == -1)
303 if( bWarnIfNotfound )
304 std::cout <<
"Setting parameter " << szKey <<
" = " << *pValue <<
" of section '" << szSect <<
305 "' in File '" <<
m_fileName.c_str() << std::endl;
314 double dDefault,
bool bWarnIfNotfound)
316 (*pValue) = dDefault;
317 return GetKeyDouble(pSect, pKey, pValue, bWarnIfNotfound);
321 int lenBuf,
bool bWarnIfNotfound)
329 if ((lS * lK) == 0)
return -1;
332 std::cout <<
"INI-File not found " <<
m_fileName.c_str() << std::endl;
339 if (
FindKey(szKey, bWarnIfNotfound) )
351 int BytesRead = fread( szBuf, 1, lenBuf,
f );
355 if(BytesRead < lenBuf)
357 if( BytesRead == 0 && (!feof(
f)) )
359 std::cout <<
"file read" << std::endl;
367 szBuf[StrLen] =
'\0';
374 bool bWarnIfNotfound)
382 if ((lS * lK) == 0)
return -1;
385 std::cout <<
"INI-File not found " <<
m_fileName.c_str() << std::endl;
392 if (
FindKey(szKey, bWarnIfNotfound) )
406 {
if(bWarnIfNotfound)
408 std::cout <<
"GetKeyString section " << szSect <<
" key " << szKey <<
" first \" not found" << std::endl;
420 std::cout <<
"GetKeyString section " << szSect <<
" key " << szKey <<
" string not found" << std::endl;
427 *pStrToRead = strRead;
437 int Char = fgetc(pFile);
442 if (Char == EOF || Char ==
'\n')
454 int Char = fgetc(pFile);
459 if (Char == EOF || Char ==
'\n')
462 ReadIntoStr.append(1,
char(Char));
472 std::string line = fgets(&NewLine[0], NewLine.size(),
f);
481 std::vector<char> line;
494 std::cout <<
"INI-File not found " <<
m_fileName.c_str() << std::endl;
497 if (feof(
f))
return -1;
500 if( prevSect !=
"" ) {
534 bool bWarnIfNotfound)
538 if (feof(
f))
return -1;
568 std::cout <<
"Section [" << sect <<
"] in IniFile " <<
m_fileName.c_str() <<
" used by " 576 bool bWarnIfNotfound)
581 if (feof(
f))
return -1;
610 fseek(
f,fpos,SEEK_SET);
620 std::cout <<
"Key " << skey <<
" in IniFile '" <<
m_fileName.c_str() <<
"' used by " 626 int IniFile::GetKey(
const char* pSect,
const char* pKey, std::string* pStrToRead,
bool bWarnIfNotfound)
628 return GetKeyString(pSect,pKey,pStrToRead,bWarnIfNotfound);
631 int IniFile::GetKey(
const char* pSect,
const char* pKey,
int* pValue,
bool bWarnIfNotfound)
633 return GetKeyInt(pSect,pKey,pValue,bWarnIfNotfound);
637 int IniFile::GetKey(
const char* pSect,
const char* pKey,
bool* pValue,
bool bWarnIfNotfound)
639 return GetKeyBool(pSect,pKey,pValue,bWarnIfNotfound);
642 int IniFile::GetKey(
const char* pSect,
const char* pKey,
double* pValue,
bool bWarnIfNotfound)
int SkipLineUntil(FILE *pFile, const char EndChar)
int FindNextLine(std::vector< char > &NewLine, int &CharInd)
int FindKey(const char *skey, bool bWarnIfNotfound=true)
int GetKeyValue(const char *pSect, const char *pKey, char *pBuf, int lenBuf, bool bWarnIfNotfound=true)
int WriteKeyString(const char *pSect, const char *pKey, const std::string *pStrToWrite, bool bWarnIfNotfound=true)
std::vector< char > m_CurLine
int GetKeyBool(const char *pSect, const char *pKey, bool *pValue, bool bWarnIfNotfound=true)
int WriteKeyDouble(const char *pSect, const char *pKey, double dValue, int StringLen=12, int decimals=5, bool bWarnIfNotfound=true)
int WriteKeyInt(const char *pSect, const char *pKey, int nValue, bool bWarnIfNotfound=true)
int GetKeyInt(const char *pSect, const char *pKey, int *pValue, bool bWarnIfNotfound=true)
int FindNextSection(std::string *pSect, std::string prevSect, bool bWarnIfNotfound=true)
int GetKeyDouble(const char *pSect, const char *pKey, double *pValue, bool bWarnIfNotfound=true)
int FindSection(const char *sect, bool bWarnIfNotfound=true)
int SetFileName(std::string fileName, std::string strIniFileUsedBy="", bool bCreate=false)
int GetKey(const char *pSect, const char *pKey, std::string *pStrToRead, bool bWarnIfNotfound=true)
int GetKeyString(const char *pSect, const char *pKey, std::string *pStrToRead, bool bWarnIfNotfound=true)
int ReadLineUntil(FILE *pFile, const char EndChar, std::string &ReadIntoStr)
int GetKeyLong(const char *pSect, const char *pKey, long *pValue, bool bWarnIfNotfound=true)
int WriteKeyBool(const char *pSect, const char *pKey, bool bValue, bool bWarnIfNotfound=true)
std::string m_strIniFileUsedBy
int WriteKeyValue(const char *pSect, const char *pKey, const char *pBuf, bool bWarnIfNotfound=true)