-
Notifications
You must be signed in to change notification settings - Fork 12
/
parse_zoneinfo.pl
59 lines (53 loc) · 1.56 KB
/
parse_zoneinfo.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/perl -w
# Construct cityinfo.h from zone.tag
# (c)2005-2012 Kevin Boone
use strict;
open IN,"</usr/share/zoneinfo/zone.tab" or die "Can't write zone.tab";
open OUT,">cityinfo.h" or die "Can't write cityinfo.h";
print OUT "//Do not edit this file by hand\n";
print OUT "City cities[] = {\n";
while (my $line=<IN>)
{
chomp ($line);
if ($line =~ /^#/) { next; }
#print ("line=$line\n");
$line =~ /([A-Z][A-Z])\s+([0-9+-]+)\s+([-a-zA-Z\/_]+)/;
my $country = $1;
my $latlong= $2;
my $name= $3;
print ("country = $country\n");
print ("latlong = $latlong\n");
print ("name = $name\n");
$latlong =~ /([+-])([0-9]+)([+-])([0-9]+)/;
my $lat_sign = $1;
my $lat = $2;
my $long_sign = $3;
my $long = $4;
print ("lat_sign= $lat_sign\n");
print ("lat= $lat\n");
print ("long_sign= $long_sign\n");
print ("long= $long\n");
$lat =~ /([0-9][0-9])([0-9][0-9])/;
my $lat_deg = $1;
my $lat_min = $2;
print ("lat_deg= $lat_deg\n");
print ("lat_min= $lat_min\n");
$long =~ /([0-9][0-9][0-9])([0-9][0-9])/;
my $long_deg = $1;
my $long_min = $2;
print OUT "{\n";
print OUT "\"$name\",";
print OUT "\"$country\",";
$lat_deg =~ s/^0//;
$lat_min =~ s/^0//;
$long_deg =~ s/^0//;
$long_deg =~ s/^0//;
$long_min =~ s/^0//;
print OUT "$lat_deg,$lat_min,";
if ($lat_sign eq "-") { print OUT "TRUE," } else { print OUT "FALSE," };
print OUT "$long_deg,$long_min,";
if ($long_sign eq "-") { print OUT "TRUE" } else { print OUT "FALSE" };
print OUT "},\n";
}
print OUT "{NULL, NULL, 0, 0, FALSE, 0, 0, FALSE}";
print OUT "};\n";