zoneinfo2tdf.pl 1.4 KB

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