From 477a573d183c3a075f7e95a026edf5832ed01a83 Mon Sep 17 00:00:00 2001 From: llsth Date: Thu, 25 Jun 2015 22:28:02 +0200 Subject: [PATCH] AmigaOS changes --- Makefile.m68k | 30 ++++----- amiga_tz.c | 32 ++++++++++ amiga_tz.h | 33 ++++++---- date_patch.c => setclockgmt.c | 114 ++++++++++++++++------------------ timezone.c | 26 ++------ timezoneinfo.c | 2 +- 6 files changed, 126 insertions(+), 111 deletions(-) rename date_patch.c => setclockgmt.c (62%) diff --git a/Makefile.m68k b/Makefile.m68k index a32eecc..0ad35b8 100644 --- a/Makefile.m68k +++ b/Makefile.m68k @@ -1,18 +1,18 @@ -all: zic zdump datepatch timezone timezoneinfo lib +all: zic zdump timezone timezoneinfo setclockgmt lib CC = m68k-amigaos-gcc -CFLAGS = -O2 -noixemul -DTZDIR=\"LOCALE:zoneinfo\" -DHAVE_ADJTIME=0 -DHAVE_DOS_FILE_NAMES -DHAVE_LINK=0 -DHAVE_SYMLINK=0 -DHAVE_SYS_STAT_H=0 -DTM_GMTOFF=tm_gmtoff -DTM_ZONE=tm_zone -Dtime_tz=long -DTLOCALTIME_IMPLEMENTATION -DALL_STATE -Wall #-Werror +CFLAGS = -O2 -noixemul -DTZDIR=\"LOCALE:zoneinfo\" -DHAVE_ADJTIME=0 -DHAVE_DOS_FILE_NAMES -DHAVE_LINK=0 -DHAVE_SYMLINK=0 -DHAVE_SYS_STAT_H=0 -DTM_GMTOFF=tm_gmtoff -DTM_ZONE=tm_zone -Dtime_tz=long -DTLOCALTIME_IMPLEMENTATION -DALL_STATE -DAOS3 -Wall #-Werror LDFLAGS = LDLIBS = -lgcc -liberty -lm AR = m68k-amigaos-ar PACKAGE = tzcode -VERSION = 2015d +VERSION = 2015e BUGEMAIL= carsten.larsen@mail.com version.h: - (echo '#define AMIGA_VERSION " 1.00 (20.06.2015) $(PACKAGE) $(VERSION)"' && \ + (echo '#define AMIGA_VERSION " 1.00 (25.06.2015) $(PACKAGE) $(VERSION)"' && \ echo 'static char const PKGVERSION[]="($(PACKAGE)) ";' && \ echo 'static char const TZVERSION[]="$(VERSION)";' && \ echo 'static char const REPORT_BUGS_TO[]="$(BUGEMAIL)";') >$@ @@ -45,12 +45,12 @@ date_amiga.o: date_amiga.c private.h amiga_tz.h date.o: date.c private.h amiga_tz.h -date_patch.o: date_patch.c private.h - timezone.o: timezone.c amiga_tz.h zone.h timezoneinfo.o: timezoneinfo.c amiga_tz.h +setclockgmt.o: setclockgmt.c amiga_tz.h + zic: zic.o ${CC} ${CFLAGS} -o zic zic.o $(LDFLAGS) $(LDLIBS) @@ -58,22 +58,22 @@ zdump: zdump.o localtime.o asctime.o strtoll.o amiga_tz.o ${CC} ${CFLAGS} -o zdump zdump.o localtime.o asctime.o strtoll.o amiga_tz.o $(LDFLAGS) $(LDLIBS) date: date.o localtime.o strftime.o asctime.o strtoll.o date_amiga.o amiga_tz.o - ${CC} ${CFLAGS} -o datetz date.o localtime.o strftime.o asctime.o strtoll.o date_amiga.o amiga_tz.o $(LDFLAGS) -lsocket $(LDLIBS) + ${CC} ${CFLAGS} -o dateTZ date.o localtime.o strftime.o asctime.o strtoll.o date_amiga.o amiga_tz.o $(LDFLAGS) -lsocket $(LDLIBS) -lib: localtime.o asctime.o difftime.o strftime.o - ${AR} rcs libtz.a localtime.o asctime.o difftime.o strftime.o - -datepatch: date_patch.o localtime.o asctime.c amiga_tz.o - ${CC} ${CFLAGS} -o datepatch date_patch.o localtime.o asctime.c amiga_tz.o $(LDFLAGS) $(LDLIBS) +lib: localtime.o asctime.o difftime.o strftime.o strtoll.o date_amiga.o amiga_tz.o + ${AR} rcs libtz.a localtime.o asctime.o difftime.o strftime.o strtoll.o date_amiga.o amiga_tz.o timezone: timezone.o localtime.o asctime.o amiga_tz.o - ${CC} ${CFLAGS} -o timezone timezone.o localtime.o asctime.o amiga_tz.o $(LDFLAGS) $(LDLIBS) + ${CC} ${CFLAGS} -o TimeZone timezone.o localtime.o asctime.o amiga_tz.o $(LDFLAGS) $(LDLIBS) timezoneinfo: timezoneinfo.o localtime.o asctime.o amiga_tz.o - ${CC} ${CFLAGS} -o timezoneinfo timezoneinfo.o localtime.o asctime.o amiga_tz.o $(LDFLAGS) $(LDLIBS) + ${CC} ${CFLAGS} -o TimeZoneInfo timezoneinfo.o localtime.o asctime.o amiga_tz.o $(LDFLAGS) $(LDLIBS) + +setclockgmt: setclockgmt.o localtime.o asctime.o amiga_tz.o + ${CC} ${CFLAGS} -o SetClockGMT setclockgmt.o localtime.o asctime.o amiga_tz.o $(LDFLAGS) $(LDLIBS) clean: - rm -f amiga_tz.o asctime.o date.o difftime.o localtime.o strftime.o zdump.o zic.o strtoll.o date_amiga.o timezone.o timezoneinfo.o version.h zic zdump date datepatch timezone timezoneinfo libtz.a + rm -f amiga_tz.o asctime.o date.o difftime.o localtime.o strftime.o zdump.o zic.o strtoll.o date_amiga.o timezone.o timezoneinfo.o setclockgmt.o version.h libtz.a zic zdump DateTZ TimeZone TimeZoneInfo SetClockGMT depend: @echo Dependencies already done diff --git a/amiga_tz.c b/amiga_tz.c index ea2bd33..d1f41b7 100644 --- a/amiga_tz.c +++ b/amiga_tz.c @@ -161,6 +161,8 @@ int create_timer() // // The return value is also stored in * tloc , provided that tloc is non-null. // +// NOTICE: This function does not comply with above specifications yet. +// tz_time_t time(tz_time_t *tloc) { struct LocaleBase* localeBase; @@ -186,6 +188,14 @@ tz_time_t time(tz_time_t *tloc) GetSysTime(&tv); + // TODO: Check TZPatch envvar + // If set time is gmt -> Do not use locale to modify + // If not set, time is local -> use locale to modify + + // TODO: Check TZ envvar is valid + // If set time is locale -> use TZ gmtoffset to get gmt. + // if not set, ignore value + if (tloc) { *tloc = (time_t)tv.tv_secs - locale->loc_GMTOffset * 60; // Check for TZ GMT offset } @@ -237,6 +247,14 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz) return error; } + // TODO: Check TZPatch envvar + // If set time is gmt -> Do not use locale to modify + // If not set, time is local -> use locale to modify + + // TODO: Check TZ envvar is valid + // If set time is locale -> use TZ gmtoffset to get gmt. + // if not set, ignore value + request->tr_node.io_Command = TR_SETSYSTIME; request->tr_time.tv_secs = (long)tv->tv_secs - AMIGAOFFSET + locale->loc_GMTOffset * 60; request->tr_time.tv_micro = tv->tv_micro; @@ -250,6 +268,20 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz) return error; } /**********************************************************************/ +int gettime(struct timeval *tv) +{ + int error = create_timer(); + if (error != 0) { + return error; + } + + GetSysTime(tv); + + error = delete_timer(); + + return error; +} + int settime(struct timeval *tv) { int error = create_timer(); diff --git a/amiga_tz.h b/amiga_tz.h index d66343b..b797b82 100644 --- a/amiga_tz.h +++ b/amiga_tz.h @@ -27,6 +27,7 @@ #ifndef _AMIGA_TZ_H #define _AMIGA_TZ_H +// --------------------------------------------------------------------------- // #include #include #include @@ -47,13 +48,22 @@ #include #include #include - // --------------------------------------------------------------------------- // - +#if defined(AOS3) || defined(AOS4) +# define ARGPTR STRPTR +# define ARGS_FORMAT ARGSFORMAT +#endif +#if defined(AROS) || defined(MORPHOS) +# define ARGPTR CONST_STRPTR +# define ARGS_FORMAT (CONST_STRPTR)ARGSFORMAT +#endif +#ifndef ARGPTR +# error Platform must be defined +#endif +// --------------------------------------------------------------------------- // #define OPEN_ERROR "Cannot open %s.\n" #define OPEN_VER_ERROR "Cannot open %s v%s.\n" #define REQ_ERROR "Requires Kickstart 2.04 (37.175) or later.\n" - #define INTUILIB_NAME "intuition.library" #define INTUILIB_REV 37L #define GADTOOLLIB_NAME "gadtools.library" @@ -67,41 +77,38 @@ #define TIMER_NAME TIMERNAME #define BATTCLOCK_NAME BATTCLOCKNAME #define PUBSCREEN_NAME "PubScreen" - // --------------------------------------------------------------------------- // - #ifndef ULONG #define ULONG long unsigned int #endif - #ifndef LLONG_MAX #define LLONG_MAX ((long long)(~0ULL>>1)) #endif - #ifndef LLONG_MIN #define LLONG_MIN (-LLONG_MAX - 1) #endif - +// --------------------------------------------------------------------------- // // 2922 is the number of days between 1.1.1970 and 1.1.1978 (2 leap years and 6 normal) #ifndef AMIGAOFFSET #define AMIGAOFFSET 2922 * 24 * 60 * 60 #endif - #define ENVSIZE 100 - +// --------------------------------------------------------------------------- // int get_gmtoffset(); +int gettime(struct timeval *tv); +int settime(struct timeval *tv); void underscore_add(char *string); void underscore_remove(char *string); - +// --------------------------------------------------------------------------- // long long int strtoll(const char *nptr, char **endptr, int base); - int isalnum(int c); int isalpha(int c); int isdigit(int c); int ispunct(int c); int isspace(int c); int isupper(int c); - +// --------------------------------------------------------------------------- // void syslog(int, const char *, ...); +// --------------------------------------------------------------------------- // #endif diff --git a/date_patch.c b/setclockgmt.c similarity index 62% rename from date_patch.c rename to setclockgmt.c index 6100743..4f1d3f1 100644 --- a/date_patch.c +++ b/setclockgmt.c @@ -27,12 +27,56 @@ #include "private.h" #include "amiga_tz.h" #include "version.h" -const char *vers = "\0$VER: datepatch" AMIGA_VERSION; +const char *vers = "\0$VER: SetClockGMT" AMIGA_VERSION; + +#define ARGSFORMAT "LOAD/S,SAVE/S,RESET/S" + +struct progargs { + long load; + long save; + long reset; +}; + +int amiga_open_libs(); +void amiga_close_libs(); -struct Library *BattClockBase; struct Library *DOSBase = NULL; struct Library *UtilityBase = NULL; -struct Library *LocaleBase = NULL; +struct Library *BattClockBase; + +int main(int argc, char **argv) +{ + int result; + struct RDArgs *rdargs; + struct timeval tv = { 0, 0 }; + struct progargs args = { FALSE, FALSE, FALSE }; + + if((result = amiga_open_libs()) != 0) { + exit(result); + } + + rdargs = ReadArgs(ARGS_FORMAT, (APTR)&args, NULL); + + if (!rdargs) + { + printf("%s %s\n", argv[0], ARGSFORMAT); + } else if (args.load) { + tv.tv_sec = ReadBattClock() + get_gmtoffset(); + settime(&tv); + } else if (args.save) { + gettime(&tv); + WriteBattClock(tv.tv_sec - get_gmtoffset()); + } else if (args.reset) { + ResetBattClock(); + } else { + printf("%s %s\n", argv[0], ARGSFORMAT); + } + + FreeArgs(rdargs); + amiga_close_libs(); + + return 0; +} void amiga_open_lib_error(char *name, int version) { @@ -42,26 +86,23 @@ void amiga_open_lib_error(char *name, int version) int amiga_open_libs() { + atexit(amiga_close_libs); + if(!(DOSBase = OpenLibrary(DOSLIB_NAME, DOSLIB_REV))) { amiga_open_lib_error(DOSLIB_NAME, DOSLIB_REV); - return 1; - } - - if(!(LocaleBase = OpenLibrary(LOCALELIB_NAME, LOCALELIB_REV))) { - amiga_open_lib_error(LOCALELIB_NAME, LOCALELIB_REV); - return 1; + return 5; } if(!(UtilityBase = OpenLibrary(UTILLIB_NAME, UTILLIB_REV))) { amiga_open_lib_error(UTILLIB_NAME, UTILLIB_REV); - return 1; + return 5; } BattClockBase = OpenResource(BATTCLOCK_NAME); if (!(BattClockBase = OpenResource(BATTCLOCK_NAME))) { printf(OPEN_ERROR, BATTCLOCK_NAME); - return 1; + return 5; } return 0; @@ -69,11 +110,6 @@ int amiga_open_libs() void amiga_close_libs() { - if (LocaleBase != NULL) { - CloseLibrary(LocaleBase); - LocaleBase = NULL; - } - if (UtilityBase != NULL) { CloseLibrary(UtilityBase); UtilityBase = NULL; @@ -85,49 +121,3 @@ void amiga_close_libs() } } -void PatchedWriteBattClock(unsigned long time) -{ - WriteBattClock(time - get_gmtoffset()); -} - -ULONG PatchedReadBattClock(void) -{ - return ReadBattClock() + get_gmtoffset(); -} - -struct Locale *PatchedOpenLocale(STRPTR name) -{ - struct Locale *locale = OpenLocale(name); - - if (name == NULL) { - locale->loc_GMTOffset = get_gmtoffset() / 60; - } - - return locale; -} - -void amiga_patch_libs() -{ - Forbid(); - SetFunction(BattClockBase,(long)&ReadBattClock,(unsigned long (*)())PatchedReadBattClock); - SetFunction(BattClockBase,(long)&WriteBattClock,(unsigned long (*)())PatchedWriteBattClock); - SetFunction(LocaleBase,(long)&OpenLocale,(unsigned long (*)())PatchedOpenLocale); - Permit(); - - ((struct CommandLineInterface *)BADDR(((struct Process *)FindTask(NULL))->pr_CLI))->cli_Module=NULL; -} - -int -main(const int argc, char *argv[]) -{ - struct timeval tv; - - amiga_open_libs(); - amiga_patch_libs(); - - tv.tv_sec = (long)PatchedReadBattClock(); - tv.tv_usec = 0; - settime(&tv); - - amiga_close_libs(); -} diff --git a/timezone.c b/timezone.c index 68e160f..528bd4d 100644 --- a/timezone.c +++ b/timezone.c @@ -41,7 +41,7 @@ #include "zone.h" #include "amiga_tz.h" #include "version.h" -const char *vers = "\0$VER: timezone" AMIGA_VERSION; +const char *vers = "\0$VER: TimeZone" AMIGA_VERSION; // --------------------------------------------------------------------------- // #define GID_LIST 1001 #define GID_STRING 1002 @@ -244,18 +244,6 @@ void amiga_setup_gui() lastgad = CreateGadget(TEXT_KIND, lastgad, &ng, TAG_END); tzgad = lastgad; - /* - ng.ng_LeftEdge += ng.ng_Width + 4; - ng.ng_GadgetText = "Remove"; - ng.ng_GadgetID = GID_REMOVE; - gad = CreateGadget (BUTTON_KIND,gad,&ng,TAG_END); - - ng.ng_LeftEdge += ng.ng_Width + 4; - ng.ng_GadgetText = "Sort"; - ng.ng_GadgetID = GID_SORT; - gad = CreateGadget (BUTTON_KIND,gad,&ng,TAG_END); - */ - ng.ng_TopEdge += (ng.ng_Height + 4) * 1.5; ng.ng_LeftEdge = screen->WBorLeft + 4; ng.ng_GadgetText = "Save"; @@ -287,8 +275,8 @@ void load_tz() tz = AllocVec(ENVSIZE, MEMF_ANY | MEMF_CLEAR); GetVar("TZ", tz, ENVSIZE - 1, GVF_GLOBAL_ONLY); - - underscore_remove(tz); + + underscore_remove(tz); gmtoffset = get_gmtoffset(); } @@ -305,11 +293,11 @@ void set_tz(char *newtz) void use_tz() { - int offset; - + int offset; + if (tz != NULL) { underscore_add(tz); - SetVar("TZ", tz, strlen(tz), GVF_GLOBAL_ONLY); + SetVar("TZ", tz, strlen(tz) + 1, GVF_GLOBAL_ONLY); } } @@ -492,5 +480,3 @@ int main (void) return 0; } - - diff --git a/timezoneinfo.c b/timezoneinfo.c index 6c22680..a4e88eb 100644 --- a/timezoneinfo.c +++ b/timezoneinfo.c @@ -28,7 +28,7 @@ #include "private.h" #include "amiga_tz.h" #include "version.h" -const char *vers = "\0$VER: timezone" AMIGA_VERSION; +const char *vers = "\0$VER: TimeZoneInfo" AMIGA_VERSION; int main(const int argc, char *argv[]) {