#!/usr/local/bin/perl
# Generate wml files for city selection. Uses list in locations.pl
$WMLDIR = "WML";
require "/data1/WWW/Tropical/Bin/locations.pl";
%locations = &LOCATIONS();
@locations = sort keys(%locations);
$piover2 = atan2(1,0);
$pi = $piover2*2;
$dtor = $piover2/90;
@alphabet = ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
foreach $place (keys(%locations)) {
$place =~ /^([^,]*)(|\,\s+)([A-Z\s\.]*)$/i;
$city = $1;
$country = $3; if (!$country) {$country = $city;}
if ($country =~ /^[A-Z][A-Z]$/) {
$state = $country;
$country = "USA";
$city = $place;
$cities_by_state{$state} .= $place."\|";
}
$cities_by_country{$country} .= $place."\|";
#print "$city | $country\n";
#if (!$country) {print "BAD $place\n";}
}
@countrylist = sort keys(%cities_by_country);
@statelist = sort keys(%cities_by_state);
#print "Countries: ",join(" ",@countrylist),"\n";
$wml_header = <<"HEADER_END";
HEADER_END
foreach $letter (@alphabet) {
$file = $letter."cities.wml";
@cities = sort grep /^$letter/i, @locations;
$access = 1;
if (open(CityFile,">$WMLDIR/$file")) {
printf CityFile "$wml_header\n";
printf CityFile "\n";
foreach $city (@cities) {
my($lat, $lon, $ocean, $dist) = split / /,$locations{$city};
my $loc = $city; $loc =~ s/ /\+/g;
my $accesskey = " accesskey=\"$access\"";
if ($access > 9) {$accesskey = "";}
printf CityFile "$city
\n";
++$access;
}
printf CityFile "Home
\n";
printf CityFile "Prev\n
\n";
printf CityFile "\n\n";
close(CityFile);
} else {print "WARNING: can't open $WMLDIR/$file\n";}
$file = $letter."countries.wml";
@countries = sort grep /^$letter/i, @countrylist;
#print "$letter countries: ",join(" ",@countries),"\n";
$access = 1;
if (open(CountryFile,">$WMLDIR/$file")) {
printf CountryFile "$wml_header\n";
printf CountryFile "\n";
foreach $country (@countries) {
my $accesskey = " accesskey=\"$access\"";
if ($access > 9) {$accesskey = "";}
$scountry = $country; $scountry =~ s/\s//g; $scountry =~ s/\.//g;
printf CountryFile "$country
\n";
++$access;
}
printf CountryFile "Home
\n";
printf CountryFile "Prev\n
\n";
printf CountryFile "\n\n";
close(CountryFile);
} else {print "WARNING: can't open $WMLDIR/$file\n";}
}
foreach $country (@countrylist) {
if ($country eq "USA") {next;}
$scountry = $country; $scountry =~ s/\s//g; $scountry =~ s/\.//g;
$file = $scountry.".wml";
#print "$country: $cities_by_country{$country}\n";
@cities = sort split /\|/,$cities_by_country{$country};
$access = 1;
if (open(CityFile,">$WMLDIR/$file")) {
printf CityFile "$wml_header\n";
printf CityFile "\n";
foreach $city (@cities) {
if ($city) {
my($lat, $lon, $ocean, $dist) = split / /,$locations{$city};
my $loc = $city; $loc =~ s/ /\+/g;
my $accesskey = " accesskey=\"$access\"";
if ($access > 9) {$accesskey = "";}
printf CityFile "$city
\n";
++$access;
}
}
printf CityFile "Home
\n";
printf CityFile "Prev\n
\n";
printf CityFile "\n\n";
close(CityFile);
} else {print "WARNING: can't open $WMLDIR/$file\n";}
}
$file = "USA.wml";
$access = 1;
if (open(CountryFile,">$WMLDIR/$file")) {
printf CountryFile "$wml_header\n";
printf CountryFile "\n";
foreach $state (sort @statelist) {
my $accesskey = " accesskey=\"$access\"";
if ($access > 9) {$accesskey = "";}
printf CountryFile "$state
\n";
++$access;
}
printf CountryFile "Home
\n";
printf CountryFile "Prev\n
\n";
printf CountryFile "\n\n";
close(CountryFile);
} else {print "WARNING: can't open $WMLDIR/$file\n";}
foreach $state (@statelist) {
$file = "USA_$state.wml";
@cities = sort split /\|/,$cities_by_state{$state};
$access = 1;
if (open(CityFile,">$WMLDIR/$file")) {
printf CityFile "$wml_header\n";
printf CityFile "\n";
foreach $city (@cities) {
if ($city) {
my($lat, $lon, $ocean, $dist) = split / /,$locations{$city};
my $loc = $city; $loc =~ s/ /\+/g;
my $accesskey = " accesskey=\"$access\"";
if ($access > 9) {$accesskey = "";}
$city =~ /^([^,]*)/; $scity = $1;
printf CityFile "$scity
\n";
++$access;
}
}
printf CityFile "Home
\n";
printf CityFile "Prev\n
\n";
printf CityFile "\n\n";
close(CityFile);
} else {print "WARNING: can't open $WMLDIR/$file\n";}
}