]> git.mxchange.org Git - simgear.git/blobdiff - simgear/timing/timezone.cxx
Add cloud movement direction and speed
[simgear.git] / simgear / timing / timezone.cxx
index 9bdb7a2f811ab6d11ce8b23c4d03f6f07e3fc00d..aac090a4466dfb4824b2a2e311758be801d012fe 100644 (file)
@@ -21,7 +21,7 @@
 
 /*************************************************************************
  *
- * Timezone is derived from geocoord, and stores the timezone centerpoint,
+ * SGTimeZone is derived from geocoord, and stores the timezone centerpoint,
  * as well as the countrycode and the timezone descriptor. The latter is 
  * used in order to get the local time. 
  *
 #include <stdio.h>
 #include "timezone.h"
 
-Timezone::Timezone(float la, float lo, char* cc, char* desc) :
-    GeoCoord(la, lo)
+SGTimeZone::SGTimeZone(float la, float lo, char* cc, char* desc) :
+    SGGeoCoord(la, lo)
 { 
-    countryCode = strdup(cc);
-    descriptor = strdup(desc);
+    countryCode = cc;
+    descriptor = desc;
 }
 
 /* Build a timezone object from a textline in zone.tab */
-Timezone::Timezone(const char *infoString) :
-    GeoCoord()
+SGTimeZone::SGTimeZone(const char *infoString) :
+    SGGeoCoord()
 {
     int i = 0;
     while (infoString[i] != '\t')
@@ -50,7 +50,7 @@ Timezone::Timezone(const char *infoString) :
     char latlon[128];
     strncpy(buffer, infoString, i);
     buffer[i] = 0;
-    countryCode = strdup(buffer);
+    countryCode = buffer;
     i ++;
     int start = i;
     while (infoString[i] != '\t') {
@@ -62,13 +62,16 @@ Timezone::Timezone(const char *infoString) :
     char sign;
     sign = latlon[0];
     strncpy(buffer, &latlon[1], 2);
+    buffer[2] = 0;
     lat = atof(buffer);
     strncpy(buffer, &latlon[3], 2);
+    buffer[2] = 0;
     lat += (atof(buffer) / 60);
     int nextPos;
     if (strlen(latlon) > 12) {
         nextPos = 7;
         strncpy(buffer, &latlon[5], 2);
+        buffer[2] = 0;
         lat += (atof(buffer) / 3600.0);
     } else {
         nextPos = 5;
@@ -80,6 +83,7 @@ Timezone::Timezone(const char *infoString) :
     sign = latlon[nextPos];
     nextPos++;
     strncpy(buffer, &latlon[nextPos], 3);
+    buffer[3] = 0;
     lon = atof(buffer);
     nextPos += 3;
     strncpy(buffer, &latlon[nextPos], 2);
@@ -89,6 +93,7 @@ Timezone::Timezone(const char *infoString) :
     if (strlen(latlon) > 12) {
         nextPos += 2;
         strncpy(buffer, &latlon[nextPos], 2); 
+        buffer[2] = 0;
         lon +=  (atof (buffer) / 3600.00);
     }
     if (sign == '-') {
@@ -102,22 +107,22 @@ Timezone::Timezone(const char *infoString) :
     size = i - start;
     strncpy(buffer, (&infoString[start]), size);
     buffer[size] = 0;
-    descriptor = strdup(buffer);
+    descriptor = buffer;
 }
 
 /* the copy constructor */
-Timezone::Timezone(const Timezone& other)
+SGTimeZone::SGTimeZone(const SGTimeZone& other)
 {
     lat = other.getLat();
     lon = other.getLon();
-    countryCode = strdup(other.countryCode);
-    descriptor = strdup(other.descriptor);
+    countryCode = other.countryCode;
+    descriptor = other.descriptor;
 }
 
 
-/********* Member functions for TimezoneContainer class ********/
+/********* Member functions for SGTimeZoneContainer class ********/
 
-TimezoneContainer::TimezoneContainer(const char *filename)
+SGTimeZoneContainer::SGTimeZoneContainer(const char *filename)
 {
     char buffer[256];
     FILE* infile = fopen(filename, "rb");
@@ -132,22 +137,23 @@ TimezoneContainer::TimezoneContainer(const char *filename)
             if (feof(infile)) {
                 break;
             }
-            for (int i = 0; i < 256; i++) {
-                if (buffer[i] == '#') {
-                    buffer[i] = 0;
-                }
+            for (char *p = buffer; *p; p++) {
+                if (*p == '#') {
+                    *p = 0;
+                    break;
+                }    
             }
             if (buffer[0]) {
-                data.push_back(new Timezone(buffer));
+                data.push_back(new SGTimeZone(buffer));
             }
         }
         if ( errno ) {
-            perror( "TimezoneContainer()" );
+            perror( "SGTimeZoneContainer()" );
             errno = 0;
         }
     }
 }
 
-TimezoneContainer::~TimezoneContainer()
+SGTimeZoneContainer::~SGTimeZoneContainer()
 {
 }