1
0
Fork 0

MSVC fixes for atis merge.

Avoid dynamic arrays such as char msg[len]; they are a gcc-ism.
This commit is contained in:
v meazza 2009-09-19 11:02:36 +01:00 committed by Tim Moore
parent 14a09673b9
commit 179186e414
2 changed files with 28 additions and 19 deletions

View file

@ -29,6 +29,9 @@
#include <ctype.h> #include <ctype.h>
#include <fstream> #include <fstream>
#include <list> #include <list>
#include <vector>
#include <boost/shared_array.hpp>
#include <simgear/misc/sg_path.hxx> #include <simgear/misc/sg_path.hxx>
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
@ -38,6 +41,14 @@
#include <Main/globals.hxx> #include <Main/globals.hxx>
#include <stdio.h>
#ifdef _MSC_VER
#define strtok_r strtok_s
#endif
using namespace std;
FGATCVoice::FGATCVoice() { FGATCVoice::FGATCVoice() {
SoundData = 0; SoundData = 0;
rawSoundData = 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. // 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. // There is no need for this - 2 should be sufficient - we can probably ditch the tokenList.
size_t n1 = 1+strlen(message); size_t n1 = 1+strlen(message);
char msg[n1]; boost::shared_array<char> msg(new char[n1]);
strncpy(msg, message, n1); // strtok requires a non-const char* strncpy(msg.get(), message, n1); // strtok requires a non-const char*
char* token; char* token;
int numWords = 0; int numWords = 0;
const char delimiters[] = " \t.,;:\"\n"; const char delimiters[] = " \t.,;:\"\n";
char* context; char* context;
token = strtok_r(msg, delimiters, &context); token = strtok_r(msg.get(), delimiters, &context);
while(token != NULL) { while(token != NULL) {
for (char *t = token; *t; t++) { for (char *t = token; *t; t++) {
*t = tolower(*t); // canonicalize the case, to *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); token = strtok_r(NULL, delimiters, &context);
} }
WordData wdptr[numWords]; vector<WordData> wdptr;
int word = 0; wdptr.reserve(numWords);
unsigned int cumLength = 0; unsigned int cumLength = 0;
tokenListItr = tokenList.begin(); tokenListItr = tokenList.begin();
@ -165,21 +176,19 @@ string FGATCVoice::WriteMessage(const char* message, bool& dataOK) {
SG_LOG(SG_ATC, SG_ALERT, "voice synth: word '" SG_LOG(SG_ATC, SG_ALERT, "voice synth: word '"
<< *tokenListItr << "' not found"); << *tokenListItr << "' not found");
} else { } else {
wdptr[word] = wordMap[*tokenListItr]; wdptr.push_back(wordMap[*tokenListItr]);
cumLength += wdptr[word].length; cumLength += wdptr.back().length;
//cout << *tokenListItr << " found at offset " << wdptr[word].offset << " with length " << wdptr[word].length << endl;
word++;
} }
++tokenListItr; ++tokenListItr;
} }
const size_t word = wdptr.size();
// Check for no tokens found else slScheduler can be crashed // Check for no tokens found else slScheduler can be crashed
if(!word) { if(!word) {
dataOK = false; dataOK = false;
return ""; return "";
} }
boost::shared_array<char> tmpbuf(new char[cumLength]);
char tmpbuf[cumLength];
unsigned int bufpos = 0; unsigned int bufpos = 0;
for(int i=0; i<word; ++i) { for(int i=0; i<word; ++i) {
/* /*
@ -196,7 +205,7 @@ string FGATCVoice::WriteMessage(const char* message, bool& dataOK) {
dataOK = false; dataOK = false;
return ""; 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; bufpos += wdptr[i].length;
} }
@ -204,8 +213,8 @@ string FGATCVoice::WriteMessage(const char* message, bool& dataOK) {
unsigned int offsetIn = (int)(cumLength * sg_random()); unsigned int offsetIn = (int)(cumLength * sg_random());
if(offsetIn > cumLength) offsetIn = cumLength; if(offsetIn > cumLength) offsetIn = cumLength;
string front(tmpbuf, offsetIn); string front(tmpbuf.get(), offsetIn);
string back(tmpbuf+offsetIn, cumLength - offsetIn); string back(tmpbuf.get() + offsetIn, cumLength - offsetIn);
dataOK = true; dataOK = true;
return back + front; return back + front;

View file

@ -285,7 +285,7 @@ int FGATIS::GenTransmission(const int regen, const int special) {
transmission += " light_and_variable"; transmission += " light_and_variable";
} else { } else {
// FIXME: get gust factor in somehow // 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); transmission += ConvertNumToSpokenDigits(buf);
snprintf(buf, bs, "%1.0f", wind_speed); snprintf(buf, bs, "%1.0f", wind_speed);
@ -314,7 +314,7 @@ int FGATIS::GenTransmission(const int regen, const int special) {
} else { } else {
transmission += " "; transmission += " ";
} }
int cig00 = int(round(ceiling/100)); // hundreds of feet int cig00 = int(SGMiscd::round(ceiling/100)); // hundreds of feet
if (cig00) { if (cig00) {
int cig000 = cig00/10; int cig000 = cig00/10;
cig00 -= cig000*10; // just the hundreds digit cig00 -= cig000*10; // just the hundreds digit
@ -337,7 +337,7 @@ int FGATIS::GenTransmission(const int regen, const int special) {
transmission += "Temperature: "; transmission += "Temperature: ";
double Tsl = fgGetDouble("/environment/temperature-sea-level-degc"); 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) { if(temp < 0) {
transmission += "minus "; transmission += "minus ";
} }
@ -345,7 +345,7 @@ int FGATIS::GenTransmission(const int regen, const int special) {
transmission += ConvertNumToSpokenDigits(buf); transmission += ConvertNumToSpokenDigits(buf);
transmission += " dewpoint "; transmission += " dewpoint ";
double dpsl = fgGetDouble("/environment/dewpoint-sea-level-degc"); 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) { if(temp < 0) {
transmission += "minus "; transmission += "minus ";
} }