Skip to content

Commit

Permalink
Merge branch 'bug/121'
Browse files Browse the repository at this point in the history
* bug/121:
  use coordinated zone without leap transitions by default, fixes issue #121
  turn tzraw into standalone program for inspection
  • Loading branch information
hroptatyr committed Jan 20, 2021
2 parents ca11f5d + 2fd9682 commit bd961aa
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 22 deletions.
6 changes: 6 additions & 0 deletions lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ tzmap_CPPFLAGS = -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -D_BSD_SOURCE
tzmap_CPPFLAGS += -DSTANDALONE
BUILT_SOURCES += tzmap.yucc

noinst_PROGRAMS += tzraw
tzraw_SOURCES = tzraw.c tzraw.h
tzraw_SOURCES += leaps.h leaps.c
tzraw_CPPFLAGS = -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -D_BSD_SOURCE
tzraw_CPPFLAGS += -DSTANDALONE

## some tzmaps we'd like to support
tzminfo_FILES =
tzminfo_FILES += iata.tzminfo
Expand Down
76 changes: 58 additions & 18 deletions lib/tzraw.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,9 @@
# define MAP_ANON (0x1000U)
#endif /* MAP_ANON->MAP_ANONYMOUS */

typedef struct zih_s *zih_t;
typedef int32_t *ztr_t;
typedef uint8_t *zty_t;
typedef struct ztrdtl_s *ztrdtl_t;
typedef char *znam_t;
typedef int32_t ztr_t;
typedef int64_t zt2_t;
typedef uint8_t zty_t;

/* this is tzhead but better */
struct zih_s {
Expand Down Expand Up @@ -122,7 +120,7 @@ struct zspec_s {
int32_t since;
unsigned int offs:31;
unsigned int dstp:1;
znam_t name;
char *name;
} __attribute__((packed, aligned(16)));

/* for leap second transitions */
Expand All @@ -136,16 +134,16 @@ struct zleap_tr_s {
/* leap second support missing */
struct zif_s {
size_t mpsz;
zih_t hdr;
struct zih_s *hdr;

/* transitions */
ztr_t trs;
ztr_t *trs;
/* types */
zty_t tys;
zty_t *tys;
/* type array, deser'd, transition details array */
ztrdtl_t tda;
struct ztrdtl_s *tda;
/* zonename array */
znam_t zn;
char *zn;

/* file descriptor, if >0 this also means all data is in BE */
int fd;
Expand All @@ -164,11 +162,13 @@ static const char tzdir[] = TZDIR;
static const char tzdir[] = "/usr/share/zoneinfo";
#endif

#if defined ZONEINFO_UTC_RIGHT
/* where can we deduce some info for our coordinated zones */
static const char coord_fn[] = ZONEINFO_UTC_RIGHT;
#if 0

#elif defined ZONEINFO_UTC
static const char coord_fn[] = ZONEINFO_UTC;
#elif defined ZONEINFO_UTC_RIGHT
/* where can we deduce some info for our coordinated zones */
static const char coord_fn[] = ZONEINFO_UTC_RIGHT;
#else /* !ZONEINFO_UTC_RIGHT && !ZONEINFO_UTC */
static const char coord_fn[] = "/usr/share/zoneinfo/UTC";
#endif /* ZONEINFO_UTC_RIGHT || ZONEINFO_UTC */
Expand Down Expand Up @@ -285,7 +285,7 @@ zif_troffs(const struct zif_s z[static 1U], int n)

/**
* Return the zonename after the N-th transition in Z. */
static __attribute__((unused)) inline znam_t
static __attribute__((unused)) inline char*
zif_trname(const struct zif_s z[static 1U], int n)
{
/* no bound check! */
Expand Down Expand Up @@ -358,9 +358,9 @@ __init_zif(struct zif_s z[static 1U])
nty = zif_ntypes(z);
}

z->trs = (ztr_t)(z->hdr + 1);
z->tys = (zty_t)(z->trs + ntr);
z->tda = (ztrdtl_t)(z->tys + ntr);
z->trs = (ztr_t*)(z->hdr + 1);
z->tys = (zty_t*)(z->trs + ntr);
z->tda = (struct ztrdtl_s*)(z->tys + ntr);
z->zn = (char*)(z->tda + nty);
return;
}
Expand Down Expand Up @@ -744,4 +744,44 @@ zif_local_time(zif_t z, int32_t t)
}

#endif /* INCLUDED_tzraw_c_ */

#if defined STANDALONE
#include <stdio.h>

int
main(int argc, char *argv[])
{
int rc = 0;

for (int i = 1; i < argc; i++) {
zif_t z = zif_open(argv[i]);

if (z == NULL) {
rc++;
continue;
}

puts(argv[i]);
printf(" tutccnt\t%u\n", z->hdr->tzh_ttisgmtcnt);
printf(" tstdcnt\t%u\n", z->hdr->tzh_ttisstdcnt);
printf(" leapcnt\t%u\n", z->hdr->tzh_leapcnt);
printf(" timecnt\t%u\n", z->hdr->tzh_timecnt);
printf(" typecnt\t%u\n", z->hdr->tzh_typecnt);
printf(" charcnt\t%u\n", z->hdr->tzh_charcnt);

for (size_t j = 0U; j < zif_ntrans(z); j++) {
printf(" tr[%zu]\t%d\n", j, z->trs[j]);
}
for (size_t j = 0U; j < zif_ntypes(z); j++) {
printf(" ty[%zu]\t%hhi\n", j, z->tys[j]);
}
for (size_t j = 0U; j < zif_ntypes(z); j++) {
printf(" dt[%zu]\t%d %hhu %hhx\n", j, z->tda[j].offs, z->tda[j].dstp, z->tda[j].abbr);
}

zif_close(z);
}
return rc;
}
#endif /* STANDALONE */
/* tzraw.c ends here */
7 changes: 3 additions & 4 deletions src/dzone.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ main(int argc, char *argv[])
/* all them datetimes to consider */
struct dt_dt_s *d = NULL;
size_t nd = 0U;
bool trnsp = false;
bool trnsp;

if (yuck_parse(argi, argc, argv)) {
rc = 1;
Expand All @@ -258,9 +258,8 @@ main(int argc, char *argv[])
if (argi->from_zone_arg) {
fromz = dt_io_zone(argi->from_zone_arg);
}
if (argi->next_flag || argi->prev_flag) {
trnsp = true;
}
trnsp = argi->next_flag || argi->prev_flag;

if (argi->base_arg) {
struct dt_dt_s base = dt_strpdt(argi->base_arg, NULL, NULL);
dt_set_base(base);
Expand Down

0 comments on commit bd961aa

Please sign in to comment.