* luci/build: add zoneinfo2lua.pl utility
[project/luci.git] / build / zoneinfo2lua.pl
1 #!/usr/bin/perl
2 # zoneinfo2lua.pl - Make Lua module from /usr/share/zoneinfo
3 # Execute from within /usr/share/zoneinfo
4 # $Id$
5
6 use strict;
7
8 my %TZ;
9
10 local $/ = "\012";
11 open( ZTAB, "< ./zone.tab" ) || die "Unable to open zone.tab: $!";
12
13 while( ! eof ZTAB ) {
14 chomp( my $line = readline ZTAB );
15 next if $line =~ /^#/ || $line =~ /^\s+$/;
16
17 my ( undef, undef, $zone, @comment ) = split /\s+/, $line;
18
19 printf STDERR "%-40s", $zone;
20
21 if( open ZONE, "< ./$zone" ) {
22 seek ZONE, -2, 2;
23
24 while( tell(ZONE) > 0 ) {
25 read ZONE, my $char, 1;
26 ( $char eq "\012" ) ? last : seek ZONE, -2, 1;
27 }
28
29 chomp( my $tz = readline ZONE );
30 print STDERR ( $tz || "(no tzinfo found)" ), "\n";
31 close ZONE;
32
33 if( $tz ) {
34 $zone =~ s/_/ /g;
35 $TZ{$zone} = $tz;
36 }
37 }
38 else
39 {
40 print STDERR "Unable to open $zone: $!\n";
41 }
42 }
43
44 close ZTAB;
45
46
47 print <<HEAD;
48 --[[
49 LuCI - Autogenerated Zoneinfo Module
50
51 Licensed under the Apache License, Version 2.0 (the "License");
52 you may not use this file except in compliance with the License.
53 You may obtain a copy of the License at
54
55 http://www.apache.org/licenses/LICENSE-2.0
56
57 ]]--
58
59 module "luci.sys.zoneinfo"
60
61 TZ = {
62 HEAD
63
64 foreach my $zone ( sort keys %TZ ) {
65 printf "\t{ '%s', '%s' },\n", $zone, $TZ{$zone}
66 }
67
68 print "}\n";