Skip to content

Commit

Permalink
Simplified timezone update handling:
Browse files Browse the repository at this point in the history
* Fix FreeRDP#4965: Adjusted the timezone update script to initialize
  structs properly.
* Updated the scripts to generate the files directly
* Added a small HOWTO
* Split zone information to separate files to allow automatic
  update without further manual editing.

Create a timezone.c file that does conform to C rules.
  • Loading branch information
akallabeth committed Nov 7, 2018
1 parent 76c91ee commit 6a2d49e
Show file tree
Hide file tree
Showing 6 changed files with 2,130 additions and 2,065 deletions.
12 changes: 12 additions & 0 deletions docs/README.timezones
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
On an up to date windows machine run the following scripts (from checkout root):

csi.exe scripts/TimeZones.csx
csi.exe scripts/WindowsZones.csx

After running the scripts check
* winpr/libwinpr/timezone/TimeZones.c
* winpr/libwinpr/timezone/WindowsZones.c
for changes.

Commit if the definitions changed and create a pull request at
https://github.com/FreeRDP/FreeRDP
18 changes: 12 additions & 6 deletions scripts/TimeZones.csx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Run with ' csi scripts/TimeZones.csx' from freerdp checkout root */

using System;
using System.IO;
Expand Down Expand Up @@ -57,13 +58,18 @@ struct TIME_ZONE_ENTRY

int i;
UInt32 index;
const string file = @"TimeZones.txt";
const string file = @"winpr/libwinpr/timezone/TimeZones.c";
TimeZoneInfo.AdjustmentRule[] rules;
StreamWriter stream = new StreamWriter(file, false);
ReadOnlyCollection<TimeZoneInfo> timeZones = TimeZoneInfo.GetSystemTimeZones();

Console.WriteLine("Updating " + file);
stream.WriteLine("/* ");
stream.WriteLine(" * Automatically generated with scripts/TimeZones.csx");
stream.WriteLine(" */ ");
stream.WriteLine();

stream.WriteLine("#pragma pack(push, 1)");
stream.WriteLine("struct _TIME_ZONE_RULE_ENTRY");
stream.WriteLine("{");
stream.WriteLine("\tUINT64 TicksStart;");
Expand All @@ -83,10 +89,11 @@ stream.WriteLine("\tBOOL SupportsDST;");
stream.WriteLine("\tconst char* DisplayName;");
stream.WriteLine("\tconst char* StandardName;");
stream.WriteLine("\tconst char* DaylightName;");
stream.WriteLine("\tTIME_ZONE_RULE_ENTRY* RuleTable;");
stream.WriteLine("\tconst TIME_ZONE_RULE_ENTRY* RuleTable;");
stream.WriteLine("\tUINT32 RuleTableCount;");
stream.WriteLine("};");
stream.WriteLine("typedef struct _TIME_ZONE_ENTRY TIME_ZONE_ENTRY;");
stream.WriteLine("#pragma pack(pop)");
stream.WriteLine();

index = 0;
Expand Down Expand Up @@ -143,14 +150,14 @@ foreach (TimeZoneInfo timeZone in timeZones)
stream.Write(" {0}ULL, {1}ULL, {2},", tzr.TicksStart, tzr.TicksEnd, tzr.DaylightDelta);

stream.Write(" { ");
stream.Write("{0}, {1}, {2}, {3}, {4}, {5}",
stream.Write("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}",
tzr.StandardDate.wYear, tzr.StandardDate.wMonth, tzr.StandardDate.wDayOfWeek,
tzr.StandardDate.wDay, tzr.StandardDate.wHour, tzr.StandardDate.wMinute,
tzr.StandardDate.wSecond, tzr.StandardDate.wMilliseconds);
stream.Write(" }, ");

stream.Write("{ ");
stream.Write("{0}, {1}, {2}, {3}, {4}, {5}",
stream.Write("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}",
tzr.DaylightDate.wYear, tzr.DaylightDate.wMonth, tzr.DaylightDate.wDayOfWeek,
tzr.DaylightDate.wDay, tzr.DaylightDate.wHour, tzr.DaylightDate.wMinute,
tzr.DaylightDate.wSecond, tzr.DaylightDate.wMilliseconds);
Expand Down Expand Up @@ -195,8 +202,7 @@ foreach (TimeZoneInfo timeZone in timeZones)
else
{
tz.RuleTableCount = (UInt32)rules.Length;
tz.RuleTable = "&TimeZoneRuleTable_" + index;
tz.RuleTable = "(TIME_ZONE_RULE_ENTRY*) &TimeZoneRuleTable_" + index;
tz.RuleTable = "TimeZoneRuleTable_" + index;
}

stream.WriteLine("\t{");
Expand Down
9 changes: 8 additions & 1 deletion scripts/WindowsZones.csx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Run with ' csi scripts/WindowsZones.csx' from freerdp checkout root */

#r "System.Xml"

Expand All @@ -32,12 +33,18 @@ using System.Collections.Generic;
*/

string tzid, windows;
const string file = @"WindowsZones.txt";
const string file = @"winpr/libwinpr/timezone/WindowsZones.c";
const string zonesUrl = @"http://www.unicode.org/repos/cldr/tags/latest/common/supplemental/windowsZones.xml";
List<string> list = new List<string>();
StreamWriter stream = new StreamWriter(file, false);
XmlTextReader reader = new XmlTextReader(zonesUrl);

Console.WriteLine("Updating " + file);
stream.WriteLine("/* ");
stream.WriteLine(" * Automatically generated with scripts/WindowsZones.csx");
stream.WriteLine(" */ ");
stream.WriteLine();

stream.WriteLine("struct _WINDOWS_TZID_ENTRY");
stream.WriteLine("{");
stream.WriteLine("\tconst char* windows;");
Expand Down
Loading

0 comments on commit 6a2d49e

Please sign in to comment.