113 lines
2.4 KiB
C
113 lines
2.4 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include "tzversion.h"
|
|
#include "clib/timezone.h"
|
|
#include "inline/timezone.h"
|
|
|
|
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 *DOSBase = NULL;
|
|
struct Library *UtilityBase = NULL;
|
|
struct Library *TimezoneBase = NULL;
|
|
struct Library *BattClockBase;
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
int result;
|
|
struct RDArgs *rdargs;
|
|
struct timeval tv;
|
|
struct progargs args = { FALSE, FALSE, FALSE };
|
|
|
|
if((result = amiga_open_libs()) != 0) {
|
|
exit(result);
|
|
}
|
|
|
|
rdargs = ReadArgs((STRPTR)ARGSFORMAT, (APTR)&args, NULL);
|
|
|
|
if (!rdargs)
|
|
{
|
|
PrintFault(IoErr(), (STRPTR)argv[0]);
|
|
} else if (args.load) {
|
|
tv.tv_secs = ReadBattClock();
|
|
setsystime(&tv);
|
|
tv.tv_secs = ReadBattClock() + gmtoffset(tv.tv_secs);
|
|
setsystime(&tv);
|
|
} else if (args.save) {
|
|
getsystime(&tv);
|
|
WriteBattClock(tv.tv_secs - gmtoffset(tv.tv_secs));
|
|
} else if (args.reset) {
|
|
ResetBattClock();
|
|
} else {
|
|
printf("%s %s\n", argv[0], ARGSFORMAT);
|
|
}
|
|
|
|
if(rdargs) {
|
|
FreeArgs(rdargs);
|
|
}
|
|
|
|
amiga_close_libs();
|
|
|
|
return 0;
|
|
}
|
|
|
|
void amiga_open_lib_error(char *name, int version)
|
|
{
|
|
FPrintf(Output(), (STRPTR)OPEN_VER_ERROR, name, version);
|
|
}
|
|
|
|
int amiga_open_libs()
|
|
{
|
|
atexit(amiga_close_libs);
|
|
|
|
if(!(DOSBase = OpenLibrary((STRPTR)DOSLIB_NAME, DOSLIB_REV))) {
|
|
amiga_open_lib_error(DOSLIB_NAME, DOSLIB_REV);
|
|
return 5;
|
|
}
|
|
|
|
if(!(UtilityBase = OpenLibrary((STRPTR)UTILLIB_NAME, UTILLIB_REV))) {
|
|
amiga_open_lib_error(UTILLIB_NAME, UTILLIB_REV);
|
|
return 5;
|
|
}
|
|
|
|
if (!(BattClockBase = OpenResource((STRPTR)BATTCLOCK_NAME))) {
|
|
FPrintf(Output(), (STRPTR)OPEN_ERROR, BATTCLOCK_NAME);
|
|
return 5;
|
|
}
|
|
|
|
if(!(TimezoneBase = OpenLibrary((CONST_STRPTR)TIMEZONELIB_NAME, TIMEZONELIB_REV))) {
|
|
amiga_open_lib_error(TIMEZONELIB_NAME, TIMEZONELIB_REV);
|
|
return 5;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
void amiga_close_libs()
|
|
{
|
|
if (TimezoneBase != NULL) {
|
|
CloseLibrary(TimezoneBase);
|
|
TimezoneBase = NULL;
|
|
}
|
|
|
|
if (UtilityBase != NULL) {
|
|
CloseLibrary(UtilityBase);
|
|
UtilityBase = NULL;
|
|
}
|
|
|
|
if (DOSBase != NULL) {
|
|
CloseLibrary(DOSBase);
|
|
DOSBase = NULL;
|
|
}
|
|
}
|