From 58341f92209a9fb76ceecd6ff69e0589aec840e6 Mon Sep 17 00:00:00 2001 From: Carsten Larsen Date: Tue, 25 Oct 2016 21:12:38 +0000 Subject: [PATCH] Release 5 changes --- ChangeLog | 26 + example/Makefile | 9 +- example/adjust.c | 61 ++ example/date1.c | 4 - example/date2.c | 4 - example/gmtime.c | 4 - example/localtime.c | 4 - example/nyc.c | 4 - example/strftime.c | 4 - example/strftime2.c | 4 - example/strptime.c | 4 - example/time.c | 4 - library/compiler.h | 5 +- library/lib.h | 2 +- library/lib_base.c | 1 + library/lib_macros.h | 1 + library/lib_string.c | 73 +- library/lib_user.c | 16 +- library/time_asctime.c | 2 + library/time_header.h | 7 +- library/time_localsub.c | 18 +- library/time_lock.c | 9 +- library/time_settzname.c | 3 +- library/time_state.c | 1 + library/time_state.h | 2 + library/time_strftime.c | 10 +- library/time_time.c | 47 +- library/time_version.h | 4 +- script/Check | 7 + script/Show | 1 + script/ShowAmerica1 | 1 + script/ShowAmerica2 | 1 + script/ShowAsia | 1 + script/ShowEurope | 1 + test/test_acstime.c | 4 - test/test_library.c | 4 - test/test_timer.c | 7 +- test/test_tzalloc.c | 4 - test/test_tzload.c | 8 +- tz.guide | 19 +- tzdev.readme | 11 +- utility/Makefile | 34 +- utility/date.c | 1042 +++++------------------------ utility/dstcheck.c | 25 +- utility/getopt.c | 117 ++++ utility/getopt.h | 51 ++ utility/include/clib/timezone.h | 2 +- utility/include/inline/timezone.h | 2 - utility/private.h | 203 +----- utility/setclockgmt.c | 4 - utility/stdint.h | 4 +- utility/strtoll.c | 47 +- utility/timezone.c | 15 +- utility/timezoneinfo.c | 22 +- utility/tzversion.c | 45 ++ utility/tzversion.h | 22 +- utility/zdump_amiga.c | 5 - utility/zone.h | 4 - 58 files changed, 728 insertions(+), 1318 deletions(-) create mode 100644 ChangeLog create mode 100644 example/adjust.c create mode 100644 script/Check create mode 100644 script/Show create mode 100644 script/ShowAmerica1 create mode 100644 script/ShowAmerica2 create mode 100644 script/ShowAsia create mode 100644 script/ShowEurope create mode 100644 utility/getopt.c create mode 100644 utility/getopt.h create mode 100644 utility/tzversion.c diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..af95e8b --- /dev/null +++ b/ChangeLog @@ -0,0 +1,26 @@ +Amiga Time zone library release log + +5.00 Sun, 16 Oct 2016 + - TimeZone selector now adjust time when timezone i changed. + - Fixed gmt calculation bug in time(), gettimeofday() and settimeofday(). + - Semaphores now work in static library. + - Cleaned up headers in source files. Copyrighted code are now clearly + marked as such. + - Updated documentation and added more examples. + - Included POSIX date command from tz release 2016g. + +4.00 Wed, 05 Oct 2016 + - Synced code to tz release 2016g. + - Added gmt offset adjust in time(), gettimeofday() and settimeofday(). + - Build of static link library libtz.a. + - Fixed buffer overflow bug in loadtz(). + - Cleaned up headers in source files. + +3.00 Thu, 30 Jul 2015 + - Miscellaneous bug fixes. + +2.00 + - Initial release. + +1.00 + - Alpha release. diff --git a/example/Makefile b/example/Makefile index cb910b6..35b3e2e 100644 --- a/example/Makefile +++ b/example/Makefile @@ -1,9 +1,14 @@ -all: date1 date2 gmtime localtime nyc strftime strftime2 strptime time +all: date1 date2 gmtime localtime nyc strftime strftime2 strptime time adjust CC = m68k-amigaos-gcc CFLAGS = -O2 -s -noixemul -I../utility/include -Wall -Werror LIBS = +adjust.o: adjust.c + +adjust: adjust.o + ${CC} ${CFLAGS} -o adjust adjust.o + date1.o: date1.c date1: date1.o @@ -50,7 +55,7 @@ time: time.o ${CC} ${CFLAGS} -o time time.o clean: - rm -f *.o date1 date2 gmtime localtime nyc strftime strftime2 strptime time + rm -f *.o date1 date2 gmtime localtime nyc strftime strftime2 strptime time adjust depend: @echo Dependencies already done diff --git a/example/adjust.c b/example/adjust.c new file mode 100644 index 0000000..2b065df --- /dev/null +++ b/example/adjust.c @@ -0,0 +1,61 @@ +#include +#include +#include +#include "clib/timezone.h" +#include "inline/timezone.h" + +struct Library *TimezoneBase; + +void show() +{ + time_t rawtime; + struct tm *info; + struct tm tmp; + char buffer[80]; + int daylight; + long timezone; + long altzone; + char** tzname; + + time(&rawtime); + info = localtime_r(&rawtime,&tmp); + strftime(buffer,80,"%+", info); + printf("%s\n", buffer); + + daylight = daylight_c(); + timezone = timezone_c(); + altzone = altzone_c(); + tzname = tzname_c(); + printf("daylight (est): %d\n", daylight); + printf("timezone: %ld\n", timezone); + printf("altzone: %ld\n", altzone); + printf("tzname[0]: %s\n", tzname[0]); + printf("tzname[1]: %s\n", tzname[1]); +} + +void set(char *tz) +{ + printf("--------------------------------------------\n"); + show(); + SetVar((STRPTR)TZVARIABLE, (STRPTR)tz, strlen(tz) + 1, GVF_GLOBAL_ONLY); + tzset(); + printf("----------------- tzset --------------------\n"); + show(); + printf("--------------------------------------------\n"); +} + +int main() +{ + TimezoneBase = OpenLibrary("timezone.library", 3L); + if (!TimezoneBase) { + printf("Cannot open timezone library.\n"); + return 5; + } + + set("Europe/Copenhagen"); + set("Europe/Moscow"); + set("Europe/Copenhagen"); + + CloseLibrary(TimezoneBase); + return 0; +} diff --git a/example/date1.c b/example/date1.c index e0a57ce..fa517d5 100644 --- a/example/date1.c +++ b/example/date1.c @@ -1,7 +1,3 @@ -//--------------------------------------------------------------------------// -// This file is in the public domain. // -//--------------------------------------------------------------------------// - #include #include #include "clib/timezone.h" diff --git a/example/date2.c b/example/date2.c index 38905df..b297aba 100644 --- a/example/date2.c +++ b/example/date2.c @@ -1,7 +1,3 @@ -//--------------------------------------------------------------------------// -// This file is in the public domain. // -//--------------------------------------------------------------------------// - #include #include #include "clib/timezone.h" diff --git a/example/gmtime.c b/example/gmtime.c index 90a28d5..35c60fd 100644 --- a/example/gmtime.c +++ b/example/gmtime.c @@ -1,7 +1,3 @@ -//--------------------------------------------------------------------------// -// This file is in the public domain. // -//--------------------------------------------------------------------------// - #include #include #include "clib/timezone.h" diff --git a/example/localtime.c b/example/localtime.c index 21e5a07..3edb494 100644 --- a/example/localtime.c +++ b/example/localtime.c @@ -1,7 +1,3 @@ -//--------------------------------------------------------------------------// -// This file is in the public domain. // -//--------------------------------------------------------------------------// - #include #include #include "clib/timezone.h" diff --git a/example/nyc.c b/example/nyc.c index 174da71..7ca5dec 100644 --- a/example/nyc.c +++ b/example/nyc.c @@ -1,7 +1,3 @@ -//--------------------------------------------------------------------------// -// This file is in the public domain. // -//--------------------------------------------------------------------------// - #include #include #include "clib/timezone.h" diff --git a/example/strftime.c b/example/strftime.c index cf4ae53..1bc89ce 100644 --- a/example/strftime.c +++ b/example/strftime.c @@ -1,7 +1,3 @@ -//--------------------------------------------------------------------------// -// This file is in the public domain. // -//--------------------------------------------------------------------------// - #include #include #include "clib/timezone.h" diff --git a/example/strftime2.c b/example/strftime2.c index b0eac99..fa8d779 100644 --- a/example/strftime2.c +++ b/example/strftime2.c @@ -1,7 +1,3 @@ -//--------------------------------------------------------------------------// -// This file is in the public domain. // -//--------------------------------------------------------------------------// - #include #include #include "clib/timezone.h" diff --git a/example/strptime.c b/example/strptime.c index a19f0e4..1a71d63 100644 --- a/example/strptime.c +++ b/example/strptime.c @@ -1,7 +1,3 @@ -//--------------------------------------------------------------------------// -// This file is in the public domain. // -//--------------------------------------------------------------------------// - #include // printf #include // memset //#include // POSIX include file diff --git a/example/time.c b/example/time.c index 9bfcec1..f27c029 100644 --- a/example/time.c +++ b/example/time.c @@ -1,7 +1,3 @@ -//--------------------------------------------------------------------------// -// This file is in the public domain. // -//--------------------------------------------------------------------------// - #include #include #include "clib/timezone.h" diff --git a/library/compiler.h b/library/compiler.h index 776978e..e677eda 100644 --- a/library/compiler.h +++ b/library/compiler.h @@ -74,14 +74,11 @@ typedef struct Locale *locale_t; #define TZDEFAULT "localtime" #define TZDEFRULES "posixrules" -//void _fmtcallback(unsigned char, unsigned char**); -const unsigned long _fmtcallback[20]; - extern struct ExecBase* SysBase; extern struct Library* DOSBase; extern struct Library* UtilityBase; extern struct Library* MathIeeeDoubBasBase; extern struct Library* LocaleBase; -extern struct SignalSemaphore TimeSemaphore; +extern struct SignalSemaphore* TimeSemaphore; #endif diff --git a/library/lib.h b/library/lib.h index 4d3ed85..7b335b6 100644 --- a/library/lib.h +++ b/library/lib.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Carsten Larsen + * Copyright (c) 2015-2016 Carsten Larsen * Copyright (c) 2002-2006 by Olaf Barthel * All rights reserved. * diff --git a/library/lib_base.c b/library/lib_base.c index b772cbe..e884fbc 100644 --- a/library/lib_base.c +++ b/library/lib_base.c @@ -1,4 +1,5 @@ /* + * Copyright (c) 2015-2016 Carsten Larsen * Copyright (c) 2002-2006 by Olaf Barthel * All rights reserved. * diff --git a/library/lib_macros.h b/library/lib_macros.h index 36e248b..1d11b7a 100644 --- a/library/lib_macros.h +++ b/library/lib_macros.h @@ -1,4 +1,5 @@ /* + * Copyright (c) 2015-2016 Carsten Larsen * Copyright (c) 2002-2006 by Olaf Barthel * All rights reserved. * diff --git a/library/lib_string.c b/library/lib_string.c index 59e0699..80d35fd 100644 --- a/library/lib_string.c +++ b/library/lib_string.c @@ -2,28 +2,63 @@ #include "compiler.h" #include "time_header.h" -int isdigit(int c) +int isdigit(char c) { - return ('0' <= c && c <= '9'); + switch (c) { + default: + return 0; + case '1': case '2': case '3': case '4': case '5': + case '6': case '7': case '8': case '9': case '0': + return 1; + } } -int isspace(int c) +int isspace(char c) { - return ( - c == '\t' || - c == '\r' || - c == '\n' || - c == '\v' || - c == '\f' || - c == ' ' - ); + switch (c) { + default: + return 0; + case '\t': case '\r': case '\n': case '\v': case '\f': case ' ': + return 1; + } } -int toupper(int c) +int isalpha(char c) +{ + switch (c) { + default: + return 0; + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': + case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': + case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': + case 'V': case 'W': case 'X': case 'Y': case 'Z': + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': + case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': + case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': + case 'v': case 'w': case 'x': case 'y': case 'z': + return 1; + } +} + +int toupper(char c) { return ('a' <= c && c <= 'z') ? (c - ('a' - 'A')) : c; } +size_t strlen(const char *string) +{ + const char *s = string; + const char *start = s; + size_t result = 0; + + while((*s) != '\0') + s++; + + result = (size_t)(s - start); + + return result; +} + void *memmove(void *, const void *, size_t); void bcopy(const void *src,void *dest,size_t len) @@ -106,20 +141,6 @@ char *strcpy(char *dest, const char *src) return(result); } -size_t strlen(const char *string) -{ - const char *s = string; - const char *start = s; - size_t result = 0; - - while((*s) != '\0') - s++; - - result = (size_t)(s - start); - - return result; -} - int strncmp(const char *s1, const char *s2, size_t n) { int result = 0; diff --git a/library/lib_user.c b/library/lib_user.c index 102bb85..f92c430 100644 --- a/library/lib_user.c +++ b/library/lib_user.c @@ -84,7 +84,8 @@ bool UserLibInit( MathIeeeDoubBasBase = NULL; UtilityBase = NULL; LocaleBase = NULL; - + TimeSemaphore = NULL; + DOSBase = OpenLibrary(DOSLIB_NAME, LIB_VERSION); if (!DOSBase) { result = false; @@ -105,12 +106,17 @@ bool UserLibInit( result = false; } - InitSemaphore(&TimeSemaphore); + TimeSemaphore = (struct SignalSemaphore*)AllocMem( + sizeof(struct SignalSemaphore), + MEMF_ANY|MEMF_PUBLIC|MEMF_CLEAR); + + InitSemaphore(TimeSemaphore); - lcl_is_set = -1; + lcl_is_set = 0; timezone = 0; altzone = 0; daylight = 0; + zonechg = 0; errno = 0; return result; @@ -201,6 +207,10 @@ void UserLibExpunge(struct UserData * ud) FreeMem(gmtptr, sizeof(struct state)); } + if(TimeSemaphore) { + FreeMem(TimeSemaphore, sizeof(struct SignalSemaphore)); + } + if (LocaleBase) { CloseLibrary(LocaleBase); } diff --git a/library/time_asctime.c b/library/time_asctime.c index ed13962..25ad9e8 100644 --- a/library/time_asctime.c +++ b/library/time_asctime.c @@ -5,6 +5,7 @@ #define MAX_ASCTIME_BUF_SIZE 64 static char buf_asctime[MAX_ASCTIME_BUF_SIZE]; +static const unsigned long _fmtcallback[] = { 0x16c04e75 }; struct out { const char* wn; @@ -66,3 +67,4 @@ char* asctime(const struct tm *timeptr) { return asctime_r(timeptr, buf_asctime); } + diff --git a/library/time_header.h b/library/time_header.h index 4c8c09d..e49da03 100644 --- a/library/time_header.h +++ b/library/time_header.h @@ -128,9 +128,10 @@ char *strchr(const char *s, int c); // int strncmp(const char *s1, const char *s2, size_t n); // char *getenv(const char * name); // -int isdigit(int c); -int isspace(int c); -int toupper(int c); +int isdigit(char c); +int isspace(char c); +int isalpha(char c); +int toupper(char c); int strncasecmp(const char * _s1, const char * _s2, size_t n); #if defined(__GNUC__) && (__GNUC__ < 3) diff --git a/library/time_localsub.c b/library/time_localsub.c index ef06797..32be34d 100644 --- a/library/time_localsub.c +++ b/library/time_localsub.c @@ -7,10 +7,10 @@ struct tm * localsub( struct tm* const tmp ) { - const struct ttinfo* ttisp; - int i; - struct tm* result; - const time_t t = *timep; + register const struct ttinfo* ttisp; + register int i; + register struct tm* result; + const time_t t = *timep; if (sp == NULL) { // Don't bother to set tzname etc.; tzset has already done it. @@ -20,8 +20,8 @@ struct tm * localsub( if ((sp->goback && t < sp->ats[0]) || (sp->goahead && t > sp->ats[sp->timecnt - 1])) { time_t newt = t; - time_t seconds; - time_t years; + register time_t seconds; + register time_t years; if (t < sp->ats[0]) { seconds = sp->ats[0] - t; @@ -68,11 +68,11 @@ struct tm * localsub( i = sp->defaulttype; } else { - int lo = 1; - int hi = sp->timecnt; + register int lo = 1; + register int hi = sp->timecnt; while (lo < hi) { - int mid = (lo + hi) >> 1; + register int mid = (lo + hi) >> 1; if (t < sp->ats[mid]) { hi = mid; diff --git a/library/time_lock.c b/library/time_lock.c index 75a73ce..6990e9e 100644 --- a/library/time_lock.c +++ b/library/time_lock.c @@ -1,14 +1,17 @@ #include "time_header.h" -struct SignalSemaphore TimeSemaphore; +struct SignalSemaphore* TimeSemaphore = NULL; int lock(void) { - ObtainSemaphore(&TimeSemaphore); + if (TimeSemaphore != NULL) + ObtainSemaphore(TimeSemaphore); + return 0; } void unlock(void) { - ReleaseSemaphore(&TimeSemaphore); + if (TimeSemaphore != NULL) + ReleaseSemaphore(TimeSemaphore); } diff --git a/library/time_settzname.c b/library/time_settzname.c index dace41e..20b8b02 100644 --- a/library/time_settzname.c +++ b/library/time_settzname.c @@ -10,7 +10,8 @@ void settzname(void) daylight = 0; timezone = 0; altzone = 0; - + zonechg = 1; + if (sp == NULL) { tzname[0] = tzname[1] = (char *) gmt; return; diff --git a/library/time_state.c b/library/time_state.c index 7043da0..9bc85ed 100644 --- a/library/time_state.c +++ b/library/time_state.c @@ -17,6 +17,7 @@ struct state *gmtptr; long timezone; long altzone; int daylight; +int zonechg; int errno; diff --git a/library/time_state.h b/library/time_state.h index 7b51778..b770762 100644 --- a/library/time_state.h +++ b/library/time_state.h @@ -86,4 +86,6 @@ extern long altzone; extern int errno; +int zonechg; + #endif diff --git a/library/time_strftime.c b/library/time_strftime.c index 137a024..db42b90 100644 --- a/library/time_strftime.c +++ b/library/time_strftime.c @@ -38,6 +38,8 @@ extern char* tzname[]; #define IN_THIS 2 #define IN_ALL 3 +static const unsigned long _fmtcallback[] = { 0x16c04e75 }; + size_t strftime( char * const s, size_t maxsize, @@ -556,11 +558,3 @@ static char* _yconv( pt = _conv(((trail < 0) ? -trail : trail), "%02d", pt, ptlim); return pt; } - -const unsigned long _fmtcallback[] = { 0x16c04e75 }; -/* -void _fmtcallback(unsigned char c, unsigned char **data) -{ - *(*data)++=c; -} -*/ diff --git a/library/time_time.c b/library/time_time.c index a7d9b28..a8edeff 100644 --- a/library/time_time.c +++ b/library/time_time.c @@ -6,7 +6,28 @@ // 2922 is the number of days between 1.1.1970 and 1.1.1978 // (2 leap years and 6 normal) // 2922 * 24 * 60 * 60 = 252460800 -#define AMIGAOFFSET 252460800 +#define AMIGAOFFSET 252460800L + +struct state *adj_lclptr; +struct tm adj_tm; + +long gmtoffset_c(struct timeval *tv) +{ + time_t time = (time_t)tv->tv_secs; + + if (!lcl_is_set) + return 0; + + if (zonechg || lclptr != adj_lclptr) { + localtime_rz(lclptr, &time, &adj_tm); + adj_lclptr = lclptr; + zonechg = 0; + } + + // TODO: include logic to detect dst change + + return -adj_tm.tm_gmtoff; +} /** * @brief @@ -22,19 +43,14 @@ time_t time(time_t *tloc) long zone; time_t time; struct timeval tv; - + if (CreateTimer() != 0) { return 0; } GetSysTime(&tv); - if(lcl_is_set) { - zone = (daylight == 0 ? timezone : altzone); - } else { - zone = 0; - } - + zone = gmtoffset_c(&tv); time = (time_t)(tv.tv_secs + AMIGAOFFSET + zone); if (tloc) { @@ -47,16 +63,19 @@ time_t time(time_t *tloc) int gettimeofday(struct timeval *tv, const timezone_t tz) { + long zone; time_t time; struct tm tm; - + if (CreateTimer() != 0) { return -1; } - + + zone = gmtoffset_c(tv); + TimeRequest->tr_node.io_Command = TR_GETSYSTIME; DoIO((struct IORequest*)TimeRequest); - tv->tv_secs = (long)TimeRequest->tr_time.tv_secs + AMIGAOFFSET; + tv->tv_secs = (long)TimeRequest->tr_time.tv_secs + AMIGAOFFSET + zone; tv->tv_micro = TimeRequest->tr_time.tv_micro; time = tv->tv_secs; @@ -72,14 +91,18 @@ int gettimeofday(struct timeval *tv, const timezone_t tz) int settimeofday(const struct timeval *tv, const timezone_t tz) { + long zone; + if (CreateTimer() != 0) { return -1; } + zone = gmtoffset_c((struct timeval*)tv); + // TODO: Include timezone in logic TimeRequest->tr_node.io_Command = TR_SETSYSTIME; - TimeRequest->tr_time.tv_secs = (long)tv->tv_secs - AMIGAOFFSET; + TimeRequest->tr_time.tv_secs = (long)tv->tv_secs - AMIGAOFFSET - zone; TimeRequest->tr_time.tv_micro = tv->tv_micro; DoIO((struct IORequest*)TimeRequest); diff --git a/library/time_version.h b/library/time_version.h index 3c41e83..3c434a4 100644 --- a/library/time_version.h +++ b/library/time_version.h @@ -3,11 +3,11 @@ #define XSTR(s) STR(s) #define STR(s) #s -#define VERSION_NO 4 +#define VERSION_NO 5 #define VERSION XSTR(VERSION_NO) #define REVISION_NO 00 #define REVISION XSTR(REVISION_NO) -#define DATE "05.10.2016" +#define DATE "15.10.2016" #define PACKAGE_TZ "tzcode" #define VERSION_TZ "2016g" #define BUGEMAIL_TZ "cs@innolan.dk" diff --git a/script/Check b/script/Check new file mode 100644 index 0000000..1ee6c28 --- /dev/null +++ b/script/Check @@ -0,0 +1,7 @@ +DSTCheck + +If Warn + Echo "We have DST !" +Else + Echo "We don't have DST !" +Endif diff --git a/script/Show b/script/Show new file mode 100644 index 0000000..85b7c03 --- /dev/null +++ b/script/Show @@ -0,0 +1 @@ +ZDump America/Argentina/Buenos_Aires America/Barbados America/Belize America/Caracas America/Chicago America/Detroit America/Grenada America/Havana America/La_Paz America/Lima America/Los_Angeles America/Mexico_City America/Nassau America/New_York America/Nome America/Puerto_Rico America/Sao_Paulo America/Thule America/Vancouver Asia/Damascus Asia/Irkutsk Asia/Karachi Asia/Samarkand Asia/Seoul Asia/Shanghai Asia/Singapore Asia/Tokyo Australia/Melbourne Pacific/Noumea Pacific/Galapagos Europe/Amsterdam Europe/Athens Europe/Lisbon Europe/London Europe/Moscow \ No newline at end of file diff --git a/script/ShowAmerica1 b/script/ShowAmerica1 new file mode 100644 index 0000000..c4b92cd --- /dev/null +++ b/script/ShowAmerica1 @@ -0,0 +1 @@ +ZDump America/Adak America/Anchorage America/Anguilla America/Antigua America/Araguaina America/Argentina/Buenos_Aires America/Argentina/Catamarca America/Argentina/Cordoba America/Argentina/Jujuy America/Argentina/La_Rioja America/Argentina/Mendoza America/Argentina/Rio_Gallegos America/Argentina/Salta America/Argentina/San_Juan America/Argentina/San_Luis America/Argentina/Tucuman America/Argentina/Ushuaia America/Aruba America/Asuncion America/Atikokan America/Bahia America/Bahia_Banderas America/Barbados America/Belem America/Belize America/Blanc-Sablon America/Boa_Vista America/Bogota America/Boise America/Cambridge_Bay America/Campo_Grande America/Cancun America/Caracas America/Cayenne America/Cayman America/Chicago America/Chihuahua America/Costa_Rica America/Creston America/Cuiaba America/Curacao America/Danmarkshavn America/Dawson America/Dawson_Creek America/Denver America/Detroit America/Dominica America/Edmonton America/Eirunepe America/El_Salvador America/Fortaleza America/Glace_Bay America/Godthab America/Goose_Bay America/Grand_Turk America/Grenada America/Guadeloupe America/Guatemala America/Guayaquil America/Guyana America/Halifax America/Havana America/Hermosillo America/Indiana/Indianapolis America/Indiana/Knox America/Indiana/Marengo America/Indiana/Petersburg America/Indiana/Tell_City America/Indiana/Vevay America/Indiana/Vincennes America/Indiana/Winamac \ No newline at end of file diff --git a/script/ShowAmerica2 b/script/ShowAmerica2 new file mode 100644 index 0000000..ae87c99 --- /dev/null +++ b/script/ShowAmerica2 @@ -0,0 +1 @@ +ZDump America/Inuvik America/Iqaluit America/Jamaica America/Juneau America/Kentucky/Louisville America/Kentucky/Monticello America/Kralendijk America/La_Paz America/Lima America/Los_Angeles America/Lower_Princes America/Maceio America/Managua America/Manaus America/Marigot America/Martinique America/Matamoros America/Mazatlan America/Menominee America/Merida America/Metlakatla America/Mexico_City America/Miquelon America/Moncton America/Monterrey America/Montevideo America/Montserrat America/Nassau America/New_York America/Nipigon America/Nome America/Noronha America/North_Dakota/Beulah America/North_Dakota/Center America/North_Dakota/New_Salem America/Ojinaga America/Panama America/Pangnirtung America/Paramaribo America/Phoenix America/Port-au-Prince America/Port_of_Spain America/Porto_Velho America/Puerto_Rico America/Rainy_River America/Rankin_Inlet America/Recife America/Regina America/Resolute America/Rio_Branco America/Santa_Isabel America/Santarem America/Santiago America/Santo_Domingo America/Sao_Paulo America/Scoresbysund America/Sitka America/St_Barthelemy America/St_Johns America/St_Kitts America/St_Lucia America/St_Thomas America/St_Vincent America/Swift_Current America/Tegucigalpa America/Thule America/Thunder_Bay America/Tijuana America/Toronto America/Tortola America/Vancouver America/Whitehorse America/Winnipeg America/Yakutat America/Yellowknife \ No newline at end of file diff --git a/script/ShowAsia b/script/ShowAsia new file mode 100644 index 0000000..5a3e845 --- /dev/null +++ b/script/ShowAsia @@ -0,0 +1 @@ +ZDump Asia/Aden Asia/Almaty Asia/Amman Asia/Anadyr Asia/Aqtau Asia/Aqtobe Asia/Ashgabat Asia/Baghdad Asia/Bahrain Asia/Baku Asia/Bangkok Asia/Beirut Asia/Bishkek Asia/Brunei Asia/Chita Asia/Choibalsan Asia/Colombo Asia/Damascus Asia/Dhaka Asia/Dili Asia/Dubai Asia/Dushanbe Asia/Gaza Asia/Hebron Asia/Ho_Chi_Minh Asia/Hong_Kong Asia/Hovd Asia/Irkutsk Asia/Istanbul Asia/Jakarta Asia/Jayapura Asia/Jerusalem Asia/Kabul Asia/Kamchatka Asia/Karachi Asia/Kathmandu Asia/Khandyga Asia/Kolkata Asia/Krasnoyarsk Asia/Kuala_Lumpur Asia/Kuching Asia/Kuwait Asia/Macau Asia/Magadan Asia/Makassar Asia/Manila Asia/Muscat Asia/Nicosia Asia/Novokuznetsk Asia/Novosibirsk Asia/Omsk Asia/Oral Asia/Phnom_Penh Asia/Pontianak Asia/Pyongyang Asia/Qatar Asia/Qyzylorda Asia/Rangoon Asia/Riyadh Asia/Sakhalin Asia/Samarkand Asia/Seoul Asia/Shanghai Asia/Singapore Asia/Srednekolymsk Asia/Taipei Asia/Tashkent Asia/Tbilisi Asia/Tehran Asia/Thimphu Asia/Tokyo Asia/Ulaanbaatar Asia/Urumqi Asia/Ust-Nera Asia/Vientiane Asia/Vladivostok Asia/Yakutsk Asia/Yekaterinburg Asia/Yerevan \ No newline at end of file diff --git a/script/ShowEurope b/script/ShowEurope new file mode 100644 index 0000000..f73dc07 --- /dev/null +++ b/script/ShowEurope @@ -0,0 +1 @@ +ZDump Europe/Amsterdam Europe/Andorra Europe/Athens Europe/Belgrade Europe/Berlin Europe/Bratislava Europe/Brussels Europe/Bucharest Europe/Budapest Europe/Busingen Europe/Chisinau Europe/Copenhagen Europe/Dublin Europe/Gibraltar Europe/Guernsey Europe/Helsinki Europe/Isle_of_Man Europe/Istanbul Europe/Jersey Europe/Kaliningrad Europe/Kiev Europe/Lisbon Europe/Ljubljana Europe/London Europe/Luxembourg Europe/Madrid Europe/Malta Europe/Mariehamn Europe/Minsk Europe/Monaco Europe/Moscow Europe/Nicosia Europe/Oslo Europe/Paris Europe/Podgorica Europe/Prague Europe/Riga Europe/Rome Europe/Samara Europe/San_Marino Europe/Sarajevo Europe/Simferopol Europe/Skopje Europe/Sofia Europe/Stockholm Europe/Tallinn Europe/Tirane Europe/Uzhgorod Europe/Vaduz Europe/Vatican Europe/Vienna Europe/Vilnius Europe/Volgograd Europe/Warsaw Europe/Zagreb Europe/Zaporozhye Europe/Zurich \ No newline at end of file diff --git a/test/test_acstime.c b/test/test_acstime.c index c9922a5..9b70caa 100644 --- a/test/test_acstime.c +++ b/test/test_acstime.c @@ -1,7 +1,3 @@ -//--------------------------------------------------------------------------// -// This file is in the public domain. // -//--------------------------------------------------------------------------// - #include #include "time_tm.h" #include "time_header.h" diff --git a/test/test_library.c b/test/test_library.c index 7e9658c..5c82dff 100644 --- a/test/test_library.c +++ b/test/test_library.c @@ -1,7 +1,3 @@ -//--------------------------------------------------------------------------// -// This file is in the public domain. // -//--------------------------------------------------------------------------// - #include #include #include "clib_timezone.h" diff --git a/test/test_timer.c b/test/test_timer.c index 34863eb..6375204 100644 --- a/test/test_timer.c +++ b/test/test_timer.c @@ -1,7 +1,3 @@ -//--------------------------------------------------------------------------// -// This file is in the public domain. // -//--------------------------------------------------------------------------// - #include "compiler.h" #include "time_header.h" #include @@ -21,7 +17,7 @@ int main(const int argc, char *argv[]) UtilityBase = NULL; LocaleBase = NULL; TimerBase = NULL; - TimeRequest = NULL; + TimeRequest = NULL; DOSBase = OpenLibrary(DOSLIB_NAME, LIB_VERSION); if (!DOSBase) { @@ -74,4 +70,3 @@ int main(const int argc, char *argv[]) return 0; } - diff --git a/test/test_tzalloc.c b/test/test_tzalloc.c index f40e8bd..7767882 100644 --- a/test/test_tzalloc.c +++ b/test/test_tzalloc.c @@ -1,7 +1,3 @@ -//--------------------------------------------------------------------------// -// This file is in the public domain. // -//--------------------------------------------------------------------------// - #include "proto/exec.h" #include "compiler.h" #include "time_tm.h" diff --git a/test/test_tzload.c b/test/test_tzload.c index 4425b22..83e07f6 100644 --- a/test/test_tzload.c +++ b/test/test_tzload.c @@ -1,13 +1,7 @@ -//--------------------------------------------------------------------------// -// This file is in the public domain. // -//--------------------------------------------------------------------------// - // Compile with: // m68k-amigaos-gcc -I../library -c test_tzload.c // Link with: -// m68k-amigaos-gcc -noixemul test_tzload.o -o tzload ../library/time_tzload.o -// ../library/time_tzparse.o ../library/time_state.o ../library/time_init_ttinfo.o -// ../library/time_length.o ../library/time_increment_ot.o +// m68k-amigaos-gcc -noixemul test_tzload.o -o tzload libtz.a #include "proto/exec.h" #include "time_tm.h" diff --git a/tz.guide b/tz.guide index 5a44b1e..fd383ef 100644 --- a/tz.guide +++ b/tz.guide @@ -1,7 +1,7 @@ @database tzc.guide @author Carsten Larsen @(c) Carsten Larsen -@$VER: tz.guide 4.00 (05.10.2016) +@$VER: tz.guide 5.00 (15.10.2016) @node Main "Amiga time zone database" @title "Amiga time zone database" @@ -50,14 +50,13 @@ Optionally * Copy SetClockGMT to your systems C: * Copy TimeZone to your systems SYS:Prefs - * Copy files in Help to LOCALE:Help/TimeZone * Assign ZONEINFO: to LOCALE:Zoneinfo in S:Startup-Sequence * Add SetClockGMT NIL: LOAD to end of S:Startup-Sequence @{b}SETUP@{ub} -Select a Time Zone: -Open TimeZone GUI +Select a time zone in TimeZone GUI: +TimeZone Save GMT time to RTC (hardware) clock: SetClockGMT SAVE @@ -69,7 +68,7 @@ Validate time zone preferences in shell: TimeZoneInfo Show time in other time zones: -Execute example/misc +Execute script/Show @@ -188,8 +187,8 @@ proposing and distributing patches is via email as illustrated above. The time zone name will be save to the TZ environment variable if selected. Do not choose this option if you already have a rule in your TZ variable. + -@{bg filltext}@{b} July 25, 2015 TimeZone@{ub}@{bg background} @endnode @node TimeZoneInfo "TimeZoneInfo user manual" @title "TimeZoneInfo user manual" @@ -206,7 +205,6 @@ proposing and distributing patches is via email as illustrated above. zone. -@{bg filltext}@{b} July 25, 2015 TimeZoneInfo@{ub}@{bg background} @endnode @node SetClockGMT "SetClockGMT user manual" @title "SetClockGMT user manual" @@ -236,7 +234,6 @@ proposing and distributing patches is via email as illustrated above. off or sets the test bit of the clock. -@{bg filltext}@{b} July 25, 2015 SetClockGMT@{ub}@{bg background} @endnode @node DSTCheck "DSTCheck user manual" @title "DSTCheck user manual" @@ -261,14 +258,13 @@ proposing and distributing patches is via email as illustrated above. ENDIF -@{bg filltext}@{b} July 25, 2015 DSTCheck@{ub}@{bg background} @endnode @node library "Timezone Library" @title "Timezone Library" @{b}timezone.library@{ub} -Version 3 of the Timezone Library implements the following functions. +Version 5 of the Timezone Library implements the following functions. time.h tzset, tzalloc, tzfree, time, mktime, mktime_z, localtime, localtime_r, localtime_rz, gmtime, gmtime_r, ctime, ctime_r, ctime_rz, difftime, @@ -346,7 +342,6 @@ extra getsystime, setsystime, tzgetlocation, gmtoffset, stou, utos @{"tzfile" link "tzfile"}, @{"zic" link "zic"} -@{bg filltext}@{b} July 25, 2015 ZDump@{ub}@{bg background} @endnode @node zic "zic developer manual" @title "Time zone compiler" @@ -699,7 +694,6 @@ extra getsystime, setsystime, tzgetlocation, gmtoffset, stou, utos @{"tzfile" link "tzfile"}, @{"zdump" link "zdump"} -@{bg filltext}@{b} July 25, 2015 ZIC@{ub}@{bg background} @endnode @node tzfile "tzfile developer manual" @title "Time zone information" @@ -811,5 +805,4 @@ extra getsystime, setsystime, tzgetlocation, gmtoffset, stou, utos @{"zdump" link "zdump"}, @{"zic" link "zic"} -@{bg filltext}@{b} July 25, 2015 TZFILE@{ub}@{bg background} @endnode diff --git a/tzdev.readme b/tzdev.readme index ff8d2f1..d0339bf 100644 --- a/tzdev.readme +++ b/tzdev.readme @@ -2,14 +2,11 @@ Short: Time Zone Database and Library (source) Author: Carsten Larsen, Arthur David Olson & others Uploader: Carsten Larsen (carsten larsen mail com) Type: util/time -Version: 4.00 +Version: 5.00 Requires: util/time/tzdata Architecture: generic URL: http://www.iana.org/time-zones -"What time is it?" -- Richard Deacon as The King -"Any time you want it to be." -- Frank Baxter as The Scientist - (from the Bell System film "About Time") The Time Zone Database (often called tz or zoneinfo) contains code and data that represent the history of local time for many representative @@ -50,11 +47,11 @@ extra Utilities - DSTCheck, SetClockGMT, TimeZone, TimeZoneInfo, ZDump + Date, DSTCheck, SetClockGMT, TimeZone, TimeZoneInfo, ZDump Example programs date1, date2, gmtime, localtime, nyc, strftime, strftime2, strptime, - time + time, adjust License and Credits @@ -75,6 +72,4 @@ None of them are responsible for remaining errors. Look in ftp://ftp.iana.org/tz/releases/ for updated versions of these files. -Amiga variants are at: ftp://aminet.net/util/time/tzdev.zip - Please send general comments or information to tz@iana.org. diff --git a/utility/Makefile b/utility/Makefile index 3414ee7..cb9cc7f 100644 --- a/utility/Makefile +++ b/utility/Makefile @@ -1,4 +1,4 @@ -all: timezone timezoneinfo setclockgmt zdump dstcheck +all: timezone timezoneinfo setclockgmt zdump dstcheck date CC = m68k-amigaos-gcc CFLAGS = -O2 -s -noixemul -DAOS3 -Iinclude -Wall @@ -11,15 +11,18 @@ tzversion.h: private.h: touch private.h +getopt.h: + touch getopt.h + zdump_amiga.o: zdump_amiga.c private.h tzversion.h zic.o: zic.c private.h tzversion.h tzfile.h -zic_amiga.o: zic_amiga.c private.h tzversion.h +zic_amiga.o: zic_amiga.c private.h tzversion.h strtoll.o: strtoll.c tzversion.h -date_amiga.o: date_amiga.c private.h tzversion.h +getopt.o: getopt.c getopt.h date.o: date.c private.h tzversion.h @@ -31,11 +34,20 @@ setclockgmt.o: setclockgmt.c tzversion.h dstcheck.o: dstcheck.c tzversion.h -zic: zic.o zic_amiga.o - ${CC} ${CFLAGS} -o zic zic.o zic_amiga.o -liberty +dstcheck_amiga.o: private.h tzversion.h + ${CC} ${CFLAGS} -DPROG_NAME=\"DSTCheck\" -c tzversion.c -o dstcheck_amiga.o -date: date.o date_amiga.o strtoll.o - ${CC} ${CFLAGS} -o Date date.o date_amiga.o strtoll.o -liberty -lm +date_amiga.o: private.h tzversion.h + ${CC} ${CFLAGS} -DPROG_NAME=\"tzdate\" -c tzversion.c -o date_amiga.o + +timezoneinfo_amiga.o: private.h tzversion.h + ${CC} ${CFLAGS} -DPROG_NAME=\"TimeZoneInfo\" -c tzversion.c -o timezoneinfo_amiga.o + +zic: zic.o zic_amiga.o getopt.o + ${CC} ${CFLAGS} -o zic zic.o zic_amiga.o getopt.o + +date: date.o date_amiga.o strtoll.o getopt.o + ${CC} ${CFLAGS} -o Date date.o date_amiga.o strtoll.o getopt.o -lm zdump: zdump_amiga.o strtoll.o ${CC} ${CFLAGS} -o ZDump zdump_amiga.o strtoll.o @@ -43,14 +55,14 @@ zdump: zdump_amiga.o strtoll.o timezone: timezone.o ${CC} ${CFLAGS} -o TimeZone timezone.o -timezoneinfo: timezoneinfo.o - ${CC} ${CFLAGS} -o TimeZoneInfo timezoneinfo.o +timezoneinfo: timezoneinfo.o timezoneinfo_amiga.o + ${CC} ${CFLAGS} -o TimeZoneInfo timezoneinfo.o timezoneinfo_amiga.o setclockgmt: setclockgmt.o ${CC} ${CFLAGS} -o SetClockGMT setclockgmt.o -dstcheck: dstcheck.o - ${CC} ${CFLAGS} -o DSTCheck dstcheck.o +dstcheck: dstcheck.o dstcheck_amiga.o + ${CC} ${CFLAGS} -o DSTCheck dstcheck.o dstcheck_amiga.o clean: rm -f *.o ZDump TimeZone TimeZoneInfo SetClockGMT DSTCheck Date zic diff --git a/utility/date.c b/utility/date.c index 2be7e47..c8f34d7 100644 --- a/utility/date.c +++ b/utility/date.c @@ -1,39 +1,35 @@ -/* - * Copyright (c) 1985, 1987, 1988 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms are permitted - * provided that the above copyright notice and this paragraph are - * duplicated in all such forms and that any documentation, - * advertising materials, and other materials related to such - * distribution and use acknowledge that the software was developed - * by the University of California, Berkeley. The name of the - * University may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - */ +/* Display or set the current time and date. */ -//#include "amiga_tz.h" +/* Copyright 1985, 1987, 1988 The Regents of the University of California. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the University nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. */ + +#include "tzversion.h" #include "private.h" -#if HAVE_ADJTIME || HAVE_SETTIMEOFDAY -#include "sys/time.h" /* for struct timeval, struct timezone */ -#endif /* HAVE_ADJTIME || HAVE_SETTIMEOFDAY */ #include "locale.h" -#if HAVE_UTMPX_H -#include "utmpx.h" -#endif - -#ifndef OTIME_MSG -#define OTIME_MSG "old time" -#endif -#ifndef NTIME_MSG -#define NTIME_MSG "new time" -#endif -#if !defined WTMPX_FILE && defined _PATH_WTMPX -# define WTMPX_FILE _PATH_WTMPX -#endif /* ** The two things date knows about time are. . . @@ -47,893 +43,199 @@ #define SECSPERMIN 60 #endif /* !defined SECSPERMIN */ -long long int strtoll(const char *nptr, char **endptr, int base); - extern char ** environ; + +#if !HAVE_POSIX_DECLS extern char * optarg; extern int optind; -extern char * tzname[2]; +extern char * tzname[]; +#endif static int retval = EXIT_SUCCESS; -static void checkfinal(char const *, bool, time_t, time_t); -static time_t convert(const char *, bool, time_t); static void display(const char *, time_t); static void dogmt(void); static void errensure(void); -static void iffy(time_t, time_t, const char *, const char *); -static const char * nondigit(const char *); -static void oops(const char *); -static void reset(time_t, bool); static void timeout(FILE *, const char *, const struct tm *); static void usage(void); -static void wildinput(const char *, const char *, - const char *); int main(const int argc, char *argv[]) { - register const char * format; - register const char * value; - register const char * cp; - register int ch; - register bool dousg; - register bool aflag = false; - register bool dflag = false; - register bool nflag = false; - register bool tflag = false; - register bool rflag = false; - register int minuteswest; - register int dsttime; - register double adjust; - time_t now; - time_t t; - intmax_t secs; - char * endarg; + register const char * format; + register const char * cp; + register int ch; + register bool rflag = false; + time_t t; + intmax_t secs; + char * endarg; - INITIALIZE(dousg); - INITIALIZE(adjust); + amiga_open_libs(); #ifdef LC_ALL - setlocale(LC_ALL, ""); + setlocale(LC_ALL, ""); #endif /* defined(LC_ALL) */ #if HAVE_GETTEXT #ifdef TZ_DOMAINDIR - bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR); + bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR); #endif /* defined(TEXTDOMAINDIR) */ - textdomain(TZ_DOMAIN); + textdomain(TZ_DOMAIN); #endif /* HAVE_GETTEXT */ - t = now = time(NULL); - format = value = NULL; - while ((ch = getopt(argc, argv, "ucr:nd:t:a:")) != EOF && ch != -1) { - switch (ch) { - default: - usage(); - case 'u': /* do it in UT */ - case 'c': - dogmt(); - break; - case 'r': /* seconds since 1970 */ - if (rflag) { - fprintf(stderr, - _("date: error: multiple -r's used")); - usage(); - } - rflag = true; - errno = 0; - secs = strtoimax (optarg, &endarg, 0); - if (*endarg || optarg == endarg) - errno = EINVAL; - else if (! (time_t_min <= secs && secs <= time_t_max)) - errno = ERANGE; - if (errno) { - perror(optarg); - errensure(); - exit(retval); - } - t = secs; - break; - case 'n': /* don't set network */ - nflag = true; - break; - case 'd': /* daylight saving time */ - if (dflag) { - fprintf(stderr, - _("date: error: multiple -d's used")); - usage(); - } - dflag = true; - cp = optarg; - dsttime = atoi(cp); - if (*cp == '\0' || *nondigit(cp) != '\0') - wildinput(_("-t value"), optarg, - _("must be a non-negative number")); - break; - case 't': /* minutes west of UTC */ - if (tflag) { - fprintf(stderr, - _("date: error: multiple -t's used")); - usage(); - } - tflag = true; - cp = optarg; - minuteswest = atoi(cp); - if (*cp == '+' || *cp == '-') - ++cp; - if (*cp == '\0' || *nondigit(cp) != '\0') - wildinput(_("-d value"), optarg, - _("must be a number")); - break; - case 'a': /* adjustment */ - if (aflag) { - fprintf(stderr, - _("date: error: multiple -a's used")); - usage(); - } - aflag = true; - cp = optarg; - adjust = atof(cp); - if (*cp == '+' || *cp == '-') - ++cp; - if (*cp == '\0' || strcmp(cp, ".") == 0) - wildinput(_("-a value"), optarg, - _("must be a number")); - cp = nondigit(cp); - if (*cp == '.') - ++cp; - if (*nondigit(cp) != '\0') - wildinput(_("-a value"), optarg, - _("must be a number")); - break; - } - } - while (optind < argc) { - cp = argv[optind++]; - if (*cp == '+') - if (format == NULL) - format = cp + 1; - else { - fprintf(stderr, - _("date: error: multiple formats in command line\n")); - usage(); - } - else if (value == NULL && !rflag) - value = cp; - else { - fprintf(stderr, - _("date: error: multiple values in command line\n")); - usage(); - } - } - if (value != NULL) { - /* - ** This order ensures that "reasonable" twelve-digit inputs - ** (such as 120203042006) won't be misinterpreted - ** even if time_t's range all the way back to the thirteenth - ** century. Do not change the order. - */ - t = convert(value, (dousg = true), now); - if (t == -1) - t = convert(value, (dousg = false), now); - if (t == -1) { - /* - ** Out of range values, - ** or time that falls in a DST transition hole? - */ - if ((cp = strchr(value, '.')) != NULL) { - /* - ** Ensure that the failure of - ** TZ=America/New_York date 8712312359.60 - ** doesn't get misdiagnosed. (It was - ** TZ=America/New_York date 8712311859.60 - ** when the leap second was inserted.) - ** The normal check won't work since - ** the given time is valid in UTC. - */ - if (atoi(cp + 1) >= SECSPERMIN) - wildinput(_("time"), value, - _("out of range seconds given")); - } - dogmt(); - t = convert(value, false, now); - if (t == -1) - t = convert(value, true, now); - wildinput(_("time"), value, - (t == -1) ? - _("out of range value given") : - _("time skipped when clock springs forward")); - } - } - /* - ** Entire command line has now been checked. - */ - if (aflag) { -#if HAVE_ADJTIME - struct timeval tv; + t = time(NULL); + format = NULL; + while ((ch = getopt(argc, argv, "ucr:")) != EOF && ch != -1) { + switch (ch) { + default: + usage(); + case 'u': /* do it in UT */ + case 'c': + dogmt(); + break; + case 'r': /* seconds since 1970 */ + if (rflag) { + fprintf(stderr, + _("date: error: multiple -r's used")); + usage(); + } + rflag = true; + errno = 0; + secs = strtoimax (optarg, &endarg, 0); + if (*endarg || optarg == endarg) + errno = EINVAL; + else if (! (time_t_min <= secs && secs <= time_t_max)) + errno = ERANGE; + if (errno) { + perror(optarg); + errensure(); + exit(retval); + } + t = secs; + break; + } + } + while (optind < argc) { + cp = argv[optind++]; + if (*cp == '+') + if (format == NULL) + format = cp + 1; + else { + fprintf(stderr, +_("date: error: multiple formats in command line\n")); + usage(); + } + else { + fprintf(stderr, _("date: unknown operand: %s\n"), cp); + usage(); + } + } - tv.tv_sec = (int) adjust; - tv.tv_usec = (int) ((adjust - tv.tv_sec) * 1000000L); - if (adjtime(&tv, NULL) != 0) - oops("adjtime"); -#endif /* HAVE_ADJTIME */ -#if !HAVE_ADJTIME - reset(now + adjust, nflag); -#endif /* !HAVE_ADJTIME */ - /* - ** Sun silently ignores everything else; we follow suit. - */ - exit(retval); - } - if (dflag || tflag) { -#if HAVE_SETTIMEOFDAY == 2 - struct timezone tz; - - if (!dflag || !tflag) - if (gettimeofday(NULL, &tz) != 0) - oops("gettimeofday"); - if (dflag) - tz.tz_dsttime = dsttime; - if (tflag) - tz.tz_minuteswest = minuteswest; - if (settimeofday(NULL, &tz) != 0) - oops("settimeofday"); -#endif /* HAVE_SETTIMEOFDAY == 2 */ -#if HAVE_SETTIMEOFDAY != 2 - (void) dsttime; - (void) minuteswest; - fprintf(stderr, - _("date: warning: kernel doesn't keep -d/-t information, option ignored\n")); -#endif /* HAVE_SETTIMEOFDAY != 2 */ - } - - if (value) { - reset(t, nflag); - checkfinal(value, dousg, t, now); - t = time(NULL); - } - - display(format, t); - return retval; + display(format, t); + return retval; } static void dogmt(void) { - static char ** fakeenv; + static char ** fakeenv; - if (fakeenv == NULL) { - register int from; - register int to; - register int n; - static char tzegmt0[] = "TZ=GMT0"; + if (fakeenv == NULL) { + register int from; + register int to; + register int n; + static char tzegmt0[] = "TZ=GMT0"; - for (n = 0; environ[n] != NULL; ++n) - continue; - fakeenv = malloc((n + 2) * sizeof *fakeenv); - if (fakeenv == NULL) { - perror(_("Memory exhausted")); - errensure(); - exit(retval); - } - to = 0; - fakeenv[to++] = tzegmt0; - for (from = 1; environ[from] != NULL; ++from) - if (strncmp(environ[from], "TZ=", 3) != 0) - fakeenv[to++] = environ[from]; - fakeenv[to] = NULL; - environ = fakeenv; - } -} - -#ifdef OLD_TIME - -/* -** We assume we're on a System-V-based system, -** should use stime, -** should write System-V-format utmp entries, -** and don't have network notification to worry about. -*/ - -#include "fcntl.h" /* for O_WRONLY, O_APPEND */ - -/*ARGSUSED*/ -static void -reset(time_t newt, bool nflag) -{ - register int fid; - time_t oldt; - static struct { - struct utmp before; - struct utmp after; - } s; -#if HAVE_UTMPX_H - static struct { - struct utmpx before; - struct utmpx after; - } sx; -#endif - - /* - ** Wouldn't it be great if stime returned the old time? - */ - oldt = time(NULL); - if (stime(&newt) != 0) - oops("stime"); - s.before.ut_type = OLD_TIME; - s.before.ut_time = oldt; - strcpy(s.before.ut_line, OTIME_MSG); - s.after.ut_type = NEW_TIME; - s.after.ut_time = newt; - strcpy(s.after.ut_line, NTIME_MSG); - fid = open(WTMP_FILE, O_WRONLY | O_APPEND); - if (fid < 0) - oops(_("log file open")); - if (write(fid, (char *) &s, sizeof s) != sizeof s) - oops(_("log file write")); - if (close(fid) != 0) - oops(_("log file close")); -#if !HAVE_UTMPX_H - pututline(&s.before); - pututline(&s.after); -#endif /* !HAVE_UTMPX_H */ -#if HAVE_UTMPX_H - sx.before.ut_type = OLD_TIME; - sx.before.ut_tv.tv_sec = oldt; - strcpy(sx.before.ut_line, OTIME_MSG); - sx.after.ut_type = NEW_TIME; - sx.after.ut_tv.tv_sec = newt; - strcpy(sx.after.ut_line, NTIME_MSG); -#if defined WTMPX_FILE && !SUPPRESS_WTMPX_FILE_UPDATE - /* In Solaris 2.5 (and presumably other systems), - 'date' does not update /var/adm/wtmpx. - This must be a bug. If you'd like to reproduce the bug, - define SUPPRESS_WTMPX_FILE_UPDATE to be nonzero. */ - fid = open(WTMPX_FILE, O_WRONLY | O_APPEND); - if (fid < 0) - oops(_("log file open")); - if (write(fid, (char *) &sx, sizeof sx) != sizeof sx) - oops(_("log file write")); - if (close(fid) != 0) - oops(_("log file close")); -# endif - pututxline(&sx.before); - pututxline(&sx.after); -#endif /* HAVE_UTMPX_H */ -} - -#endif /* defined OLD_TIME */ -#ifndef OLD_TIME - -/* -** We assume we're on a BSD-based system, -** should use settimeofday, -** should write BSD-format utmp entries (using logwtmp), -** and may get to worry about network notification. -** The "time name" changes between 4.3-tahoe and 4.4; -** we include sys/param.h to determine which we should use. -*/ - -#ifndef TIME_NAME -#include "sys/param.h" -#ifdef BSD4_4 -#define TIME_NAME "date" -#endif /* defined BSD4_4 */ -#ifndef BSD4_4 -#define TIME_NAME "" -#endif /* !defined BSD4_4 */ -#endif /* !defined TIME_NAME */ - -#include "syslog.h" -#include "sys/socket.h" -#include "netinet/in.h" -#include "netdb.h" -#define TSPTYPES -//#include "protocols/timed.h" - -extern int logwtmp(); - -#if HAVE_SETTIMEOFDAY == 1 -#define settimeofday(t, tz) (settimeofday)(t) -#endif /* HAVE_SETTIMEOFDAY == 1 */ - -#ifdef TSP_SETDATE -static bool netsettime(struct timeval); -#endif - -#ifndef TSP_SETDATE -/*ARGSUSED*/ -#endif /* !defined TSP_SETDATE */ -static void -reset(time_t newt, bool nflag) -{ - register const char * username; - static struct timeval tv; /* static so tv_usec is 0 */ - - username = getlogin(); - if (username == NULL || *username == '\0') /* single-user or no tty */ - username = "root"; - tv.tv_sec = newt; -#ifdef TSP_SETDATE - if (nflag || !netsettime(tv)) -#endif /* defined TSP_SETDATE */ - { - /* - ** "old" entry is always written, for compatibility. - */ - logwtmp("|", TIME_NAME, ""); - if (settimeofday(&tv, NULL) == 0) { - logwtmp("{", TIME_NAME, ""); /* } */ - syslog(LOG_AUTH | LOG_NOTICE, _("date set by %s"), - username); - } else oops("settimeofday"); - } -} - -#endif /* !defined OLD_TIME */ - -static void -wildinput(const char *const item, const char *const value, - const char *const reason) -{ - fprintf(stderr, - _("date: error: bad command line %s \"%s\", %s\n"), - item, value, reason); - usage(); + for (n = 0; environ[n] != NULL; ++n) + continue; + fakeenv = malloc((n + 2) * sizeof *fakeenv); + if (fakeenv == NULL) { + perror(_("Memory exhausted")); + errensure(); + exit(retval); + } + to = 0; + fakeenv[to++] = tzegmt0; + for (from = 1; environ[from] != NULL; ++from) + if (strncmp(environ[from], "TZ=", 3) != 0) + fakeenv[to++] = environ[from]; + fakeenv[to] = NULL; + environ = fakeenv; + } } static void errensure(void) { - if (retval == EXIT_SUCCESS) - retval = EXIT_FAILURE; -} - -static const char * ATTRIBUTE_PURE -nondigit(register const char *cp) -{ - while (is_digit(*cp)) - ++cp; - return cp; + if (retval == EXIT_SUCCESS) + retval = EXIT_FAILURE; } static void usage(void) { - fprintf(stderr, - _("date: usage: date [-u] [-c] [-r seconds] [-n]" - " [-d dst] [-t min-west] [-a sss.fff]" - " [[yyyy]mmddhhmm[yyyy][.ss]] [+format]\n")); - errensure(); - exit(retval); + fprintf(stderr, + _("date: usage: date [-u] [-c] [-r seconds]" + " [+format]\n")); + errensure(); + exit(retval); } static void -oops(const char *const string) +display(char const *format, time_t now) { - int e = errno; + struct tm *tmp; - fprintf(stderr, _("date: error: ")); - errno = e; - perror(string); - errensure(); - display(NULL, time(NULL)); - exit(retval); -} - -static void -display(const char *const format, time_t const now) -{ - struct tm *tmp; - - tmp = localtime(&now); - if (!tmp) { - fprintf(stderr, - _("date: error: time out of range\n")); - errensure(); - return; - } - timeout(stdout, format ? format : "%+", tmp); - putchar('\n'); - fflush(stdout); - fflush(stderr); - if (ferror(stdout) || ferror(stderr)) { - fprintf(stderr, - _("date: error: couldn't write results\n")); - errensure(); - } + tmp = localtime(&now); + if (!tmp) { + fprintf(stderr, + _("date: error: time out of range\n")); + errensure(); + return; + } + timeout(stdout, format ? format : "%+", tmp); + putchar('\n'); + fflush(stdout); + fflush(stderr); + if (ferror(stdout) || ferror(stderr)) { + fprintf(stderr, + _("date: error: couldn't write results\n")); + errensure(); + } } #define INCR 1024 static void -timeout(FILE *const fp, const char *const format, const struct tm *tmp) +timeout(FILE *fp, char const *format, struct tm const *tmp) { - char * cp; - size_t result; - size_t size; - struct tm tm; + char * cp; + size_t result; + size_t size; + struct tm tm; - if (*format == '\0') - return; - if (!tmp) { - fprintf(stderr, _("date: error: time out of range\n")); - errensure(); - return; - } - tm = *tmp; - tmp = &tm; - size = INCR; - cp = malloc(size); - for ( ; ; ) { - if (cp == NULL) { - fprintf(stderr, - _("date: error: can't get memory\n")); - errensure(); - exit(retval); - } - cp[0] = '\1'; - result = strftime(cp, size, format, tmp); - if (result != 0 || cp[0] == '\0') - break; - size += INCR; - cp = realloc(cp, size); - } - fwrite(cp, 1, result, fp); - free(cp); + if (*format == '\0') + return; + if (!tmp) { + fprintf(stderr, _("date: error: time out of range\n")); + errensure(); + return; + } + tm = *tmp; + tmp = &tm; + size = INCR; + cp = malloc(size); + for ( ; ; ) { + if (cp == NULL) { + fprintf(stderr, + _("date: error: can't get memory\n")); + errensure(); + exit(retval); + } + cp[0] = '\1'; + result = strftime(cp, size, format, tmp); + if (result != 0 || cp[0] == '\0') + break; + size += INCR; + cp = realloc(cp, size); + } + fwrite(cp, 1, result, fp); + free(cp); } - -static bool -sametm(register const struct tm *const atmp, - register const struct tm *const btmp) -{ - return atmp->tm_year == btmp->tm_year && - atmp->tm_mon == btmp->tm_mon && - atmp->tm_mday == btmp->tm_mday && - atmp->tm_hour == btmp->tm_hour && - atmp->tm_min == btmp->tm_min && - atmp->tm_sec == btmp->tm_sec; -} - -/* -** convert -- -** convert user's input into a time_t. -*/ - -#define ATOI2(ar) (ar[0] - '0') * 10 + (ar[1] - '0'); ar += 2; - -static time_t -convert(char const *value, bool dousg, time_t t) -{ - register const char * cp; - register const char * dotp; - register int cent, year_in_cent, month, hour, day, mins, secs; - struct tm tm, outtm, *tmp; - time_t outt; - - tmp = localtime(&t); - if (!tmp) - return -1; - tm = *tmp; -#define DIVISOR 100 - year_in_cent = tm.tm_year % DIVISOR + TM_YEAR_BASE % DIVISOR; - cent = tm.tm_year / DIVISOR + TM_YEAR_BASE / DIVISOR + - year_in_cent / DIVISOR; - year_in_cent %= DIVISOR; - if (year_in_cent < 0) { - year_in_cent += DIVISOR; - --cent; - } - month = tm.tm_mon + 1; - day = tm.tm_mday; - hour = tm.tm_hour; - mins = tm.tm_min; - secs = 0; - - dotp = strchr(value, '.'); - for (cp = value; *cp != '\0'; ++cp) - if (!is_digit(*cp) && cp != dotp) - wildinput(_("time"), value, _("contains a nondigit")); - - if (dotp == NULL) - dotp = strchr(value, '\0'); - else { - cp = dotp + 1; - if (strlen(cp) != 2) - wildinput(_("time"), value, - _("seconds part is not two digits")); - secs = ATOI2(cp); - } - - cp = value; - switch (dotp - cp) { - default: - wildinput(_("time"), value, - _("main part is wrong length")); - case 12: - if (!dousg) { - cent = ATOI2(cp); - year_in_cent = ATOI2(cp); - } - month = ATOI2(cp); - day = ATOI2(cp); - hour = ATOI2(cp); - mins = ATOI2(cp); - if (dousg) { - cent = ATOI2(cp); - year_in_cent = ATOI2(cp); - } - break; - case 8: /* mmddhhmm */ - month = ATOI2(cp); - /* fall through to. . . */ - case 6: /* ddhhmm */ - day = ATOI2(cp); - /* fall through to. . . */ - case 4: /* hhmm */ - hour = ATOI2(cp); - mins = ATOI2(cp); - break; - case 10: - if (!dousg) { - year_in_cent = ATOI2(cp); - } - month = ATOI2(cp); - day = ATOI2(cp); - hour = ATOI2(cp); - mins = ATOI2(cp); - if (dousg) { - year_in_cent = ATOI2(cp); - } - break; - } - - tm.tm_year = cent * 100 + year_in_cent - TM_YEAR_BASE; - tm.tm_mon = month - 1; - tm.tm_mday = day; - tm.tm_hour = hour; - tm.tm_min = mins; - tm.tm_sec = secs; - tm.tm_isdst = -1; - outtm = tm; - outt = mktime(&outtm); - return sametm(&tm, &outtm) ? outt : -1; -} - -/* -** Code from here on out is either based on code provided by UCB -** or is only called just before the program exits. -*/ - -/* -** Check for iffy input. -*/ - -static void -checkfinal(char const *value, bool didusg, time_t t, time_t oldnow) -{ - time_t othert; - struct tm tm, *tmp; - struct tm othertm; - register int pass, offset; - - /* - ** See if there's both a USG and a BSD interpretation. - */ - othert = convert(value, !didusg, oldnow); - if (othert != -1 && othert != t) - iffy(t, othert, value, _("year could be at start or end")); - /* - ** See if there's both a DST and a STD version. - */ - tmp = localtime(&t); - if (!tmp) - iffy(t, othert, value, _("time out of range")); - othertm = tm = *tmp; - othertm.tm_isdst = !tm.tm_isdst; - othert = mktime(&othertm); - if (othert != -1 && othertm.tm_isdst != tm.tm_isdst && - sametm(&tm, &othertm)) - iffy(t, othert, value, - _("both standard and summer time versions exist")); - /* - ** Final check. - ** - ** If a jurisdiction shifts time *without* shifting whether time is - ** summer or standard (as Hawaii, the United Kingdom, and Saudi Arabia - ** have done), routine checks for iffy times may not work. - ** So we perform this final check, deferring it until after the time has - ** been set; it may take a while, and we don't want to introduce an unnecessary - ** lag between the time the user enters their command and the time that - ** stime/settimeofday is called. - ** - ** We just check nearby times to see if any have the same representation - ** as the time that convert returned. We work our way out from the center - ** for quick response in solar time situations. We only handle common cases: - ** offsets of at most a minute, and offsets of exact numbers of minutes - ** and at most an hour. - */ - for (offset = 1; offset <= 60; ++offset) - for (pass = 1; pass <= 4; ++pass) { - if (pass == 1) - othert = t + offset; - else if (pass == 2) - othert = t - offset; - else if (pass == 3) - othert = t + 60 * offset; - else othert = t - 60 * offset; - tmp = localtime(&othert); - if (!tmp) - iffy(t, othert, value, - _("time out of range")); - othertm = *tmp; - if (sametm(&tm, &othertm)) - iffy(t, othert, value, - _("multiple matching times exist")); - } -} - -static void -iffy(const time_t thist, const time_t thatt, - const char * const value, const char * const reason) -{ - struct tm *tmp; - bool dst; - - fprintf(stderr, _("date: warning: ambiguous time \"%s\", %s.\n"), - value, reason); - tmp = gmtime(&thist); - /* - ** Avoid running afoul of SCCS! - */ - timeout(stderr, _("Time was set as if you used\n\tdate -u %m%d%H\ -%M\ -%Y.%S\n"), tmp); - tmp = localtime(&thist); - dst = tmp && tmp->tm_isdst; - timeout(stderr, _("to get %c"), tmp); - fprintf(stderr, _(" (%s). Use\n"), - dst ? _("summer time") : _("standard time")); - tmp = gmtime(&thatt); - timeout(stderr, _("\tdate -u %m%d%H\ -%M\ -%Y.%S\n"), tmp); - tmp = localtime(&thatt); - dst = tmp && tmp->tm_isdst; - timeout(stderr, _("to get %c"), tmp); - fprintf(stderr, _(" (%s).\n"), - dst ? _("summer time") : _("standard time")); - errensure(); - exit(retval); -} - -#ifdef TSP_SETDATE -#define WAITACK 2 /* seconds */ -#define WAITDATEACK 5 /* seconds */ - -/* - * Set the date in the machines controlled by timedaemons - * by communicating the new date to the local timedaemon. - * If the timedaemon is in the master state, it performs the - * correction on all slaves. If it is in the slave state, it - * notifies the master that a correction is needed. - * Return true on success. - */ -static bool -netsettime(struct timeval ntv) -{ /* - int s, length, port, timed_ack, found, err, waittime; - fd_set ready; - struct timeval tout; - struct servent *sp; - struct tsp msg; - struct sockaddr_in sin, dest, from; - - sp = getservbyname("timed", "udp"); - if (! sp) { - fputs(_("udp/timed: unknown service\n"), stderr); - retval = 2; - return false; - } - dest.sin_port = sp->s_port; - dest.sin_family = AF_INET; - dest.sin_addr.s_addr = htonl(INADDR_ANY); - s = socket(AF_INET, SOCK_DGRAM, 0); - if (s < 0) { - if (errno != EPROTONOSUPPORT) - perror("date: socket"); - goto bad; - } - bzero((char *)&sin, sizeof (sin)); - sin.sin_family = AF_INET; - for (port = IPPORT_RESERVED - 1; port > IPPORT_RESERVED / 2; port--) { - sin.sin_port = htons(port); - if (bind(s, (struct sockaddr *)&sin, sizeof (sin)) >= 0) - break; - if (errno != EADDRINUSE) { - if (errno != EADDRNOTAVAIL) - perror("date: bind"); - goto bad; - } - } - if (port == IPPORT_RESERVED / 2) { - fputs(_("date: All ports in use\n"), stderr); - goto bad; - } - msg.tsp_type = TSP_SETDATE; - msg.tsp_vers = TSPVERSION; - msg.tsp_name[sizeof msg.tsp_name - 1] = '\0'; - if (gethostname(msg.tsp_name, sizeof msg.tsp_name) != 0) { - perror("gethostname"); - goto bad; - } - if (msg.tsp_name[sizeof msg.tsp_name - 1]) { - fprintf(stderr, "hostname too long\n"); - goto bad; - } - msg.tsp_seq = htons(0); - msg.tsp_time.tv_sec = htonl(ntv.tv_sec); - msg.tsp_time.tv_usec = htonl(ntv.tv_usec); - length = sizeof (struct sockaddr_in); - if (connect(s, &dest, length) < 0) { - perror("date: connect"); - goto bad; - } - if (send(s, (char *)&msg, sizeof (struct tsp), 0) < 0) { - if (errno != ECONNREFUSED) - perror("date: send"); - goto bad; - } - timed_ack = -1; - waittime = WAITACK; - loop: - tout.tv_sec = waittime; - tout.tv_usec = 0; - FD_ZERO(&ready); - FD_SET(s, &ready); - found = select(FD_SETSIZE, &ready, NULL, NULL, &tout); - length = sizeof err; - if (getsockopt(s, SOL_SOCKET, SO_ERROR, (char *)&err, &length) == 0 - && err) { - errno = err; - if (errno != ECONNREFUSED) - perror(_("date: send (delayed error)")); - goto bad; - } - if (found > 0 && FD_ISSET(s, &ready)) { - length = sizeof (struct sockaddr_in); - if (recvfrom(s, (char *)&msg, sizeof (struct tsp), 0, &from, - &length) < 0) { - if (errno != ECONNREFUSED) - perror("date: recvfrom"); - goto bad; - } - msg.tsp_seq = ntohs(msg.tsp_seq); - msg.tsp_time.tv_sec = ntohl(msg.tsp_time.tv_sec); - msg.tsp_time.tv_usec = ntohl(msg.tsp_time.tv_usec); - switch (msg.tsp_type) { - - case TSP_ACK: - timed_ack = TSP_ACK; - waittime = WAITDATEACK; - goto loop; - - case TSP_DATEACK: - lose(s); - return true; - - default: - fprintf(stderr, - _("date: Wrong ack received from timed: %s\n"), - tsptype[msg.tsp_type]); - timed_ack = -1; - break; - } - } - if (timed_ack == -1) - fputs(_("date: Can't reach time daemon, time set locally.\n"), - stderr); - bad: - lose(s); - retval = 2;*/ - return false; -} -#endif /* defined TSP_SETDATE */ diff --git a/utility/dstcheck.c b/utility/dstcheck.c index 4bc21cc..8bc00fa 100644 --- a/utility/dstcheck.c +++ b/utility/dstcheck.c @@ -1,34 +1,13 @@ -//--------------------------------------------------------------------------// -// This file is in the public domain. // -//--------------------------------------------------------------------------// - -#include -#include -#include #include "tzversion.h" -#include "clib/timezone.h" -#include "inline/timezone.h" - -const char *vers = "\0$VER: DSTCheck" AMIGA_VERSION; - -struct Library *TimezoneBase; int main(const int argc, char *argv[]) { int result; struct tm tm; - time_t now ; - - TimezoneBase = (struct Library*)OpenLibrary((STRPTR)"timezone.library", 0); - if (!TimezoneBase) { - printf("Cannot open timezone library.\n"); - return 0; - } - + time_t now; + amiga_open_libs(); now = time(NULL); localtime_r(&now, &tm); result = tm.tm_isdst ? 5 : 0; - - CloseLibrary(TimezoneBase); return result; } diff --git a/utility/getopt.c b/utility/getopt.c new file mode 100644 index 0000000..c6ef3f8 --- /dev/null +++ b/utility/getopt.c @@ -0,0 +1,117 @@ +/* + * getopt.c -- + * + * Standard UNIX getopt function. Code is from BSD. + * + * Copyright (c) 1987-2002 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * A. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * B. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * C. Neither the names of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS + * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* #if !defined(lint) + * static char sccsid[] = "@(#)getopt.c 8.2 (Berkeley) 4/2/94"; + * #endif + */ +#include +#include +#include + +#include "getopt.h" + +int opterr = 1, /* if error message should be printed */ + optind = 1, /* index into parent argv vector */ + optopt, /* character checked for validity */ + optreset; /* reset getopt */ +char *optarg; /* argument associated with option */ + +#define BADCH (int)'?' +#define BADARG (int)':' +#define EMSG "" + +/* + * getopt -- + * Parse argc/argv argument vector. + */ +int +getopt( int nargc, + char * const *nargv, + const char *ostr) +{ + static char *place = EMSG; /* option letter processing */ + char *oli; /* option letter list index */ + + if (optreset || !*place) { /* update scanning pointer */ + optreset = 0; + if (optind >= nargc || *(place = nargv[optind]) != '-') { + place = EMSG; + return (EOF); + } + if (place[1] && *++place == '-') { /* found "--" */ + ++optind; + place = EMSG; + return (EOF); + } + } /* option letter okay? */ + if ((optopt = (int)*place++) == (int)':' || + !(oli = (char*) strchr(ostr, optopt))) { + /* + * if the user didn't specify '-' as an option, + * assume it means EOF. + */ + if (optopt == (int)'-') + return (EOF); + if (!*place) + ++optind; + if (opterr && *ostr != ':') + (void)fprintf(stderr, + "illegal option -- %c\n", optopt); + return (BADCH); + } + if (*++oli != ':') { /* don't need argument */ + optarg = NULL; + if (!*place) + ++optind; + } + else { /* need an argument */ + if (*place) /* no white space */ + optarg = place; + else if (nargc <= ++optind) { /* no arg */ + place = EMSG; + if (*ostr == ':') + return (BADARG); + if (opterr) + (void)fprintf(stderr, + "option requires an argument -- %c\n", + optopt); + return (BADCH); + } + else /* white space */ + optarg = nargv[optind]; + place = EMSG; + ++optind; + } + return (optopt); /* dump back option letter */ +} diff --git a/utility/getopt.h b/utility/getopt.h new file mode 100644 index 0000000..5bcb06f --- /dev/null +++ b/utility/getopt.h @@ -0,0 +1,51 @@ +#ifndef _HAD_GETOPT_H +#define _HAD_GETOPT_H + +/* + getopt.h -- header for getopt() replacement function + Copyright (C) 1999-2011 Dieter Baron and Thomas Klausner + + This file is part of libzip, a library to manipulate ZIP archives. + The authors can be contacted at + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. The names of the authors may not be used to endorse or promote + products derived from this software without specific prior + written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS + OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +extern char *optarg; +extern int optind; +extern int opterr; + +extern int getopt(int, char * const *, const char *); + +#ifdef __cplusplus +} +#endif + +#endif /* _HAD_GETOPT_H */ diff --git a/utility/include/clib/timezone.h b/utility/include/clib/timezone.h index d6d9886..dcd006f 100644 --- a/utility/include/clib/timezone.h +++ b/utility/include/clib/timezone.h @@ -16,7 +16,7 @@ typedef struct timezone* timezone_t; #endif -#ifndef HAVE_LOCATE_T +#ifndef HAVE_LOCALE_T typedef struct Locale* locale_t; #endif diff --git a/utility/include/inline/timezone.h b/utility/include/inline/timezone.h index d203314..7eeaf73 100644 --- a/utility/include/inline/timezone.h +++ b/utility/include/inline/timezone.h @@ -1,5 +1,3 @@ -/* Automatically generated header! Do not edit! */ - #ifndef _INLINE_TIMEZONE_H #define _INLINE_TIMEZONE_H diff --git a/utility/private.h b/utility/private.h index 71bc9d9..4fc04b3 100644 --- a/utility/private.h +++ b/utility/private.h @@ -1,25 +1,5 @@ -//--------------------------------------------------------------------------// -// This file is in the public domain, so clarified as of // -// 2009-05-17 by Arthur David Olson. // -//--------------------------------------------------------------------------// - -#ifndef PRIVATE_H -#define PRIVATE_H - -/* -** This header is for use ONLY with the time conversion code. -** There is no guarantee that it will remain unchanged, -** or that it will remain at all. -** Do NOT copy it to any system include directory. -** Thank you! -*/ - -#define GRANDPARENTED "Local time zone must be set--see zic manual page" - -/* -** Defaults for preprocessor symbols. -** You can override these in your C compiler options, e.g. '-DHAVE_ADJTIME=0'. -*/ +#ifndef TZ_PRIVATE_H +#define TZ_PRIVATE_H #ifndef HAVE_ADJTIME #define HAVE_ADJTIME 1 @@ -81,28 +61,9 @@ /* Enable strtoimax on Solaris 10. */ #define __EXTENSIONS__ 1 -void tz_cleanup(); - -/* -** Nested includes -*/ - -/* Avoid clashes with NetBSD by renaming NetBSD's declarations. */ -#define localtime_rz sys_localtime_rz -#define mktime_z sys_mktime_z -#define posix2time_z sys_posix2time_z -#define time2posix_z sys_time2posix_z -#define timezone_t sys_timezone_t -#define tzalloc sys_tzalloc -#define tzfree sys_tzfree -#include -#undef localtime_rz -#undef mktime_z -#undef posix2time_z -#undef time2posix_z -#undef timezone_t -#undef tzalloc -#undef tzfree +#ifndef __LONG_LONG_MAX__ +#define __LONG_LONG_MAX__ 0x7fffffffffffffffLL +#endif #include "sys/types.h" /* for time_t */ #include "stdio.h" @@ -297,126 +258,6 @@ typedef unsigned long uintmax_t; # define restrict /* empty */ #endif -/* -** Workarounds for compilers/systems. -*/ - -/* -** Compile with -Dtime_tz=T to build the tz package with a private -** time_t type equivalent to T rather than the system-supplied time_t. -** This debugging feature can test unusual design decisions -** (e.g., time_t wider than 'long', or unsigned time_t) even on -** typical platforms. -*/ -#ifdef time_tz -# ifdef LOCALTIME_IMPLEMENTATION -static time_t sys_time(time_t *x) { - return time(x); -} -# endif - -typedef time_tz tz_time_t; - -# undef ctime -# define ctime tz_ctime -# undef ctime_r -# define ctime_r tz_ctime_r -# undef difftime -# define difftime tz_difftime -# undef gmtime -# define gmtime tz_gmtime -# undef gmtime_r -# define gmtime_r tz_gmtime_r -# undef localtime -# define localtime tz_localtime -# undef localtime_r -# define localtime_r tz_localtime_r -# undef localtime_rz -# define localtime_rz tz_localtime_rz -# undef mktime -# define mktime tz_mktime -# undef mktime_z -# define mktime_z tz_mktime_z -# undef offtime -# define offtime tz_offtime -# undef posix2time -# define posix2time tz_posix2time -# undef posix2time_z -# define posix2time_z tz_posix2time_z -# undef time -# define time tz_time -# undef time2posix -# define time2posix tz_time2posix -# undef time2posix_z -# define time2posix_z tz_time2posix_z -# undef time_t -# define time_t tz_time_t -# undef timegm -# define timegm tz_timegm -# undef timelocal -# define timelocal tz_timelocal -# undef timeoff -# define timeoff tz_timeoff -# undef tzalloc -# define tzalloc tz_tzalloc -# undef tzfree -# define tzfree tz_tzfree -# undef tzset -# define tzset tz_tzset -# undef tzsetwall -# define tzsetwall tz_tzsetwall - -char *ctime(time_t const *); -char *ctime_r(time_t const *, char *); -double difftime(time_t, time_t); -struct tm *gmtime(time_t const *); -struct tm *gmtime_r(time_t const *restrict, struct tm *restrict); -struct tm *localtime(time_t const *); -struct tm *localtime_r(time_t const *restrict, struct tm *restrict); -time_t mktime(struct tm *); -time_t time(time_t *); -void tzset(void); -#endif - -/* -** Some time.h implementations don't declare asctime_r. -** Others might define it as a macro. -** Fix the former without affecting the latter. -*/ - -#ifndef asctime_r -extern char * asctime_r(struct tm const *restrict, char *restrict); -#endif - -/* -** The STD_INSPIRED functions are similar, but most also need -** declarations if time_tz is defined. -*/ - -#ifdef STD_INSPIRED -# if !defined tzsetwall || defined time_tz -void tzsetwall(void); -# endif -# if !defined offtime || defined time_tz -struct tm *offtime(time_t const *, long); -# endif -# if !defined timegm || defined time_tz -time_t timegm(struct tm *); -# endif -# if !defined timelocal || defined time_tz -time_t timelocal(struct tm *); -# endif -# if !defined timeoff || defined time_tz -time_t timeoff(struct tm *, long); -# endif -# if !defined time2posix || defined time_tz -time_t time2posix(time_t); -# endif -# if !defined posix2time || defined time_tz -time_t posix2time(time_t); -# endif -#endif - /* Infer TM_ZONE on systems where this information is known, but suppress guessing if NO_TM_ZONE is defined. Similarly for TM_GMTOFF. */ #if (defined __GLIBC__ \ @@ -430,31 +271,6 @@ time_t posix2time(time_t); # endif #endif -/* -** Define functions that are ABI compatible with NetBSD but have -** better prototypes. NetBSD 6.1.4 defines a pointer type timezone_t -** and labors under the misconception that 'const timezone_t' is a -** pointer to a constant. This use of 'const' is ineffective, so it -** is not done here. What we call 'struct state' NetBSD calls -** 'struct __state', but this is a private name so it doesn't matter. -*/ -#if NETBSD_INSPIRED -typedef struct state *timezone_t; -struct tm *localtime_rz(timezone_t restrict, time_t const *restrict, - struct tm *restrict); -time_t mktime_z(timezone_t restrict, struct tm *restrict); -timezone_t tzalloc(char const *); -void tzfree(timezone_t); -# ifdef STD_INSPIRED -# if !defined posix2time_z || defined time_tz -time_t posix2time_z(timezone_t, time_t) ATTRIBUTE_PURE; -# endif -# if !defined time2posix_z || defined time_tz -time_t time2posix_z(timezone_t, time_t) ATTRIBUTE_PURE; -# endif -# endif -#endif - /* ** Finally, some convenience items. */ @@ -534,13 +350,6 @@ static time_t const time_t_max = MAXVAL(time_t, TYPE_BIT(time_t)); # define TZ_DOMAIN "tz" #endif -#if HAVE_INCOMPATIBLE_CTIME_R -#undef asctime_r -#undef ctime_r -char *asctime_r(struct tm const *, char *); -char *ctime_r(time_t const *, char *); -#endif /* HAVE_INCOMPATIBLE_CTIME_R */ - #ifndef YEARSPERREPEAT #define YEARSPERREPEAT 400 /* years before a Gregorian repeat */ #endif /* !defined YEARSPERREPEAT */ @@ -561,4 +370,4 @@ char *ctime_r(time_t const *, char *); #define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */ #endif /* !defined SECSPERREPEAT_BITS */ -#endif /* !defined PRIVATE_H */ +#endif /* !defined TZ_PRIVATE_H */ diff --git a/utility/setclockgmt.c b/utility/setclockgmt.c index b12d914..5ba27a3 100644 --- a/utility/setclockgmt.c +++ b/utility/setclockgmt.c @@ -1,7 +1,3 @@ -//--------------------------------------------------------------------------// -// This file is in the public domain. // -//--------------------------------------------------------------------------// - #include #include #include "tzversion.h" diff --git a/utility/stdint.h b/utility/stdint.h index e19ab6b..32ee38d 100644 --- a/utility/stdint.h +++ b/utility/stdint.h @@ -1,5 +1,5 @@ -#ifndef __STDINT_H -#define __STDINT_H 1 +#ifndef TZ_STDINT_H +#define TZ_STDINT_H 1 #if 0 typedef signed char int8_t; diff --git a/utility/strtoll.c b/utility/strtoll.c index d49c101..6f6b394 100644 --- a/utility/strtoll.c +++ b/utility/strtoll.c @@ -43,13 +43,6 @@ #include "tzversion.h" -extern struct Locale* locale; - -#define isalpha(c) IsAlpha(locale, (ULONG)c) -#define isupper(c) IsUpper(locale, (ULONG)c) -#define isdigit(c) IsDigit(locale, (ULONG)c) -#define isspace(c) IsSpace(locale, (ULONG)c) - #ifndef LLONG_MAX #define LLONG_MAX ((long long)(~0ULL>>1)) #endif @@ -57,6 +50,46 @@ extern struct Locale* locale; #define LLONG_MIN (-LLONG_MAX - 1) #endif +#define isupper(x) ((unsigned)(x)-'A'<='Z'-'A') + +int isdigit(char c) +{ + switch (c) { + default: + return 0; + case '1': case '2': case '3': case '4': case '5': + case '6': case '7': case '8': case '9': case '0': + return 1; + } +} + +int isspace(char c) +{ + switch (c) { + default: + return 0; + case '\t': case '\r': case '\n': case '\v': case '\f': case ' ': + return 1; + } +} + +int isalpha(char c) +{ + switch (c) { + default: + return 0; + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': + case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': + case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': + case 'V': case 'W': case 'X': case 'Y': case 'Z': + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': + case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': + case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': + case 'v': case 'w': case 'x': case 'y': case 'z': + return 1; + } +} + long long int strtoll(const char *nptr, char **endptr, int base) { const char *s; diff --git a/utility/timezone.c b/utility/timezone.c index 0c80a7b..b52b6a4 100644 --- a/utility/timezone.c +++ b/utility/timezone.c @@ -1,14 +1,9 @@ -//--------------------------------------------------------------------------// -// This file is in the public domain. // -//--------------------------------------------------------------------------// - +#include "tzversion.h" #include #include #include +#include #include "zone.h" -#include "tzversion.h" -#include "clib/timezone.h" -#include "inline/timezone.h" const char *vers = "\0$VER: TimeZone" AMIGA_VERSION; @@ -279,7 +274,10 @@ void set_tz(char *newtz) void use_tz() { long checked; - + struct timeval tv; + + gettimeofday(&tv, NULL); + if (tz != NULL) { stou(tz); SetVar((STRPTR)TZVARIABLE, (STRPTR)tz, strlen(tz) + 1, GVF_GLOBAL_ONLY); @@ -290,6 +288,7 @@ void use_tz() } tzset(); + settimeofday(&tv, NULL); } } diff --git a/utility/timezoneinfo.c b/utility/timezoneinfo.c index c43f4bf..a38e30d 100644 --- a/utility/timezoneinfo.c +++ b/utility/timezoneinfo.c @@ -1,18 +1,4 @@ -//--------------------------------------------------------------------------// -// This file is in the public domain. // -//--------------------------------------------------------------------------// - -#include -#include -#include -#include #include "tzversion.h" -#include "clib/timezone.h" -#include "inline/timezone.h" - -const char *vers = "\0$VER: TimeZoneInfo" AMIGA_VERSION; - -struct Library *TimezoneBase; int main(const int argc, char *argv[]) { @@ -24,12 +10,7 @@ int main(const int argc, char *argv[]) time_t now ; const char* loc; - TimezoneBase = (struct Library*)OpenLibrary((STRPTR)"timezone.library", 0); - if (!TimezoneBase) { - printf("Cannot open timezone library.\n"); - return 5; - } - + amiga_open_libs(); now = time(NULL); localtime_r(&now, &tm); @@ -47,6 +28,5 @@ int main(const int argc, char *argv[]) FPrintf(Output(), (STRPTR)"It is not daylight-saving time.\n"); } - CloseLibrary(TimezoneBase); return 0; } diff --git a/utility/tzversion.c b/utility/tzversion.c new file mode 100644 index 0000000..5a2ce7f --- /dev/null +++ b/utility/tzversion.c @@ -0,0 +1,45 @@ +#include "tzversion.h" +#include + +const char *vers = AMIGA_VERSION_STRING; +char ** environ = NULL; + +struct Library *DOSBase = NULL; +struct Library *TimezoneBase = NULL; + +void amiga_open_lib_error(char *name, int version) +{ + FPrintf(Output(), (STRPTR)OPEN_VER_ERROR, name, version); +} + +void amiga_close_libs() +{ + if (TimezoneBase != NULL) { + CloseLibrary(TimezoneBase); + TimezoneBase = NULL; + } + + if (DOSBase != NULL) { + CloseLibrary(DOSBase); + DOSBase = NULL; + } +} + +int amiga_open_libs() +{ + atexit(amiga_close_libs); + + DOSBase = OpenLibrary((STRPTR)DOSLIB_NAME, DOSLIB_REV); + if(!DOSBase) { + amiga_open_lib_error(DOSLIB_NAME, DOSLIB_REV); + return 5; + } + + TimezoneBase = OpenLibrary((CONST_STRPTR)TIMEZONELIB_NAME, TIMEZONELIB_REV); + if(!TimezoneBase) { + amiga_open_lib_error(TIMEZONELIB_NAME, TIMEZONELIB_REV); + return 5; + } + + return 0; +} diff --git a/utility/tzversion.h b/utility/tzversion.h index 50792a8..2f58097 100644 --- a/utility/tzversion.h +++ b/utility/tzversion.h @@ -1,7 +1,3 @@ -//--------------------------------------------------------------------------// -// This file is in the public domain. // -//--------------------------------------------------------------------------// - #ifndef TZ_VERSION_H #define TZ_VERSION_H #if defined(__amiga__) || defined(__AMIGA__) || defined(__amigaos4__) || \ @@ -38,6 +34,7 @@ # define HAVE_LINK 0 # define HAVE_SYMLINK 0 # define HAVE_SYS_STAT_H 0 +# define HAVE_INTTYPES_H 0 # define HAVE_TIME_T 1 # define HAVE_TIMEVAL 1 # define HAVE_STDINT_H 1 @@ -83,6 +80,9 @@ #include #include +#include "clib/timezone.h" +#include "inline/timezone.h" + #define OPEN_ERROR "Cannot open %s.\n" #define OPEN_VER_ERROR "Cannot open %s (%ld.0)\n" @@ -97,7 +97,7 @@ #define DOSLIB_NAME "dos.library" #define DOSLIB_REV 37L #define TIMEZONELIB_NAME "timezone.library" -#define TIMEZONELIB_REV 4L +#define TIMEZONELIB_REV 5L #define TIMER_NAME TIMERNAME #define BATTCLOCK_NAME BATTCLOCKNAME #define PUBSCREEN_NAME "PubScreen" @@ -112,20 +112,28 @@ #define XSTR(s) STR(s) #define STR(s) #s -#define VERSION_NO 4 +#define VERSION_NO 5 #define VERSION XSTR(VERSION_NO) #define REVISION_NO 00 #define REVISION XSTR(REVISION_NO) -#define DATE "05.10.2016" +#define DATE "15.10.2016" #define PACKAGE_TZ "tzcode" #define VERSION_TZ "2016g" #define BUGEMAIL_TZ "cs@innolan.dk" #define AMIGA_VERSION " " VERSION "." REVISION " (" DATE ") " \ PACKAGE_TZ " " VERSION_TZ +#define AMIGA_VERSION_STRING "\0$VER: " PROG_NAME AMIGA_VERSION; + static char const PKGVERSION[] = "(" PACKAGE_TZ ")"; static char const TZVERSION[] = VERSION_TZ; static char const REPORT_BUGS_TO[] = BUGEMAIL_TZ; +struct Library *DOSBase; +struct Library *TimezoneBase; + +int amiga_open_libs(); +long long int strtoll(const char *nptr, char **endptr, int base); + #endif #endif diff --git a/utility/zdump_amiga.c b/utility/zdump_amiga.c index 2ef8708..84a2586 100644 --- a/utility/zdump_amiga.c +++ b/utility/zdump_amiga.c @@ -1,8 +1,3 @@ -//--------------------------------------------------------------------------// -// This file is in the public domain, so clarified as of // -// 2009-05-17 by Arthur David Olson. // -//--------------------------------------------------------------------------// - #include "tzversion.h" #include "clib/timezone.h" #include "inline/timezone.h" diff --git a/utility/zone.h b/utility/zone.h index 8bf2915..e5b9a88 100644 --- a/utility/zone.h +++ b/utility/zone.h @@ -1,7 +1,3 @@ -//--------------------------------------------------------------------------// -// This file is in the public domain. // -//--------------------------------------------------------------------------// - #ifndef TZ_ZONE_H #define TZ_ZONE_H