<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none"><!-- p { margin-top: 0px; margin-bottom: 0px; }--></style>
</head>
<body dir="ltr" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<div>From 4093e426a42421fd2d8579b07e8edb3fb116f561 Mon Sep 17 00:00:00 2001</div>
<div>From: Christopher Wong <christwo@axis.com></div>
<div>Date: Tue, 5 Feb 2019 15:02:57 +0100</div>
<div>Subject: [PATCH] zic.c: Add -k option to keep specified year and onward</div>
<div><br>
</div>
<div>The -k option will take a year as input. It will strip away</div>
<div>historical transition data before the specified year. The</div>
<div>TZif files will be truncated.</div>
<div>---</div>
<div> zic.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---</div>
<div> 1 file changed, 69 insertions(+), 3 deletions(-)</div>
<div><br>
</div>
<div>diff --git a/zic.c b/zic.c</div>
<div>index 2ebc66a..9a3b1f5 100644</div>
<div>--- a/zic.c</div>
<div>+++ b/zic.c</div>
<div>@@ -178,6 +178,7 @@ static void<span style="white-space:pre"> </span>mkdirs(char const *, bool);</div>
<div> static void<span style="white-space:pre"> </span>newabbr(const char * abbr);</div>
<div> static zic_t<span style="white-space:pre"> </span>oadd(zic_t t1, zic_t t2);</div>
<div> static void<span style="white-space:pre"> </span>outzone(const struct zone * zp, ptrdiff_t ntzones);</div>
<div>+static zic_t<span style="white-space:pre"> </span>ytime(zic_t year);</div>
<div> static zic_t<span style="white-space:pre"> </span>rpytime(const struct rule * rp, zic_t wantedy);</div>
<div> static void<span style="white-space:pre"> </span>rulesub(struct rule * rp,</div>
<div> <span style="white-space:pre"> </span>const char * loyearp, const char * hiyearp,</div>
<div>@@ -610,6 +611,10 @@ static const char *<span style="white-space:pre"> </span>
leapsec;</div>
<div> static const char *<span style="white-space:pre"> </span>tzdefault;</div>
<div> static const char *<span style="white-space:pre"> </span>yitcommand;</div>
<div> </div>
<div>+/* This is used to truncate tzfiles. Only year specified by keepyear and</div>
<div>+   onward will be kept. Don't expect year to be outside range 0-9999. */</div>
<div>+static zic_t keepyear;</div>
<div>+</div>
<div> int</div>
<div> main(int argc, char **argv)</div>
<div> {</div>
<div>@@ -640,7 +645,8 @@ main(int argc, char **argv)</div>
<div> <span style="white-space:pre"> </span>} else if (strcmp(argv[k], "--help") == 0) {</div>
<div> <span style="white-space:pre"> </span>usage(stdout, EXIT_SUCCESS);</div>
<div> <span style="white-space:pre"> </span>}</div>
<div>-<span style="white-space:pre"> </span>while ((c = getopt(argc, argv, "d:l:L:p:st:vy:")) != EOF && c != -1)</div>
<div>+<span style="white-space:pre"> </span>keepyear = ZIC_MIN;</div>
<div>+<span style="white-space:pre"> </span>while ((c = getopt(argc, argv, "d:k:l:L:p:st:vy:")) != EOF && c != -1)</div>
<div> <span style="white-space:pre"> </span>switch (c) {</div>
<div> <span style="white-space:pre"> </span>default:</div>
<div> <span style="white-space:pre"> </span>usage(stderr, EXIT_FAILURE);</div>
<div>@@ -654,6 +660,22 @@ _("%s: More than one -d option specified\n"),</div>
<div> <span style="white-space:pre"> </span>return EXIT_FAILURE;</div>
<div> <span style="white-space:pre"> </span>}</div>
<div> <span style="white-space:pre"> </span>break;</div>
<div>+<span style="white-space:pre"> </span>case 'k':</div>
<div>+<span style="white-space:pre"> </span>if (keepyear == ZIC_MIN) {</div>
<div>+<span style="white-space:pre"> </span>keepyear = atoi(optarg);</div>
<div>+<span style="white-space:pre"> </span>/* Don't expect year to be outside range 0-9999. */</div>
<div>+<span style="white-space:pre"> </span>if (keepyear < 0)</div>
<div>+<span style="white-space:pre"> </span>keepyear = 0;</div>
<div>+<span style="white-space:pre"> </span>if (keepyear > 9999)</div>
<div>+<span style="white-space:pre"> </span>keepyear = 9999;</div>
<div>+<span style="white-space:pre"> </span>}</div>
<div>+<span style="white-space:pre"> </span>else {</div>
<div>+<span style="white-space:pre"> </span>fprintf(stderr,</div>
<div>+_("%s: More than one -k option specified\n"),</div>
<div>+<span style="white-space:pre"> </span>progname);</div>
<div>+<span style="white-space:pre"> </span>return EXIT_FAILURE;</div>
<div>+<span style="white-space:pre"> </span>}</div>
<div>+<span style="white-space:pre"> </span>break;</div>
<div> <span style="white-space:pre"> </span>case 'l':</div>
<div> <span style="white-space:pre"> </span>if (lcltime == NULL)</div>
<div> <span style="white-space:pre"> </span>lcltime = optarg;</div>
<div>@@ -1749,7 +1771,7 @@ writezone(const char *const name, const char *const string, char version,</div>
<div> <span style="white-space:pre"> </span>register FILE *<span style="white-space:pre">
</span>fp;</div>
<div> <span style="white-space:pre"> </span>register ptrdiff_t<span style="white-space:pre">
</span>i, j;</div>
<div> <span style="white-space:pre"> </span>register int<span style="white-space:pre">
</span>leapcnt32, leapi32;</div>
<div>-<span style="white-space:pre"> </span>register ptrdiff_t<span style="white-space:pre">
</span>timecnt32, timei32;</div>
<div>+<span style="white-space:pre"> </span>register ptrdiff_t<span style="white-space:pre">
</span>timecnt32, timei32, timei;</div>
<div> <span style="white-space:pre"> </span>register int<span style="white-space:pre">
</span>pass;</div>
<div> <span style="white-space:pre"> </span>static const struct tzhead<span style="white-space:pre">
</span>tzh0;</div>
<div> <span style="white-space:pre"> </span>static struct tzhead<span style="white-space:pre">
</span>tzh;</div>
<div>@@ -1865,6 +1887,37 @@ writezone(const char *const name, const char *const string, char version,</div>
<div> <span style="white-space:pre"> </span>--leapcnt32;</div>
<div> <span style="white-space:pre"> </span>++leapi32;</div>
<div> <span style="white-space:pre"> </span>}</div>
<div>+</div>
<div>+<span style="white-space:pre"> </span>timei = 0;</div>
<div>+<span style="white-space:pre"> </span>if (keepyear != ZIC_MIN) {</div>
<div>+<span style="white-space:pre"> </span>/* Discard transitions that happened before the keepyear. */</div>
<div>+<span style="white-space:pre"> </span>int nbr_removes;</div>
<div>+</div>
<div>+<span style="white-space:pre"> </span>nbr_removes = 0;</div>
<div>+<span style="white-space:pre"> </span>for (i = timei32; i < timecnt; ++i)</div>
<div>+<span style="white-space:pre"> </span>if (ats[i] < ytime(keepyear))</div>
<div>+<span style="white-space:pre"> </span>++nbr_removes;</div>
<div>+<span style="white-space:pre"> </span>timecnt32 -= nbr_removes;</div>
<div>+<span style="white-space:pre"> </span>timei32 += nbr_removes;</div>
<div>+</div>
<div>+<span style="white-space:pre"> </span>nbr_removes = 0;</div>
<div>+<span style="white-space:pre"> </span>for (i = 0; i < timecnt; ++i)</div>
<div>+<span style="white-space:pre"> </span>if (ats[i] < ytime(keepyear))</div>
<div>+<span style="white-space:pre"> </span>++nbr_removes;</div>
<div>+</div>
<div>+<span style="white-space:pre"> </span>if (nbr_removes > 0) {</div>
<div>+<span style="white-space:pre"> </span>/* Override the last removed transition time with the first transition</div>
<div>+<span style="white-space:pre"> </span>   time that is the start point of the truncation range. Set defaulttype</div>
<div>+<span style="white-space:pre"> </span>   to this first transition time. */</div>
<div>+<span style="white-space:pre"> </span>--nbr_removes;</div>
<div>+<span style="white-space:pre"> </span>ats[nbr_removes] = ytime(keepyear);</div>
<div>+<span style="white-space:pre"> </span>defaulttype = types[nbr_removes];</div>
<div>+<span style="white-space:pre"> </span>}</div>
<div>+</div>
<div>+<span style="white-space:pre"> </span>timecnt -= nbr_removes;</div>
<div>+<span style="white-space:pre"> </span>timei += nbr_removes;</div>
<div>+<span style="white-space:pre"> </span>}</div>
<div>+</div>
<div> <span style="white-space:pre"> </span>/*</div>
<div> <span style="white-space:pre"> </span>** Remove old file, if any, to snap links.</div>
<div> <span style="white-space:pre"> </span>*/</div>
<div>@@ -1910,7 +1963,7 @@ writezone(const char *const name, const char *const string, char version,</div>
<div> <span style="white-space:pre"> </span>thisleapi = leapi32;</div>
<div> <span style="white-space:pre"> </span>thisleapcnt = leapcnt32;</div>
<div> <span style="white-space:pre"> </span>} else {</div>
<div>-<span style="white-space:pre"> </span>thistimei = 0;</div>
<div>+<span style="white-space:pre"> </span>thistimei = timei;</div>
<div> <span style="white-space:pre"> </span>thistimecnt = timecnt;</div>
<div> <span style="white-space:pre"> </span>toomanytimes = thistimecnt >> 31 >> 31 >> 2 != 0;</div>
<div> <span style="white-space:pre"> </span>thisleapi = 0;</div>
<div>@@ -3107,6 +3160,19 @@ tadd(zic_t t1, zic_t t2)</div>
<div> }</div>
<div> </div>
<div> /*</div>
<div>+** Given a year, compute the date (in seconds since January 1,</div>
<div>+** 1970, 00:00).</div>
<div>+*/</div>
<div>+</div>
<div>+static zic_t</div>
<div>+ytime(zic_t year)</div>
<div>+{</div>
<div>+<span style="white-space:pre"> </span>struct rule xr = { 0 };</div>
<div>+<span style="white-space:pre"> </span>xr.r_dayofmonth = 1;</div>
<div>+<span style="white-space:pre"> </span>return rpytime(&xr, year);</div>
<div>+}</div>
<div>+</div>
<div>+/*</div>
<div> ** Given a rule, and a year, compute the date (in seconds since January 1,</div>
<div> ** 1970, 00:00 LOCAL time) in that year that the rule refers to.</div>
<div> */</div>
<div>-- </div>
<div>2.11.0</div>
<div><br>
​<br>
</div>
<p><br>
</p>
</body>
</html>