|
| 1 | +################################################################# |
| 2 | +# |
| 3 | +# win32tzlist.pl -- compare Windows timezone information |
| 4 | +# |
| 5 | +# Copyright (c) 2008-2010, PostgreSQL Global Development Group |
| 6 | +# |
| 7 | +# $PostgreSQL: pgsql/src/tools/win32tzlist.pl,v 1.1 2010/04/15 11:00:45 mha Exp $ |
| 8 | +################################################################# |
| 9 | + |
| 10 | +# |
| 11 | +# This script compares the timezone information in the Windows |
| 12 | +# registry with that in pgtz.c. A list of changes will be written |
| 13 | +# to stdout - no attempt is made to automatically edit the file. |
| 14 | +# |
| 15 | +# Run the script from the src/timezone directory. |
| 16 | +# |
| 17 | + |
| 18 | +use strict; |
| 19 | +use warnings; |
| 20 | + |
| 21 | +use Win32::Registry; |
| 22 | + |
| 23 | +# |
| 24 | +# Fetch all timezones in the registry |
| 25 | +# |
| 26 | +my$basekey; |
| 27 | +$HKEY_LOCAL_MACHINE->Open("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones",$basekey) |
| 28 | +ordie$!; |
| 29 | + |
| 30 | +my@subkeys; |
| 31 | +$basekey->GetKeys(\@subkeys); |
| 32 | + |
| 33 | +my@system_zones; |
| 34 | + |
| 35 | +foreachmy$keyname (@subkeys) |
| 36 | +{ |
| 37 | +my$subkey; |
| 38 | +my%vals; |
| 39 | + |
| 40 | +$basekey->Open($keyname,$subkey)ordie$!; |
| 41 | +$subkey->GetValues(\%vals)ordie$!; |
| 42 | +$subkey->Close(); |
| 43 | + |
| 44 | +die"Incomplete timezone data for$keyname!\n" |
| 45 | +unless ($vals{Std} &&$vals{Dlt} &&$vals{Display}); |
| 46 | +push@system_zones, |
| 47 | + { |
| 48 | +'std'=>$vals{Std}->[2], |
| 49 | +'dlt'=>$vals{Dlt}->[2], |
| 50 | +'display'=>clean_displayname($vals{Display}->[2]), |
| 51 | + }; |
| 52 | +} |
| 53 | + |
| 54 | +$basekey->Close(); |
| 55 | + |
| 56 | +# |
| 57 | +# Fetch all timezones currently in the file |
| 58 | +# |
| 59 | +my@file_zones; |
| 60 | +open(PGTZ,'<pgtz.c')ordie"Could not open pgtz.c!\n"; |
| 61 | +my$t =$/; |
| 62 | +undef$/; |
| 63 | +my$pgtz = <PGTZ>; |
| 64 | +close(PGTZ); |
| 65 | +$/ =$t; |
| 66 | + |
| 67 | +# Attempt to locate and extract the complete win32_tzmap struct |
| 68 | +$pgtz =~/win32_tzmap\[\] =\s+{\s+\/\*[^\/]+\*\/\s+(.+?)};/gs |
| 69 | +ordie"Could not locate struct win32_tzmap in pgtz.c!"; |
| 70 | +$pgtz =$1; |
| 71 | + |
| 72 | +# Extract each individual record from the struct |
| 73 | +while ($pgtz =~m/{\s+"([^"]+)",\s+"([^"]+)",\s+"([^"]+)",?\s+},\s+\/\*(.+?)\*\//gs) |
| 74 | +{ |
| 75 | +push@file_zones, |
| 76 | + { |
| 77 | +'std'=>$1, |
| 78 | +'dlt'=>$2, |
| 79 | +'match'=>$3, |
| 80 | +'display'=>clean_displayname($4), |
| 81 | + }; |
| 82 | +} |
| 83 | + |
| 84 | +# |
| 85 | +# Look for anything that has changed |
| 86 | +# |
| 87 | +my@add; |
| 88 | + |
| 89 | +formy$sys (@system_zones) |
| 90 | +{ |
| 91 | +my$match = 0; |
| 92 | +formy$file (@file_zones) |
| 93 | + { |
| 94 | +if ($sys->{std}eq$file->{std}) |
| 95 | + { |
| 96 | +$match=1; |
| 97 | +if ($sys->{dlt}ne$file->{dlt}) |
| 98 | + { |
| 99 | +print"Timezone$sys->{std}, changed name of daylight zone!\n"; |
| 100 | + } |
| 101 | +if ($sys->{display}ne$file->{display}) |
| 102 | + { |
| 103 | +print |
| 104 | +"Timezone$sys->{std} changed displayname ('$sys->{display}' from '$file->{display}')!\n"; |
| 105 | + } |
| 106 | +last; |
| 107 | + } |
| 108 | + } |
| 109 | +unless ($match) |
| 110 | + { |
| 111 | +push@add,$sys; |
| 112 | + } |
| 113 | +} |
| 114 | + |
| 115 | +if (@add) |
| 116 | +{ |
| 117 | +print"\n\nOther than that, add the following timezones:\n"; |
| 118 | +formy$z (@add) |
| 119 | + { |
| 120 | +print |
| 121 | +"\t{\n\t\t\"$z->{std}\",\"$z->{dlt}\",\n\t\t\"FIXME\"\n\t},\t\t\t\t\t\t\t/*$z->{display} */\n"; |
| 122 | + } |
| 123 | +} |
| 124 | + |
| 125 | +subclean_displayname |
| 126 | +{ |
| 127 | +my$dn =shift; |
| 128 | + |
| 129 | +$dn =~s/\s+//gs; |
| 130 | +$dn =~s/\*//gs; |
| 131 | +$dn =~s/^\s+//gs; |
| 132 | +$dn =~s/\s+$//gs; |
| 133 | +return$dn; |
| 134 | +} |