12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- #!/usr/bin/perl
- use strict;
- use warnings;
- use Getopt::Long;
- use XML::Entities;
- use HTML::Entities;
- require "./fix-tzstr.pl";
- my $base = "/usr/share/zoneinfo";
- my $output = "timezones.conf.xml";
- my $debug;
- my $help;
- my %zones = ();
- my %name_to_file = ();
- my $res = GetOptions(
- "base=s" => \$base,
- "debug+" => \$debug,
- "help" => \$help,
- "output=s" => \$output
- );
- if ( !$res || $help ) {
- print "$0 [--base=/usr/share/zoneinfo] [--output=timezones.conf.xml] [--debug] [--help]\n";
- exit;
- }
- my @dirs = ($base);
- while (@dirs) {
- my $dir = shift @dirs;
- opendir( my $top, $dir );
- while ( my $file = readdir($top) ) {
- next if ( $file eq "." || $file eq ".." );
- if ( -f "$dir/$file" ) {
- $debug && print "Found $dir/$file\n";
- my $name = "$dir/$file";
- $name =~ s|^${base}/||o;
- $name_to_file{$name} = "$dir/$file";
- }
- elsif ( -d "$dir/$file" ) {
- $debug && print "Found subdir $dir/$file\n";
- push( @dirs, "$dir/$file" );
- }
- }
- closedir($top);
- }
- foreach my $name ( sort( keys(%name_to_file) ) ) {
- my $file = $name_to_file{$name};
- $debug && print "Processing $file...\n";
- open( my $in, "<$file" );
- my $data = join( "", <$in> );
- close($in);
- my @strings = $data =~ (m/[ -~]{4,}/g);
- if ( shift(@strings) !~ /^TZif/o ) {
- $debug && print "Skipped $file\n";
- next;
- }
- my $tzstr = fixTzstr( pop(@strings), $name );
- $zones{$name} = $tzstr;
- }
- open( my $out, ">$output" );
- print $out "<configuration name=\"timezones.conf\" description=\"Timezones\">\n";
- print $out " " x 4, "<timezones>\n";
- my $lastprefix = "";
- foreach my $zone ( sort( keys(%zones) ) ) {
- my $str = encode_entities($zones{$zone});
- next if ( !$str );
- my $newprefix = $zone;
- $newprefix =~ s|/.*||go;
- if ( $newprefix ne $lastprefix && $lastprefix ne "" ) {
- print $out "\n";
- }
- $lastprefix = $newprefix;
- print $out " " x 8, "<zone name=\"$zone\" value=\"$str\" />\n";
- }
- print $out " " x 4, "</timezones>\n";
- print $out "</configuration>\n";
- close($out);
|