diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-09-08 18:08:29 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-09-08 18:08:29 +0200 |
commit | 8c43857b739566be1e59d61aec192ef63e77cbb1 (patch) | |
tree | 7b69b805537c776fd7620cf5cba539e32f01fef5 /iniFile | |
parent | Relaxed the check for held item, the client sometimes sends wrong ItemType. (diff) | |
download | cuberite-8c43857b739566be1e59d61aec192ef63e77cbb1.tar cuberite-8c43857b739566be1e59d61aec192ef63e77cbb1.tar.gz cuberite-8c43857b739566be1e59d61aec192ef63e77cbb1.tar.bz2 cuberite-8c43857b739566be1e59d61aec192ef63e77cbb1.tar.lz cuberite-8c43857b739566be1e59d61aec192ef63e77cbb1.tar.xz cuberite-8c43857b739566be1e59d61aec192ef63e77cbb1.tar.zst cuberite-8c43857b739566be1e59d61aec192ef63e77cbb1.zip |
Diffstat (limited to 'iniFile')
-rw-r--r-- | iniFile/iniFile.cpp | 147 |
1 files changed, 88 insertions, 59 deletions
diff --git a/iniFile/iniFile.cpp b/iniFile/iniFile.cpp index 530c05178..76f71284f 100644 --- a/iniFile/iniFile.cpp +++ b/iniFile/iniFile.cpp @@ -52,68 +52,97 @@ cIniFile::cIniFile( const string iniPath) bool cIniFile::ReadFile() { - // Normally you would use ifstream, but the SGI CC compiler has - // a few bugs with ifstream. So ... fstream used. - fstream f; - string line; - string keyname, valuename, value; - string::size_type pLeft, pRight; - - f.open( (FILE_IO_PREFIX + path).c_str(), ios::in); - if ( f.fail()) - return false; + // Normally you would use ifstream, but the SGI CC compiler has + // a few bugs with ifstream. So ... fstream used. + fstream f; + string line; + string keyname, valuename, value; + string::size_type pLeft, pRight; + + f.open( (FILE_IO_PREFIX + path).c_str(), ios::in); + if ( f.fail()) + return false; + + while (getline( f, line)) + { + // To be compatible with Win32, check for existence of '\r'. + // Win32 files have the '\r' and Unix files don't at the end of a line. + // Note that the '\r' will be written to INI files from + // Unix so that the created INI file can be read under Win32 + // without change. + unsigned int lineLength = line.length(); + if (lineLength == 0) + { + continue; + } + if ( line[lineLength - 1] == '\r') + { + line = line.substr( 0, lineLength - 1); + } + + if (line.length() == 0) + { + continue; + } + + // Check that the user hasn't opened a binary file by checking the first + // character of each line! + if ( !isprint( line[0])) + { + printf( "Failing on char %d\n", line[0]); + f.close(); + return false; + } + if (( pLeft = line.find_first_of(";#[=")) == string::npos) + { + continue; + } + + switch ( line[pLeft]) + { + case '[': + { + if ( + ((pRight = line.find_last_of("]")) != string::npos) && + (pRight > pLeft) + ) + { + keyname = line.substr( pLeft + 1, pRight - pLeft - 1); + AddKeyName( keyname); + } + break; + } + + case '=': + { + valuename = line.substr( 0, pLeft); + value = line.substr( pLeft + 1); + SetValue( keyname, valuename, value); + break; + } + + case ';': + case '#': + { + if (names.size() == 0) + { + HeaderComment( line.substr( pLeft + 1)); + } + else + { + KeyComment( keyname, line.substr( pLeft + 1)); + } + break; + } + } // switch (line[pLeft]) + } // while (getline()) - while( getline( f, line)) { - // To be compatible with Win32, check for existence of '\r'. - // Win32 files have the '\r' and Unix files don't at the end of a line. - // Note that the '\r' will be written to INI files from - // Unix so that the created INI file can be read under Win32 - // without change. - unsigned int lineLength = line.length(); - if(lineLength == 0) continue; - if ( line[lineLength - 1] == '\r') - line = line.substr( 0, lineLength - 1); - - if ( line.length()) { - // Check that the user hasn't opened a binary file by checking the first - // character of each line! - if ( !isprint( line[0])) { - printf( "Failing on char %d\n", line[0]); f.close(); - return false; - } - if (( pLeft = line.find_first_of(";#[=")) != string::npos) { - switch ( line[pLeft]) { - case '[': - if ((pRight = line.find_last_of("]")) != string::npos && - pRight > pLeft) { - keyname = line.substr( pLeft + 1, pRight - pLeft - 1); - AddKeyName( keyname); - } - break; - - case '=': - valuename = line.substr( 0, pLeft); - value = line.substr( pLeft + 1); - SetValue( keyname, valuename, value); - break; - - case ';': - case '#': - if ( !names.size()) - HeaderComment( line.substr( pLeft + 1)); - else - KeyComment( keyname, line.substr( pLeft + 1)); - break; + if (names.size() > 0) + { + return true; } - } - } - } - - f.close(); - if ( names.size()) - return true; - return false; + return false; } |