]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/transmissionlist.cxx
Ima Sudonim:
[flightgear.git] / src / ATC / transmissionlist.cxx
index 7f5b09f62c673ff7238e17b799244e73e5e277e4..97eee3c01fa9ea3f85b9f452fcf88b0c71a14f1a 100644 (file)
@@ -3,7 +3,7 @@
 // Written by Alexander Kappes, started March 2002.
 // Based on navlist.cxx by Curtis Olson, started April 2000.
 //
-// Copyright (C) 2000  Curtis L. Olson - curt@flightgear.org
+// Copyright (C) 2000  Curtis L. Olson - http://www.flightgear.org/~curt
 //
 // This program is free software; you can redistribute it and/or
 // modify it under the terms of the GNU General Public License as
@@ -89,21 +89,24 @@ bool FGTransmissionList::init( SGPath path ) {
 
     while ( ! in.eof() ) {
         in >> a;
-       transmissionlist_station[a.get_station()].push_back(a);
-       
+        transmissionlist_station[a.get_station()].push_back(a);
+
         in >> skipcomment;
 
-       if ( a.get_station() < min ) {
-         min = a.get_station();
-       }
-       if ( a.get_station() > max ) {
-         max = a.get_station();
-       }
-       cout << a.get_station() << " " << a.get_code().c1 << " " << a.get_code().c2 << " "
-            << a.get_code().c3 << " " << a.get_transtext() 
-            << " " << a.get_menutext() << endl;
+        if ( a.get_station() < min ) {
+            min = a.get_station();
+        }
+        if ( a.get_station() > max ) {
+            max = a.get_station();
+        }
+
+        /*
+        cout << a.get_station() << " " << a.get_code().c1 << " " << a.get_code().c2 << " "
+             << a.get_code().c3 << " " << a.get_transtext() 
+             << " " << a.get_menutext() << endl;
+        */
     }
-    
 #endif
 
     // init ATC menu
@@ -114,7 +117,7 @@ bool FGTransmissionList::init( SGPath path ) {
 
 // query the database for the specified station type; 
 // for station see FlightGear/ATC/default.transmissions
-bool FGTransmissionList::query_station( const int &station, FGTransmission *t,
+bool FGTransmissionList::query_station( const atc_type &station, FGTransmission *t,
                                        int max_trans, int &num_trans ) 
 {
   transmission_list_type     tmissions = transmissionlist_station[station];
@@ -139,10 +142,10 @@ bool FGTransmissionList::query_station( const int &station, FGTransmission *t,
   }
 }
 
-string FGTransmissionList::gen_text(const int &station, const TransCode code, 
+string FGTransmissionList::gen_text(const atc_type &station, const TransCode code, 
                                     const TransPar &tpars, const bool ttext )
 {
-       const int cmax = 100;
+       const int cmax = 300;
        string message;
        char tag[4];
        char crej = '@';
@@ -161,15 +164,17 @@ string FGTransmissionList::gen_text(const int &station, const TransCode code,
        for ( ; current != last ; ++current ) {
                if ( current->get_code().c1 == code.c1 &&  
                        current->get_code().c2 == code.c2 &&
-               current->get_code().c3 == code.c3 ) {
+                   current->get_code().c3 == code.c3 ) {
                        
                        if ( ttext ) message = current->get_transtext();
                        else message = current->get_menutext();
                        strcpy( &mes[0], message.c_str() ); 
                        
-                       while ( strchr(&mes[0], crej) != NULL  ) {
+                       // Replace all the '@' parameters with the actual text.
+                       int check = 0;  // If mes gets overflowed the while loop can go infinite
+                       while ( strchr(&mes[0], crej) != NULL  ) {      // ie. loop until no more occurances of crej ('@') found
                                pos = strchr( &mes[0], crej );
-                               bcopy(pos, &tag[0], 3);
+                               memmove(&tag[0], pos, 3);
                                tag[3] = '\0';
                                int i;
                                len = 0;
@@ -240,6 +245,12 @@ string FGTransmissionList::gen_text(const int &station, const TransCode code,
                                }
                                strcat( &dum[0], &mes[len+3] );
                                strcpy( &mes[0], &dum[0] );
+                               
+                               ++check;
+                               if(check > 10) {
+                                       SG_LOG(SG_ATC, SG_WARN, "WARNING: Possibly endless loop terminated in FGTransmissionlist::gen_text(...)"); 
+                                       break;
+                               }
                        }
                        
                        //cout << mes  << endl;