X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FFDM%2FJSBSim%2FFGConfigFile.cpp;h=8930caafd0af459284e5f093cc75a13cdc418ced;hb=95440173caef3ce92ee7308fd58a24dabe4c5f8a;hp=42fbe6a32c458ed657b1c21113f1cd99af0d4a82;hpb=6bc2f595728571329c094a5a7904e920f325f940;p=flightgear.git diff --git a/src/FDM/JSBSim/FGConfigFile.cpp b/src/FDM/JSBSim/FGConfigFile.cpp index 42fbe6a32..8930caafd 100644 --- a/src/FDM/JSBSim/FGConfigFile.cpp +++ b/src/FDM/JSBSim/FGConfigFile.cpp @@ -21,6 +21,8 @@ INCLUDES #include #include +namespace JSBSim { + static const char *IdSrc = "$Id$"; static const char *IdHdr = ID_CONFIGFILE; @@ -30,7 +32,7 @@ CLASS IMPLEMENTATION FGConfigFile::FGConfigFile(string cfgFileName) { -#if defined ( sgi ) && !defined( __GNUC__ ) +#if defined ( sgi ) && !defined( __GNUC__ ) && (_COMPILER_VERSION < 740) cfgfile.open(cfgFileName.c_str(), ios::in ); #else cfgfile.open(cfgFileName.c_str(), ios::in | ios::binary ); @@ -38,14 +40,14 @@ FGConfigFile::FGConfigFile(string cfgFileName) CommentsOn = false; CurrentIndex = 0; Opened = true; -#if defined ( sgi ) && !defined( __GNUC__ ) +#if defined ( sgi ) && !defined( __GNUC__ ) && (_COMPILER_VERSION < 740) if (!cfgfile.fail() && !cfgfile.eof()) GetNextConfigLine(); #else if (cfgfile.is_open()) GetNextConfigLine(); #endif else Opened = false; - if (debug_lvl & 2) cout << "Instantiated: FGConfigFile" << endl; + Debug(0); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -53,60 +55,78 @@ FGConfigFile::FGConfigFile(string cfgFileName) FGConfigFile::~FGConfigFile() { cfgfile.close(); - if (debug_lvl & 2) cout << "Destroyed: FGConfigFile" << endl; + Debug(1); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% string FGConfigFile::GetNextConfigLine(void) { - int deblank; + int comment_starts_at; + int comment_ends_at; + int comment_length; + int line_length; + bool start_comment, end_comment; + string CommentStringTemp; do { CurrentLine = GetLine(); - if (CurrentLine.find(""); + + if (comment_ends_at >= 0) end_comment = true; + else end_comment = false; + + if (!start_comment && !end_comment) { // command comment + if (CommentsOn) CommentStringTemp = CurrentLine; + CommentString += CommentStringTemp + "\r\n"; + } else if (start_comment && comment_ends_at > comment_starts_at) { // + CommentsOn = false; + comment_length = comment_ends_at + 2 - comment_starts_at + 1; + LineComment = CurrentLine.substr(comment_starts_at+4, comment_length-4-3); + CurrentLine.erase(comment_starts_at, comment_length); + if (CurrentLine.find_first_not_of(" ") == string::npos) { + CurrentLine.erase(); + } + } else if ( start_comment && !end_comment) { // ") != CurrentLine.npos) { + comment_length = line_length - comment_starts_at; + CommentStringTemp = CurrentLine.substr(comment_starts_at+4, comment_length-4); + CommentString = CommentStringTemp + "\r\n"; + CurrentLine.erase(comment_starts_at, comment_length); + } else if (!start_comment && end_comment) { // ... --> CommentsOn = false; - - if (CurrentLine.find("-->") != CurrentLine.npos) - CurrentLine.erase(CurrentLine.find("-->"),4); - - while((deblank = CurrentLine.find(" ")) != CurrentLine.npos) CurrentLine.erase(deblank,1); - if (CurrentLine.size() <= 2) CurrentLine = ""; - - CommentString += CurrentLine; - GetNextConfigLine(); + comment_length = comment_ends_at + 2 + 1; + CommentStringTemp = CurrentLine.substr(0, comment_length-4); + CommentString += CommentStringTemp + "\r\n"; + CurrentLine.erase(0, comment_length); + } else if (start_comment && comment_ends_at < comment_starts_at) { // --> command