Trying to fix ascii file parsing and line terminator handling.
This commit is contained in:
parent
aea664cd15
commit
69a4aa083d
1 changed files with 39 additions and 27 deletions
|
@ -463,7 +463,7 @@ parse_wp( const string& arg ) {
|
||||||
string id, alt_str;
|
string id, alt_str;
|
||||||
double alt = 0.0;
|
double alt = 0.0;
|
||||||
|
|
||||||
int pos = arg.find( "@" );
|
unsigned int pos = arg.find( "@" );
|
||||||
if ( pos != string::npos ) {
|
if ( pos != string::npos ) {
|
||||||
id = arg.substr( 0, pos );
|
id = arg.substr( 0, pos );
|
||||||
alt_str = arg.substr( pos + 1 );
|
alt_str = arg.substr( pos + 1 );
|
||||||
|
@ -492,20 +492,25 @@ parse_wp( const string& arg ) {
|
||||||
static bool
|
static bool
|
||||||
parse_flightplan(const string& arg)
|
parse_flightplan(const string& arg)
|
||||||
{
|
{
|
||||||
sg_gzifstream infile(arg.c_str());
|
sg_gzifstream in(arg.c_str());
|
||||||
if ( !infile.is_open() ) {
|
if ( !in.is_open() ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
while ( true ) {
|
while ( true ) {
|
||||||
string line;
|
string line;
|
||||||
#ifdef GETLINE_NEEDS_TERMINATOR
|
|
||||||
getline( infile, line, '\n' );
|
#if defined( macintosh )
|
||||||
#elif defined( macintosh )
|
getline( in, line, '\r' );
|
||||||
getline( infile, line, '\r' );
|
|
||||||
#else
|
#else
|
||||||
getline( infile, line );
|
getline( in, line, '\n' );
|
||||||
#endif
|
#endif
|
||||||
if ( infile.eof() ) {
|
|
||||||
|
// catch extraneous (DOS) line ending character
|
||||||
|
if ( line[line.length() - 1] < 32 ) {
|
||||||
|
line = line.substr( 0, line.length()-1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( in.eof() ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
parse_wp(line);
|
parse_wp(line);
|
||||||
|
@ -804,9 +809,9 @@ parse_option (const string& arg)
|
||||||
#endif
|
#endif
|
||||||
} else if ( arg.find( "--prop:" ) == 0 ) {
|
} else if ( arg.find( "--prop:" ) == 0 ) {
|
||||||
string assign = arg.substr(7);
|
string assign = arg.substr(7);
|
||||||
int pos = assign.find('=');
|
unsigned int pos = assign.find('=');
|
||||||
if (pos == arg.npos || pos == 0) {
|
if ( pos == arg.npos || pos == 0 ) {
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg);
|
SG_LOG( SG_GENERAL, SG_ALERT, "Bad property assignment: " << arg );
|
||||||
return FG_OPTIONS_ERROR;
|
return FG_OPTIONS_ERROR;
|
||||||
}
|
}
|
||||||
string name = assign.substr(0, pos);
|
string name = assign.substr(0, pos);
|
||||||
|
@ -841,9 +846,9 @@ parse_option (const string& arg)
|
||||||
fgSetDouble("/environment/visibility", visibility);
|
fgSetDouble("/environment/visibility", visibility);
|
||||||
} else if ( arg.find( "--wind=" ) == 0 ) {
|
} else if ( arg.find( "--wind=" ) == 0 ) {
|
||||||
string val = arg.substr(7);
|
string val = arg.substr(7);
|
||||||
int pos = val.find('@');
|
unsigned int pos = val.find('@');
|
||||||
if (pos == string::npos) {
|
if ( pos == string::npos ) {
|
||||||
SG_LOG(SG_GENERAL, SG_ALERT, "bad wind value " << val);
|
SG_LOG( SG_GENERAL, SG_ALERT, "bad wind value " << val );
|
||||||
return FG_OPTIONS_ERROR;
|
return FG_OPTIONS_ERROR;
|
||||||
}
|
}
|
||||||
double dir = atof(val.substr(0,pos).c_str());
|
double dir = atof(val.substr(0,pos).c_str());
|
||||||
|
@ -924,14 +929,17 @@ fgScanForRoot (const string& path)
|
||||||
#endif
|
#endif
|
||||||
string line;
|
string line;
|
||||||
|
|
||||||
#ifdef GETLINE_NEEDS_TERMINATOR
|
#if defined( macintosh )
|
||||||
getline( in, line, '\n' );
|
|
||||||
#elif defined( macintosh )
|
|
||||||
getline( in, line, '\r' );
|
getline( in, line, '\r' );
|
||||||
#else
|
#else
|
||||||
getline( in, line );
|
getline( in, line, '\n' );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// catch extraneous (DOS) line ending character
|
||||||
|
if ( line[line.length() - 1] < 32 ) {
|
||||||
|
line = line.substr( 0, line.length()-1 );
|
||||||
|
}
|
||||||
|
|
||||||
if ( line.find( "--fg-root=" ) == 0 ) {
|
if ( line.find( "--fg-root=" ) == 0 ) {
|
||||||
return line.substr( 10 );
|
return line.substr( 10 );
|
||||||
}
|
}
|
||||||
|
@ -969,8 +977,9 @@ fgParseOptions (int argc, char **argv) {
|
||||||
void
|
void
|
||||||
fgParseOptions (const string& path) {
|
fgParseOptions (const string& path) {
|
||||||
sg_gzifstream in( path );
|
sg_gzifstream in( path );
|
||||||
if ( !in.is_open() )
|
if ( !in.is_open() ) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path );
|
SG_LOG( SG_GENERAL, SG_INFO, "Processing config file: " << path );
|
||||||
|
|
||||||
|
@ -984,14 +993,17 @@ fgParseOptions (const string& path) {
|
||||||
#endif
|
#endif
|
||||||
string line;
|
string line;
|
||||||
|
|
||||||
#ifdef GETLINE_NEEDS_TERMINATOR
|
#if defined( macintosh )
|
||||||
getline( in, line, '\n' );
|
|
||||||
#elif defined( macintosh )
|
|
||||||
getline( in, line, '\r' );
|
getline( in, line, '\r' );
|
||||||
#else
|
#else
|
||||||
getline( in, line );
|
getline( in, line, '\n' );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// catch extraneous (DOS) line ending character
|
||||||
|
if ( line[line.length() - 1] < 32 ) {
|
||||||
|
line = line.substr( 0, line.length()-1 );
|
||||||
|
}
|
||||||
|
|
||||||
if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
|
if ( parse_option( line ) == FG_OPTIONS_ERROR ) {
|
||||||
SG_LOG( SG_GENERAL, SG_ALERT,
|
SG_LOG( SG_GENERAL, SG_ALERT,
|
||||||
"Config file parse error: " << path << " '"
|
"Config file parse error: " << path << " '"
|
||||||
|
|
Loading…
Add table
Reference in a new issue