File: zoneinfo2tdf.pl

package info (click to toggle)
tzdata 2015g-0+deb6u1
  • links: PTS
  • area: main
  • in suites: squeeze-lts
  • size: 3,888 kB
  • ctags: 91
  • sloc: sh: 456; makefile: 444; awk: 263; perl: 34
file content (52 lines) | stat: -rwxr-xr-x 1,409 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#! /usr/bin/perl -w

# Courtesy Ken Pizzini.

use strict;

#This file released to the public domain.

# Note: error checking is poor; trust the output only if the input
# has been checked by zic.

my $contZone = '';
while (<>) {
  my $origline = $_;
  my @fields = ();
  while (s/^\s*((?:"[^"]*"|[^\s#])+)//) {
    push @fields, $1;
  }
  next unless @fields;

  my $type = lc($fields[0]);
  if ($contZone) {
    @fields >= 3 or warn "bad continuation line";
    unshift @fields, '+', $contZone;
    $type = 'zone';
  }

  $contZone = '';
  if ($type eq 'zone') {
    # Zone  NAME  GMTOFF  RULES/SAVE  FORMAT  [UNTIL]
    my $nfields = @fields;
    $nfields >= 5 or warn "bad zone line";
    if ($nfields > 6) {
      #this splice is optional, depending on one's preference
      #(one big date-time field, or componentized date and time):
      splice(@fields, 5, $nfields-5, "@fields[5..$nfields-1]");
    }
    $contZone = $fields[1] if @fields > 5;
  } elsif ($type eq 'rule') {
    # Rule  NAME  FROM  TO  TYPE  IN  ON  AT  SAVE  LETTER/S
    @fields == 10 or warn "bad rule line";
  } elsif ($type eq 'link') {
    # Link  TARGET  LINK-NAME
    @fields == 3 or warn "bad link line";
  } elsif ($type eq 'leap') {
    # Leap  YEAR  MONTH  DAY  HH:MM:SS  CORR  R/S
    @fields == 7 or warn "bad leap line";
  } else {
    warn "Fubar at input line $.: $origline";
  }
  print join("\t", @fields), "\n";
}