From: Jo-Philipp Wich Date: Sat, 10 Sep 2022 11:59:59 +0000 (+0200) Subject: build: add zoneinfo2ucode.pl X-Git-Url: http://git.openwrt.org/?a=commitdiff_plain;h=f2133059e1d6695e6a1b572ae6aded9d7dd3db35;p=project%2Fluci.git build: add zoneinfo2ucode.pl Add a zoneinfo2ucode.pl script which is the ucode equivalent to zoneinfo2lua.pl. It will generate a ucode module exporting a dictionary of known timezone names and their corresponding TZ strings. Signed-off-by: Jo-Philipp Wich --- diff --git a/build/zoneinfo2ucode.pl b/build/zoneinfo2ucode.pl new file mode 100755 index 0000000000..35dfac3797 --- /dev/null +++ b/build/zoneinfo2ucode.pl @@ -0,0 +1,93 @@ +#!/usr/bin/perl +# zoneinfo2ucode.pl - Make ucode module from /usr/share/zoneinfo +# Execute from within root of Luci feed, usually feeds/luci + +use strict; + +my %TZ; + +my $tzdin = $ARGV[0] || "/usr/share/zoneinfo"; +my $tzdout = $ARGV[1] || "./modules/luci-base-ucode/ucode/zoneinfo.uc"; + +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; + +# Add Etc/GMT zones from manually as they are not in zone.tab +$TZ{"Etc/GMT"} = "GMT0"; +$TZ{"Etc/GMT-1"} = "<+01>-1"; +$TZ{"Etc/GMT-2"} = "<+02>-2"; +$TZ{"Etc/GMT-3"} = "<+03>-3"; +$TZ{"Etc/GMT-4"} = "<+04>-4"; +$TZ{"Etc/GMT-5"} = "<+05>-5"; +$TZ{"Etc/GMT-6"} = "<+06>-6"; +$TZ{"Etc/GMT-7"} = "<+07>-7"; +$TZ{"Etc/GMT-8"} = "<+08>-8"; +$TZ{"Etc/GMT-9"} = "<+09>-9"; +$TZ{"Etc/GMT-10"} = "<+10>-10"; +$TZ{"Etc/GMT-11"} = "<+11>-11"; +$TZ{"Etc/GMT-12"} = "<+12>-12"; +$TZ{"Etc/GMT-13"} = "<+13>-13"; +$TZ{"Etc/GMT-14"} = "<+14>-14"; +$TZ{"Etc/GMT+1"} = "<-01>1"; +$TZ{"Etc/GMT+2"} = "<-02>2"; +$TZ{"Etc/GMT+3"} = "<-03>3"; +$TZ{"Etc/GMT+4"} = "<-04>4"; +$TZ{"Etc/GMT+5"} = "<-05>5"; +$TZ{"Etc/GMT+6"} = "<-06>6"; +$TZ{"Etc/GMT+7"} = "<-07>7"; +$TZ{"Etc/GMT+8"} = "<-08>8"; +$TZ{"Etc/GMT+9"} = "<-09>9"; +$TZ{"Etc/GMT+10"} = "<-10>10"; +$TZ{"Etc/GMT+11"} = "<-11>11"; +$TZ{"Etc/GMT+12"} = "<-12>12"; + +open(O, "> $tzdout") || die "open($tzdout): $!\n"; + +print STDERR "Writing time zones to $tzdout ... "; +print O <