diff --git a/src/ATCDCL/ATCVoice.cxx b/src/ATCDCL/ATCVoice.cxx index 05f24daac..46ab81df7 100644 --- a/src/ATCDCL/ATCVoice.cxx +++ b/src/ATCDCL/ATCVoice.cxx @@ -29,6 +29,9 @@ #include #include #include +#include + +#include #include #include @@ -38,6 +41,14 @@ #include
+#include + +#ifdef _MSC_VER +#define strtok_r strtok_s +#endif + +using namespace std; + FGATCVoice::FGATCVoice() { SoundData = 0; rawSoundData = 0; @@ -135,13 +146,13 @@ string FGATCVoice::WriteMessage(const char* message, bool& dataOK) { // TODO - at the moment we're effectively taking 3 passes through the data. // There is no need for this - 2 should be sufficient - we can probably ditch the tokenList. size_t n1 = 1+strlen(message); - char msg[n1]; - strncpy(msg, message, n1); // strtok requires a non-const char* + boost::shared_array msg(new char[n1]); + strncpy(msg.get(), message, n1); // strtok requires a non-const char* char* token; int numWords = 0; const char delimiters[] = " \t.,;:\"\n"; char* context; - token = strtok_r(msg, delimiters, &context); + token = strtok_r(msg.get(), delimiters, &context); while(token != NULL) { for (char *t = token; *t; t++) { *t = tolower(*t); // canonicalize the case, to @@ -154,8 +165,8 @@ string FGATCVoice::WriteMessage(const char* message, bool& dataOK) { token = strtok_r(NULL, delimiters, &context); } - WordData wdptr[numWords]; - int word = 0; + vector wdptr; + wdptr.reserve(numWords); unsigned int cumLength = 0; tokenListItr = tokenList.begin(); @@ -165,21 +176,19 @@ string FGATCVoice::WriteMessage(const char* message, bool& dataOK) { SG_LOG(SG_ATC, SG_ALERT, "voice synth: word '" << *tokenListItr << "' not found"); } else { - wdptr[word] = wordMap[*tokenListItr]; - cumLength += wdptr[word].length; - //cout << *tokenListItr << " found at offset " << wdptr[word].offset << " with length " << wdptr[word].length << endl; - word++; + wdptr.push_back(wordMap[*tokenListItr]); + cumLength += wdptr.back().length; } ++tokenListItr; } - + const size_t word = wdptr.size(); + // Check for no tokens found else slScheduler can be crashed if(!word) { dataOK = false; return ""; } - - char tmpbuf[cumLength]; + boost::shared_array tmpbuf(new char[cumLength]); unsigned int bufpos = 0; for(int i=0; i cumLength) offsetIn = cumLength; - string front(tmpbuf, offsetIn); - string back(tmpbuf+offsetIn, cumLength - offsetIn); + string front(tmpbuf.get(), offsetIn); + string back(tmpbuf.get() + offsetIn, cumLength - offsetIn); dataOK = true; return back + front; diff --git a/src/ATCDCL/atis.cxx b/src/ATCDCL/atis.cxx index e05556977..82f2a8f97 100644 --- a/src/ATCDCL/atis.cxx +++ b/src/ATCDCL/atis.cxx @@ -285,7 +285,7 @@ int FGATIS::GenTransmission(const int regen, const int special) { transmission += " light_and_variable"; } else { // FIXME: get gust factor in somehow - snprintf(buf, bs, "%03.0f", 5*round(wind_dir/5)); + snprintf(buf, bs, "%03.0f", 5*SGMiscd::round(wind_dir/5)); transmission += ConvertNumToSpokenDigits(buf); snprintf(buf, bs, "%1.0f", wind_speed); @@ -314,7 +314,7 @@ int FGATIS::GenTransmission(const int regen, const int special) { } else { transmission += " "; } - int cig00 = int(round(ceiling/100)); // hundreds of feet + int cig00 = int(SGMiscd::round(ceiling/100)); // hundreds of feet if (cig00) { int cig000 = cig00/10; cig00 -= cig000*10; // just the hundreds digit @@ -337,7 +337,7 @@ int FGATIS::GenTransmission(const int regen, const int special) { transmission += "Temperature: "; double Tsl = fgGetDouble("/environment/temperature-sea-level-degc"); - int temp = int(round(FGAtmo().fake_T_vs_a_us(_geod.getElevationFt(), Tsl))); + int temp = int(SGMiscd::round(FGAtmo().fake_T_vs_a_us(_geod.getElevationFt(), Tsl))); if(temp < 0) { transmission += "minus "; } @@ -345,7 +345,7 @@ int FGATIS::GenTransmission(const int regen, const int special) { transmission += ConvertNumToSpokenDigits(buf); transmission += " dewpoint "; double dpsl = fgGetDouble("/environment/dewpoint-sea-level-degc"); - temp = int(round(FGAtmo().fake_dp_vs_a_us(dpsl, _geod.getElevationFt()))); + temp = int(SGMiscd::round(FGAtmo().fake_dp_vs_a_us(dpsl, _geod.getElevationFt()))); if(temp < 0) { transmission += "minus "; }