1 /* -*- Mode: C++ -*- *****************************************************
3 * Written by Durk Talsma. Started July 1999.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 **************************************************************************/
21 /*************************************************************************
23 * Timezone is derived from geocoord, and stores the timezone centerpoint,
24 * as well as the countrycode and the timezone descriptor. The latter is
25 * used in order to get the local time.
27 ************************************************************************/
32 Timezone::Timezone(float la, float lo, char* cc, char* desc) :
35 countryCode = strdup(cc);
36 descriptor = strdup(desc);
39 /* Build a timezone object from a textline in zone.tab */
40 Timezone::Timezone(const char *infoString) :
44 while (infoString[i] != '\t')
48 strncpy(buffer, infoString, i);
50 countryCode = strdup(buffer);
53 while (infoString[i] != '\t')
56 strncpy(latlon, (&infoString[start]), size);
60 strncpy(buffer, &latlon[1], 2);
62 strncpy(buffer, &latlon[3], 2);
63 lat += (atof(buffer) / 60);
65 if (strlen(latlon) > 12)
68 strncpy(buffer, &latlon[5], 2);
69 lat += (atof(buffer) / 3600.0);
76 sign = latlon[nextPos];
78 strncpy(buffer, &latlon[nextPos], 3);
81 strncpy(buffer, &latlon[nextPos], 2);
84 lon += (atof(buffer) / 60);
85 if (strlen(latlon) > 12)
88 strncpy(buffer, &latlon[nextPos], 2);
89 lon += (atof (buffer) / 3600.00);
95 while (!((infoString[i] == '\t') || (infoString[i] == '\n')))
98 strncpy(buffer, (&infoString[start]), size);
100 descriptor = strdup(buffer);
103 /* the copy constructor */
104 Timezone::Timezone(const Timezone& other)
106 lat = other.getLat();
107 lon = other.getLon();
108 countryCode = strdup(other.countryCode);
109 descriptor = strdup(other.descriptor);
113 /********* Member functions for TimezoneContainer class ********/
115 TimezoneContainer::TimezoneContainer(const char *filename)
118 FILE* infile = fopen(filename, "r");
121 fprintf(stderr, "Unable to open file %s\n", filename);
129 fgets(buffer, 256, infile);
132 for (int i = 0; i < 256; i++)
134 if (buffer[i] == '#')
139 data.push_back(new Timezone(buffer));
145 TimezoneContainer::~TimezoneContainer()