Merge commit 'f06dce2c1f0f3af78581e7574f65bfba843ddb6e' into merges
[unleashed.git] / contrib / tzdata / zoneinfo2tdf.pl
blobe05ec010082a8f4de4be7e2664402c9189bfbcb0
1 #! /usr/bin/perl -w
3 # Courtesy Ken Pizzini.
5 use strict;
7 #This file released to the public domain.
9 # Note: error checking is poor; trust the output only if the input
10 # has been checked by zic.
12 my $contZone = '';
13 while (<>) {
14 my $origline = $_;
15 my @fields = ();
16 while (s/^\s*((?:"[^"]*"|[^\s#])+)//) {
17 push @fields, $1;
19 next unless @fields;
21 my $type = lc($fields[0]);
22 if ($contZone) {
23 @fields >= 3 or warn "bad continuation line";
24 unshift @fields, '+', $contZone;
25 $type = 'zone';
28 $contZone = '';
29 if ($type eq 'zone') {
30 # Zone NAME GMTOFF RULES/SAVE FORMAT [UNTIL]
31 my $nfields = @fields;
32 $nfields >= 5 or warn "bad zone line";
33 if ($nfields > 6) {
34 #this splice is optional, depending on one's preference
35 #(one big date-time field, or componentized date and time):
36 splice(@fields, 5, $nfields-5, "@fields[5..$nfields-1]");
38 $contZone = $fields[1] if @fields > 5;
39 } elsif ($type eq 'rule') {
40 # Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S
41 @fields == 10 or warn "bad rule line";
42 } elsif ($type eq 'link') {
43 # Link TARGET LINK-NAME
44 @fields == 3 or warn "bad link line";
45 } elsif ($type eq 'leap') {
46 # Leap YEAR MONTH DAY HH:MM:SS CORR R/S
47 @fields == 7 or warn "bad leap line";
48 } else {
49 warn "Fubar at input line $.: $origline";
51 print join("\t", @fields), "\n";