21 int util_ignore(
int iSize,
char cDelimiter, FILE* hFileHandle)
24 for(
int i = 0; i < iSize; i++)
26 cChar = fgetc(hFileHandle);
29 if(cChar == cDelimiter)
40 cChar = fgetc(hFileHandle);
43 if(cChar !=
' ' && cChar !=
'"' && cChar !=
'\t')
45 ungetc(cChar, hFileHandle);
55 fgets(acReturnString, iSize, hFileHandle);
56 for(
int i = 0; i < iSize; i++)
58 cChar = acReturnString[i];
59 if(cChar ==
' ' || cChar ==
'"' || cChar ==
'#' || cChar ==
';' || cChar ==
'\t' || cChar ==
'\r' || cChar ==
'\n' || cChar ==
'\0')
61 acReturnString[i] =
'\0';
74 iSectionLength = strlen(acSectionName);
77 cChar = fgetc(hFileHandle);
80 else if(cChar ==
'#' || cChar ==
';')
88 fgets(acBuffer, iSectionLength+1, hFileHandle);
90 if(strncmp(acBuffer, acSectionName, iSectionLength) == 0)
92 cChar = fgetc(hFileHandle);
107 int iKeyLength, iBufferLength;
110 iKeyLength = strlen(acKeyName);
113 cChar = fgetc(hFileHandle);
116 else if(cChar ==
'[')
118 ungetc(cChar, hFileHandle);
121 else if(cChar ==
'#' || cChar ==
';')
127 else if(cChar !=
' ' && cChar !=
'\t' && cChar !=
'\r' && cChar !=
'\n')
131 fgets(acBuffer + 1, iKeyLength, hFileHandle);
133 iBufferLength = strlen(acBuffer);
134 if(iBufferLength > iKeyLength || (iBufferLength == iKeyLength && acBuffer[iBufferLength - 1] !=
'\n'))
136 if(strncmp(acBuffer, acKeyName, iKeyLength) == 0)
139 cChar = fgetc(hFileHandle);
158 int util_searchString(
const char* acSectionName,
const char* acKeyName,
const char* acDefaultString,
char* acReturnString,
int iSize,
const char* acFileName)
160 FILE* hFileHandle = fopen( acFileName,
"r" );
163 strncpy(acReturnString, acDefaultString, iSize);
169 strncpy(acReturnString, acDefaultString, iSize);
175 strncpy(acReturnString, acDefaultString, iSize);
181 return strlen(acReturnString);
186 int iRetVal = fseek(hFileHandle,0,SEEK_CUR);
192 iRetVal = fprintf(hFileHandle,
"\n\n[%s]", acSectionName);
193 if(iRetVal == strlen(acSectionName) + 4)
196 fseek(hFileHandle,0,SEEK_CUR);
208 int iRetVal = fseek(hFileHandle,0,SEEK_CUR);
214 iRetVal = fprintf(hFileHandle,
"\n%s = ", acKeyName);
215 if(iRetVal == strlen(acKeyName) + 4)
218 fseek(hFileHandle,0,SEEK_CUR);
228 int util_setString(
const char* acSectionName,
const char* acKeyName,
const char* acString,
const char* acFileName)
232 char* acBuffer = NULL;
233 FILE* hFileHandle = fopen( acFileName,
"r+" );
236 hFileHandle = fopen( acFileName,
"w+" );
260 iRetVal = fgetpos(hFileHandle, &fposRest);
270 #if defined(__LINUX__) 275 iRetVal = fsetpos(hFileHandle, &fposRest);
282 cChar = fgetc(hFileHandle);
285 #if defined(__LINUX__) 290 iRetVal = fsetpos(hFileHandle, &fposRest);
303 cChar = fgetc(hFileHandle);
308 iRetVal = fgetpos(hFileHandle, &fposEnd);
315 #if defined(__LINUX__) 316 iLength = fposEnd.__pos - fposRest.__pos;
318 iLength = fposEnd - fposRest;
322 acBuffer =
new char[iLength];
325 iRetVal = fsetpos(hFileHandle, &fposRest);
335 iLength = fread(acBuffer,
sizeof(
char), iLength, hFileHandle);
344 acBuffer[iLength] =
'\0';
347 iRetVal = fsetpos(hFileHandle, &fposRest);
364 iRetVal = fprintf(hFileHandle,
"%s", acString);
365 if(iRetVal != strlen(acString))
377 iLength = fwrite(acBuffer,
sizeof(
char), iLength, hFileHandle);
378 if(iLength != iLength)
394 iRetVal = fgetpos(hFileHandle, &fposString);
406 cChar = fgetc(hFileHandle);
407 if(cChar == EOF || cChar ==
'\n' || cChar ==
';' || cChar ==
'#')
409 ungetc(cChar, hFileHandle);
415 iRetVal = fgetpos(hFileHandle, &fposRest);
425 cChar = fgetc(hFileHandle);
430 iRetVal = fgetpos(hFileHandle, &fposEnd);
433 std::cout <<
"get End pos error" << std::endl;
437 #if defined(__LINUX__) 438 iLength = fposEnd.__pos - fposRest.__pos;
440 iLength = fposEnd - fposRest;
444 acBuffer =
new char[iLength];
447 iRetVal = fsetpos(hFileHandle, &fposRest);
457 iLength = fread(acBuffer,
sizeof(
char), iLength, hFileHandle);
466 acBuffer[iLength] =
'\0';
469 iRetVal = fsetpos(hFileHandle, &fposString);
479 iRetVal = fprintf(hFileHandle,
"%s ", acString);
480 iErase -= strlen(acString) + 1;
481 if(iRetVal != strlen(acString) + 1)
494 iLength = fwrite(acBuffer,
sizeof(
char), iLength, hFileHandle);
495 if(iLength != iLength)
504 for(
int i = 0; i < iErase; i++)
506 cChar = fputc(
'\0', hFileHandle);
571 int util_posArgForKey(
585 if(cL ==
'#' || cL ==
';')
586 in.ignore(0x7FFF,
'\n');
592 in.get(buf+1, strlen(key),
'\n');
594 if(strncmp(buf, key, strlen(key)) == 0)
631 void util_parseError(
641 std::cerr <<
"\nread(in) parse error : '=' expected behind";
644 std::cerr <<
" " << number;
648 std::cerr <<
"\nread(in) parse error : '";
651 std::cerr <<
" " << number;
652 std::cerr <<
"' expected !";
655 std::cerr <<
"\nread(in) parse error : premature EOF '";
658 std::cerr <<
" " << number;
659 std::cerr <<
"' expected !";
662 std::cerr <<
"\nread(in) parse error : '[' expected before";
665 std::cerr <<
" " << number;
666 std::cerr <<
" argument !";
669 std::cerr <<
"\nread(in) parse error : ', ' expected ";
670 std::cerr <<
" between components of " << key;
672 std::cerr <<
" " << number;
673 std::cerr <<
" argument !";
676 std::cerr <<
"\nread(in) parse error : ']' expected behind";
679 std::cerr <<
" " << number;
680 std::cerr <<
" argument !";
683 std::cerr <<
"\nread(in) : unknown error !?!?!?!?!?!?!?!?!";
701 void util_posArgForKeyWithCheck(
709 status = util_posArgForKey(in, key, number, delim);
712 util_parseError(status, key);
const int KEY_BUT_NO_EQUAL
const int NO_CLOSED_BRACKET
int util_getStringCutWhiteSpace(char *acReturnString, int iSize, FILE *hFileHandle)
int util_skipWhiteSpace(FILE *hFileHandle)
int util_searchKey(const char *acKeyName, FILE *hFileHandle)
const int KEY_BUT_WRONG_NUMBER
int util_setString(const char *acSectionName, const char *acKeyName, const char *acString, const char *acFileName)
int util_searchSection(const char *acSectionName, FILE *hFileHandle)
int util_searchString(const char *acSectionName, const char *acKeyName, const char *acDefaultString, char *acReturnString, int iSize, const char *acFileName)
int util_setSection(const char *acSectionName, FILE *hFileHandle)
int util_setKey(const char *acKeyName, FILE *hFileHandle)
int util_ignore(int iSize, char cDelimiter, FILE *hFileHandle)
const int NO_OPEN_BRACKET