1#! /usr/bin/perl -w
2
3# Courtesy Ken Pizzini.
4
5use strict;
6
7#This file released to the public domain.
8
9# Note: error checking is poor; trust the output only if the input
10# has been checked by zic.
11
12my $contZone = '';
13while (<>) {
14  my $origline = $_;
15  my @fields = ();
16  while (s/^\s*((?:"[^"]*"|[^\s#])+)//) {
17    push @fields, $1;
18  }
19  next unless @fields;
20
21  my $type = lc($fields[0]);
22  if ($contZone) {
23    @fields >= 3 or warn "bad continuation line";
24    unshift @fields, '+', $contZone;
25    $type = 'zone';
26  }
27
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]");
37    }
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";
50  }
51  print join("\t", @fields), "\n";
52}
53