From 4b145ff0d0cbd77c80e2b03b30773a9ea51b736d Mon Sep 17 00:00:00 2001 From: "vladimir%pobox.com" Date: Mon, 10 Jan 2005 19:51:37 +0000 Subject: [PATCH] script that generates tzdata.c --- calendar/libical/zoneinfo/maketzdata.pl | 138 ++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 calendar/libical/zoneinfo/maketzdata.pl diff --git a/calendar/libical/zoneinfo/maketzdata.pl b/calendar/libical/zoneinfo/maketzdata.pl new file mode 100644 index 00000000000..286ebcae751 --- /dev/null +++ b/calendar/libical/zoneinfo/maketzdata.pl @@ -0,0 +1,138 @@ +#!/usr/bin/perl + +# +# maketzdata.pl +# +# This script takes a zones.tab file in the root directory of +# the libical zoneinfo dir, and generates a tzdata.c file which +# is used by Mozilla Calendar. tzdata.c normally lives in +# calendar/base/src/tzdata.c, and is #include'd by calICSService.cpp +# +# The reason for the ugly large char array is that MSVC can't +# handle string literals longer than 2048 chars; it can, however, +# handle multiple-megabyte array literals. Go figure. +# +# Usage of this is: perl ./maketzdata.pl zones.tab tzdata.c +# + +use File::Basename; + +$tzid_prefix = "/softwarestudio.org/Olson_20010626_2/"; + +if ($#ARGV != 1) { + print "Usage: maketzdata.pl zones.tab tzdata.c\n"; + die; +} + +$zonetabfile = $ARGV[0]; +$zonetabdir = dirname($zonetabfile); +$tzdatafile = $ARGV[1]; + +open ZONETAB, $zonetabfile || die "Can't open $zonetab"; +@zonetab = ; +close ZONETAB; + +open TZDATA, ">" . $tzdatafile || die "Can't open $tzdata for writing"; + +print TZDATA <; + close TZFILE; + } + + $hashdata = { + name => $name, + offset => $data_offset, + lat => $lat, + long => $long + }; + + # add in the softwarestudio prefix + $name = $tzid_prefix . $name; + + # put the data in the hash for later + $tzs{$name} = $hashdata; + + $bytestr = unpack("H*", $tzdata); + + $bytelen = length($bytestr); + $clen = 0; + while ($clen < $bytelen) { + print TZDATA "\n" if ($data_offset % 30 == 0); + + $b = substr $bytestr, $clen, 2; + print TZDATA "0x$b,"; + $clen += 2; + $data_offset += 2; + } + + print TZDATA "\n" if ($data_offset % 30 == 0); + print TZDATA "0x00,"; + $data_offset += 2; +} + +print TZDATA "0x00\n};\n\n"; +print TZDATA "static ical_timezone_data_struct ical_timezone_data[] = {\n"; + +foreach my $k (keys %tzs) { + $tz = $tzs{$k}; + + $name = $tz->{name}; + $lat = $tz->{lat}; + $long = $tz->{long}; + $offt = $tz->{offset}; + + print TZDATA " { \"$name\", \"$lat\", \"$long\", ical_timezone_data_timezones + $offt },\n"; +} + +print TZDATA " { NULL, NULL, NULL, NULL }\n"; +print TZDATA "};\n\n"; + +close TZDATA; +