]> git.mxchange.org Git - flightgear.git/blobdiff - src/Airports/apt_loader.cxx
Don't restore initial screen geometry because there is nothing in fg_os* to resize...
[flightgear.git] / src / Airports / apt_loader.cxx
index 8de4822a0788c858d94ad319044f9833d808efdb..0c62ea31dd214f50a3f9a52e816441a0c6fbb412 100644 (file)
@@ -17,7 +17,7 @@
 //
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 // $Id$
 
@@ -29,6 +29,8 @@
 #include <simgear/compiler.h>
 
 #include <stdlib.h> // atof(), atoi()
+#include <string.h> // memchr()
+#include <ctype.h> // isspace()
 
 #include <simgear/constants.h>
 #include <simgear/debug/logstream.hxx>
@@ -66,8 +68,11 @@ bool fgAirportDBLoad( FGAirportList *airports, FGRunwayList *runways,
     string last_apt_info = "";
     string last_apt_type = "";
     string line;
-    char tmp[2048];
+    char tmp[2049];
+    tmp[2048] = 0;
 
+    unsigned int line_id = 0;
+    unsigned int line_num = 0;
     double rwy_lon_accum = 0.0;
     double rwy_lat_accum = 0.0;
     int rwy_count = 0;
@@ -75,34 +80,40 @@ bool fgAirportDBLoad( FGAirportList *airports, FGRunwayList *runways,
     while ( ! in.eof() ) {
        in.getline(tmp, 2048);
        line = tmp;
-       SG_LOG( SG_GENERAL, SG_BULK, "-> '" << line << "'" );
-        if ( line.length() ) {
-            token = simgear::strutils::split( line );
-            if ( token.size() ) {
-                SG_LOG( SG_GENERAL, SG_BULK, "token[0] " << token[0] );
-            }
-        } else {
-            token.clear();
+        line_num++;
+
+        SG_LOG( SG_GENERAL, SG_BULK, "#" << line_num << " '" << line << "'" );
+        if ( !line.size() || isspace(tmp[0]))
+            continue;
+
+        if (line.size() >= 3) {
+            char *p = (char *)memchr(tmp, ' ', 3);
+            if ( p )
+                *p = 0;
         }
 
-        if ( !line.length() || !token.size() ) {
-            // empty line, skip
-        } else if ( (token[0] == "#") || (token[0] == "//") ) {
-           // comment, skip
-        } else if ( token[0] == "I" ) {
+        line_id = atoi(tmp);
+        if ( tmp[0] == 'I' ) {
             // First line, indicates IBM (i.e. DOS line endings I
             // believe.)
 
             // move past this line and read and discard the next line
             // which is the version and copyright information
             in.getline(tmp, 2048);
-            vector<string> vers_token = simgear::strutils::split( tmp );
+            // vector<string> vers_token = simgear::strutils::split( tmp );
+            if ( strlen(tmp) > 4 ) {
+               char *p = (char *)memchr(tmp, ' ', 4);
+               if ( p )
+                  *p = 0;
+            }
             SG_LOG( SG_GENERAL, SG_INFO, "Data file version = "
-                    << vers_token[0] );
-       } else if ( token[0] == "1" /* Airport */ ||
-                    token[0] == "16" /* Seaplane base */ ||
-                    token[0] == "17" /* Heliport */ ) {
+                    << tmp );
+       } else if ( line_id == 1 /* Airport */ ||
+                    line_id == 16 /* Seaplane base */ ||
+                    line_id == 17 /* Heliport */ ) {
 
+            token.clear();
+            token = simgear::strutils::split(line);
             string id = token[4];
             double elev = atof( token[1].c_str() );
             SG_LOG( SG_GENERAL, SG_BULK, "Next airport = " << id << " "
@@ -141,7 +152,10 @@ bool fgAirportDBLoad( FGAirportList *airports, FGRunwayList *runways,
             rwy_lon_accum = 0.0;
             rwy_lat_accum = 0.0;
             rwy_count = 0;
-        } else if ( token[0] == "10" ) {
+        } else if ( line_id == 10 ) {
+            token.clear();
+            token = simgear::strutils::split(line);
+
             // runway entry
             double lat = atof( token[1].c_str() );
             double lon = atof( token[2].c_str() );
@@ -179,24 +193,21 @@ bool fgAirportDBLoad( FGAirportList *airports, FGRunwayList *runways,
                           stopway1, stopway2, lighting_flags, surface_code,
                           shoulder_code, marking_code, smoothness,
                           dist_remaining );
-        } else if ( token[0] == "18" ) {
+        } else if ( line_id == 18 ) {
             // beacon entry (ignore)
-        } else if ( token[0] == "14" ) {
+        } else if ( line_id == 14 ) {
             // control tower entry (ignore)
-        } else if ( token[0] == "19" ) {
+        } else if ( line_id == 19 ) {
             // windsock entry (ignore)
-        } else if ( token[0] == "15" ) {
+        } else if ( line_id == 15 ) {
             // custom startup locations (ignore)
-        } else if ( token[0] == "50" || token[0] == "51" || token[0] == "52" 
-                    || token[0] == "53" || token[0] == "54" || token[0] == "55" 
-                    || token[0] == "56" )
-        {
+        } else if ( line_id >= 50 && line_id <= 56 ) {
             // frequency entries (ignore)
-        } else if ( token[0] == "99" ) {
+        } else if ( line_id == 99 ) {
             SG_LOG( SG_GENERAL, SG_DEBUG, "End of file reached" );
         } else {
             SG_LOG( SG_GENERAL, SG_ALERT, 
-                    "Unknown line in file: " << line );
+                    "Unknown line(#" << line_num << ") in file: " << line );
             exit(-1);
         }
     }
@@ -232,10 +243,8 @@ bool fgAirportDBLoad( FGAirportList *airports, FGRunwayList *runways,
         if ( ident == "#" || ident == "//" ) {
             metar_in >> skipeol;
         } else {
-            const FGAirport &a = airports->search( ident );
-            if ( a.getId() == ident ) {
-                airports->has_metar( ident );
-            }
+            const FGAirport* a = airports->search( ident );
+            if ( a ) airports->has_metar( ident );
         }
     }