summaryrefslogtreecommitdiff
path: root/src/timezone/zic.c
diff options
context:
space:
mode:
authorPavan Deolasee2015-05-05 09:19:18 +0000
committerPavan Deolasee2015-05-05 09:19:18 +0000
commit73fa25c67cbfa24c03e28c96bf356f2592671730 (patch)
tree10ded7e26abd78d93658cb72fc5cb9d4672eff2a /src/timezone/zic.c
parentda4d108859bcd7a308ca75aba54281e32968822c (diff)
parent4a9ab6d8619817f9e3989c99b65140e19041dab7 (diff)
Merge branch 'XL_MASTER_MERGE_9_4' into XL_NEW_MASTER
Conflicts: src/test/regress/expected/aggregates.out src/test/regress/expected/create_index.out src/test/regress/expected/inherit.out src/test/regress/expected/join.out src/test/regress/expected/window.out src/test/regress/expected/with.out
Diffstat (limited to 'src/timezone/zic.c')
-rw-r--r--src/timezone/zic.c44
1 files changed, 31 insertions, 13 deletions
diff --git a/src/timezone/zic.c b/src/timezone/zic.c
index 8a95d6ac3f..2e38990323 100644
--- a/src/timezone/zic.c
+++ b/src/timezone/zic.c
@@ -8,14 +8,11 @@
#include "postgres_fe.h"
-#ifdef HAVE_GETOPT_H
-#include <getopt.h>
-#endif
#include <limits.h>
#include <locale.h>
+#include <time.h>
-extern int optind;
-extern char *optarg;
+#include "pg_getopt.h"
#include "private.h"
#include "pgtz.h"
@@ -181,6 +178,8 @@ static int max_year;
static zic_t min_time;
static int min_year;
static int noise;
+static int print_abbrevs;
+static zic_t print_cutoff;
static const char *rfilename;
static int rlinenum;
static const char *progname;
@@ -457,7 +456,7 @@ static void
usage(FILE *stream, int status)
{
(void) fprintf(stream, _("%s: usage is %s \
-[ --version ] [ --help ] [ -v ] [ -l localtime ] [ -p posixrules ] \\\n\
+[ --version ] [ --help ] [ -v ] [ -P ] [ -l localtime ] [ -p posixrules ] \\\n\
\t[ -d directory ] [ -L leapseconds ] [ -y yearistype ] [ filename ... ]\n\
\n\
Report bugs to tz@elsie.nci.nih.gov.\n"),
@@ -482,7 +481,7 @@ main(int argc, char *argv[])
(void) umask(umask(S_IWGRP | S_IWOTH) | (S_IWGRP | S_IWOTH));
#endif /* !WIN32 */
progname = argv[0];
- if (TYPE_BIT(zic_t) < 64)
+ if (TYPE_BIT(zic_t) <64)
{
(void) fprintf(stderr, "%s: %s\n", progname,
_("wild compilation-time specification of zic_t"));
@@ -498,14 +497,14 @@ main(int argc, char *argv[])
{
usage(stdout, EXIT_SUCCESS);
}
- while ((c = getopt(argc, argv, "d:l:p:L:vsy:")) != EOF && c != -1)
+ while ((c = getopt(argc, argv, "d:l:p:L:vPsy:")) != EOF && c != -1)
switch (c)
{
default:
usage(stderr, EXIT_FAILURE);
case 'd':
if (directory == NULL)
- directory = optarg;
+ directory = strdup(optarg);
else
{
(void) fprintf(stderr,
@@ -516,7 +515,7 @@ main(int argc, char *argv[])
break;
case 'l':
if (lcltime == NULL)
- lcltime = optarg;
+ lcltime = strdup(optarg);
else
{
(void) fprintf(stderr,
@@ -527,7 +526,7 @@ main(int argc, char *argv[])
break;
case 'p':
if (psxrules == NULL)
- psxrules = optarg;
+ psxrules = strdup(optarg);
else
{
(void) fprintf(stderr,
@@ -538,7 +537,7 @@ main(int argc, char *argv[])
break;
case 'y':
if (yitcommand == NULL)
- yitcommand = optarg;
+ yitcommand = strdup(optarg);
else
{
(void) fprintf(stderr,
@@ -549,7 +548,7 @@ main(int argc, char *argv[])
break;
case 'L':
if (leapsec == NULL)
- leapsec = optarg;
+ leapsec = strdup(optarg);
else
{
(void) fprintf(stderr,
@@ -561,6 +560,10 @@ main(int argc, char *argv[])
case 'v':
noise = TRUE;
break;
+ case 'P':
+ print_abbrevs = TRUE;
+ print_cutoff = time(NULL);
+ break;
case 's':
(void) printf("%s: -s ignored\n", progname);
break;
@@ -1780,6 +1783,21 @@ writezone(const char *name, const char *string)
puttzcode(gmtoffs[i], fp);
(void) putc(isdsts[i], fp);
(void) putc((unsigned char) indmap[abbrinds[i]], fp);
+
+ /* Print current timezone abbreviations if requested */
+ if (print_abbrevs && pass == 2 &&
+ (ats[i] >= print_cutoff || i == typecnt - 1))
+ {
+ char *thisabbrev = &thischars[indmap[abbrinds[i]]];
+
+ /* filter out assorted junk entries */
+ if (strcmp(thisabbrev, GRANDPARENTED) != 0 &&
+ strcmp(thisabbrev, "zzz") != 0)
+ fprintf(stdout, "%s\t%ld%s\n",
+ thisabbrev,
+ gmtoffs[i],
+ isdsts[i] ? "\tD" : "");
+ }
}
if (thischarcnt != 0)
(void) fwrite((void *) thischars,