Simplified timezone update handling:

* Fix #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.
This commit is contained in:
Armin Novak
2018-10-24 17:40:05 +02:00
parent 76c91ee51a
commit 6a2d49e0ed
6 changed files with 2131 additions and 2066 deletions

View File

@@ -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;
@@ -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;");
@@ -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;
@@ -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);
@@ -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{");

View File

@@ -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"
@@ -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;");