MSVC fixes for atis merge.
Avoid dynamic arrays such as char msg[len]; they are a gcc-ism.
This commit is contained in:
parent
14a09673b9
commit
179186e414
2 changed files with 28 additions and 19 deletions
|
@ -29,6 +29,9 @@
|
|||
#include <ctype.h>
|
||||
#include <fstream>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/shared_array.hpp>
|
||||
|
||||
#include <simgear/misc/sg_path.hxx>
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
|
@ -38,6 +41,14 @@
|
|||
|
||||
#include <Main/globals.hxx>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#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<char> 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<WordData> 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<char> tmpbuf(new char[cumLength]);
|
||||
unsigned int bufpos = 0;
|
||||
for(int i=0; i<word; ++i) {
|
||||
/*
|
||||
|
@ -196,7 +205,7 @@ string FGATCVoice::WriteMessage(const char* message, bool& dataOK) {
|
|||
dataOK = false;
|
||||
return "";
|
||||
}
|
||||
memcpy(tmpbuf + bufpos, rawSoundData + wdptr[i].offset, wdptr[i].length);
|
||||
memcpy(tmpbuf.get() + bufpos, rawSoundData + wdptr[i].offset, wdptr[i].length);
|
||||
bufpos += wdptr[i].length;
|
||||
}
|
||||
|
||||
|
@ -204,8 +213,8 @@ string FGATCVoice::WriteMessage(const char* message, bool& dataOK) {
|
|||
unsigned int offsetIn = (int)(cumLength * sg_random());
|
||||
if(offsetIn > 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;
|
||||
|
|
|
@ -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 ";
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue