nbtree VACUUM: cope with topparent inconsistencies.
[pgsql.git] / src / tools / win32tzlist.pl
blob657f7d4879c00493b51bf69e7b98740b269d5385
1 #################################################################
3 # win32tzlist.pl -- compare Windows timezone information
5 # Copyright (c) 2008-2023, PostgreSQL Global Development Group
7 # src/tools/win32tzlist.pl
8 #################################################################
11 # This script compares the timezone information in the Windows registry
12 # with that in src/bin/initdb/findtimezone.c. A list of changes will be
13 # written to stdout - no attempt is made to automatically edit the file.
15 # Run the script from the top-level PG source directory.
18 use strict;
19 use warnings;
21 use Win32::Registry;
23 my $tzfile = 'src/bin/initdb/findtimezone.c';
26 # Fetch all timezones in the registry
28 my $basekey;
29 $HKEY_LOCAL_MACHINE->Open(
30 "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones", $basekey)
31 or die $!;
33 my @subkeys;
34 $basekey->GetKeys(\@subkeys);
36 my @system_zones;
38 foreach my $keyname (@subkeys)
40 my $subkey;
41 my %vals;
43 $basekey->Open($keyname, $subkey) or die $!;
44 $subkey->GetValues(\%vals) or die $!;
45 $subkey->Close();
47 die "Incomplete timezone data for $keyname!\n"
48 unless ($vals{Std} && $vals{Dlt} && $vals{Display});
49 push @system_zones,
51 'std' => $vals{Std}->[2],
52 'dlt' => $vals{Dlt}->[2],
53 'display' => clean_displayname($vals{Display}->[2]),
57 $basekey->Close();
60 # Fetch all timezones currently in the file
62 my @file_zones;
63 my $pgtz;
64 open(my $tzfh, '<', $tzfile) or die "Could not open $tzfile!\n";
66 local $/ = undef;
67 $pgtz = <$tzfh>;
69 close($tzfh);
71 # Attempt to locate and extract the complete win32_tzmap struct
72 $pgtz =~ /win32_tzmap\[\] =\s+{\s+\/\*[^\/]+\*\/\s+(.+?)};/gs
73 or die "Could not locate struct win32_tzmap in $tzfile!";
74 $pgtz = $1;
76 # Extract each individual record from the struct
77 while ($pgtz =~
78 m/{\s+\/\*(.+?)\*\/\s+"([^"]+)",\s+"([^"]+)",\s+"([^"]+)",?\s+},/gs)
80 push @file_zones,
82 'display' => clean_displayname($1),
83 'std' => $2,
84 'dlt' => $3,
85 'match' => $4,
90 # Look for anything that has changed
92 my @add;
94 for my $sys (@system_zones)
96 my $match = 0;
97 for my $file (@file_zones)
99 if ($sys->{std} eq $file->{std})
101 $match = 1;
102 if ($sys->{dlt} ne $file->{dlt})
104 print
105 "Timezone $sys->{std}, changed name of daylight zone!\n";
107 if ($sys->{display} ne $file->{display})
109 print
110 "Timezone $sys->{std} changed displayname ('$sys->{display}' from '$file->{display}')!\n";
112 last;
115 unless ($match)
117 push @add, $sys;
121 if (@add)
123 print "\n\nOther than that, add the following timezones:\n";
124 for my $z (@add)
126 print
127 "\t{\n\t\t/* $z->{display} */\n\t\t\"$z->{std}\", \"$z->{dlt}\",\n\t\t\"FIXME\"\n\t},\n";
131 sub clean_displayname
133 my $dn = shift;
135 $dn =~ s/\*//gs;
136 $dn =~ s/\s+/ /gs;
137 $dn =~ s/^\s+//gs;
138 $dn =~ s/\s+$//gs;
139 return $dn;