Changeset 6666

Show
Ignore:
Timestamp:
01/02/11 18:52:06 (2 years ago)
Author:
jow
Message:

build: zoneinfo2lua.pl: rework script to accommodate split tzdata.lua and tzoffset.lua libs

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • luci/trunk/build/zoneinfo2lua.pl

    r6665 r6666  
    77 
    88my %TZ; 
    9 my $tzdir = $ARGV[0] || "/usr/share/zoneinfo"; 
    109 
    11 chdir($tzdir) || die "chdir($tzdir): $!\n"; 
     10my $tzdin  = $ARGV[0] || "/usr/share/zoneinfo"; 
     11my $tzdout = $ARGV[1] || "./libs/sys/luasrc/sys/zoneinfo"; 
    1212 
    1313local $/ = "\012"; 
    14 open( ZTAB, "< ./zone.tab" ) || die "Unable to open zone.tab: $!"; 
     14open( ZTAB, "< $tzdin/zone.tab" ) || die "open($tzdin/zone.tab): $!"; 
    1515 
    1616while( ! eof ZTAB ) { 
     
    2222    printf STDERR "%-40s", $zone; 
    2323 
    24     if( open ZONE, "< ./$zone" ) { 
     24    if( open ZONE, "< $tzdin/$zone" ) { 
    2525        seek ZONE, -2, 2; 
    2626 
     
    4141    else 
    4242    { 
    43         print STDERR "Unable to open $zone: $!\n"; 
     43        print STDERR "open($tzdin/$zone): $!\n"; 
    4444    } 
    4545} 
     
    4848 
    4949 
    50 print <<HEAD; 
     50open(O, "> $tzdout/tzdata.lua") || die "open($tzdout/tzdata.lua): $!\n"; 
     51 
     52print STDERR "Writing time zones to $tzdout/tzdata.lua ... "; 
     53print O <<HEAD; 
    5154--[[ 
    5255LuCI - Autogenerated Zoneinfo Module 
     
    6063]]-- 
    6164 
    62 module "luci.sys.zoneinfo" 
     65module "luci.sys.zoneinfo.tzdata" 
    6366 
    6467TZ = { 
     
    6669 
    6770foreach my $zone ( sort keys %TZ ) { 
    68     printf "\t{ '%s', '%s' },\n", $zone, $TZ{$zone} 
     71    printf O "\t{ '%s', '%s' },\n", $zone, $TZ{$zone} 
    6972} 
    7073 
    71 print <<HEAD; 
    72 } 
     74print O "}\n"; 
     75close O; 
     76 
     77print STDERR "done\n"; 
     78 
     79 
     80open (O, "> $tzdout/tzoffset.lua") || die "open($tzdout/tzoffset.lua): $!\n"; 
     81 
     82print STDERR "Writing time offsets to $tzdout/tzoffset.lua ... "; 
     83print O <<HEAD; 
     84--[[ 
     85LuCI - Autogenerated Zoneinfo Module 
     86 
     87Licensed under the Apache License, Version 2.0 (the "License"); 
     88you may not use this file except in compliance with the License. 
     89You may obtain a copy of the License at 
     90 
     91    http://www.apache.org/licenses/LICENSE-2.0 
     92 
     93]]-- 
     94 
     95module "luci.sys.zoneinfo.tzoffset" 
    7396 
    7497OFFSET = { 
     
    104127            $offset += $s * $m * 60; 
    105128 
    106             printf("\t%-5s = %6d,\t-- %s\n", 
    107                 lc($std), $offset, $std); 
     129            printf O "\t%-5s = %6d,\t-- %s\n", 
     130                lc($std), $offset, $std; 
    108131 
    109132            $seen{$std} = 1; 
     
    123146                } 
    124147 
    125                 printf("\t%-5s = %6d,\t-- %s\n", 
    126                     lc($dst), $offset, $dst); 
     148                printf O "\t%-5s = %6d,\t-- %s\n", 
     149                    lc($dst), $offset, $dst; 
    127150     
    128151                $seen{$dst} = 1; 
     
    130153        } 
    131154        else { 
    132             printf("\t%-5s = %6d,\t-- %s\n", 
    133                 lc($std), $offset, $std); 
     155            printf O "\t%-5s = %6d,\t-- %s\n", 
     156                lc($std), $offset, $std; 
    134157 
    135158            $seen{$std} = 1; 
     
    139162} 
    140163 
    141 print "}\n"; 
     164print O "}\n"; 
     165close O; 
     166 
     167print STDERR "done\n";