From d56a0fb1983d26341bdfb2d2f2165a69e785cfb6 Mon Sep 17 00:00:00 2001 From: Brian West Date: Fri, 14 Feb 2014 15:15:22 -0600 Subject: [PATCH] timezones.conf.xml generator --- scripts/perl/timezone-gen.pl | 87 ++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 scripts/perl/timezone-gen.pl diff --git a/scripts/perl/timezone-gen.pl b/scripts/perl/timezone-gen.pl new file mode 100644 index 0000000000..f70a13e477 --- /dev/null +++ b/scripts/perl/timezone-gen.pl @@ -0,0 +1,87 @@ +#!/usr/bin/perl + +use strict; +use Getopt::Long; + +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" => \$output +); +if ( !$res || $help ) { + print "$0 [--base=/usr/share/zoneinfo] [--output=timezones.conf] [--debug] [--help]\n"; + exit; + } + +opendir( my $top, $base ); +while ( my $file = readdir($top) ) { + next if ( $file eq "." || $file eq "." ); + + if ( -f "$base/$file" ) { + $debug && print "Found $base/$file\n"; + $name_to_file{$file} = "$base/$file"; + } + elsif ( -d "$base/$file" ) { + opendir( my $sdir, "$base/$file" ); + while ( my $subfile = readdir($sdir) ) { + next if ( $subfile eq "." || $subfile eq "." ); + if ( -f "$base/$file/$subfile" ) { + $debug && print "Found $base/$file/$subfile...\n"; + $name_to_file{"$file/$subfile"} = "$base/$file/$subfile"; + } + } + closedir($sdir); + } + } +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); + + if ( $data !~ /^TZif2/o ) { + $debug && print "Skipped $file\n"; + next; + } + + my $tmp = $data; + $tmp =~ s/\n$//s; + $tmp =~ s/.*\n//sgmo; + + $zones{$name} = $tmp; + } + +open( my $out, ">$output" ); +print $out "\n"; +print $out " " x 4, "\n"; + +my $lastprefix = ""; +foreach my $zone ( sort( keys(%zones) ) ) { + my $str = $zones{$zone}; + next if ( !$str ); + + my $newprefix = $zone; + $newprefix =~ s|/.*||go; + if ( $newprefix ne $lastprefix && $lastprefix ne "" ) { + print $out "\n"; + } + $lastprefix = $newprefix; + + print $out "\t\n"; + } +print $out " " x 4, "\n"; +print $out "\n"; +close($out);