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