#!/usr/bin/perl # zoneinfo2lua.pl - Make Lua module from /usr/share/zoneinfo # Execute from within /usr/share/zoneinfo # $Id$ use strict; my %TZ; my $tzdin = $ARGV[0] || "/usr/share/zoneinfo"; my $tzdout = $ARGV[1] || "./modules/luci-base/luasrc/sys/zoneinfo"; local $/ = "\012"; open( ZTAB, "< $tzdin/zone.tab" ) || die "open($tzdin/zone.tab): $!"; while( ! eof ZTAB ) { chomp( my $line = readline ZTAB ); next if $line =~ /^#/ || $line =~ /^\s+$/; my ( undef, undef, $zone, @comment ) = split /\s+/, $line; printf STDERR "%-40s", $zone; if( open ZONE, "< $tzdin/$zone" ) { seek ZONE, -2, 2; while( tell(ZONE) > 0 ) { read ZONE, my $char, 1; ( $char eq "\012" ) ? last : seek ZONE, -2, 1; } chomp( my $tz = readline ZONE ); print STDERR ( $tz || "(no tzinfo found)" ), "\n"; close ZONE; if( $tz ) { $zone =~ s/_/ /g; $TZ{$zone} = $tz; } } else { print STDERR "open($tzdin/$zone): $!\n"; } } close ZTAB; open(O, "> $tzdout/tzdata.lua") || die "open($tzdout/tzdata.lua): $!\n"; print STDERR "Writing time zones to $tzdout/tzdata.lua ... "; print O < $tzdout/tzoffset.lua") || die "open($tzdout/tzoffset.lua): $!\n"; print STDERR "Writing time offsets to $tzdout/tzoffset.lua ... "; print O <