1308265Sgjb#! /usr/bin/perl -w 2339630Sphilip# Summarize .zi input in a .zi-like format. 3308265Sgjb 4308265Sgjb# Courtesy Ken Pizzini. 5308265Sgjb 6308265Sgjbuse strict; 7308265Sgjb 8308265Sgjb#This file released to the public domain. 9308265Sgjb 10308265Sgjb# Note: error checking is poor; trust the output only if the input 11308265Sgjb# has been checked by zic. 12308265Sgjb 13308265Sgjbmy $contZone = ''; 14308265Sgjbwhile (<>) { 15308265Sgjb my $origline = $_; 16308265Sgjb my @fields = (); 17308265Sgjb while (s/^\s*((?:"[^"]*"|[^\s#])+)//) { 18308265Sgjb push @fields, $1; 19308265Sgjb } 20308265Sgjb next unless @fields; 21308265Sgjb 22308265Sgjb my $type = lc($fields[0]); 23308265Sgjb if ($contZone) { 24308265Sgjb @fields >= 3 or warn "bad continuation line"; 25308265Sgjb unshift @fields, '+', $contZone; 26308265Sgjb $type = 'zone'; 27308265Sgjb } 28308265Sgjb 29308265Sgjb $contZone = ''; 30308265Sgjb if ($type eq 'zone') { 31349598Sphilip # Zone NAME STDOFF RULES/SAVE FORMAT [UNTIL] 32308265Sgjb my $nfields = @fields; 33308265Sgjb $nfields >= 5 or warn "bad zone line"; 34308265Sgjb if ($nfields > 6) { 35308265Sgjb #this splice is optional, depending on one's preference 36308265Sgjb #(one big date-time field, or componentized date and time): 37308265Sgjb splice(@fields, 5, $nfields-5, "@fields[5..$nfields-1]"); 38308265Sgjb } 39308265Sgjb $contZone = $fields[1] if @fields > 5; 40308265Sgjb } elsif ($type eq 'rule') { 41366625Sphilip # Rule NAME FROM TO - IN ON AT SAVE LETTER/S 42308265Sgjb @fields == 10 or warn "bad rule line"; 43308265Sgjb } elsif ($type eq 'link') { 44308265Sgjb # Link TARGET LINK-NAME 45308265Sgjb @fields == 3 or warn "bad link line"; 46308265Sgjb } elsif ($type eq 'leap') { 47308265Sgjb # Leap YEAR MONTH DAY HH:MM:SS CORR R/S 48308265Sgjb @fields == 7 or warn "bad leap line"; 49308265Sgjb } else { 50308265Sgjb warn "Fubar at input line $.: $origline"; 51308265Sgjb } 52308265Sgjb print join("\t", @fields), "\n"; 53308265Sgjb} 54